Example #1
0
        /// <summary>
        /// Кнопки без изменения ширины
        /// метод добавляет в классы к существуюющему, но не перезаписует
        /// </summary>
        /// <param name="html">Current Html object in View</param>
        /// <param name="text">Value of button</param>
        /// <param name="htmlAttrsDic">Dictionary of html attributes</param>
        /// <param name="useDefaultClasses">should use default classes</param>
        /// <returns>Html button</returns>
        public static MvcHtmlString Button(this HtmlHelper html, IDictionary<string, string> htmlAttrsDic,
            string text = "Send Data", bool useDefaultClasses = true)
        {

            TagBuilder tag = new TagBuilder("input");

            IDictionary<string, string> attributes = new Dictionary<string, string>()
                {
                    {"type", _btnType},
                    {"value", text}
                };

            if (useDefaultClasses)
            {
                attributes.Add(_class, _btnClass);

                var res = htmlAttrsDic.SingleOrDefault(z => z.Key == _class);
                if (res.Key != null)
                {
                    attributes[res.Key] += " " + res.Value;
                    htmlAttrsDic.Remove(res.Key);
                }
            }

            attributes = attributes
                .Union(htmlAttrsDic)
                .ToDictionary(z => z.Key, v => v.Value);

            tag.MergeAttributes(attributes);

            return new MvcHtmlString(tag.ToString(TagRenderMode.SelfClosing));
        }
        public void AddRangeTest_ShouldAddAllElement_IfDistinctDictionaryIsPassed()
        {
            // Arrange
            var dictionary = new Dictionary<string, int>();
            dictionary.Add("a", 1);
            dictionary.Add("d", 4);
            dictionary.Add("b", 2);
            dictionary.Add("c", 3);
            dictionary.Add("e", 5);
            var target = new Dictionary<string, int>();

            // Act
            target.AddRange(dictionary);

            // Assert
            CollectionAssert.AreEqual(
                new int[] { 1, 2, 3, 4, 5 }.AsEnumerable(),
                target.Union(dictionary, (_1, _2) => _1.Is(_2)).
                       OrderBy(_ => _.Key).
                       Select(_=>_.Value)
            );
        }
Example #3
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);
        }
 private Dictionary<ISymbolicExpressionTreeNode, int> FindStatementSymbolsInTree(ISymbolicExpressionTreeNode node, IEnumerable<string> productions, ref int curline) {
   Dictionary<ISymbolicExpressionTreeNode, int> symbolToLineDict = new Dictionary<ISymbolicExpressionTreeNode, int>();
   if (node.Subtrees.Count() > 0) {
     // node
     var symbol = node.Symbol as CFGSymbol;
     if (symbol != null) {
       var partsEnumerator = symbol.GetTerminalParts().GetEnumerator();
       var subtreeEnumerator = node.Subtrees.GetEnumerator();
       if (productions.Contains(symbol.Name)) {
         symbolToLineDict.Add(node, curline);
       }
       while (partsEnumerator.MoveNext() && subtreeEnumerator.MoveNext()) {
         curline += partsEnumerator.Current.Count(c => c == '\n');
         symbolToLineDict = symbolToLineDict.Union(FindStatementSymbolsInTree(subtreeEnumerator.Current, productions, ref curline)).ToDictionary(k => k.Key, v => v.Value);
       }
       curline += partsEnumerator.Current.Count(c => c == '\n');
     } else {
       // ProgramRoot or StartSymbol
       foreach (var subtree in node.Subtrees) {
         symbolToLineDict = symbolToLineDict.Union(FindStatementSymbolsInTree(subtree, productions, ref curline)).ToDictionary(k => k.Key, v => v.Value);
       }
     }
   } else {
     // leaf
     var symbol = node.Symbol as CFGSymbol;
     if (productions.Contains(symbol.Name)) {
       symbolToLineDict.Add(node, curline);
     }
     var parts = symbol.GetTerminalParts();
     curline += parts.First().Count(c => c == '\n');
   }
   return symbolToLineDict;
 }
        public void UnionShouldMergeDictionariesWithComparer()
        {
            // arrange
            var d1 = new Dictionary<string, int>()
            {
                { "Key1", 1 },
                { "Key3", 3 },
                { "Key5", 5 }
            };
            var d2 = new Dictionary<string, int>()
            {
                { "Key1", 1 },
                { "Key2", 2 },
                { "Key4", 4 }
            };

            // act
            var actual = d1.Union( d2, StringComparer.Ordinal );

            // assert
            Assert.Equal( 5, actual.Count );
            Assert.True( actual.ContainsKey( "Key1" ) );
            Assert.True( actual.ContainsKey( "Key2" ) );
            Assert.True( actual.ContainsKey( "Key3" ) );
            Assert.True( actual.ContainsKey( "Key4" ) );
            Assert.True( actual.ContainsKey( "Key5" ) );
        }