private void CreateProxy() { NetTcpBinding binding = new NetTcpBinding(); // Create a partition resolver IServicePartitionResolver partitionResolver = ServicePartitionResolver.GetDefault(); //create calllback // duplex channel for DMS transaction // TransactionCallback CallBackTransactionDMS2 = new TransactionCallback(); // create a WcfCommunicationClientFactory object. var wcfClientFactory = new WcfCommunicationClientFactory <IPublishing> (clientBinding: BindingForTCP.CreateCustomNetTcp(), servicePartitionResolver: partitionResolver); // // Create a client for communicating with the ICalculator service that has been created with the // Singleton partition scheme. // proxyToCloud = new PublishServiceCloud( wcfClientFactory, new Uri("fabric:/ServiceFabricOMS/PubSubStatelessService"), ServicePartitionKey.Singleton, listenerName: "PublishingService"); //string address = ""; //try //{ // address = "net.tcp://localhost:7001/Pub"; // EndpointAddress endpointAddress = new EndpointAddress(address); // NetTcpBinding netTcpBinding = new NetTcpBinding(); // proxy = ChannelFactory<IPublishing>.CreateChannel(netTcpBinding, endpointAddress); //} //catch (Exception e) //{ // throw e; // //TODO log error; //} }
private ICommunicationListener CreateWcfHiCommunicationListener(StatelessServiceContext context) { string host = context.NodeContext.IPAddressOrFQDN; // ServiceManifest fajl var endpointConfig = context.CodePackageActivationContext.GetEndpoint("NMTransactionServiceEndpoint"); int port = endpointConfig.Port; var scheme = endpointConfig.Protocol.ToString(); var pathSufix = endpointConfig.PathSuffix.ToString(); var binding = new NetTcpBinding(); //var binding = WcfUtility.CreateTcpListenerBinding(); string uri = string.Format(CultureInfo.InvariantCulture, "net.{0}://{1}:{2}/ITransaction/{3}", scheme, host, port, pathSufix); NetworkModelTransactionService networkModelTransactionService = new NetworkModelTransactionService(); var listener = new WcfCommunicationListener <ITransaction>( serviceContext: context, wcfServiceObject: networkModelTransactionService, listenerBinding: BindingForTCP.CreateCustomNetTcp(), //address: new EndpointAddress(uri) endpointResourceName: "NMTransactionServiceEndpoint" ); return(listener); }
private ICommunicationListener CreateWcfCommunicationListener(StatefulServiceContext context) { string host = context.NodeContext.IPAddressOrFQDN; // ServiceManifest fajl var endpointConfig = context.CodePackageActivationContext.GetEndpoint("TMServiceEndpoint"); int port = endpointConfig.Port; var scheme = endpointConfig.Protocol.ToString(); var pathSufix = endpointConfig.PathSuffix.ToString(); var binding = new NetTcpBinding(); //var binding = WcfUtility.CreateTcpListenerBinding(); string uri = string.Format(CultureInfo.InvariantCulture, "net.{0}://{1}:{2}/TMServiceEndpoint", scheme, host, port); var listener = new WcfCommunicationListener <IOMSClient>( serviceContext: context, wcfServiceObject: new TransactionManager(this.Context), listenerBinding: BindingForTCP.CreateCustomNetTcp(), address: new EndpointAddress(uri) // endpointResourceName: "TMServiceEndpoint" ); return(listener); }
private void CreateProxy() { try { //***git NetTcpBinding binding = new NetTcpBinding(); binding.CloseTimeout = TimeSpan.FromDays(10); binding.OpenTimeout = TimeSpan.FromDays(10); binding.ReceiveTimeout = TimeSpan.FromDays(10); binding.SendTimeout = TimeSpan.FromDays(10); binding.MaxReceivedMessageSize = Int32.MaxValue; EndpointAddress endpointAddress = new EndpointAddress("net.tcp://localhost:4080/SubscriptionService"); InstanceContext callback = new InstanceContext(this); DuplexChannelFactory <ISubscription> channelFactory = new DuplexChannelFactory <ISubscription>(callback, BindingForTCP.CreateCustomNetTcp(), endpointAddress); subscriptionProxy = channelFactory.CreateChannel(); } catch (Exception e) { throw e; //TODO Log error : PubSub not started } }
/// <summary> /// Processing answers from Simulator - Process Controller /// </summary> public void ProcessPCAnwers(TimeSpan timeout, CancellationToken token) { while (!token.IsCancellationRequested) { bool isSuccessful; IORequestBlock answer = IORequests.DequeueAnswer(out isSuccessful, timeout); if (isSuccessful) { bool isChange = false; RTU rtu; // sporno //while (!Database.IsConfigurationRunning) if ((rtu = dbContext.GetRTUByName(answer.ProcessControllerName)) != null) { switch (rtu.Protocol) { case IndustryProtocols.ModbusTCP: ModbusHandler mdbHandler = new ModbusHandler(); try { mdbHandler.UnpackData(answer.RcvBuff, answer.RcvMsgLength); switch (mdbHandler.Response.FunCode) { case FunctionCodes.ReadDiscreteInput: { BitReadResponse response = (BitReadResponse)mdbHandler.Response; var responsePVCount = answer.Flags; ushort varAddr = answer.ReqAddress; for (int i = 0; i < responsePVCount; i++, varAddr++) { ProcessVariable pv; if (rtu.GetProcessVariableByAddress(varAddr, out pv)) { Digital target = (Digital)pv; try { bool isOpened = response.BitValues[i]; if (target.State != target.ValidStates[isOpened ? 1 : 0]) { isChange = true; target.State = target.ValidStates[isOpened ? 1 : 0]; Console.WriteLine(" CHANGE! Digital variable {0}, state: {1}", target.Name, target.State); IServicePartitionResolver partitionResolverToDMS = ServicePartitionResolver.GetDefault(); var wcfClientFactoryToDMS = new WcfCommunicationClientFactory <IDMSToSCADAContract> (clientBinding: BindingForTCP.CreateCustomNetTcp(), servicePartitionResolver: partitionResolverToDMS); DmsClientSF dMSClient = new DmsClientSF( wcfClientFactoryToDMS, new Uri("fabric:/ServiceFabricOMS/DMStatelessService"), ServicePartitionKey.Singleton, listenerName: "DMSServiceForSCADA" ); dMSClient.InvokeWithRetry(c => c.Channel.ChangeOnSCADADigital(target.Name, target.State)); } } catch (Exception e) { Console.WriteLine("Digital variable {0}, state: INVALID", target.Name); } } } if (isChange) { ScadaModelParser parser = new ScadaModelParser(); parser.SerializeScadaModel(); } } break; // analog input case FunctionCodes.ReadInputRegisters: { RegisterReadResponse response = (RegisterReadResponse)mdbHandler.Response; var responsePVCount = answer.Flags; ushort varAddr = answer.ReqAddress; for (int i = 0; i < responsePVCount; i++, varAddr++) { ProcessVariable pv; if (rtu.GetProcessVariableByAddress(varAddr, out pv)) { Analog target = (Analog)pv; try { ushort newRawAcqValue = response.RegValues[target.RelativeAddress]; float newAcqValue; AnalogProcessor.RawValueToEGU(target, newRawAcqValue, out newAcqValue); if (target.AcqValue != newAcqValue) { isChange = true; target.RawAcqValue = newRawAcqValue; target.AcqValue = newAcqValue; Console.WriteLine(" CHANGE! Analog variable {0}, AcqValue: {1}", target.Name, target.AcqValue); //to do: propagacija analogih promena(ako se secate Pavlica je prvo rekao da nam to ne treba da samo jednom zakucamo vrednost na pocetku) xD IServicePartitionResolver partitionResolverToDMS = ServicePartitionResolver.GetDefault(); var wcfClientFactoryToDMS = new WcfCommunicationClientFactory <IDMSToSCADAContract> (clientBinding: BindingForTCP.CreateCustomNetTcp(), servicePartitionResolver: partitionResolverToDMS); DmsClientSF dMSClient = new DmsClientSF( wcfClientFactoryToDMS, new Uri("fabric:/ServiceFabricOMS/DMStatelessService"), ServicePartitionKey.Singleton, listenerName: "DMSServiceForSCADA" ); dMSClient.InvokeWithRetry(c => c.Channel.ChangeOnSCADAAnalog(target.Name, target.AcqValue)); } } catch { // Console.WriteLine("Digital variable {0}, state: INVALID", target.Name); } } } if (isChange) { ScadaModelParser parser = new ScadaModelParser(); parser.SerializeScadaModel(); } } break; } } catch (Exception e) { Console.WriteLine(e.Message); } break; } } } } Console.WriteLine("ProcessPCAnswers.shutdown=true"); return; }