Beispiel #1
0
        static Instance()
        {
#if DEBUG
            Imitators.Add(new Devices.DummyImitatorFactory(new Interfaces.SerialSettings("COM3")));
            Devices.Add(new Devices.DummyDeviceFactory(new Interfaces.SerialSettings("COM4")));
#endif

            //Devices.Add(new Devices.OctopusFactory(new Interfaces.SerialSettings("COM4")));
            Devices.Add(new Devices.BPhasantFactory(new Interfaces.SerialSettings("COM4")));
            Devices.Add(new Devices.BOctopustFactory(new Interfaces.SerialSettings("COM4")));
            Devices.Add(new Devices.BOctopusMFactory(new Interfaces.SerialSettings("COM4")));
            Imitators.Add(new Devices.Sapsan3Factory(new Interfaces.SerialSettings("COM3")));

            try
            {
                if (System.IO.File.Exists(@".\environment.json"))
                {
                    string json = System.IO.File.ReadAllText(@".\environment.json");

                    var s = Newtonsoft.Json.JsonConvert.DeserializeObject <ObservableCollection <ViewModel.EnvironmentModel> >(json, new JsonSerializerSettings()
                    {
                        TypeNameHandling = TypeNameHandling.Auto
                    });

                    Environments = s;
                }
            }
            catch (Exception) { }

            Environments.CollectionChanged += Environments_CollectionChanged;
        }
Beispiel #2
0
        //Загружет списки проектов и провайдеров для потока
        public void ReadSetup()
        {
            try
            {
                Projects.Clear();
                ProjectsList.Clear();
                foreach (var provider in ProvidersDic.Values)
                {
                    var pi = provider.ProviderInstance;
                    if (pi != null)
                    {
                        if (ApplicationType == ApplicationType.Controller && General.ProvidersQueues.ContainsKey(pi.Hash))
                        {
                            General.ProvidersQueues.Remove(pi.Hash);
                        }
                        pi.Dispose();
                    }
                }

                ProvidersDic.Clear();
                Sources.Clear();
                Receivers.Clear();
                Imitators.Clear();
                Archive   = null;
                ArchivePr = null;

                using (var rec = new RecDao(General.ControllerFile, "SELECT * FROM Projects WHERE ThreadId =" + Id + " ORDER BY Project"))
                    while (rec.Read())
                    {
                        var proj = new Project(rec, this);
                        if (!Command.IsError && !Projects.ContainsKey(proj.Code))
                        {
                            Projects.Add(proj.Code, proj);
                            ProjectsList.Add(proj);
                            AddEvent("Добавлен проект", proj.Code + ", " + proj.File);
                            proj.ReadProviders();//Чтение списка провайдеров
                        }
                    }
                MakeProviders();
                MakeProjectString();
            }
            catch (Exception ex)
            {
                AddError("Ошибка загрузки списка проектов. Необходимо повторить настройку", ex);
            }
            Procent = 70;

            try //Список провайдеров
            {
                AddEvent("Чтение настроек провайдеров");
                using (var rec = new RecDao(General.ControllerFile, "SELECT * FROM Providers WHERE ThreadId =" + Id))
                    while (rec.Read())
                    {
                        var name = rec.GetString("ProviderName");
                        if (ProvidersDic.ContainsKey(name))
                        {
                            var prov = ProvidersDic[name];
                            prov.Code = rec.GetString("ProviderCode");
                            prov.Inf  = rec.GetString("ProviderInf");
                            prov.Otm  = rec.GetBool("Otm");
                        }
                    }
                foreach (var prov in ProvidersDic.Values)
                {
                    if (prov.Otm)
                    {
                        prov.ProviderInstance = General.RunProvider(prov.Code, prov.Name, prov.Inf, this);
                        if (prov.ProviderInstance != null)
                        {
                            switch (prov.Type.ToProviderType())
                            {
                            case ProviderType.Archive:
                                Archive   = (IArchive)prov.ProviderInstance;
                                ArchivePr = prov;
                                break;

                            case ProviderType.Source:
                                Sources.Add(prov.Name, (ISource)prov.ProviderInstance);
                                break;

                            case ProviderType.Imitator:
                                var ims = (Imitator)prov.ProviderInstance;
                                Imitators.Add(prov.Name, ims);
                                var pname = prov.Name.Substring(0, prov.Name.Length - 4);
                                if (Projects.ContainsKey(pname))
                                {
                                    Projects[pname].Imitator = ims;
                                }
                                else
                                {
                                    AddError("Недопустимое имя провайдера имитатора", null, prov.Name);
                                }
                                break;

                            case ProviderType.Receiver:
                                Receivers.Add(prov.Name, (IReceiver)prov.ProviderInstance);
                                break;
                            }
                            if (ApplicationType == ApplicationType.Controller)
                            {
                                string hash = prov.ProviderInstance.Hash;
                                if (!General.ProvidersQueues.ContainsKey(hash))
                                {
                                    General.ProvidersQueues.Add(hash, new Queue <int>());
                                }
                                prov.ProviderQueue = General.ProvidersQueues[hash];
                            }
                        }
                    }
                }
                MakeProviders();
            }
            catch (Exception ex)
            {
                AddError("Ошибка при чтении настроек провайдеров", ex);
            }
        }