예제 #1
0
 public static SourcesController CreateSourceController(SourcesControl view, PresentationInfo presentation)
 {
     return new SourcesController(view, presentation);
 }
예제 #2
0
        SourcesController(SourcesControl AView, PresentationInfo APresentation)
        {
            _instance = this;
            _view = AView;

            resourceNodes = new Dictionary<ResourceDescriptor, ISourceNode>();
            m_presentation = APresentation = new PresentationInfo(APresentation); //избавляемся от *Ext

            Dictionary<string, IList<ResourceDescriptor>> local_rd = DesignerClient.Instance.PresentationWorker.GetLocalSources(APresentation.UniqueName);
            Dictionary<string, IList<ResourceDescriptor>> common_rd = DesignerClient.Instance.PresentationWorker.GetGlobalSources();
            
            global_categories = new Dictionary<string, SourceCategory>();
            local_categories = new Dictionary<string, SourceCategory>();

            List<String> sourceTypes = new List<string>();
            foreach (SourceType t in _config.ModuleConfiguration.SourceList)
            {
                if (!sourceTypes.Contains(t.Type))
                {
                    sourceTypes.Add(t.Type);

                    if (!(t.IsHardware))
                    {
                        SourceCategory local_cat = new SourceCategory(t, false) { Icon = Properties.Resources.soft };
                        local_categories.Add(t.Type, local_cat);
                    }

                    SourceCategory global_cat = new SourceCategory(t, true) { Icon = Properties.Resources.soft };
                    global_categories.Add(t.Type, global_cat);
                }
            }

            foreach (var rd in local_rd.Union(common_rd))
            {
                foreach (var r in rd.Value)
                {
                    if (r.ResourceInfo is INonVisibleResource)
                    {
                        nonVisibleResources.Add(r);
                    }
                }
            }


            /// Сортировка источников: сперва программные, потом аппаратные, в каждой группе -- по названию.
            foreach (var category in global_categories.Union(local_categories).OrderBy(gos => gos.Value.IsHardware ? "1" + gos.Key: "0" + gos.Key))
            {
                IEnumerable<ResourceDescriptor> e = new List<ResourceDescriptor>();
                if (local_rd.ContainsKey(category.Key))
                    e = local_rd[category.Key];
                if (common_rd.ContainsKey(category.Key))
                    e = e.Union(common_rd[category.Key]);

                foreach (ResourceDescriptor resource in e/*.OrderBy(res=>res.ResourceInfo.Name)*/)
                {
                    if (!(resource is BackgroundImageDescriptor) && !(resource is INonVisibleResource))
                    {
                        ISourceNode node = null;
                        SourceType type = null;

                        if (resource.ResourceInfo.IsHardware)
                            type = _config.ModuleConfiguration.SourceList.Where(t => t.Name == resource.ResourceInfo.Name && t.Type == resource.ResourceInfo.Type).FirstOrDefault();
                        else
                            type = category.Value.Type;

                        if (type != null)
                            node = new SourceWindow(resource) { SourceType = type };


                        if (node != null)
                        {
                            if ((category.Value.Global && !resource.IsLocal) || (!category.Value.Global && resource.IsLocal))
                            {
                                category.Value.Resources.Add(node);
                                resourceNodes.Add(resource, node);
                            }


                            if (resource.ResourceInfo != null && resource.ResourceInfo.IsHardware && type != null)
                            {
                                node.IsOnline = ShowClient.Instance.IsOnLine(type);
                            }
                        }

                    }
                    else
                    {

                        if (resource.ResourceInfo is INonVisibleResource)
                        {
                            nonVisibleResources.Add(resource);
                        }

                    }
                }

                _view.AddSourceCategory(category.Value, category.Value.Global);
            }

            _view.SelectFirstGlobalSource();
            UndoService.Instance.OnHistoryChanged += new HistoryChanged(Instance_OnHistoryChanged);
            DesignerClient.Instance.PresentationNotifier.OnResourceAdded += new EventHandler<NotifierEventArg<ResourceDescriptor>>(PresentationNotifier_OnResourceAdded);
            DesignerClient.Instance.PresentationNotifier.OnResourceDeleted += new EventHandler<NotifierEventArg<ResourceDescriptor>>(PresentationNotifier_OnResourceDeleted);
            //DesignerClient.Instance.PresentationNotifier.OnObjectChanged += new EventHandler<NotifierEventArg<IList<ObjectInfo>>>(PresentationNotifier_OnObjectChanged);
            PresentationController.Instance.OnSelectedResourceChanged += new SelectedResourceChanged(Instance_OnSelectedResourceChanged);
            PresentationController.Instance.OnPresentationChangedExternally += new PresentationDataChanged(Instance_OnPresentationChangedExternally);
            PresentationController.Instance.OnHardwareStateChanged += new Action<EquipmentType, bool?>(Instance_OnHardwareStateChanged);
            PresentationController.Instance.OnSlideSelectionChanged += new SlideSelectionChanged(Instance_OnSlideSelectionChanged);
        }