public EventManager(DemoClient client) { _client = client; _client.EventTriggered += _client_EventTriggered; _client.Connected += _client_Connected; _client.Disconnected += _client_Disconnected; }
static void Main(string[] args) { //DemoClient.Init(new RabbitMissionConfig("amqp://127.0.0.1", "http://localhost:9008/", serializerType: SerializerType.MessagePack), new Logger()); DemoClient.Init("rabbit", new Logger()); //ThreadPool.SetMaxThreads(24, 100); var j = 0; while (j < 10000) { j++; var list = new List <Task>(); var watch = new Stopwatch(); watch.Start(); for (var i = 0; i < 1000; i++) { var request = new DemoRequest { OrderNo = i.ToString(), }; //ThreadPool.QueueUserWorkItem(DoWork,request); list.Add(Task.Factory.StartNew(async() => await DemoClient.Instace.DemoInvoke(request))); //list.Add(DemoClient.Instace.DemoInvoke(request)); } Task.WaitAll(list.ToArray()); watch.Stop(); Console.WriteLine($"第{j}次,1000条请求耗时:{watch.ElapsedMilliseconds}ms"); Task.Delay(200).Wait(); } Console.WriteLine("一万次请求完成,按回车退出!"); Console.ReadLine(); DemoClient.Stop(); }
static void Main(string[] args) { ServicePointManager.DefaultConnectionLimit = 100; //DemoClient.Init(new RabbitMissionConfig("amqp://127.0.0.1", "http://localhost:9008/", serializerType: SerializerType.MessagePack), new Logger()); DemoClient.Init("rabbit", new Logger()); var j = 0; while (j < 10000) { j++; var list = new List <Task>(); var watch = new Stopwatch(); watch.Start(); for (var i = 0; i < 10000; i++) { var request = new DemoRequest { OrderNo = i.ToString(), }; list.Add(Task.Run(async() => await DemoClient.Instace.DemoInvoke(request))); } Task.WaitAll(list.ToArray()); watch.Stop(); Console.WriteLine($"第{j}次,1000条请求耗时:{watch.ElapsedMilliseconds}ms"); Task.Delay(200).Wait(); } Console.WriteLine("一万次请求完成,按回车退出!"); Console.ReadLine(); DemoClient.Stop(); }
public IExecutor(IHttpClientFactory clientFactory, string clientName) { var httpClient = clientFactory.CreateClient(clientName); client = httpClient; _client = new DemoClient(httpClient.BaseAddress.ToString(), httpClient); }
private void BtnClicked(object sender, RoutedEventArgs e) { var proxy = new DemoClient(); proxy.DoSomething(); proxy.Close(); }
public AlarmSynchronizer(DemoClient client, IACAlarmRepository alarmRepository) { _client = client; _alarmRepository = alarmRepository; _client.AlarmCleared += _client_AlarmCleared; _alarmRepository.AlarmChanged += _alarmRepository_AlarmChanged; }
public StateManager(DemoClient client) { _client = client; _client.StateChanged += _client_StateChanged; _client.Connected += _client_Connected; _client.Disconnected += _client_Disconnected; SetServerState(StateTypes.ServerDisconnected, false); }
public void Test_demo() { // Test iwth real subject DemoClient client = new DemoClient(); RealSubject realSubject = new RealSubject(); client.ClientCode(realSubject); // Test with proxy DemoProxy proxy = new DemoProxy(realSubject); client.ClientCode(proxy); }
public ConfigurationManager(SystemProperties systemProperties, DemoClient client, ACConfiguration configuration) { _systemProperties = systemProperties; _client = client; _client.UserRightsChanged += _client_UserRightsChanged; // Implemented in PersonalizedConfigurationManger.cs if (configuration == null) { // Configuration will be null when initially creating a system. Make up a new server id. _client.ServerId = Guid.NewGuid().ToString(); } else { ApplyConfiguration(configuration); } }
public override void Init(ACConfiguration configuration) { ACUtil.Log(false, "DemoACPlugin.DemoAccessControlSystem", "Initializing access control system."); _systemProperties = new SystemProperties(); _client = new DemoClient(_systemProperties); _commandManager = new CommandManager(_systemProperties, _client); _configurationManager = new ConfigurationManager(_systemProperties, _client, configuration); _connectionManager = new ConnectionManager(_client); _credentialHolderManager = new CredentialHolderManager(_systemProperties, _client); _eventManager = new EventManager(_client); _stateManager = new StateManager(_client); // Pass the ACAlarmRepository to a separate class for handling two-way alarm synchronization, if needed _alarmSynchronizer = new AlarmSynchronizer(_client, ACAlarmRepository); }
static void Main(string[] args) { var appDesc = new ApplicationDescription( "urn:qs:DemoClient", "uri:qs:DemoClient", new LocalizedText("UA SDK client"), ApplicationType.Client, null, null, null); ApplicationDescription[] appDescs = null; EndpointDescription[] endpointDescs = null; //var client = new DemoClient("192.168.1.7", 7718, 10); var client = new DemoClient("127.0.0.1", 7718, 1000); client.Connect(); client.OpenSecureChannel(MessageSecurityMode.None, SecurityPolicy.None, null); client.FindServers(out appDescs, new[] { "en" }); client.GetEndpoints(out endpointDescs, new[] { "en" }); client.Disconnect(); // Check matching message security mode and security policy too // Lazy way to find server certificate is just grab any endpoint with one byte[] serverCert = endpointDescs .First(e => e.ServerCertificate != null && e.ServerCertificate.Length > 0) .ServerCertificate; var usernamePolicyDesc = endpointDescs .First(e => e.UserIdentityTokens.Any(t => t.TokenType == UserTokenType.UserName)) .UserIdentityTokens.First(t => t.TokenType == UserTokenType.UserName) .PolicyId; var connectRes = client.Connect(); var openRes = client.OpenSecureChannel(MessageSecurityMode.SignAndEncrypt, SecurityPolicy.Basic256Sha256, serverCert); //var openRes = client.OpenSecureChannel(MessageSecurityMode.None, SecurityPolicy.None, null); var createRes = client.CreateSession(appDesc, "urn:qs:DemoClient", 120); var activateRes = client.ActivateSession(new UserIdentityAnonymousToken("0"), new[] { "en" }); //var activateRes = client.ActivateSession( // new UserIdentityUsernameToken(usernamePolicyDesc, "Username", // (new UTF8Encoding()).GetBytes("Password"), Types.SignatureAlgorithmRsa15), // new[] { "en" }); DataValue[] dvs = null; var readRes = client.Read(new ReadValueId[] { new ReadValueId(new NodeId(2, 1), NodeAttribute.Value, null, new QualifiedName(0, null)), new ReadValueId(new NodeId(2, 2), NodeAttribute.Value, null, new QualifiedName(0, null)), new ReadValueId(new NodeId(2, 3), NodeAttribute.Value, null, new QualifiedName(0, null)), }, out dvs); BrowseResult[] browseResults; //client.Browse(new BrowseDescription[] //{ // new BrowseDescription( // new NodeId(2, 0), // BrowseDirection.Both, // NodeId.Zero, // true, 0xFFFFFFFFu, BrowseResultMask.All) //}, 20, out browseResults); //while (browseResults[0].ContinuationPoint != null) //{ // client.BrowseNext(new[] { browseResults[0].ContinuationPoint }, false, out browseResults); //} client.Browse(new BrowseDescription[] { new BrowseDescription( new NodeId(2, 0), BrowseDirection.Both, NodeId.Zero, true, 0xFFFFFFFFu, BrowseResultMask.All) }, 10000, out browseResults); uint[] respStatuses; client.Write(new WriteValue[] { new WriteValue( new NodeId(2, 0), NodeAttribute.Value, null, new DataValue(3.14159265, StatusCode.GoodClamped, DateTime.Now)) }, out respStatuses); HistoryReadResult[] histResults = null; client.HistoryRead(new ReadRawModifiedDetails(false, new DateTime(2015, 12, 1), new DateTime(2015, 12, 2), 100, true), TimestampsToReturn.Both, false, new HistoryReadValueId[] { new HistoryReadValueId(new NodeId(2, 1), null, new QualifiedName(), null), new HistoryReadValueId(new NodeId(2, 2), null, new QualifiedName(), null), new HistoryReadValueId(new NodeId(2, 3), null, new QualifiedName(), null), }, out histResults); client.HistoryUpdate(new HistoryUpdateData[] { new HistoryUpdateData(new NodeId(2, 1), PerformUpdateType.Replace, new DataValue[] { new DataValue(3.14159265, StatusCode.Good, DateTime.Now), }) }, out respStatuses); var eventFilterOperands = new SimpleAttributeOperand[] { new SimpleAttributeOperand( new[] { new QualifiedName("EventId") } ), new SimpleAttributeOperand( new[] { new QualifiedName("EventType") } ), new SimpleAttributeOperand( new[] { new QualifiedName("SourceName") } ), new SimpleAttributeOperand( new[] { new QualifiedName("Time") } ), new SimpleAttributeOperand( new[] { new QualifiedName("Message") } ), new SimpleAttributeOperand( new[] { new QualifiedName("Severity") } ), new SimpleAttributeOperand( new[] { new QualifiedName("ActiveState") } ), new SimpleAttributeOperand( new[] { new QualifiedName("AckedState") } ), new SimpleAttributeOperand( new[] { new QualifiedName("ConditionName") } ), new SimpleAttributeOperand( new[] { new QualifiedName("ConditionType") } ), }; client.HistoryRead(new ReadEventDetails( new DateTime(2015, 12, 1), new DateTime(2015, 12, 2), 100, eventFilterOperands), TimestampsToReturn.Both, false, new HistoryReadValueId[] { new HistoryReadValueId(new NodeId(0, 2253), null, new QualifiedName(), null), }, out histResults); uint subscrId; client.CreateSubscription(0, 1000, true, 0, out subscrId); // Second will have response BadSubscriptionIdInvalid client.SetPublishingMode(true, new[] { subscrId, 10u }, out respStatuses); uint respStatus; client.ModifySubscription(subscrId, 0, 100, true, 0, out respStatus); uint clientHandleEventMonitor = 0; var tagsMonitorId = new uint[3]; for (int i = 0; i < 3; i++) { tagsMonitorId[i] = (uint)(1 + i); } MonitoredItemCreateResult[] monitorCreateResults; client.CreateMonitoredItems(subscrId, TimestampsToReturn.Both, new MonitoredItemCreateRequest[] { new MonitoredItemCreateRequest( new ReadValueId(new NodeId(0, 2253), NodeAttribute.EventNotifier, null, new QualifiedName()), MonitoringMode.Reporting, new MonitoringParameters(clientHandleEventMonitor, 0, new EventFilter(eventFilterOperands, null), 100, true)), new MonitoredItemCreateRequest( new ReadValueId(new NodeId(2, 1), NodeAttribute.Value, null, new QualifiedName()), MonitoringMode.Reporting, new MonitoringParameters(tagsMonitorId[0], 0, null, 100, false)), new MonitoredItemCreateRequest( new ReadValueId(new NodeId(2, 2), NodeAttribute.Value, null, new QualifiedName()), MonitoringMode.Reporting, new MonitoringParameters(tagsMonitorId[1], 0, null, 100, false)), new MonitoredItemCreateRequest( new ReadValueId(new NodeId(2, 3), NodeAttribute.Value, null, new QualifiedName()), MonitoringMode.Reporting, new MonitoringParameters(tagsMonitorId[2], 0, null, 100, false)) }, out monitorCreateResults); Console.ReadKey(); // Last two should have BadMonitoredItemIdInvalid resp status client.DeleteMonitoredItems(subscrId, new uint[] { 0, 1, 2, 3, 4, 5 }, out respStatuses); client.DeleteSubscription(new[] { subscrId }, out respStatuses); client.Dispose(); }
private void BtnClicked(object sender, RoutedEventArgs e) { this._proxy = new DemoClient(new InstanceContext(this)); this._proxy.DoSomething(); }
public CredentialHolderManager(SystemProperties systemProperties, DemoClient client) { _systemProperties = systemProperties; _client = client; _client.CredentialHolderChanged += _client_CredentialHolderChanged; }
public CommandManager(SystemProperties systemProperties, DemoClient client) { _systemProperties = systemProperties; _client = client; }
public ConnectionManager(DemoClient client) { _client = client; _client.Connected += _client_Connected; _client.Disconnected += _client_Disconnected; }