Exemple #1
0
        private static ComparableList <XenAPI.Network> NetworksProperty(IXenObject o)
        {
            var networks = new ComparableList <XenAPI.Network>();

            if (o is VM vm)
            {
                if (vm.is_a_real_vm() && vm.Connection != null)
                {
                    foreach (VIF vif in vm.Connection.ResolveAll(vm.VIFs))
                    {
                        XenAPI.Network network = vm.Connection.Resolve(vif.network);
                        if (network == null)
                        {
                            continue;
                        }

                        networks.Add(network);
                    }
                }
            }
            else if (o is XenAPI.Network network)
            {
                networks.Add(network);
            }

            return(networks);
        }
Exemple #2
0
        private static ComparableList <VDI> DisksProperty(IXenObject o)
        {
            var vdis = new ComparableList <VDI>();

            if (o.Connection == null)
            {
                return(vdis);
            }

            if (o is VDI theVdi)
            {
                vdis.Add(theVdi);
            }
            else if (o is VM vm)
            {
                if (vm.is_a_real_vm())
                {
                    foreach (VBD vbd in vm.Connection.ResolveAll(vm.VBDs))
                    {
                        VDI vdi = vbd.Connection.Resolve(vbd.VDI);
                        if (vdi != null && !vdis.Contains(vdi))
                        {
                            vdis.Add(vdi);
                        }
                    }
                }
            }

            return(vdis);
        }
Exemple #3
0
        public void CompareByIndices()
        {
            var list = new ComparableList <double>();

            list.Add(2.5);
            list.Add(2.6);

            Assert.Equal(0, list.Compare(0, 0));
            Assert.Equal(1, list.Compare(1, 0));
            Assert.Equal(-1, list.Compare(0, 1));
        }
    static void Main()
    {
        Console.WriteLine("Enter initial length");
        int length = int.Parse(Console.ReadLine());
        ComparableList<string> sentence = new ComparableList<string>(length);      //ComparableList<int> sentence = new ComparableList<int>(length);
        Console.WriteLine("Elements of ComparableList\r\n{0}", sentence.ToString());

        for (int count = 0; count < length; count++)
        {
            Console.WriteLine("Enter element to add");
            sentence.Add(Console.ReadLine());
            Console.WriteLine("Elements of ComparableList\r\n{0}", sentence.ToString());
        }

        Console.WriteLine("Enter element to insert");
        string insertElement = Console.ReadLine();
        Console.WriteLine("Enter position");
        int insertIndex = int.Parse(Console.ReadLine());
        sentence.Insert(insertIndex, insertElement);
        Console.WriteLine("Elements of ComparableList\r\n{0}", sentence.ToString());

        string min = sentence[0];
        string max = sentence[0];
        for (int position = 1; position < sentence.Count; position++)
        {
            min = sentence.Min(min, sentence[position]);
            max = sentence.Max(max, sentence[position]);
        }

        Console.WriteLine("The min element in ComparableList is {0}", min);
        Console.WriteLine("The max element in ComparableList is {0}", max);
    }
Exemple #5
0
        private static ComparableList <SR> StorageProperty(IXenObject o)
        {
            var srs = new ComparableList <SR>();

            if (o.Connection == null)
            {
                return(srs);
            }

            if (o is VM vm)
            {
                if (vm.is_a_real_vm())
                {
                    foreach (VBD vbd in vm.Connection.ResolveAll(vm.VBDs))
                    {
                        VDI vdi = vbd.Connection.Resolve(vbd.VDI);
                        if (vdi == null)
                        {
                            continue;
                        }

                        SR sr = vdi.Connection.Resolve(vdi.SR);
                        if (sr != null && !srs.Contains(sr))
                        {
                            srs.Add(sr);
                        }
                    }
                }
            }
            else if (o is SR sr)
            {
                srs.Add(sr);
            }
            else if (o is VDI vdi)
            {
                SR theSr = vdi.Connection.Resolve(vdi.SR);
                if (theSr == null)
                {
                    return(null);
                }

                srs.Add(theSr);
            }

            return(srs);
        }
Exemple #6
0
        public void GetByIndex()
        {
            var list = new ComparableList <decimal>();

            list.Add(1m);

            Assert.Equal(1m, list.Get(0));
        }
Exemple #7
0
        public void AddLengthChange()
        {
            var list = new ComparableList <int>();

            list.Add(1);

            Assert.Equal(1, list.Length());
        }
Exemple #8
0
        public void RemoveByIndex()
        {
            var list = new ComparableList <bool>();

            list.Add(false);

            list.Remove(0);

            Assert.Equal(0, list.Length());
        }
Exemple #9
0
        public static ComparableList <Folder> GetAncestorFolders(IXenObject o)
        {
            ComparableList <Folder> folders = new ComparableList <Folder>();

            for (Folder folder = GetFolder(o);
                 folder != null && !folder.IsRootFolder;
                 folder = folder.Parent)
            {
                folders.Add(folder);
            }

            return(folders);
        }
        private void FindUniqueTraces(ByteDcrGraph inputGraph, ComparableList<int> currentTrace)
        {
            //compare trace length with desired depth
            foreach (var activity in inputGraph.GetRunnableIndexes())
            {
                if (currentTrace.Count == 100)
                {
                    var test = 252354;
                }

                var inputGraphCopy = new ByteDcrGraph(inputGraph);
                var currentTraceCopy = new ComparableList<int>(currentTrace);

                inputGraphCopy.ExecuteActivity(activity);

                //add event to trace
                currentTraceCopy.Add(activity);

                if (ByteDcrGraph.IsFinalState(inputGraphCopy.State))
                {
                    _uniqueTraceSet.Add(currentTraceCopy);

                    if(_compareSet != null &&
                        (!_compareSet.Contains(currentTraceCopy)))
                    {
                        _comparisonResult = false;
                        return;
                    }
                }
                //if we have not seen the state before
                if (!_seenStates.Contains(inputGraphCopy.State))
                {
                    if (_compareStates != null
                        && !_compareStates.Contains(inputGraphCopy.StateWithNonRunnableActivitiesEqual(inputGraphCopy.State)))
                    {
                        _comparisonResult = false;
                        return;
                    }
                    _seenStates.Add(inputGraphCopy.State);
                    FindUniqueTraces(inputGraphCopy,currentTraceCopy);
                }
            }
        }
Exemple #11
0
        private static ComparableList <Host> HostProperty(IXenObject o)
        {
            var hosts = new ComparableList <Host>();

            if (o.Connection == null)
            {
                return(hosts);
            }

            // If we're not in a pool then just group everything under the same host
            Pool pool = Helpers.GetPool(o.Connection);

            if (pool == null)
            {
                hosts.AddRange(o.Connection.Cache.Hosts);
            }
            else if (o is VM vm)
            {
                Host host = vm.Home();
                if (host != null)
                {
                    hosts.Add(host);
                }
            }
            else if (o is SR sr)
            {
                Host host = sr.Home();
                if (host != null)
                {
                    hosts.Add(host);
                }
            }
            else if (o is XenAPI.Network network)
            {
                if (network.PIFs.Count == 0)
                {
                    hosts.AddRange(network.Connection.Cache.Hosts);
                }
            }
            else if (o is Host host)
            {
                hosts.Add(host);
            }
            else if (o is VDI vdi)
            {
                SR theSr = vdi.Connection.Resolve(vdi.SR);
                if (theSr != null)
                {
                    hosts.Add(theSr.Home());
                }
            }
            else if (o is DockerContainer container)
            {
                VM   parent   = container.Parent;
                Host homeHost = parent.Home();
                if (homeHost != null)
                {
                    hosts.Add(homeHost);
                }
            }

            return(hosts);
        }
Exemple #12
0
        private static ComparableList <VM> VMProperty(IXenObject o)
        {
            var vms = new ComparableList <VM>();

            if (o.Connection == null)
            {
                return(vms);
            }

            if (o is Pool)
            {
                vms.AddRange(o.Connection.Cache.VMs);
            }
            else if (o is Host host)
            {
                vms.AddRange(host.Connection.ResolveAll(host.resident_VMs));
            }
            else if (o is SR sr)
            {
                foreach (VDI vdi in sr.Connection.ResolveAll(sr.VDIs))
                {
                    foreach (VBD vbd in vdi.Connection.ResolveAll(vdi.VBDs))
                    {
                        VM vm = vbd.Connection.Resolve(vbd.VM);
                        if (vm == null)
                        {
                            continue;
                        }

                        vms.Add(vm);
                    }
                }
            }
            else if (o is XenAPI.Network network)
            {
                foreach (VIF vif in network.Connection.ResolveAll(network.VIFs))
                {
                    VM vm = vif.Connection.Resolve(vif.VM);
                    if (vm == null)
                    {
                        continue;
                    }

                    vms.Add(vm);
                }
            }
            else if (o is VDI vdi)
            {
                foreach (VBD vbd in vdi.Connection.ResolveAll(vdi.VBDs))
                {
                    VM vm = vbd.Connection.Resolve(vbd.VM);
                    if (vm == null)
                    {
                        continue;
                    }

                    vms.Add(vm);
                }
            }
            else if (o is VM vm)
            {
                if (vm.is_a_snapshot)
                {
                    VM from = vm.Connection.Resolve(vm.snapshot_of);
                    if (from != null)  // Can be null if VM has been deleted: CA-29249
                    {
                        vms.Add(from);
                    }
                }
                else
                {
                    vms.Add(vm);
                }
            }
            else if (o is DockerContainer container)
            {
                vms.Add(container.Parent);
            }

            vms.RemoveAll(vm => !vm.is_a_real_vm());
            return(vms);
        }
Exemple #13
0
        private static ComparableList <ComparableAddress> IPAddressProperty(IXenObject o)
        {
            var addresses = new ComparableList <ComparableAddress>();

            if (o.Connection == null)
            {
                return(addresses);
            }

            if (o is VM vm)
            {
                if (!vm.is_a_real_vm())
                {
                    return(addresses);
                }

                VM_guest_metrics metrics = vm.Connection.Resolve(vm.guest_metrics);
                if (metrics == null)
                {
                    return(null);
                }

                List <VIF> vifs = vm.Connection.ResolveAll(vm.VIFs);

                foreach (VIF vif in vifs)
                {
                    foreach (var value in Helpers.FindIpAddresses(metrics.networks, vif.device))
                    {
                        if (ComparableAddress.TryParse(value, false, true, out var ipAddress))
                        {
                            addresses.Add(ipAddress);
                        }
                    }
                }

                addresses = new ComparableList <ComparableAddress>(addresses.Distinct());
            }
            else if (o is Host host)
            {
                foreach (PIF pif in host.Connection.ResolveAll(host.PIFs))
                {
                    if (ComparableAddress.TryParse(pif.IP, false, true, out var ipAddress))
                    {
                        addresses.Add(ipAddress);
                    }
                }
            }
            else if (o is SR sr)
            {
                string target = sr.Target();
                if (!string.IsNullOrEmpty(target))
                {
                    if (ComparableAddress.TryParse(target, false, true, out var ipAddress))
                    {
                        addresses.Add(ipAddress);
                    }
                }
            }

            return(addresses.Count == 0 ? null : addresses);   // CA-28300
        }
        private void ComposeVMData()
        {
            m_VMs = new List<VMInfo>();
            var VMs = new List<XenAPI.VM>(Connection.Cache.VMs);
            VMs.Sort();
            foreach (XenAPI.VM vm in VMs)
            {
                string OSinfo = vm.GetOSName();
                string srInfo = "";
                string MacInfo = "";
                string running_on = Messages.HYPHEN;

                if (Cancelling)
                    throw new CancelledException();

                if (!vm.is_a_real_vm)
                {
                    PercentComplete = Convert.ToInt32((++itemIndex) * baseIndex / itemCount);
                    continue;
                }

                ComparableList<ComparableAddress> addresses = new ComparableList<ComparableAddress>();
                if (vm.guest_metrics != null && !string.IsNullOrEmpty(vm.guest_metrics.opaque_ref) && !(vm.guest_metrics.opaque_ref.ToLower().Contains("null")))
                {
                    VM_guest_metrics metrics = vm.Connection.Resolve(vm.guest_metrics);

                    List<VIF> vifs = vm.Connection.ResolveAll(vm.VIFs);
                    foreach (VIF vif in vifs)
                    {
                        MacInfo += vif.MAC + " ";
                        foreach (var network in metrics.networks.Where(n => n.Key.StartsWith(String.Format("{0}/ip", vif.device))))
                        {
                            ComparableAddress ipAddress;
                            if (!ComparableAddress.TryParse(network.Value, false, true, out ipAddress))
                                continue;

                            addresses.Add(ipAddress);
                        }
                    }
                }
                if (MacInfo.Length == 0)
                    MacInfo = Messages.HYPHEN;

                foreach (XenRef<VBD> vbdRef in vm.VBDs)
                {
                    var vbd = vm.Connection.Resolve(vbdRef);
                    if (vbd != null && !vbd.IsCDROM && !vbd.IsFloppyDrive && vbd.bootable)
                    {
                        VDI vdi = vm.Connection.Resolve(vbd.VDI);
                        srInfo += vdi.name_label + ":" + vdi.SizeText + ";";
                    }
                }
                if (srInfo.Length == 0)
                    srInfo = Messages.HYPHEN;

                if (vm.resident_on != null && !string.IsNullOrEmpty(vm.resident_on.opaque_ref) && !(vm.resident_on.opaque_ref.ToLower().Contains("null")))
                {
                    running_on = vm.Connection.Resolve(vm.resident_on).Name;
                }

                string default_template_name = Messages.HYPHEN;
                if(vm.other_config.ContainsKey("base_template_name"))
                    default_template_name = vm.other_config["base_template_name"];

                VMInfo buf = new VMInfo(vm.Name, vm.uuid, PropertyAccessorHelper.vmCpuUsageStringByMetric(vm, MetricUpdater),
                    PropertyAccessorHelper.vmMemoryUsagePercentageStringByMetric(vm, MetricUpdater), srInfo, Convert.ToString(vm.VIFs.Count),
                    Convert.ToString(addresses), MacInfo, OSinfo, Convert.ToString(vm.power_state),
                    Convert.ToString(vm.RunningTime), running_on, default_template_name, vm.Description);

                m_VMs.Add(buf);

                PercentComplete = Convert.ToInt32((++itemIndex) * baseIndex / itemCount);
            }
        }
        private void ComposeVMData()
        {
            m_VMs = new List <VMInfo>();
            var VMs = new List <XenAPI.VM>(Connection.Cache.VMs);

            VMs.Sort();
            foreach (XenAPI.VM vm in VMs)
            {
                string OSinfo     = vm.GetOSName();
                string srInfo     = "";
                string MacInfo    = "";
                string running_on = Messages.HYPHEN;

                if (Cancelling)
                {
                    throw new CancelledException();
                }

                if (!vm.is_a_real_vm())
                {
                    PercentComplete = Convert.ToInt32((++itemIndex) * baseIndex / itemCount);
                    continue;
                }

                ComparableList <ComparableAddress> addresses = new ComparableList <ComparableAddress>();
                if (vm.guest_metrics != null && !string.IsNullOrEmpty(vm.guest_metrics.opaque_ref) && !(vm.guest_metrics.opaque_ref.ToLower().Contains("null")))
                {
                    VM_guest_metrics metrics = vm.Connection.Resolve(vm.guest_metrics);

                    List <VIF> vifs = vm.Connection.ResolveAll(vm.VIFs);
                    foreach (VIF vif in vifs)
                    {
                        MacInfo += vif.MAC + " ";
                        foreach (var network in metrics.networks.Where(n => n.Key.StartsWith(String.Format("{0}/ip", vif.device))))
                        {
                            ComparableAddress ipAddress;
                            if (!ComparableAddress.TryParse(network.Value, false, true, out ipAddress))
                            {
                                continue;
                            }

                            addresses.Add(ipAddress);
                        }
                    }
                }
                addresses = new ComparableList <ComparableAddress>(addresses.Distinct());
                if (MacInfo.Length == 0)
                {
                    MacInfo = Messages.HYPHEN;
                }

                foreach (XenRef <VBD> vbdRef in vm.VBDs)
                {
                    var vbd = vm.Connection.Resolve(vbdRef);
                    if (vbd != null && !vbd.IsCDROM() && !vbd.IsFloppyDrive() && vbd.bootable)
                    {
                        VDI vdi = vm.Connection.Resolve(vbd.VDI);
                        srInfo += vdi.name_label + ":" + vdi.SizeText() + ";";
                    }
                }
                if (srInfo.Length == 0)
                {
                    srInfo = Messages.HYPHEN;
                }

                if (vm.resident_on != null && !string.IsNullOrEmpty(vm.resident_on.opaque_ref) && !(vm.resident_on.opaque_ref.ToLower().Contains("null")))
                {
                    running_on = vm.Connection.Resolve(vm.resident_on).Name();
                }

                string default_template_name = Messages.HYPHEN;
                if (vm.other_config.ContainsKey("base_template_name"))
                {
                    default_template_name = vm.other_config["base_template_name"];
                }

                VMInfo buf = new VMInfo(vm.Name(), vm.uuid, PropertyAccessorHelper.vmCpuUsageStringByMetric(vm, MetricUpdater),
                                        PropertyAccessorHelper.vmMemoryUsagePercentageStringByMetric(vm, MetricUpdater), srInfo, Convert.ToString(vm.VIFs.Count),
                                        Convert.ToString(addresses), MacInfo, OSinfo, Convert.ToString(vm.power_state),
                                        Convert.ToString(vm.RunningTime()), running_on, default_template_name, vm.Description());

                m_VMs.Add(buf);

                PercentComplete = Convert.ToInt32((++itemIndex) * baseIndex / itemCount);
            }
        }
        public static void Main(string[] args)
        {
            // colectii orientate pe obiect - care contin doar object, ele pot fi eterogene ca tip de date

            #region ArrayList
            // ArrayList contine doar object
            ArrayList arrayList = new ArrayList();
            arrayList.Add(100);
            string str = "Decebal";
            arrayList.Add(str);
            arrayList.AddRange(new object[] { 1, "fulala", 'c' });

            foreach (var element in arrayList)
            {
                Console.WriteLine(element);
            }

            // accesarea unui element in ArrayList
            object obj = arrayList[2];

            /*
             * // sort nu merge pe un ArrayList eterogen (adica int, string, object etc.), caci nu are cum sa ii compare
             * arrayList.Sort();
             * int index = arrayList.BinarySearch(str);
             * Console.WriteLine(index);
             */

            arrayList.Clear();
            arrayList.Add(42);
            arrayList.Add(124);
            arrayList.Add(10);
            arrayList.Add(420);
            Console.WriteLine("Unsorted");
            foreach (var element in arrayList)
            {
                Console.WriteLine(element);
            }
            // aici merge sortat arrayList, este omogen acum
            arrayList.Sort();
            Console.WriteLine("Sorted");
            foreach (var element in arrayList)
            {
                Console.WriteLine(element);
            }
            Console.WriteLine();
            #endregion

            #region Stack - objects only
            // Stack - aici putem avea doar obiecte
            Stack st1 = new Stack();
            st1.Push(1);
            st1.Push('c');
            st1.Push("C# rullz");
            var top = st1.Peek();
            Console.WriteLine("Top of the stack: " + top);
            while (st1.Count != 0)
            {
                Console.WriteLine("We popped: " + st1.Pop());
            }
            Console.WriteLine();
            #endregion

            #region Queue - objects only
            Queue q1 = new Queue();
            q1.Enqueue(1);
            q1.Enqueue(new object());
            q1.Enqueue("C# beats Java");
            top = q1.Peek();
            Console.WriteLine("Top of the queue: " + top);
            while (q1.Count != 0)
            {
                Console.WriteLine("We dequeued: " + q1.Dequeue());
            }
            Console.WriteLine();
            #endregion

            #region Hashtable
            Hashtable hashtable = new Hashtable();
            hashtable['c'] = 250;
            object c = hashtable['c'];
            hashtable[23]          = "C# is da best";
            hashtable["something"] = "ceva";
            hashtable.Remove(23);

            Console.WriteLine("\nIterating through hashtable...");
            foreach (DictionaryEntry elem in hashtable)
            {
                Console.WriteLine(elem.Key + ": " + elem.Value);
            }

            #region SortedList
            // aici cheile trebuie sa fie de acelasi tip
            SortedList sortedList = new SortedList();
            sortedList['c'] = 'p';
            sortedList.Add('a', 42);
            sortedList.Remove('a');
            sortedList['a'] = "ceva";
            // exemplele de mai jos nu merg, pentru ca avem cheie de tip int, mai sus avem elemente cu cheie de tip char
            // sortedList.Add(1, 2);
            // sortedList[34] = 12;
            Console.WriteLine(sortedList.Count);

            Console.WriteLine("\nIterating through sorted list...");
            foreach (DictionaryEntry elem in sortedList)
            {
                Console.WriteLine(elem.Key + ": " + elem.Value);
            }
            #endregion

            #region BitArray
            // array de biti (0/1)
            BitArray bitArray = new BitArray(3); // trebuie mentionata capacitatea, se comporta fix ca un array de biti
            bitArray[0] = true;
            bitArray[1] = false;
            bitArray[2] = bitArray[1] ^ bitArray[0]; // xor

            Console.WriteLine("\nIterating through bit array...");
            foreach (var elem in bitArray)
            {
                Console.WriteLine(elem);
            }
            #endregion

            #endregion
            // colectii generice - tipizate

            #region List
            List <int> integersList = new List <int>();
            integersList.Add(1);
            integersList.AddRange(new int[] { 2, 3, 4, 5 });
            integersList.Remove(4);
            integersList.Sort();
            Console.WriteLine("\nIterating through list...");
            foreach (var elem in integersList)
            {
                Console.WriteLine(elem);
            }

            integersList.Sort(new MyCompare());
            Console.WriteLine("\nIterating through reversed list...");
            foreach (var elem in integersList)
            {
                Console.WriteLine(elem);
            }

            ComparableList <int> comparableList = new ComparableList <int>();
            comparableList.Add(5);
            comparableList.Add(8);
            comparableList.Add(1);
            comparableList.Add(20);
            comparableList.Add(3);

            Console.WriteLine("\nIterating to unsorted Comparable list...");
            foreach (var elem in comparableList)
            {
                Console.WriteLine(elem);
            }

            comparableList.Sort();

            Console.WriteLine("\nIterating to sorted Comparable list...");
            foreach (var elem in comparableList)
            {
                Console.WriteLine(elem);
            }

            #endregion

            #region Predicate + Action
            // Folosirea de Predicate, care de fapt e o functie booleana
            List <int> greaterThan3 = integersList.FindAll(x => x > 3); // putem folosi

            // Action - se paseaza o metoda de tip void - lista se modifica in place
            greaterThan3.ForEach(Increment);
            #endregion

            #region LinkedList
            LinkedList <string> linkedList = new LinkedList <string>();
            linkedList.AddFirst("first");                              // adaugam la capul listei
            linkedList.AddLast("last");                                // adaugam la coada listei
            linkedList.AddAfter(linkedList.First, "second");           // adaugarea dupa un nod din lista inlantuita
            linkedList.AddBefore(linkedList.Last, "not last element"); // adaugarea inaintea unui nod din lista

            Console.WriteLine("\nIterating through linked list...");
            foreach (var node in linkedList)
            {
                Console.WriteLine(node);
            }
            #endregion

            #region Generic Stack
            Stack <int> stack = new Stack <int>();
            stack.Push(1);
            stack.Push(5);
            stack.Pop();
            int front = stack.Peek();
            #endregion

            #region Generic Queue
            Queue <int> queueInt = new Queue <int>();
            queueInt.Enqueue(42);
            queueInt.Enqueue(41);
            front = queueInt.Dequeue();
            #endregion

            #region Dictionary
            Dictionary <int, string> dict1 = new Dictionary <int, string>();
            dict1.Add(69, "ayyy");
            dict1.Add(420, "weeeeed");
            dict1.Remove(12);
            dict1.Remove(69);
            dict1[42] = "pwpik";
            Console.WriteLine("\nIterating through dictionary...");

            foreach (KeyValuePair <int, string> elem in dict1)
            {
                Console.WriteLine(elem.Key + ": " + elem.Value);
            }
            #endregion

            #region SortedDictionary
            SortedDictionary <int, string> dict2 = new SortedDictionary <int, string>();
            dict2.Add(69, "ayyy");
            dict2.Add(420, "weeeeed");
            dict2.Remove(12);
            dict2.Remove(69);
            dict2[42] = "pwpik";
            dict2[12] = "mwah";
            Console.WriteLine("\nIterating through sorted dictionary...");

            foreach (KeyValuePair <int, string> elem in dict2)
            {
                Console.WriteLine(elem.Key + ": " + elem.Value);
            }
            #endregion

            #region SortedList
            SortedList <int, string> dict3 = new SortedList <int, string>();
            dict3.Add(69, "ayyy");
            dict3.Add(420, "weeeeed");
            dict3.Remove(12);
            dict3.Remove(69);
            dict3[42] = "pwpik";
            dict3[12] = "mwah";
            Console.WriteLine("\nIterating through generic sorted list...");

            foreach (KeyValuePair <int, string> elem in dict3)
            {
                Console.WriteLine(elem.Key + ": " + elem.Value);
            }
            #endregion

            // colectii specializate
            #region StringCollection
            StringCollection stringCollection = new StringCollection();
            stringCollection.Add("ayy");
            stringCollection.Add("ceva");
            stringCollection.Add("auuuuch");
            stringCollection[1] = "altceva";
            stringCollection.RemoveAt(2);
            #endregion

            #region StringDictionary
            StringDictionary stringDictionary = new StringDictionary();
            stringDictionary.Add("first", "ayy");
            stringDictionary.Add("second", "altceva");
            stringDictionary["third"] = "ceva, dar mai altceva";

            Console.WriteLine("\nIterating through stringDictionary...");
            foreach (DictionaryEntry elem in stringDictionary)
            {
                Console.WriteLine(elem.Key + ": " + elem.Value);
            }
            #endregion

            #region NameValueCollection
            NameValueCollection collection = new NameValueCollection();
            collection.Add("ceva", "altceva");
            collection.Add("ceva", "inca ceva");
            collection.Add("ceva", "69");
            collection.Add("altceva", "nimic");

            Console.WriteLine("\nIterating through NameValueCollection...");
            foreach (string elem in collection)
            {
                Console.WriteLine(elem + ": " + collection.Get(elem));
            }
            #endregion
        }
Exemple #17
0
        public static ComparableList<Folder> GetAncestorFolders(IXenObject o)
        {
            ComparableList<Folder> folders = new ComparableList<Folder>();

            for (Folder folder = GetFolder(o);
                folder != null && !folder.IsRootFolder;
                folder = folder.Parent)
            {
                folders.Add(folder);
            }

            return folders;
        }