Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TreeItem{T}"/> class.
 /// </summary>
 /// <param name="id">The identifier.</param>
 /// <param name="parent">The parent.</param>
 /// <param name="ownerCollection">The owner collection.</param>
 internal TreeItem(string id, string parent, ref TreeCollection <T> ownerCollection)
 {
     _id              = id;
     _parent          = parent;
     _ownerCollection = ownerCollection;
     _subitems        = new LightCollection <string>();
 }
Exemplo n.º 2
0
        public void ComparerString_Test(string[] source, string[] NLR, string[] LNR, string[] LRN, IComparer <string> comparer)
        {
            var tree = new TreeCollection <string>(source, comparer);

            CollectionAssert.AreEqual(tree.NLR(), NLR);
            CollectionAssert.AreEqual(tree.LNR(), LNR);
            CollectionAssert.AreEqual(tree.LRN(), LRN);
        }
Exemplo n.º 3
0
        public void ComparerInt32_Test(int[] source, int[] NLR, int[] LNR, int[] LRN, IComparer <int> comparer)
        {
            var tree = new TreeCollection <int>(source, comparer);

            CollectionAssert.AreEqual(tree.NLR(), NLR);
            CollectionAssert.AreEqual(tree.LNR(), LNR);
            CollectionAssert.AreEqual(tree.LRN(), LRN);
        }
Exemplo n.º 4
0
        public void ComparerBookWithComparer_Test(Book[] source, Book[] NLR, Book[] LNR, Book[] LRN, IComparer <Book> comparer)
        {
            var tree = new TreeCollection <Book>(source, comparer);

            CollectionAssert.AreEqual(tree.NLR(), NLR);
            CollectionAssert.AreEqual(tree.LNR(), LNR);
            CollectionAssert.AreEqual(tree.LRN(), LRN);
        }
Exemplo n.º 5
0
 public TreeTests(T[] source, T value, int count, T[] NLR, T[] LNR, T[] LRN, Comparer <T> comparer)
 {
     _tree      = new TreeCollection <T>(source, comparer);
     _array     = source;
     _value     = value;
     _initCount = count;
     this.NLR   = NLR;
     this.LNR   = LNR;
     this.LRN   = LRN;
 }
Exemplo n.º 6
0
        public JsonTreeCollection BuildJsonTreeCollection(TreeCollection collection)
        {
            JsonTreeCollection jsonTreeCollection = new JsonTreeCollection();

            foreach (Tree tree in collection.Collection)
            {
                jsonTreeCollection.Collection.Add(BuildJsonTreeObject(tree));
            }

            return(jsonTreeCollection);
        }
Exemplo n.º 7
0
        public void ComparerTimeStruct_Test(Time[] source, Time[] NLR, Time[] LNR, Time[] LRN, IComparer <Time> comparer)
        {
            var tree  = new TreeCollection <Time>(source, comparer);
            var test  = tree.NLR();
            var test1 = tree.LNR();
            var test2 = tree.LRN();

            CollectionAssert.AreEqual(tree.NLR(), NLR);
            CollectionAssert.AreEqual(tree.LNR(), LNR);
            CollectionAssert.AreEqual(tree.LRN(), LRN);
        }
Exemplo n.º 8
0
        private TreeInfo GetTreeByName(string name)
        {
            TreeInfo treeInfo;

            TreeCollection   treeCollection = GameObject.FindObjectOfType <TreeCollection>();
            IList <TreeInfo> treeInfos      = treeCollection.m_prefabs;

//			treeInfo = (from TreeInfo info in treeInfos
//			            where info.name.Equals (name)
//			            select info).FirstOrDefault();
            treeInfo = treeInfos [4];
            return(treeInfo);
        }
Exemplo n.º 9
0
        public void BuildJsonTreeCollectionFile(Stream stream, TreeCollection collection)
        {
            using (StreamWriter sw = new StreamWriter(stream))
            {
                using (JsonWriter jw = new JsonTextWriter(sw))
                {
                    jw.Formatting = Formatting.Indented;

                    JsonSerializer serializer = new JsonSerializer();

                    serializer.NullValueHandling = NullValueHandling.Ignore;
                    serializer.Serialize(jw, BuildJsonTreeCollection(collection));
                }
            }
        }
        public BackOfficeServerVariables(
            LinkGenerator linkGenerator,
            IRuntimeState runtimeState,
            UmbracoFeatures features,
            IOptionsMonitor <GlobalSettings> globalSettings,
            IUmbracoVersion umbracoVersion,
            IOptionsMonitor <ContentSettings> contentSettings,
            IHttpContextAccessor httpContextAccessor,
            TreeCollection treeCollection,
            IHostingEnvironment hostingEnvironment,
            IOptionsMonitor <RuntimeSettings> runtimeSettings,
            IOptionsMonitor <SecuritySettings> securitySettings,
            IRuntimeMinifier runtimeMinifier,
            IBackOfficeExternalLoginProviders externalLogins,
            IImageUrlGenerator imageUrlGenerator,
            PreviewRoutes previewRoutes,
            IEmailSender emailSender,
            IOptionsMonitor <MemberPasswordConfigurationSettings> memberPasswordConfigurationSettings,
            IOptionsMonitor <DataTypesSettings> dataTypesSettings)
        {
            _linkGenerator       = linkGenerator;
            _runtimeState        = runtimeState;
            _features            = features;
            _globalSettings      = globalSettings.CurrentValue;
            _umbracoVersion      = umbracoVersion;
            _contentSettings     = contentSettings.CurrentValue ?? throw new ArgumentNullException(nameof(contentSettings));
            _httpContextAccessor = httpContextAccessor;
            _treeCollection      = treeCollection ?? throw new ArgumentNullException(nameof(treeCollection));
            _hostingEnvironment  = hostingEnvironment;
            _runtimeSettings     = runtimeSettings.CurrentValue;
            _securitySettings    = securitySettings.CurrentValue;
            _runtimeMinifier     = runtimeMinifier;
            _externalLogins      = externalLogins;
            _imageUrlGenerator   = imageUrlGenerator;
            _previewRoutes       = previewRoutes;
            _emailSender         = emailSender;
            _memberPasswordConfigurationSettings = memberPasswordConfigurationSettings.CurrentValue;
            _dataTypesSettings = dataTypesSettings.CurrentValue;

            globalSettings.OnChange(x => _globalSettings       = x);
            contentSettings.OnChange(x => _contentSettings     = x);
            runtimeSettings.OnChange(x => _runtimeSettings     = x);
            securitySettings.OnChange(x => _securitySettings   = x);
            dataTypesSettings.OnChange(x => _dataTypesSettings = x);
            memberPasswordConfigurationSettings.OnChange(x => _memberPasswordConfigurationSettings = x);
        }
        public void SetBehaviourPropertyInTreeView()
        {
            // Remove the current element (if any) in the TreeCollection that is of BehaviourViewModelBase
            foreach (StateCollectionViewModelBase s in TreeCollection)
            {
                if (s is BehaviourViewModelBase)
                {
                    TreeCollection.Remove(s);
                    break;
                }
            }

            if ((Behaviour != null) &&
                ((Behaviour.Type == "breakableObject") || (Behaviour.Type == "scene")))
            {
                TreeCollection.Insert(0, Behaviour.BehaviourProperties);
            }
        }
Exemplo n.º 12
0
        public void ImportTrees(BoundingBox BoundingBox)
        {
            //RaiseTreeMapperEvent("Starting Import Trees..");
            Bitmap bitmap = null;

            bitmap = TreeCoverClient.LoadTreeCover(BoundingBox);

            int trees_found = 0;

            if (bitmap == null)
            {
                return;
            }

            for (int x = 0; x < 1081; x += Density)
            {
                for (int y = 0; y < 1081; y += Density)
                {
                    System.Drawing.Color pixel_color;

                    pixel_color = bitmap.GetPixel(x, y);

                    double intensity = ((int)pixel_color.G - (int)pixel_color.R) / 179.0;
                    if (intensity > 0.0)
                    {
                        trees_found++;
                        //RaiseTreeMapperEvent(string.Format("Adding tree {0} {1}", x, y));
                        TreeCollection   treeCollection = GameObject.FindObjectOfType <TreeCollection>();
                        IList <TreeInfo> treeInfos      = treeCollection.m_prefabs;

                        //			treeInfo = (from TreeInfo info in treeInfos
                        //			            where info.name.Equals (name)
                        //			            select info).FirstOrDefault();
                        TreeInfo treeInfo = treeInfos [4];

                        AddTreeFromPixelPosition(x, y, treeInfo);
                    }
                }

                Thread.Sleep(20);
            }
        }
Exemplo n.º 13
0
        public override void Start()
        {
            float y = 0.0f;

            treeCol = GameObject.FindObjectOfType <TreeCollection>();
            string[] items = new string[treeCol.m_prefabs.Length + 1];
            items[0] = "Use Random Trees";
            for (int n = 0; n < treeCol.m_prefabs.Length; n++)
            {
                items[n + 1] = treeCol.m_prefabs[n].name;
            }

            TerrainUI.MakeDropDown(this, y, "Tree Type", items, listbox_eventClick);
            y += 50;

            followCheckbox = TerrainUI.MakeCheckBox(this, "Follow Resources", y, followcb_eventClick, "Use forest resources to place trees. If unchecked trees are placed randomly.");
            y += 30;

            insideCheckbox = TerrainUI.MakeCheckBox(this, "Only inside game area.", y, insidecb_eventClick, "Do not place trees outside the center 25 tiles.");
            y += 30;

            TerrainUI.MakeSlider(this, "DensitySlider", "Max Density", y, density, 1.0f, 64.0f, 1.0f, value => { density = value; });
            y += 45;

            UILabel txt = AddUIComponent <UILabel>();

            txt.text             = "Please Note: It can take a couple\nof minutes for the trees\nto show on the map.";
            txt.name             = "TreePlacementInfoText";
            txt.relativePosition = new Vector3(15.0f, y);
            txt.textScale        = 0.8f;
            txt.textColor        = new Color(.7f, .7f, .7f, 1f);
            txt.size             = new Vector2(200, 86);
            txt.autoSize         = false;
            txt.autoHeight       = false;

            okButton             = TerrainUI.MakeButton(this, "Create Trees", 10, 210, 110);
            okButton.eventClick += okButton_eventClick;

            delallButton             = TerrainUI.MakeButton(this, "Delete All", 140, 210, 90);
            delallButton.eventClick += delallButton_eventClick;
        }
Exemplo n.º 14
0
        public static IEnumerable <ITree <TSource> > ToTree <TSource, TKey>(this IEnumerable <TSource> source,
                                                                            Func <TSource, TKey> keySelector,
                                                                            Func <TSource, TKey> parentKeySelector)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (keySelector == null)
            {
                throw new ArgumentNullException(nameof(keySelector));
            }

            if (parentKeySelector == null)
            {
                throw new ArgumentNullException(nameof(parentKeySelector));
            }

            return(TreeCollection.CreateTree(source, keySelector, parentKeySelector));
        }
 public BackOfficeServerVariables(
     LinkGenerator linkGenerator,
     IRuntimeState runtimeState,
     UmbracoFeatures features,
     IOptionsMonitor <GlobalSettings> globalSettings,
     IUmbracoVersion umbracoVersion,
     IOptionsMonitor <ContentSettings> contentSettings,
     IHttpContextAccessor httpContextAccessor,
     TreeCollection treeCollection,
     IHostingEnvironment hostingEnvironment,
     IOptionsMonitor <RuntimeSettings> runtimeSettings,
     IOptionsMonitor <SecuritySettings> securitySettings,
     IRuntimeMinifier runtimeMinifier,
     IBackOfficeExternalLoginProviders externalLogins,
     IImageUrlGenerator imageUrlGenerator,
     PreviewRoutes previewRoutes,
     IEmailSender emailSender,
     IOptionsMonitor <MemberPasswordConfigurationSettings> memberPasswordConfigurationSettings)
     : this(
         linkGenerator,
         runtimeState,
         features,
         globalSettings,
         umbracoVersion,
         contentSettings,
         httpContextAccessor,
         treeCollection,
         hostingEnvironment,
         runtimeSettings,
         securitySettings,
         runtimeMinifier,
         externalLogins,
         imageUrlGenerator,
         previewRoutes,
         emailSender,
         memberPasswordConfigurationSettings,
         StaticServiceProvider.Instance.GetRequiredService <IOptionsMonitor <DataTypesSettings> >())
 {
 }
Exemplo n.º 16
0
        /// <summary>
        /// recrusively processes the xml file for breadcrumb nodes
        /// </summary>
        /// <param name="child">xml child node</param>
        /// <param name="tree">collection of breadcrumbs</param>
        private void ProcessChild(XmlNode child, TreeCollection <Breadcrumb>?tree)
        {
            if (child.NodeType != XmlNodeType.Element)
            {
                return;
            }

            var a    = child.Attributes?.GetNamedItem("Action");
            var c    = child.Attributes?.GetNamedItem("Controller");
            var f    = child.Attributes?.GetNamedItem("Fragment");
            var t    = child.Attributes?.GetNamedItem("Text");
            var type = child.Attributes?.GetNamedItem("Type")?.Value;

            if (a == null || c == null || t == null)
            {
                throw new XmlException("BreadCrumb node must contain 'Controller', 'Action', and 'Text' attributes");
            }

            var node = new Breadcrumb();

            if (type.IsNotBlank())
            {
                var actualType = Type.GetType(type);

                node = (Breadcrumb)this.serviceProvider.GetService(actualType !) !;
            }

            node.Action     = a.Value ?? string.Empty;
            node.Controller = c.Value ?? string.Empty;
            node.Text       = t.Value ?? string.Empty;
            node.Fragment   = f?.Value ?? string.Empty;

            tree = tree == null ? (this.root = new TreeCollection <Breadcrumb>(node)) : tree.AddChild(node);

            child.ChildNodes.Cast <XmlNode>()
            .ToList()
            .ForEach(n => this.ProcessChild(n, tree));
        }
Exemplo n.º 17
0
        public MainControlViewModel()
        {
            LoadedCommand = new DelegateCommand <RoutedEventArgs>(Loaded);

            TreeCollection.Add(new TreeViewModel {
                Name = "FileA.xml"
            });
            TreeCollection.Add(new TreeViewModel {
                Name = "FileB.xml"
            });
            TreeCollection.Add(new TreeViewModel {
                Name = "FileC.xml"
            });
            TreeCollection.Add(new TreeViewModel {
                Name = "FileD.xml"
            });
            TreeCollection.Add(new TreeViewModel {
                Name = "FileE.xml"
            });
            TreeCollection.Add(new TreeViewModel {
                Name = "FileF.xml"
            });
            TreeCollection.Add(new TreeViewModel {
                Name = "FileG.xml"
            });
            TreeCollection.Add(new TreeViewModel {
                Name = "FileH.xml"
            });
            TreeCollection.Add(new TreeViewModel {
                Name = "FileI.xml"
            });
            TreeCollection.Add(new TreeViewModel {
                Name = "FileJ.xml"
            });
            TreeCollection.Add(new TreeViewModel {
                Name = "FileK.xml"
            });
        }
Exemplo n.º 18
0
        private static IEnumerable <TreeEntry> Traverse(TreeCollection collection)
        {
            var stack = new Stack <TreeEntry>();

            PushChildren(collection);
            while (stack.Count > 0)
            {
                var current = stack.Pop();
                yield return(current);

                if (current.Entry is TreeCollection children)
                {
                    PushChildren(children);
                }
            }

            void PushChildren(TreeCollection entries)
            {
                foreach (var child in entries)
                {
                    stack.Push(child);
                }
            }
        }
Exemplo n.º 19
0
        public void DoTrees(bool follow, int treeNum, bool inside25, int density)
        {
            SquareDiamond sd;

            if (follow)
            {
                sd = sdResources;
            }
            else
            {
                sd = new SquareDiamond(512, new System.Random());
                sd.Generate(9, 1.0, SquareDiamond.InitMode.INIT_RANDOM, SquareDiamond.InitMode.INIT_RANDOM, SquareDiamond.InitMode.INIT_RANDOM, SquareDiamond.InitMode.INIT_RANDOM);
                sd.Blur(3);
            }

            TreeInfo tree;
            NaturalResourceManager m  = NaturalResourceManager.instance;
            TreeCollection         tc = GameObject.FindObjectOfType <TreeCollection>();
            int numTrees = tc.m_prefabs.Length;

            // TODO: Do something with TerrainManager.instance.GetShorePos() and HasWater()

            int start = 0;
            int end   = 512;

            if (inside25 == true)
            {
                // Create trees only inside center 25 tiles.
                start = (512 / 9) * 2;
                end   = 512 - (512 / 9) * 2;
            }

            int matches = 0;

            for (int y = start; y < end; y++)
            {
                for (int x = start; x < end; x++)
                {
                    int    pos = x * 512 + y;
                    double pt  = sd.Point(x, y);
                    if (follow ? m.m_naturalResources[pos].m_forest == 255 : (pt > 0.0 && pt < 0.5))
                    {
                        matches++;
                    }
                }
            }

            int max = TreeManager.MAX_MAP_TREES / matches > density ? density : TreeManager.MAX_MAP_TREES / matches;

            for (int y = start; y < end; y++)
            {
                for (int x = start; x < end; x++)
                {
                    int    pos = x * 512 + y;
                    double pt  = sd.Point(x, y);
                    if (follow ? m.m_naturalResources[pos].m_forest == 255 : (pt > 0.0 && pt < 0.5))
                    {
                        for (int n = 0; n < max; n++)
                        {
                            float xscale = 33.75f;                             // 540/16=33.75
                            float center = 270 * 32;
                            int   newx   = (int)(((float)x * xscale) - center + (frand() * xscale));
                            int   newy   = (int)(((float)y * xscale) - center + (frand() * xscale));

                            if (treeNum == 0)
                            {
                                tree = tc.m_prefabs[r.Next() & numTrees - 1];
                            }
                            else
                            {
                                tree = tc.m_prefabs[treeNum - 1];
                            }
                            SimulationManager.instance.AddAction(AddTree(newy, newx, SimulationManager.instance.m_randomizer, tree));
                        }
                    }
                }
            }
        }
Exemplo n.º 20
0
        static void Main()
        {
            Console.WriteLine();
            //Basic Overview understanding
#if false
            TestClassForBoxingAndUnboxing.UnboxTheRefType();
            TestClassForBoxingAndUnboxing.BoxTheValueType2(5);

            //Generic list<T> usage which ensures type safety
            ClassWithGenericList.MakeAGenericList(6);
            var classForListAdding = new ClassGenericListTest();
            var res = ClassAddingDifferentDataToList.AddDifferentTypeToGenericList("The string", 12, classForListAdding);
            Console.WriteLine(res.Item1.GetType());
            Console.WriteLine(res.Item2.GetType());
            Console.WriteLine(res.Item3.GetType());
            object o = "Some string";
            Console.WriteLine(o.GetType()); // prints System.String
#endif
            // Non generic linked list
#if false
            var linkedList = new NonGenericLinkedList();
            linkedList.AddLast(1);
            linkedList.AddLast(12);
            /*linkedList.AddLast("6");*/ // this gives us error because it cannot be converted to in the for each loop
            foreach (int item in linkedList)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();
#endif
            // generic linked list
#if false
            var listOfints = new GenericLinkedList <int>();
            listOfints.AddLast(21);
            //genLink.AddLast("Test") /*Nope, i can't be added the Linked list is type safe now which is now int with this instance*/
            foreach (int item in listOfints)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();

            var listOfStr = new GenericLinkedList <string>();
            listOfStr.AddLast("hello");

            foreach (string item in listOfStr)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();

            /**Note the class type an object you still be able to add things still unsafely */
            var listOfObjects = new GenericLinkedList <object>();

            /**Also note the first line is determining the type of all the entries. Not sure how is this behavior showing up   */
            listOfObjects.AddLast(12);
            listOfObjects.AddLast("TEst");

            foreach (var item in listOfObjects)
            {
                Console.Write(item + " ");
            }
#endif
            // generic inheritance
#if false
            var t = new Derived <string>();
            t.X = "Wohaha";
            t.Y = "hello";
            // t.Y = 13; /*error*/
            // t.X = 13; /*error*/
            var y = new DerivedWithDifferentBaseType <string, int>();
            y.PropInDerived = "Test dance";
            //y.PropInDerived = 12;/*error*/
            Console.WriteLine($"assignNull: {y.SetThedefaultVar(101)}, PropInDerived: { y.PropInDerived}");/**This is powerful stuff see how the parameter type in this very method is determined */
#endif
            //generic constrains

#if false
            //var u = new GenericClassWithInterFaceConstrain<string>(); /*Error since the string class does not implement the interface required */
            //var u = new GenericClassWithInterFaceConstrain<int>(); /*Error since the int class does not implement the interface required */
            //var u = new GenericClassWithInterFaceConstrain<object>(); /*Error since the object class does not implement the interface required */

            /**Tda it works now since the class does inherits the required interface */

            var u = new ConstrainStuff <TheHardWay, IShowText>();
            u.WonderLandString(u);
            u.R(u);

            //Partial specialization
            var g = new EnglisBook <int>();
            g.BName = "The heaven highway";
            g.Bpage = 1;
            g.PrintBookInfo(g);
#endif
            //static members in generics
#if false
            //var i = new StaticDemo<string>();
            //var s = new StaticDemo<int>();
            var i = StaticDemo <string> .x = 4; /*Note that the int and string are not have any affect on the field!!!, Because the field has its own type defined explicitly and that is int */
            var s = StaticDemo <int> .x = 4;    /*Note that the int and string are not have any affect on the field!!!, Because the field has its own type defined explicitly and that is int */
            Console.WriteLine("i: " + i.GetType());
            Console.WriteLine("s: " + s.GetType());
#endif
            // generic interfaces
#if false
            //StationCollection.PrintFakeChannels();

            //COVARIANCE with generic interfaces
            TreeCollection treesCollection = TreeCollection.GetTreeCollection();

            /** The magic of OUT keyword is to be seen in the next two lines*/

            IPlants <Flower> flower = treesCollection; /*Note how we are going form more specific to more general*/

            IPlants <Plant> plant = flower;            /*Note how we are going form more specific to more general*/

            for (int i = 0; i < plant.Count; i++)
            {
                /**Note you are calling the THIS[INT INDEX] method defined int the Flower class which RETURNS a Flower record AT INDEX I
                 * Each time a record is retrieved then the WRITELINE is and OFF-COURSE SINCE THE ARGUMENT TO IT IS A WHOLE OBJECT it goes to fire the overridden
                 * ToString that is defined in some class in the hierarchy!!! */
                Console.WriteLine(treesCollection[i]);
            }

            //CONTRA-VARIANCE with Generic Interfaces
            IAnimals <Animal>    quadruped         = Zoo.GetAnimalCollection();
            IAnimals <Quadruped> genericToSpecific = quadruped; //from more GENERIC TO more SPECIFIC

            Animal[] zoodata = Zoo.GetAnimal;
            quadruped.PrintPalntInfo(zoodata);
#endif
            //Nullable<int> i; ==> is same as int? i ;
#if false
            int?x1 = ATest.GetNullableType(12);
            int?x2 = ATest.GetNullableType(null);
            int?x3 = x1 + x2;
            Console.WriteLine("X3: " + (x3.HasValue ? x3.Value : x3.GetValueOrDefault()));
#endif
            //generic methods
#if false
            int i = 4;
            int j = 5;
            MethodPlaceHolder.Swap <int>(ref i, ref j);

            /**Note the LIst implement some interface and one of those is IEnumerable
             * which is the type of parameter of our method PrintAnimal
             * */
            var animalList = new List <Animal>()
            {
                new Animal {
                    Name = "A", Color = "B"
                },
                new Animal {
                    Name = "C", Color = "D"
                },
                new Animal {
                    Name = "E", Color = "F"
                }
            };
            //MethodPlaceHolder.PrintAnimalSimple(animalList);

            var sampleList = new List <MethodPlaceHolder>()
            {
                new MethodPlaceHolder {
                    Age = "A1", Height = 12
                },
                new MethodPlaceHolder {
                    Age = "A2", Height = 11
                },
                new MethodPlaceHolder {
                    Age = "A3", Height = 10
                },
            };

            MethodPlaceHolder.PrintAnimal1 <MethodPlaceHolder>(sampleList);

            var res = MethodPlaceHolder.PrintAnimal2 <MethodPlaceHolder, decimal>(sampleList, (sampleList, sum) => sum += sampleList.Height);
            Console.WriteLine(res);
#endif
            //generic methods specialization
#if true
            MethodSpecialisationePlaceHolder.Test1(12);
            MethodSpecialisationePlaceHolder.Test2 <int>(30);
            MethodSpecialisationePlaceHolder.Test2("Hello");              // The same method without type parameter
            MethodSpecialisationePlaceHolder.Test3 <int, float>(13, 12.0f);
            MethodSpecialisationePlaceHolder.Test3(13, 134.0f);           //The same method without type parameter
            MethodSpecialisationePlaceHolder.Test4 <string>("Test", 12);
            MethodSpecialisationePlaceHolder.Test4("Test2", 12);          //The same method without type parameter
            MethodSpecialisationePlaceHolder.YourSurprise <decimal>(12.000012m);
            MethodSpecialisationePlaceHolder.YourSurprise(12.000010002m); //The same method without type parameter
#endif

            Console.WriteLine();
        }
Exemplo n.º 21
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="TreeService" /> class.
 /// </summary>
 /// <param name="treeCollection"></param>
 public TreeService(TreeCollection treeCollection) => _treeCollection = treeCollection;
Exemplo n.º 22
0
        public FileTreeControlViewModel()
        {
            LoadedCommand = new DelegateCommand <RoutedEventArgs>(Loaded);

            TreeCollection.Add(new TreeViewModel
            {
                Name   = "FolderA",
                IsNode = true,
                Nodes  = new ObservableCollection <TreeViewModel>
                {
                    new TreeViewModel
                    {
                        Name   = "FileA.xml",
                        IsNode = false
                    },
                    new TreeViewModel
                    {
                        Name   = "FileB.xml",
                        IsNode = false
                    }
                }
            });

            var folderB = new TreeViewModel
            {
                Name   = "FolderB",
                IsNode = true
            };

            TreeCollection.Add(folderB);

            folderB.Nodes = new ObservableCollection <TreeViewModel>
            {
                new TreeViewModel
                {
                    Name   = "FolderA",
                    IsNode = true,
                    Parent = folderB
                },
                new TreeViewModel
                {
                    Name   = "FolderB",
                    IsNode = true,
                    Parent = folderB
                },
                new TreeViewModel
                {
                    Name   = "FileA.xml",
                    IsNode = false,
                    Parent = folderB,
                },
                new TreeViewModel
                {
                    Name   = "FileB.xml",
                    IsNode = false,
                    Parent = folderB,
                }
            };

            var folderB1 = ((ObservableCollection <TreeViewModel>)folderB.Nodes)[0];

            folderB1.Nodes = new ObservableCollection <TreeViewModel>
            {
                new TreeViewModel
                {
                    Name   = "FileA.xml",
                    IsNode = false,
                    Parent = folderB1
                },
                new TreeViewModel
                {
                    Name   = "FileB.xml",
                    IsNode = false,
                    Parent = folderB1
                }
            };

            var folderB2 = ((ObservableCollection <TreeViewModel>)folderB.Nodes)[1];

            folderB2.Nodes = new ObservableCollection <TreeViewModel>
            {
                new TreeViewModel
                {
                    Name   = "FileA.xml",
                    IsNode = false,
                    Parent = folderB2
                },
                new TreeViewModel
                {
                    Name   = "FileB.xml",
                    IsNode = false,
                    Parent = folderB2
                }
            };

            TreeCollection.AddRange(new List <TreeViewModel>
            {
                new TreeViewModel
                {
                    Name   = "FolderC",
                    IsNode = true
                },
                new TreeViewModel
                {
                    Name   = "FileA.xml",
                    IsNode = false
                },
                new TreeViewModel
                {
                    Name   = "FileB.xml",
                    IsNode = false
                }
            });
        }
Exemplo n.º 23
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            var result = Result.Succeeded;

            try
            {
                var ui_app = commandData.Application;
                var ui_doc = ui_app.ActiveUIDocument;
                var doc    = ui_doc.Document;

                var roomCollection = new FilteredElementCollector(doc)
                                     .OfCategory(BuiltInCategory.OST_Rooms)
                                     .WhereElementIsNotElementType()
                                     .Cast <Room>()
                                     .Where(x =>
                {
                    if (x.Location != null)
                    {
                        var zoneValue = x.LookupParameter(filteredParameterName)?.AsString();
                        if (!string.IsNullOrEmpty(zoneValue))
                        {
                            return(zoneValue.Contains(filteredParameterValue));
                        }
                    }
                    return(false);
                })
                                     .ToList();

                if (roomCollection.Count() > 0)
                {
                    var tree          = new TreeCollection(startGroupName, startTreeName, startIndex, ParametersLine);
                    var parameterName = tree.Parameters[0];
                    foreach (var room in roomCollection)
                    {
                        var collectionName = ParameterUtil.GetParameterValue(room, parameterName);
                        TreeCollectionWorker.AddElement(room, collectionName, tree);
                    }

                    var levelGroupName = tree.Parameters[1];
                    var appartmentType = tree.Parameters[3];
                    var collections    = tree.GetGroups(levelGroupName);
                    var sb             = new StringBuilder();
                    using (var tr = new Transaction(doc, "Помещения"))
                    {
                        tr.Start();
                        int counter = 1;

                        foreach (TreeCollection appartment in collections)
                        {
                            var            sortedAppList = appartment.Cast <TreeCollection>().OrderBy(x => x.Name);
                            TreeCollection temp          = null;
                            foreach (var app in sortedAppList)
                            {
                                var type = app.GetGroups(appartmentType).FirstOrDefault();
                                if (temp == null)
                                {
                                    temp = type;
                                }
                                else
                                {
                                    if (string.Compare(temp.Name, type.Name) == 0)
                                    {
                                        counter++;
                                        if (counter % 2 == 0)
                                        {
                                            var rooms    = app.GetElements().Cast <Element>();
                                            var room     = rooms.First();
                                            var subValue = ParameterUtil.GetParameterValue(room, subzoneId);
                                            ParameterUtil.SetValue(rooms, subzoneIndex, $"{subValue}.Полутон");
                                        }
                                    }
                                    else
                                    {
                                        counter = 1;
                                    }
                                    temp = type;
                                }
                            }
                        }
                        tr.Commit();
                    }
                }
            }
            catch (Exception ex)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine(ex.Message);
                sb.AppendLine();
                sb.AppendLine($"Тип ошибки {ex.GetType()}");
                sb.AppendLine();
                sb.AppendLine(ex.StackTrace);
                WPF.MessageBox.Show(sb.ToString());

                result = Result.Failed;
            }

            return(result);
        }