Ejemplo n.º 1
0
            /// <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
            }
Ejemplo n.º 2
0
        /// <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
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        /// <returns>Initialize information</returns>
        public string Initialize()
        {
            #region _scheduler = new EventLoopScheduler(...)

            _scheduler = new EventLoopScheduler(treadStart =>
                {
                    var trd = new Thread(treadStart);
                    trd.Priority = ThreadPriority.Normal;
                    trd.IsBackground = true;
                    trd.Name = "Monitor Proxy " + Kind;

                    return trd;
                });

            _scheduler.Catch<Exception>(e =>
                {
                    TraceSourceMonitorHelper.Error("Scheduling (OnBulkSend): {0}", e);
                    return true;
                });

            #endregion _scheduler = new EventLoopScheduler(...)

            SendThreshold threshhold = _actualProxy.SendingThreshold ?? _defaultThreshold;
            
            _subject = new Subject<MarbleBase>();
            var tmpStream = _subject
                .ObserveOn(_scheduler) // single thread
                //.Synchronize()
                .Retry()
                .Buffer(threshhold.WindowDuration, threshhold.WindowCount)
                .Where(items => items.Count != 0);
            _unsubSubject = tmpStream.Subscribe(_actualProxy.OnBulkSend);

            return _actualProxy.OnInitialize();
        }
Ejemplo n.º 4
0
        private static void CreateQueueIfNotExists(string queueName)
        {
            #region Validation

            if (string.IsNullOrWhiteSpace(queueName))
            {
                return;
            }

            #endregion // Validation

            try
            {
                string queueFullName = ".\\private$\\" + queueName;
                if (!MessageQueue.Exists(queueFullName))
                {
                    MessageQueue.Create(queueFullName, false);
                }
            }
            #region Exception Handling

            catch (Exception ex)
            {
                TraceSourceMonitorHelper.Error("Fail to create MSMQ queue: {0}", ex);
            }

            #endregion Exception Handling
        }
            public void Dispose()
            {
                var factory = _factory;

                if (factory == null)
                {
                    return;
                }
                if (Interlocked.CompareExchange(ref _factory, null, factory) != factory)
                {
                    return;
                }

                try
                {
                    if (factory.State == CommunicationState.Faulted)
                    {
                        factory.Abort();
                    }
                    else
                    {
                        factory.Close();
                    }
                }
                catch (Exception ex)
                {
                    TraceSourceMonitorHelper.Error("Dispose: close factory failed: {0}", ex);
                }
                GC.SuppressFinalize(this);
            }
        /// <summary>
        /// Loads the configuration.
        /// </summary>
        public static void Load()
        {
            if (!File.Exists(FILE_PATH))
            {
                Save();
                return;
            }

            try
            {
                var ser = new NetDataContractSerializer();
                var fs  = File.OpenRead(FILE_PATH);
                using (var crypto = new CryptoStream(fs, _cryptoAlgorithm.CreateDecryptor(), CryptoStreamMode.Read))
                {
                    Value = ser.Deserialize(crypto) as Configuration;
                }
            }
            #region Exception Handling

            catch (Exception ex)
            {
                string date = DateTime.Now.ToString("yyyyMMdd.HHmmss");
                File.Move(FILE_PATH, FILE_PATH + "." + date);
                Value = new Configuration();
                Save();
                TraceSourceMonitorHelper.Error("Fail to load the Configuration: {0}", ex);
            }

            #endregion // Exception Handling
        }
Ejemplo n.º 7
0
        /// <summary>
        /// select the template for the marble diagram
        /// </summary>
        /// <param name="item">The data object for which to select the template.</param>
        /// <param name="container">The data-bound object.</param>
        /// <returns>
        /// Returns a <see cref="T:System.Windows.DataTemplate"/> or null. The default value is null.
        /// </returns>
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            var element       = container as FrameworkElement;
            var marbleDiagram = item as IMarbleDiagramContext;

            IMarblePanelPlugin[] plugins =
                MarbleController.MarbleDiagramTemplateSelectorPlugin.ToArray();

            foreach (var plugin in plugins)
            {
                try
                {
                    DataTemplate template = plugin.SelectTemplate(marbleDiagram, element);
                    if (template != null)
                    {
                        return(template);
                    }
                }

                #region Exception Handling

                catch (Exception ex)
                {
                    TraceSourceMonitorHelper.Error("Fail to select template for marble diagram, plugins: {0}, \r\n\terror = {1}",
                                                   plugin, ex);
                    return(null);
                }

                #endregion Exception Handling
            }
            return(element.FindResource("DiagramTemplate") as DataTemplate);
        }
            /// <summary>
            /// Pings this instance.
            /// </summary>
            public async void Ping()
            {
                var factory = _factory;

                try
                {
                    var proxy = GetProxy(factory);
                    await proxy.PingAsync();
                }
                #region Exception Handling

                //catch (CommunicationException ex)
                //{
                //    factory.Abort();
                //    TraceSourceMonitorHelper.Error("Ping CommunicationException: {0}", ex);
                //}
                //catch (TimeoutException ex)
                //{
                //    factory.Abort();
                //    TraceSourceMonitorHelper.Error("Ping timeout: {0}", ex);
                //}
                catch (Exception ex)
                {
                    //factory.Abort();
                    TraceSourceMonitorHelper.Error("Ping failed: {0}", ex);
                }

                #endregion // Exception Handling
            }
Ejemplo n.º 9
0
        /// <summary>
        /// Selects a template from the Tab.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="container">The container.</param>
        /// <returns></returns>
        public override DataTemplate SelectTemplate(object model, DependencyObject container)
        {
            FrameworkElement element = container as FrameworkElement;
            var tabModel             = model as ITabModel;

            ITabPlugin plugin =
                MarbleController.TabTemplateSelectorPlugins.FirstOrDefault(
                    p => p.TabModel.Keyword == tabModel.Keyword);

            if (plugin != null)
            {
                try
                {
                    DataTemplate template = plugin.SelectTemplate(tabModel, element);
                    if (template != null)
                    {
                        return(template);
                    }
                }

                #region Exception Handling

                catch (Exception ex)
                {
                    TraceSourceMonitorHelper.Error("Fail to select template for tab, plugins: {0}, \r\n\terror = {1}",
                                                   plugin.TabModel.Keyword, ex);
                    return(null);
                }

                #endregion Exception Handling
            }
            return(element.FindResource("DiagramsTemplate") as DataTemplate);
        }
Ejemplo n.º 10
0
            /// <summary>
            /// Sends the specified item.
            /// </summary>
            /// <param name="item">The item.</param>
            public async void Send(MarbleBase[] item)
            {
                var factory = _factory;

                try
                {
                    var proxy = GetProxy(factory);
                    await proxy.SendAsync(item);
                }
                #region Exception Handling

                //catch (CommunicationException ex)
                //{
                //    factory.Abort();
                //    TraceSourceMonitorHelper.Error("Send CommunicationException: {0}", ex);
                //}
                //catch (TimeoutException ex)
                //{
                //    factory.Abort();
                //    TraceSourceMonitorHelper.Error("Send timeout: {0}", ex);
                //}
                catch (Exception ex)
                {
                    //factory.Abort();
                    TraceSourceMonitorHelper.Error("Send failed: {0}", ex);
                }

                #endregion // Exception Handling
            }
Ejemplo n.º 11
0
        /// <summary>
        /// Called when [setting handler].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void OnSettingHandler(object sender, RoutedEventArgs e)
        {
            try
            {
                SettingWindow win = null;
                try
                {
                    win       = new SettingWindow();
                    win.Owner = this;
                    win.ShowDialog();
                }
                finally
                {
                    win.Close();
                }
            }
            #region Exception Handling

            catch (Exception ex)
            {
                TraceSourceMonitorHelper.Error("UI event handler failed: {0}", ex);
            }

            #endregion // Exception Handling
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Merges the plug-in's resources.
        /// </summary>
        /// <param name="dictionary">The dictionary.</param>
        private static void MergeResources(ResourceDictionary dictionary)
        {
            try
            {
                foreach (var resourcePlugin in LoadResourcesPlugins)
                {
                    try
                    {
                        foreach (var resource in resourcePlugin.GetResources())
                        {
                            dictionary.MergedDictionaries.Add(resource);
                        }
                    }

                    #region Exception Handling

                    catch (Exception ex)
                    {
                        TraceSourceMonitorHelper.Error("Fail to get resource [plug-in = {0}]: {1}", resourcePlugin.GetType().Name, ex);
                    }

                    #endregion Exception Handling
                }
            }
            #region Exception Handling

            catch (Exception ex)
            {
                TraceSourceMonitorHelper.Error("Fail to add plug-ins resources: {0}", ex);
            }

            #endregion Exception Handling
        }
Ejemplo n.º 13
0
            /// <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
            }
 protected override void Dispose(bool disposed)
 {
     try
     {
         _proxy.Value.Dispose();
     }
     catch (Exception ex)
     {
         TraceSourceMonitorHelper.Error("VisualRxWcfFixedAddressProxy: {0}", ex);
     }
 }
Ejemplo n.º 15
0
 protected override void Dispose(bool disposed)
 {
     try
     {
         _trace.Close();
     }
     catch (Exception ex)
     {
         TraceSourceMonitorHelper.Error("VisualRxTraceSourceProxy: {0}", ex);
     }
 }
Ejemplo n.º 16
0
        /// <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);
        }
Ejemplo n.º 17
0
            /// <summary>
            /// Discovers this listeners.
            /// </summary>
            private bool Discover()
            {
                lock (_sync)
                {
                    if (_isDiscovering)
                    {
                        return(false);
                    }
                    _isDiscovering = true;
                }
                try
                {
                    var client = new DiscoveryClient(new UdpDiscoveryEndpoint());

                    var criteria = new FindCriteria(typeof(IVisualRxServiceAdapter));
                    criteria.Duration = TimeSpan.FromSeconds(_setting.DiscoveryTimeoutSeconds);

                    var endpoints         = client.Find(criteria).Endpoints;
                    var addressesNamepipe = (from item in endpoints
                                             where item.Address.Uri.Scheme == CHANNEL_TYPE_NAMEPIPE
                                             select item.Address).ToArray();
                    var addressesTcp = (from item in endpoints
                                        where item.Address.Uri.Scheme == CHANNEL_TYPE_TCP
                                        select item.Address).ToArray();

                    string[] oldProxies = _liveChannels.Keys.ToArray();

                    AddProxies(addressesTcp, () => new NetTcpBinding());
                    AddProxies(addressesNamepipe, () => new NetNamedPipeBinding());

                    string[] forCleanup = oldProxies.Except(_liveChannels.Keys).ToArray();

                    Cleanup(forCleanup);
                }

                #region Exception Handling

                catch (Exception ex)
                {
                    TraceSourceMonitorHelper.Error("Monitor channel discovery: ", ex);
                }

                #endregion Exception Handling

                finally
                {
                    lock (_sync)
                    {
                        _isDiscovering = false;
                    }
                }

                return(true);
            }
Ejemplo n.º 18
0
        /// <summary>
        /// Saves the configuration.
        /// </summary>
        /// <returns></returns>
        public static Exception Save()
        {
            try
            {
                ObservableCollection <DiscoveryPath> paths = Value.PluginDiscoveryPaths;
                #region Validation

                for (int i = paths.Count - 1; i >= 0; i--)
                {
                    if (string.IsNullOrWhiteSpace(paths[i].Path))
                    {
                        paths.RemoveAt(i);
                    }
                }

                #region Validation

                if (File.Exists(FILE_PATH))
                {
                    File.Delete(FILE_PATH);
                }

                #endregion // Validation

                #endregion // Validation

                var ser = new NetDataContractSerializer();
                var fs  = File.OpenWrite(FILE_PATH);
                using (var crypto = new CryptoStream(fs, _cryptoAlgorithm.CreateEncryptor(), CryptoStreamMode.Write))
                {
                    ser.Serialize(crypto, Value);
                }
                return(null);
            }
            #region Exception Handling

            catch (Exception ex)
            {
                try
                {
                    File.Move(FILE_PATH, FILE_PATH + "." + DateTime.Now.ToString("yyyy-MM-dd HHmmss"));
                }
                #region Exception Handling

                catch { }

                #endregion // Exception Handling
                TraceSourceMonitorHelper.Error("Fail to Save the Configuration: {0}", ex);
                return(ex);
            }

            #endregion // Exception Handling
        }
Ejemplo n.º 19
0
 public void Dispose()
 {
     try
     {
         _factory.Close();
     }
     catch (Exception ex)
     {
         TraceSourceMonitorHelper.Error("Dispose: close factory failed: {0}", ex);
     }
     GC.SuppressFinalize(this);
 }
Ejemplo n.º 20
0
 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);
 }
Ejemplo n.º 21
0
        /// <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);
        }
Ejemplo n.º 22
0
        /// <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);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Bulk send.
        /// </summary>
        /// <param name="items">The items.</param>
        public void OnBulkSend(IEnumerable <MarbleBase> items)
        {
            try
            {
                _service.Send(items.ToArray());
            }
            #region Exception Handling

            catch (Exception ex)
            {
                TraceSourceMonitorHelper.Error("MonitorWcfDiscoveryProxy: {0}", ex);
            }

            #endregion Exception Handling
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Called when [pause handler].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void OnPauseHandler(object sender, RoutedEventArgs e)
        {
            try
            {
                MarbleController.ViewModel.TogglePause();
            }
            #region Exception Handling

            catch (Exception ex)
            {
                TraceSourceMonitorHelper.Error("UI event handler failed: {0}", ex);
            }

            #endregion // Exception Handling
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Called when [close handler].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void OnCloseHandler(object sender, RoutedEventArgs e)
        {
            try
            {
            }
            #region Exception Handling

            catch (Exception ex)
            {
                TraceSourceMonitorHelper.Error("UI event handler failed: {0}", ex);
            }

            #endregion // Exception Handling
            this.Close();
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Called when [hide handler].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void OnHideHandler(object sender, RoutedEventArgs e)
        {
            try
            {
                this.WindowState = Windows.WindowState.Minimized;
            }
            #region Exception Handling

            catch (Exception ex)
            {
                TraceSourceMonitorHelper.Error("UI event handler failed: {0}", ex);
            }

            #endregion // Exception Handling
        }
Ejemplo n.º 27
0
        /// <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);
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources
        /// </summary>
        /// <param name="disposed"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        private void DisposeInternal(bool disposed)
        {
            try
            {
                IDisposable unsubSubject = _unsubSubject;
                if (unsubSubject != null)
                    unsubSubject.Dispose();

                _actualProxy.Dispose();

                Dispose(disposed);
            }
            catch (Exception ex)
            {
                TraceSourceMonitorHelper.Error("VisualRxTraceSourceProxy: {0}", ex);
            }
        }
Ejemplo n.º 29
0
        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
        }
Ejemplo n.º 30
0
        /// <summary>
        ///  Enforce the dispose
        /// </summary>
        /// <param name="disposing"></param>
        #endregion // Documentation
        private void Dispose(bool disposing)
        {
            try
            {
                var pauseSubject = _pauseSubject as IDisposable;
                if (pauseSubject != null)
                {
                    pauseSubject.Dispose();
                }
            }
            #region Exception Handling

            catch (Exception ex)
            {
                TraceSourceMonitorHelper.Error("Dispose filed: {0}", ex);
            }

            #endregion // Exception Handling
        }