2016-06-16 4 views
0

私は異なるexeファイルの間で作ったDLLを共有したいと思います。すべてのファイルは同じマップにあります。しかし、どのように私は1つのexeからdllに私のデータに変更を加えることができますまた、別のdllの変更を参照してください?C#別のexeファイル間で異なるDLLを共有する

インターネットでは、WCFサービスを使用する必要があるようです。しかし私がしているのは地元だけなので、他の方法はないと思っていましたか?

他の方法がない場合、私はまた私のWCFサービスに問題がある、私は次のエラーを取得する:

The type Newtonsoft.Json.Linq.JToken is a recursive data collection contract. This is not supported. To work around this problem by changing the definition of the collection Newtonsoft.Json.Linq.JToken so that it contains no references to himself.

そしてbeneedは私のコードです:

//SERVER SIDE 
internal class CommunicationService 
{ 
    #region Fields 
    private ServiceHost _service_host; 
    private static CommunicationService _instance; 
    #endregion 

    #region Init 
    internal static CommunicationService Instance 
    { 
     get 
     { 
      if (_instance == null) 
      { 
       _instance = new CommunicationService(); 
      } 
      return _instance; 
     } 
    } 
    private CommunicationService() 
    { 
     string address = string.Format("http://127.0.0.1:{0}", RegSettings.Instance.Port); 
     _service_host = new ServiceHost(typeof(NGX3WCFService.Interfaces.NGX3Service), new Uri(address)); 
     BasicHttpBinding basic_http_binding = new BasicHttpBinding(); 
     Uri uri_address = new Uri(address); 
     ServiceMetadataBehavior service_metadata_behavior = _service_host.Description.Behaviors.Find<ServiceMetadataBehavior>(); 

     if (service_metadata_behavior == null) 
     { 
      service_metadata_behavior = new ServiceMetadataBehavior(); 
      _service_host.Description.Behaviors.Add(service_metadata_behavior); 
     } 

     service_metadata_behavior.HttpGetEnabled = true; 
     service_metadata_behavior.HttpGetUrl = new Uri(string.Format("{0}/ngx3wsd", address)); 
     _service_host.AddServiceEndpoint(typeof(INGX3Service), basic_http_binding, string.Format("{0}/ngx3", address)); 
    } 
    #endregion 

    #region StartStop 
    internal void Start() 
    { 
     _service_host.UnknownMessageReceived += _service_host_UnknownMessageReceived; 
     _service_host.Open(); 
    } 

    internal void Stop() 
    { 
     _service_host.Close(); 
     _service_host.UnknownMessageReceived -= _service_host_UnknownMessageReceived; 
    } 

    private void _service_host_UnknownMessageReceived(object sender, UnknownMessageReceivedEventArgs e) 
    { 
     LogFile.Instance().Append(e.Message.ToString()); 
    } 
    #endregion 
} 

//INTERFACE 
[ServiceContract] 
public interface INGX3Service 
{ 
    [OperationContract] 
    bool ValidateConnection(); 

    [OperationContract] 
    Dictionary<string, JToken> GetCustomerPrinterScanInfo(); 
    [OperationContract] 
    Dictionary<string, JToken> GetCustomerPrinterReadInfo(); 
    [OperationContract] 
    Dictionary<string, List<SNMPVariable>> GetCustomerPrinterFetchInfo(); 
    [OperationContract] 
    Dictionary<string, JToken> GetCustomerPrinterSpoolerInfo(); 
    [OperationContract] 
    void SetCustomerPrinterReadInfo(string id, JToken data); 
    [OperationContract] 
    void SetCustomerPrinterFetchInfo(string id, List<SNMPVariable> data); 
    [OperationContract] 
    void SetCustomerPrinterSpoolerInfo(string id, JToken data); 

    [OperationContract] 
    void UpdateJsonSettings(JToken data); 
    [OperationContract] 
    RegSettings GetRegSettings(); 
} 


[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Multiple)] 
public class NGX3Service : INGX3Service 
{ 
    #region Validate 
    public bool ValidateConnection() 
    { 
     return true; 
    } 
    #endregion 

    #region CustomerPrinterInfo 
    public Dictionary<string, JToken> GetCustomerPrinterScanInfo() 
    { 
     Dictionary<string, JToken> data = new Dictionary<string, JToken>(); 

     foreach (Subnet subnet in NetworkController.Instance.Subnets) 
     { 
      foreach (Host host in subnet.Hosts) 
      { 
       if (!string.IsNullOrEmpty(host.Id) && host.Id.Length == 40 && host.Protocol == NetworkEngine.Enumerations.Protocol.SNMP && host.DeviceType == NetworkEngine.Enumerations.DeviceType.Printer && !data.ContainsKey(host.Id)) 
       { 
        data[host.Id] = host.ReadScanData(); 
       } 
      } 
     } 

     return data; 
    } 

    public Dictionary<string, JToken> GetCustomerPrinterReadInfo() 
    { 
     Dictionary<string, JToken> data = new Dictionary<string, JToken>(); 

     foreach (Subnet subnet in NetworkController.Instance.Subnets) 
     { 
      foreach (Host host in subnet.Hosts) 
      { 
       if (!string.IsNullOrEmpty(host.Id) && host.Id.Length == 40 && host.Protocol == NetworkEngine.Enumerations.Protocol.SNMP && host.DeviceType == NetworkEngine.Enumerations.DeviceType.Printer && !data.ContainsKey(host.Id)) 
       { 
        data[host.Id] = host.ReadInfo(); 
       } 
      } 
     } 

     return data; 
    } 

    public Dictionary<string, List<SNMPVariable>> GetCustomerPrinterFetchInfo() 
    { 
     Dictionary<string, List<SNMPVariable>> data = new Dictionary<string, List<SNMPVariable>>(); 

     foreach (Subnet subnet in NetworkController.Instance.Subnets) 
     { 
      foreach (Host host in subnet.Hosts) 
      { 
       if (!string.IsNullOrEmpty(host.Id) && host.Id.Length == 40 && host.Protocol == NetworkEngine.Enumerations.Protocol.SNMP && host.DeviceType == NetworkEngine.Enumerations.DeviceType.Printer && !data.ContainsKey(host.Id)) 
       { 
        data[host.Id] = host.ReadFetchData(); 
       } 
      } 
     } 

     return data; 
    } 

    public Dictionary<string, JToken> GetCustomerPrinterSpoolerInfo() 
    { 
     Dictionary<string, JToken> data = new Dictionary<string, JToken>(); 

     foreach (Printer printer in PrintSpooler.Instance.Printers) 
     { 
      if (printer.Id != null && printer.Id.Length == 40) 
      { 
       JObject jobject = new JObject(); 
       jobject.Add("customer_printer_id", printer.Id); 
       jobject.Add("printer_info", JsonFile.Instance("printer_info", printer.Id).Read<JToken>()); 
       jobject.Add("job_info", printer.ReadJobs()); 

       data.Add(printer.Id, jobject); 
      } 
     } 

     return data; 
    } 

    public void SetCustomerPrinterReadInfo(string id, JToken data) 
    { 
     foreach (Subnet subnet in NetworkController.Instance.Subnets) 
     { 
      Host host = subnet.Hosts.FirstOrDefault(h => h.Id.Equals(id)); 

      if (host != null) 
      { 
       host.WriteInfo(data); 
      } 
     } 
    } 

    public void SetCustomerPrinterFetchInfo(string id, List<SNMPVariable> data) 
    { 
     foreach (Subnet subnet in NetworkController.Instance.Subnets) 
     { 
      Host host = subnet.Hosts.FirstOrDefault(h => h.Id.Equals(id)); 

      if (host != null) 
      { 
       host.WriteFetchInfo(data); 
      } 
     } 
    } 

    public void SetCustomerPrinterSpoolerInfo(string id, JToken data) 
    { 
     Printer printer = PrintSpooler.Instance.Printers.FirstOrDefault(p => p.Id.Equals(id)); 

     if (printer != null) 
     { 
      printer.WriteJobs(data["job_info"]); 
     } 
    } 
    #endregion 

    #region Settings 
    public void UpdateJsonSettings(JToken data) 
    { 
     JsonSettings.Instance.Load(data); 
    } 

    public RegSettings GetRegSettings() 
    { 
     return RegSettings.Instance; 
    } 
    #endregion 
} 
+0

これは2つの質問です。プロセス間でデータを共有するには、ミドルウェア、ロックなどで潜在的な混乱を招くなど、さまざまな方法でデータを共有することができます。それをデータベースに入れて、調整をしましょう....これは意見に基づいています。 2番目の問題はより具体的です - しかし、私はそれに答えるためにもっと詳細が必要です。 – doctorlove

答えて

1

あなたが疑われると - DLLはデータのみではなくコードを共有します。それぞれは別のプロセスで実行されます。

2つのプロセス間で共有するにはいくつかの方法があります。興味のあるオプションはShared Memory/Memory mapped filesです。

関連する問題