public VolumeControl() { InitializeComponent(); _setVolumeTimer = new Timer(new TimerCallback(SetVolumeCallback)); _disc = ((wpf.App)Application.Current).Discover; }
static void Main(string[] args) { Thread.CurrentThread.SetApartmentState(ApartmentState.MTA); Discover disc = new Discover(); disc.PropertyChanged += new PropertyChangedEventHandler(OnZonePlayerChanged); Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadStart(ThreadFunc)); Dispatcher.Run(); }
public ZoneGroup(Discover disc, XPathNavigator node) { _coordinator = node.SelectSingleNode("@Coordinator").Value; _id = node.SelectSingleNode("@ID").Value; foreach (XPathNavigator nav in node.Select("ZoneGroupMember")) { ZonePlayer zp = disc.Intern(String.Concat("uuid:", nav.SelectSingleNode("@UUID").Value)); _members.Add(zp); } _coordinatorZone = disc.Intern(String.Concat("uuid:", _coordinator)); _members.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(_members_CollectionChanged); }
/// <summary> /// Discovers tests in the application and maps routes to allow them to be called over HTTP. /// </summary> /// <param name="configuration">The configuration.</param> /// <param name="configureTargets">A delegate to configure the test targets.</param> /// <param name="baseUri">The base URI segment that the tests will be routed under.</param> /// <param name="testTypes">The Types to map routes for. If omitted, all discovered implementations of <see cref="IMonitoringTest" /> will be routed.</param> /// <param name="handler">A message handler to handle test requests, if you would like to provide authentication, logging, or other functionality during calls to monitoring tests.</param> /// <param name="testUiScriptUrl">The location of the test UI script.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">configuration</exception> public static HttpConfiguration MapTestRoutes( this HttpConfiguration configuration, Action <TestTargetRegistry> configureTargets = null, string baseUri = "tests", IEnumerable <Type> testTypes = null, HttpMessageHandler handler = null, string testUiScriptUrl = null) { if (configuration == null) { throw new ArgumentNullException("configuration"); } if (!Trace.Listeners.OfType <TracingFilter.TraceListener>().Any()) { var traceListener = new TracingFilter.TraceListener(); Trace.Listeners.Add(traceListener); Instrumentation.Log.EntryPosted += (_, args) => traceListener.WriteLine(args.LogEntry.ToLogString()); } // set up specialized handling on the specified routes configuration.Filters.Add(new TestErrorFilter(baseUri)); if (!string.IsNullOrEmpty(testUiScriptUrl) && Uri.IsWellFormedUriString(testUiScriptUrl, UriKind.RelativeOrAbsolute)) { configuration.TestUiUriIs(testUiScriptUrl); } var testRootRouteTemplate = baseUri.AppendSegment("{environment}/{application}"); configuration.RootTestUriIs(baseUri); // set up test discovery routes configuration.Routes.MapHttpRoute( TestRootRouteName, testRootRouteTemplate, defaults: new { controller = "MonitoringTest", action = "tests", application = RouteParameter.Optional, environment = RouteParameter.Optional }, constraints: null, handler: handler); // set up test execution routes var targetRegistry = new TestTargetRegistry(configuration); configuration.TestTargetsAre(targetRegistry); if (configureTargets != null) { configureTargets(targetRegistry); } testTypes = testTypes ?? Discover.ConcreteTypes() .DerivedFrom(typeof(IMonitoringTest)); var testDefinitions = testTypes.GetTestDefinitions(); configuration.TestDefinitionsAre(testDefinitions); foreach (var test in testDefinitions.Select(p => p.Value)) { configuration.Routes.MapHttpRoute( test.RouteName, testRootRouteTemplate.AppendSegment(test.TestName), defaults: new { controller = "MonitoringTest", action = "run", testName = test.TestName }, constraints: new { tag = new TagConstraint(test), application = new ApplicationConstraint(test), environment = new EnvironmentConstraint(test), target = new TargetConstraint(test) }, handler: handler ); } return(configuration); }
public DiscoverTest() { _discover = new Discover(); }
/// <summary> /// Discovers schemas based on a query /// </summary> /// <param name="request"></param> /// <param name="context"></param> /// <returns>Discovered schemas</returns> public override async Task <DiscoverSchemasResponse> DiscoverSchemas(DiscoverSchemasRequest request, ServerCallContext context) { Logger.SetLogPrefix("discover"); Logger.Info("Discovering Schemas..."); var sampleSize = checked ((int)request.SampleSize); DiscoverSchemasResponse discoverSchemasResponse = new DiscoverSchemasResponse(); // only return requested schemas if refresh mode selected if (request.Mode == DiscoverSchemasRequest.Types.Mode.All) { // get all schemas try { await DiscoverSemaphoreSlim.WaitAsync(); var files = _server.Settings.GetAllFilesByRootPath(); Logger.Info($"Files attempted: {files.Count}"); var schemas = _server.Settings.RootPaths.Select(p => Discover.GetSchemasForDirectory(context, Utility.GetImportExportFactory(p.Mode), p, files[p.RootPathName()], sampleSize)).Select(l => l.Where(s => s != null)) .ToList(); discoverSchemasResponse.Schemas.AddRange(schemas.SelectMany(s => s)); Logger.Info($"Schemas returned: {discoverSchemasResponse.Schemas.Count}"); return(discoverSchemasResponse); } catch (Exception e) { Logger.Error(e, e.Message, context); return(new DiscoverSchemasResponse()); } finally { DiscoverSemaphoreSlim.Release(); } } try { await DiscoverSemaphoreSlim.WaitAsync(); var refreshSchemas = request.ToRefresh; Logger.Info($"Refresh schemas attempted: {refreshSchemas.Count}"); var files = _server.Settings.GetAllFilesByRootPath(); var conn = Utility.GetSqlConnection(Constants.DiscoverDbPrefix); if (sampleSize == 0) { sampleSize = 5; } foreach (var rootPath in _server.Settings.RootPaths) { var schemaName = Constants.SchemaName; var tableName = string.IsNullOrWhiteSpace(rootPath.Name) ? new DirectoryInfo(rootPath.RootPath).Name : rootPath.Name; Utility.LoadDirectoryFilesIntoDb( Utility.GetImportExportFactory(rootPath.Mode), conn, rootPath, tableName, schemaName, files[rootPath.RootPathName()], false, sampleSize, 1); } var schemas = refreshSchemas.Select(s => Discover.GetSchemaForQuery(context, s, sampleSize)) .ToArray(); discoverSchemasResponse.Schemas.AddRange(schemas.Where(x => x != null)); // return all schemas Logger.Info($"Schemas returned: {discoverSchemasResponse.Schemas.Count}"); return(discoverSchemasResponse); } catch (Exception e) { Logger.Error(e, e.Message, context); return(new DiscoverSchemasResponse()); } finally { DiscoverSemaphoreSlim.Release(); } }
/// <summary> /// Gets a schema for a given query /// </summary> /// <param name="schema"></param> /// <returns>A schema or null</returns> private async Task <Schema> GetSchemaProperties(Schema schema) { try { if (schema.Properties.Count > 0) { return(schema); } //check if query is empty or invalid json if (string.IsNullOrWhiteSpace(schema.Query) || !IsValidJson(schema.Query)) { Logger.Error(null, "Invalid schema query"); return(null); } // add "_id", "_rev" as required field Logger.Info("getting couchdb response for schema discovery"); var schemaQueryJson = JObject.Parse(schema.Query); var getSchemaUri = $"{_server.Settings.DatabaseName}/_find"; var response = await _client.PostAsync(getSchemaUri, new StringContent(Discover.GetValidSchemaQuery(schemaQueryJson), Encoding.UTF8, "application/json")); //Logger.Info($"discover schema response: {await response.Content.ReadAsStringAsync()}"); response.EnsureSuccessStatusCode(); var documents = JObject.Parse(await response.Content.ReadAsStringAsync())["docs"]; // get each field and create a property for the field Logger.Info($"Getting property type for all {documents.ToList().Count} documents"); if (documents.ToList().Count > 0) { var discoveredPropertyTypes = Discover.GetPropertyTypes(documents, 100); foreach (KeyValuePair <string, Dictionary <PropertyType, int> > entry in discoveredPropertyTypes) { var propertyTypeofMaxValue = entry.Value.Aggregate((x, y) => x.Value > y.Value ? x : y).Key; // create property var property = new Property { Id = entry.Key, Name = entry.Key, Description = "", Type = propertyTypeofMaxValue, IsKey = false, IsCreateCounter = false, IsUpdateCounter = false, PublisherMetaJson = "" }; schema.Properties.Add(property); } } else { schema = null; } return(schema); } catch (Exception e) { Logger.Error(e, e.Message); return(null); } }
protected virtual IEnumerable <Type> GetEntityModelConfigurationTypes() { return(Discover.ConcreteTypesDerivedFrom(typeof(IEntityModelConfiguration))); }
private async Task <Session> ConsoleSampleClient() { var application = new ApplicationInstance { ApplicationType = ApplicationType.Client }; #region Create an Application Configuration Console.WriteLine(" 1 - Create an Application Configuration."); ExitCode = ExitCode.ErrorCreateApplication; // Load the Application Configuration and use the specified config section "Technosoftware.SimpleClient" var config = await application.LoadConfigurationAsync("Technosoftware.SimpleClient"); // check the application certificate. var haveAppCertificate = await application.CheckApplicationInstanceCertificateAsync(false, CertificateFactory.DefaultKeySize, CertificateFactory.DefaultLifeTime); reverseConnectManager_ = null; if (ReverseConnectUri != null) { // start the reverse connection manager reverseConnectManager_ = new ReverseConnectManager(); reverseConnectManager_.AddEndpoint(ReverseConnectUri); reverseConnectManager_.StartService(config); } if (haveAppCertificate) { config.ApplicationUri = X509Utils.GetApplicationUriFromCertificate(config.SecurityConfiguration.ApplicationCertificate.Certificate); if (config.SecurityConfiguration.AutoAcceptUntrustedCertificates) { autoAccept_ = true; } config.CertificateValidator.CertificateValidation += OnCertificateValidation; } else { Console.WriteLine(" WARN: missing application certificate, using unsecured connection."); } #endregion #region Discover endpoints Console.WriteLine(" 2 - Discover endpoints of {0}.", endpointUrl_); ExitCode = ExitCode.ErrorDiscoverEndpoints; EndpointDescription selectedEndpoint; if (reverseConnectManager_ == null) { selectedEndpoint = Discover.SelectEndpoint(endpointUrl_, haveAppCertificate && !SecurityNone, 15000); } else { Console.WriteLine(" Waiting for reverse connection."); var connection = await reverseConnectManager_.WaitForConnection( new Uri(endpointUrl_), null, new CancellationTokenSource(60000).Token); if (connection == null) { throw new ServiceResultException(StatusCodes.BadTimeout, "Waiting for a reverse connection timed out."); } selectedEndpoint = Discover.SelectEndpoint(config, connection, haveAppCertificate && !SecurityNone, 15000); } Console.WriteLine(" Selected endpoint uses: {0}", selectedEndpoint.SecurityPolicyUri.Substring(selectedEndpoint.SecurityPolicyUri.LastIndexOf('#') + 1)); #endregion #region Create a session with OPC UA server Console.WriteLine(" 3 - Create a session with OPC UA server."); ExitCode = ExitCode.ErrorCreateSession; // create the user identity UserIdentity userIdentity; if (String.IsNullOrEmpty(Username) && String.IsNullOrEmpty(Password)) { userIdentity = new UserIdentity(new AnonymousIdentityToken()); } else { userIdentity = new UserIdentity(Username, Password); } // create worker session if (reverseConnectManager_ == null) { session_ = await CreateSessionAsync(config, selectedEndpoint, userIdentity).ConfigureAwait(false); } else { Console.WriteLine(" Waiting for reverse connection."); // Define the cancellation token. var source = new CancellationTokenSource(60000); var token = source.Token; try { var connection = await reverseConnectManager_.WaitForConnection( new Uri(endpointUrl_), null, token); if (connection == null) { throw new ServiceResultException(StatusCodes.BadTimeout, "Waiting for a reverse connection timed out."); } session_ = await CreateSessionAsync(config, connection, selectedEndpoint, userIdentity) .ConfigureAwait(false); } finally { source.Dispose(); } } // register keep alive handler session_.SessionKeepAliveEvent += OnSessionKeepAliveEvent; #endregion #region Browse the OPC UA Server Console.WriteLine(" 4 - Browse address space."); // Create the browser var browser = new Browser(session_) { BrowseDirection = BrowseDirection.Forward, ReferenceTypeId = ReferenceTypeIds.HierarchicalReferences, IncludeSubtypes = true, NodeClassMask = 0, ContinueUntilDone = false }; // Browse from the RootFolder var references = browser.Browse(Objects.ObjectsFolder); GetElements(session_, browser, 0, references, Verbose); #endregion #region Read a single value Console.WriteLine(" 5 - Read a single value."); var simulatedDataValue = session_.ReadValue(simulatedDataNodeId_); Console.WriteLine("Node Value:" + simulatedDataValue.Value); #endregion #region Read multiple values Console.WriteLine(" 6 - Read multiple values."); // The input parameters of the ReadValues() method var variableIds = new List <NodeId>(); var expectedTypes = new List <Type>(); // Add a node to the list variableIds.Add(simulatedDataNodeId_); // Add an expected type to the list (null means we get the original type from the server) expectedTypes.Add(null); // Add another node to the list variableIds.Add(staticDataNodeId1_); // Add an expected type to the list (null means we get the original type from the server) expectedTypes.Add(null); // Add another node to the list variableIds.Add(staticDataNodeId2_); // Add an expected type to the list (null means we get the original type from the server) expectedTypes.Add(null); session_.ReadValues(variableIds, expectedTypes, out var values, out var errors); // write the result to the console. for (var i = 0; i < values.Count; i++) { Console.WriteLine("Status of Read of Node {0} is: {1}", variableIds[i].ToString(), errors[i]); } for (var i = 0; i < values.Count; i++) { Console.WriteLine("Value of Read of Node {0} is: Value: {1}", variableIds[i].ToString(), values[i]); } #endregion #region Read multiple values asynchronous Console.WriteLine(" 7 - Read multiple values asynchronous."); // start reading the value (setting a 10 second timeout). session_.BeginReadValues( variableIds, 0, TimestampsToReturn.Both, OnReadComplete, new UserData { Session = session_, NodeIds = variableIds }); #endregion #region Write a value Console.WriteLine(" 8 - Write a value."); short writeInt = 1234; Console.WriteLine("Write Value: " + writeInt); session_.WriteValue(staticDataNodeId1_, new DataValue(writeInt)); // read it again to check the new value Console.WriteLine("Node Value (should be {0}): {1}", session_.ReadValue(staticDataNodeId1_).Value, writeInt); #endregion #region Write multiple values at once Console.WriteLine(" 9 - Write multiple values at once."); writeInt = 5678; var writeDouble = 1234.1234; var nodeIds = new List <NodeId>(); var dataValues = new List <DataValue>(); nodeIds.Add(staticDataNodeId1_); nodeIds.Add(staticDataNodeId2_); dataValues.Add(new DataValue(writeInt)); dataValues.Add(new DataValue(writeDouble)); Console.WriteLine("Write Values: {0} and {1}", writeInt, writeDouble); var statusCodes = session_.WriteValues(nodeIds, dataValues); Console.WriteLine("Returned status codes:"); foreach (var statusCode in statusCodes) { Console.WriteLine("Status: {0}", statusCode.ToString()); } // read it again to check the new value Console.WriteLine("Node Value (should be {0}): {1}", session_.ReadValue(staticDataNodeId1_).Value, writeInt); Console.WriteLine("Node Value (should be {0}): {1}", session_.ReadValue(staticDataNodeId2_).Value, writeDouble); #endregion #region Write multiple values asynchronous Console.WriteLine("10 - Write multiple values asynchronous."); // start writing the values. session_.BeginWriteValues( nodeIds, dataValues, OnWriteComplete, new UserData { Session = session_, NodeIds = nodeIds }); #endregion #region Call a Method Console.WriteLine("11 - Call a Method."); INode node = session_.ReadNode(callHelloMethodNodeId_); if (node is MethodNode) { var methodId = callHelloMethodNodeId_; var objectId = methodsNodeId_; var inputArguments = new VariantCollection { new Variant("from Technosoftware") }; var request = new CallMethodRequest { ObjectId = objectId, MethodId = methodId, InputArguments = inputArguments }; var requests = new CallMethodRequestCollection { request }; var responseHeader = session_.Call( null, requests, out var results, out var diagnosticInfos); if (StatusCode.IsBad(results[0].StatusCode)) { throw new ServiceResultException(new ServiceResult(results[0].StatusCode, 0, diagnosticInfos, responseHeader.StringTable)); } Console.WriteLine("{0}", results[0].OutputArguments[0]); } #endregion #region Create a subscription with publishing interval of 1 second Console.WriteLine("12 - Create a subscription with publishing interval of 1 second."); ExitCode = ExitCode.ErrorCreateSubscription; subscription_ = new Subscription(session_.DefaultSubscription) { PublishingInterval = 1000 }; #endregion #region Add all dynamic values and the server time to the subscription Console.WriteLine("13 - Add all dynamic values and the server time to the subscription."); ExitCode = ExitCode.ErrorMonitoredItem; var list = new List <MonitoredItem> { new MonitoredItem(subscription_.DefaultItem) { DisplayName = "ServerStatusCurrentTime", StartNodeId = "i=" + Variables.Server_ServerStatus_CurrentTime } }; list.ForEach(i => i.MonitoredItemNotificationEvent += OnNotification); var newItem = new MonitoredItem(subscription_.DefaultItem) { DisplayName = "Simulated Data Value", StartNodeId = new NodeId(simulatedDataNodeId_) }; newItem.MonitoredItemNotificationEvent += OnMonitoredItemNotificationEvent; list.Add(newItem); subscription_.AddItems(list); #endregion #region Add the subscription to the session Console.WriteLine("14 - Add the subscription to the session."); ExitCode = ExitCode.ErrorAddSubscription; session_.AddSubscription(subscription_); subscription_.Create(); #endregion #region Running...Press Ctrl-C to exit... Console.WriteLine("15 - Running...Press Ctrl-C to exit..."); ExitCode = ExitCode.ErrorRunning; #endregion return(session_); }