/// <summary> /// Plug-ins the discovery. /// </summary> /// <param name="configuration">The configuration.</param> private static void PluginDiscovery(Configuration configuration) { try { #region AggregateCatalog aggregateCatalog = ... var allTabCatalog = new TypeCatalog(typeof(DefaultPlugin)); var aggregateCatalog = new AggregateCatalog(allTabCatalog); #region Plug-in catalogs string[] commandlines = GetPluginFoldersFromCommandline(); var paths = from path in commandlines .Union(configuration.PluginDiscoveryPaths.Select(v => v.Path)) .Distinct() where !string.IsNullOrWhiteSpace(path) select path; foreach (var path in paths) { if (Directory.Exists(path)) { var catalog = new DirectoryCatalog(path); aggregateCatalog.Catalogs.Add(catalog); } else { TraceSourceMonitorHelper.Warn("Discovery path not found: {0}", path); } } #endregion // Plug-in catalogs #endregion AggregateCatalog aggregateCatalog = ... var container = new CompositionContainer(aggregateCatalog); var plugins = container.GetExportedValues <IPluginBundle>().Distinct().ToArray(); var plugActivation = configuration.PluginsActivation; if (plugActivation == null) { configuration.PluginsActivation = new ConcurrentDictionary <Guid, bool>(); plugActivation = configuration.PluginsActivation; foreach (var p in plugins) { plugActivation.TryAdd(p.Id, true); } } Plugins = (from p in plugins select new PluginVM(p)).ToArray(); } #region Exception Handling catch (Exception ex) { TraceSourceMonitorHelper.Error("Fail to load plugins: {0}", ex); } #endregion Exception Handling }
/// <summary> /// Called when [online annoncement]. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.ServiceModel.Discovery.AnnouncementEventArgs"/> instance containing the event data.</param> private void OnOnlineAnnoncement(object sender, AnnouncementEventArgs e) { var address = e.EndpointDiscoveryMetadata.Address; Uri uri = address.Uri; if (uri.AbsoluteUri.EndsWith("mex")) { return; } if (uri.Scheme == CHANNEL_TYPE_NAMEPIPE) { AddProxies(() => new NetNamedPipeBinding(), address); } else if (uri.Scheme != CHANNEL_TYPE_NAMEPIPE) { AddProxies(() => new NetTcpBinding(), address); } try { Ping(); } #region Exception Handling catch (Exception ex) { TraceSourceMonitorHelper.Warn("MonitorWcfDiscoveryProxy: ping faild, {0}", ex); } #endregion Exception Handling }
/// <summary> /// Pings this instance. /// </summary> public void Ping() { try { //#region Validation //if (_liveChannels.Count == 0) // Discover(); //#endregion // Validation IEnumerable <ChannelInfo> channels = _liveChannels.Values; foreach (ChannelInfo channel in channels) { if (channel.Channel.State == CommunicationState.Opened) { channel.Proxy.Ping(); } else if (channel.Channel.State != CommunicationState.Opening) { Discover(); break; } } } #region Exception Handling catch (Exception ex) { TraceSourceMonitorHelper.Warn("Ping failed: {0}", ex); } #endregion Exception Handling }
/// <summary> /// Adds a filter. /// </summary> /// <param name="key">The key.</param> /// <param name="filter">The filter.</param> /// <returns>success indication</returns> /// <remarks>may failed when trying to add a key multiple times</remarks> public bool AddFilter(string key, Func <MarbleCandidate, bool> filter) { if (!_filterMap.TryAdd(key, filter)) { TraceSourceMonitorHelper.Warn("Failed to add a named filter ({0})", key); return(false); } ExchangeFilters(); return(true); }
public static void SetDispatcher() { if (CurrentDispatcher != null) { throw new InvalidOperationException("Only single assignment is allowed"); } CurrentDispatcher = Dispatcher.CurrentDispatcher; CurrentDispatcher.Hooks.OperationAborted += (s, e) => TraceSourceMonitorHelper.Warn("UI abort: {0}", e.Operation.Status); CurrentDispatcher.UnhandledException += (s, e) => TraceSourceMonitorHelper.Error("UI unhandled error: {0}", e.Exception); }
/// <summary> /// remove a filter. /// </summary> /// <param name="key">The key.</param> /// <returns>success indication</returns> /// <remarks>may failed if not contain the key</remarks> public bool RemoveFilter(string key) { Func <MarbleCandidate, bool> filter; if (!_filterMap.TryRemove(key, out filter)) { TraceSourceMonitorHelper.Warn("Failed to remove a named filter ({0})", key); return(false); } ExchangeFilters(); return(true); }
/// <summary> /// Adds the filter. /// </summary> /// <param name="filter"> /// Gets marble and filter kind /// and return whether to forward /// the monitor information to this channel /// </param> /// <returns>the filter's key or null on failure</returns> public static string AddFilter(Func <MarbleCandidate, string, bool> filter) { string key = Guid.NewGuid().ToString(); if (!_filterMap.TryAdd(key, filter)) { TraceSourceMonitorHelper.Warn("Failed to add a filter"); return(null); } ExchangeFilters(); return(key); }
/// <summary> /// Gets the proxies. /// </summary> /// <param name="candidate">The candidate.</param> /// <returns></returns> internal static VisualRxProxyWrapper[] GetProxies(MarbleCandidate candidate) { if (VisualRxSettings.Proxies == null || !VisualRxSettings.Proxies.Any()) { TraceSourceMonitorHelper.Warn("MonitorOperator: No proxy found"); return(new VisualRxProxyWrapper[0]); } var proxies = (from p in VisualRxSettings.Proxies where VisualRxSettings.Filter(candidate, p.Kind) && p.Filter(candidate) select p).ToArray(); return(proxies); }
public MonitorOperator( string name, double indexOrder, IMonitorSurrogate <T> surrogate, string[] keywords) { #region Validation if (keywords == null) { keywords = new string[0]; } if (keywords == null) { keywords = new string[0]; } if (surrogate == null) { surrogate = _defaultSurrogate; } #endregion Validation _name = name; _surrogate = surrogate; _keyworkds = keywords; _indexOrder = indexOrder; try { if (VisualRxSettings.CollectMachineInfo) { _machineName = Environment.MachineName; } } #region Exception Handling catch (Exception ex) { TraceSourceMonitorHelper.Warn("fail to collect machine information {0}", ex); } #endregion Exception Handling }
/// <summary> /// Initializes this instance. /// </summary> public string OnInitialize() { try { _service = new ServiceFactory(); string info = _service.Init(Settings); _service.Ping(); return(info); } #region Exception Handling catch (Exception ex) { TraceSourceMonitorHelper.Warn("MonitorWcfDiscoveryProxy: ping faild, {0}", ex); return(ex.ToString()); } #endregion Exception Handling }
/// <summary> /// Sends the specified item. /// </summary> /// <param name="item">The item.</param> internal static void Send(MarbleBase item, IEnumerable <VisualRxProxyWrapper> proxies) { #region Validation if (VisualRxSettings.Proxies == null || !VisualRxSettings.Proxies.Any()) { TraceSourceMonitorHelper.Warn("MonitorOperator: No proxy found"); return; } #endregion Validation foreach (VisualRxProxyWrapper proxy in proxies) { try { //string kind = proxy.Kind; //if (!VisualRxSettings.Filter(item, kind)) // continue; //if (!proxy.Filter(item)) // continue; // the proxy wrapper apply parallelism and batching (VIA Rx Subject) proxy.Send(item); } #region Exception Handling catch (Exception ex) { TraceSourceMonitorHelper.Error("MonitorOperator: {0}", ex); } #endregion Exception Handling } }
/// <summary> /// Sets the crypto keys. /// </summary> private static void SetCryptoKeys() { #region var prm = new CspParameters (...) var prm = new CspParameters { KeyContainerName = FILE_NAME, Flags = CspProviderFlags.NoPrompt | CspProviderFlags.UseNonExportableKey | CspProviderFlags.UseMachineKeyStore }; #endregion // var prm = new CspParameters (...) var cryptoStorage = new RSACryptoServiceProvider(prm) { PersistKeyInCsp = true, }; #region Restore the secure key bool keyInfoExists = File.Exists(FILE_KEY_PATH); if (keyInfoExists) { try { var fs = File.OpenRead(FILE_KEY_PATH); using (var br = new BinaryReader(fs)) { // read the symmetric key int len = br.ReadInt32(); byte[] k = br.ReadBytes(len); _cryptoAlgorithm.Key = cryptoStorage.Decrypt(k, true); len = br.ReadInt32(); byte[] iv = br.ReadBytes(len); _cryptoAlgorithm.IV = cryptoStorage.Decrypt(iv, true); } } #region Exception Handling catch (CryptographicException ex) { TraceSourceMonitorHelper.Warn("Fail to decrypt the symmetric key: {0}", ex); keyInfoExists = false; string date = DateTime.Now.ToString("yyyyMMdd.HHmmss"); File.Move(FILE_KEY_PATH, FILE_KEY_PATH + "." + date); File.Move(FILE_PATH, FILE_PATH + "." + date); } #endregion // Exception Handling } if (!keyInfoExists) { // regenerate and save symmetric key byte[] k = cryptoStorage.Encrypt(_cryptoAlgorithm.Key, true); byte[] iv = cryptoStorage.Encrypt(_cryptoAlgorithm.IV, true); var fs = File.OpenWrite(FILE_KEY_PATH); using (var bw = new BinaryWriter(fs)) { bw.Write(k.Length); bw.Write(k); bw.Write(iv.Length); bw.Write(iv); } } #endregion // Restore the secure key }