public static void EnsureApplicationResources()
 {
     Xceed.Wpf.DataGrid.Licenser.LicenseKey = "DGP44D4AAUZB475PUNA";
     if (Application.Current == null)
     {
         // create the Application object and add global resources
         new Application { ShutdownMode = ShutdownMode.OnExplicitShutdown };
         object vml = new ViewModelLocator();
         if (Application.Current != null) Application.Current.Resources.Add("Locator", vml);
     }
 }
Exemple #2
0
        public static bool ConnectToBrokers()
        {
            try
            {
                //List<string> excludeList = new List<string> { "FH1-134|NB20x", "FH1-002|NB20x", "FH1-065|NB20x", "FH1-118|NB20x" };
                List<string> excludeList = new List<string> { };
                foreach (KeyValuePair<string, NB.Configuration.Config> _config in Config.NbConfigs)
                {
                    if (excludeList.Contains(_config.Key))
                        continue;

                    if (!subscribers.ContainsKey(_config.Key))
                    {
                        if (Application.Current == null)
                        {
                            // create the Application object and add global resources
                            new Application();
                            object vml = new ViewModelLocator();
                            if (Application.Current != null) Application.Current.Resources.Add("Locator", vml);
                        }

                        ParameterizedThreadStart pts = new ParameterizedThreadStart(ConnectToBrokerAsClient);
                        Thread tConnect = new Thread(pts);
                        tConnect.Start(_config.Key);
                        log.DebugFormat("Created thread to connect to new subscriber to {0}", _config.Key);

                        //Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
                        //(Action)delegate() { BrokerConnection.Subscribers.Add(_config.Key, new Subscriber(_config.Value)); });
                    }
                }
            }
            catch (Exception ex)
            {
                log.WarnFormat("Client is not connected to message broker.\n{0}", ex);
                return false;
            }

            return true;
        }