Example #1
0
        public static void dictionaryIteration()
        {
            Console.WriteLine("# Dictionary Iteration Sample");

            Dictionary<Int32, String> map = new Dictionary<Int32, String>();
            map[10] = "Hello";
            map[20] = "Lorem";
            map[30] = "Ipsum";

            Dictionary<Int32, String>.Enumerator iterator = map.GetEnumerator();
            while (iterator.MoveNext())
            {
                KeyValuePair<Int32, String> pair = iterator.Current;
                Console.WriteLine(pair.Key + " : " + pair.Value);
            }

            IEnumerator<KeyValuePair<Int32, String>> iterator2 = map.GetEnumerator();
            while (iterator2.MoveNext())
            {
                KeyValuePair<Int32, String> pair = iterator2.Current;
                Console.WriteLine(pair.Key + " : " + pair.Value);
            }

            foreach (KeyValuePair<Int32, String> pair in map)
            {
                Console.WriteLine(pair.Key + " : " + pair.Value);
            }
        }
Example #2
0
        public Task Run()
        {
            var allTestMethods = testMethodExtractor.GetTestMethods();

            var testMethodsDistribution = new Dictionary<ITestRunner, IList<IMethodInfo>>();
            foreach (var runner in testRunners)
            {
                testMethodsDistribution.Add(runner, new List<IMethodInfo>());
            }

            var testMethodsDistributionEnum = testMethodsDistribution.GetEnumerator();
            foreach (var testMethod in allTestMethods)
            {
                KeyValuePair<ITestRunner, IList<IMethodInfo>> distribution;

                if (testMethodsDistributionEnum.MoveNext())
                {
                    distribution = testMethodsDistributionEnum.Current;
                }
                else
                {
                    testMethodsDistributionEnum = testMethodsDistribution.GetEnumerator();
                    testMethodsDistributionEnum.MoveNext();
                    distribution = testMethodsDistributionEnum.Current;
                }

                distribution.Value.Add(testMethod);
            }

            var allRunnersTasks = testMethodsDistribution.Select(r=>r.Key.Run(r.Value.ToArray()));

            return Task.Factory.StartNew( () => Task.WaitAll(allRunnersTasks.ToArray()));
        }
Example #3
0
 public void foo()
 {
     long n = long.Parse(Console.ReadLine());
     string[] sp = Console.ReadLine().Split(' ');
     Dictionary<long, long> dict = new Dictionary<long, long>();
     for (long i = 0; i < n; i++)
     {
         long a = long.Parse(sp[i]);
         if (dict.ContainsKey(a))
         {
             dict[a]++;
         }
         else
         {
             dict.Add(a, 1);
         }
     }
     Dictionary<long, long> dict1 = new Dictionary<long, long>();
     var e = dict.GetEnumerator();
     while (e.MoveNext())
     {
         var p = e.Current;
         dict1.Add(p.Key, p.Value);
     }
     sp = Console.ReadLine().Split(' ');
     for (long i = 0; i < n - 1; i++)
     {
         long a = long.Parse(sp[i]);
         dict[a]--;
         if (dict[a] == 0)
             dict.Remove(a);
     }
     e = dict.GetEnumerator();e.MoveNext();
     Console.WriteLine(e.Current.Key);
     dict1[e.Current.Key]--;
     if (dict1[e.Current.Key] == 0)
         dict1.Remove(e.Current.Key);
     sp = Console.ReadLine().Split(' ');
     for (long i = 0; i < n - 2; i++)
     {
         long a = long.Parse(sp[i]);
         dict1[a]--;
         if (dict1[a] == 0)
             dict1.Remove(a);
     }
     e = dict1.GetEnumerator();e.MoveNext();
     Console.WriteLine(e.Current.Key);
 }
 public bool PosTest1()
 {
     bool retVal = true;
     TestLibrary.TestFramework.BeginScenario("Return the property get_Entry in the IDictionaryEnumerator 1");
     try
     {
         Dictionary<string, string> dictionary = new Dictionary<string, string>();
         dictionary.Add("str1", "helloworld");
         Dictionary<string, string>.Enumerator enumer = dictionary.GetEnumerator();
         IDictionaryEnumerator idicEnumer = (IDictionaryEnumerator)enumer;
         if (idicEnumer.MoveNext())
         {
             DictionaryEntry entryVal = idicEnumer.Entry;
             if (entryVal.Key.ToString() != "str1" || entryVal.Value.ToString() != "helloworld")
             {
                 TestLibrary.TestFramework.LogError("001", "the ExpectResult is not the ActualResult");
                 retVal = false;
             }
         }
     }
     catch (Exception e)
     {
         TestLibrary.TestFramework.LogError("002", "Unexpect exception:" + e);
         retVal = false;
     }
     return retVal;
 }
 public bool PosTest2()
 {
     bool retVal = true;
     TestLibrary.TestFramework.BeginScenario("Return the property get_Current in the IEnumerator 2");
     try
     {
         Dictionary<TestClass, TestClass> dictionary = new Dictionary<TestClass, TestClass>();
         TestClass Tkey1 = new TestClass();
         TestClass TVal1 = new TestClass();
         dictionary.Add(Tkey1, TVal1);
         Dictionary<TestClass, TestClass>.Enumerator enumer = dictionary.GetEnumerator();
         IEnumerator iEnumer = (IEnumerator)enumer;
         while(iEnumer.MoveNext())
         {
             object objCurrent = iEnumer.Current;
             KeyValuePair<TestClass, TestClass> keyVal = new KeyValuePair<TestClass, TestClass>(Tkey1, TVal1);
             if (!objCurrent.Equals(keyVal))
             {
                 TestLibrary.TestFramework.LogError("003", "the ExpectResult is not the ActualResult");
                 retVal = false;
             }
         }
     }
     catch (Exception e)
     {
         TestLibrary.TestFramework.LogError("004", "Unexpect exception:" + e);
         retVal = false;
     }
     return retVal;
 }
Example #6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="url"></param>
        /// <param name="referer"></param>
        /// <returns></returns>
        protected HttpWebRequest PostRequest(string url, string referer, Dictionary<string,string> prams)
        {
            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
            req.Proxy = Proxy;
            req.AllowAutoRedirect = false;
            req.UserAgent = ConstData.UserAgent;
            req.Referer = referer;
            req.Headers.Add("Cookie", Cookie);
            req.Timeout = 30 * 1000;

            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";

            System.Text.StringBuilder sb = new StringBuilder();
            Dictionary<string, string>.Enumerator e = prams.GetEnumerator();
            while (e.MoveNext())
            {
                sb.AppendFormat("{0}={1}&", e.Current.Key, e.Current.Value);
            }
            req.ContentLength = System.Text.Encoding.UTF8.GetByteCount(sb.ToString());
            using(System.IO.StreamWriter sw = new System.IO.StreamWriter(req.GetRequestStream()))
            {            
                sw.Write(sb.ToString());
            }

            return req;
        }
 public bool PosTest1()
 {
     bool retVal = true;
     TestLibrary.TestFramework.BeginScenario("PosTest1:Invoke the method GetEnumerator in ValueCollection Generic IEnumerable 1");
     try
     {
         Dictionary<string, string> dic = new Dictionary<string, string>();
         dic.Add("str1", "Test1");
         dic.Add("str2", "Test2");
         IEnumerable<string> ienumer = (IEnumerable<string>)new Dictionary<string, string>.ValueCollection(dic);
         IEnumerator<string> ienumerator = ienumer.GetEnumerator();
         Dictionary<string, string>.Enumerator dicEnumer = dic.GetEnumerator();
         while (ienumerator.MoveNext() && dicEnumer.MoveNext())
         {
             if (!ienumerator.Current.Equals(dicEnumer.Current.Value))
             {
                 TestLibrary.TestFramework.LogError("001", "the ExpecResult is not the ActualResult");
                 retVal = false;
             }
         }
     }
     catch (Exception e)
     {
         TestLibrary.TestFramework.LogError("002", "Unexpect exception:" + e);
         retVal = false;
     }
     return retVal;
 }
Example #8
0
        public void foo()
        {
            int q = int.Parse(Console.ReadLine());

            Dictionary<string, string> ch = new Dictionary<string, string>();
            for (int i = 0; i < q; i++)
            {
                string[] sp = Console.ReadLine().Split(' ');
                string o = sp[0];
                string n = sp[1];

                if (ch.ContainsKey(o))
                {
                    ch.Add(n, ch[o]);
                    ch.Remove(o);
                }
                else
                {
                    ch.Add(n, o);
                }
            }

            Console.WriteLine(ch.Count);
            Dictionary<string, string>.Enumerator e = ch.GetEnumerator();
            while(e.MoveNext())
            {
                Console.WriteLine(e.Current.Value + " " + e.Current.Key);
            }
        }
     public JSONStructIterator(JSONEntry oEntry)
     {
 	    m_object = oEntry.getObject();
         m_enumStruct = m_object.GetEnumerator();
         if (m_enumStruct.MoveNext())
             m_strCurKey = m_enumStruct.Current.Key;
     }
Example #10
0
     public JSONStructIterator(JSONEntry oEntry, String strName)
     {
 	    m_object = (Dictionary<string, object>)oEntry.getObject(strName);
         m_enumStruct = m_object.GetEnumerator();
         if (m_enumStruct.MoveNext())
             m_strCurKey = m_enumStruct.Current.Key;
     }
 private void SetFunctions(Dictionary<string, int> functions)
 {
   this.m_FunctionsListInputData.m_ListElements.Clear();
   if (functions == null)
     this.m_FunctionsListInputData.NewOrMatchingElement("Querying instrumentable functions...").enabled = false;
   else if (functions.Count == 0)
   {
     this.m_FunctionsListInputData.NewOrMatchingElement("No instrumentable child functions found").enabled = false;
   }
   else
   {
     this.m_FunctionsListInputData.m_MaxCount = Mathf.Clamp(functions.Count + 1, 0, 30);
     if (this.m_ShowAllCheckbox)
     {
       this.m_AllCheckbox = new PopupList.ListElement(" All", false, float.MaxValue);
       this.m_FunctionsListInputData.m_ListElements.Add(this.m_AllCheckbox);
     }
     using (Dictionary<string, int>.Enumerator enumerator = functions.GetEnumerator())
     {
       while (enumerator.MoveNext())
       {
         KeyValuePair<string, int> current = enumerator.Current;
         PopupList.ListElement listElement = new PopupList.ListElement(current.Key, current.Value != 0);
         listElement.ResetScore();
         this.m_FunctionsListInputData.m_ListElements.Add(listElement);
       }
     }
     if (!this.m_ShowAllCheckbox)
       return;
     this.UpdateAllCheckbox();
   }
 }
 public bool PosTest1()
 {
     bool retVal = true;
     TestLibrary.TestFramework.BeginScenario("Return the property get_Current in the IEnumerator 1");
     try
     {
         Dictionary<string, string> dictionary = new Dictionary<string, string>();
         dictionary.Add("str1", "helloworld");
         Dictionary<string, string>.Enumerator enumer = dictionary.GetEnumerator();
         IEnumerator iEnumer = (IEnumerator)enumer;
         while (iEnumer.MoveNext())
         {
             object objCurrent = iEnumer.Current;
             KeyValuePair<string, string> keyVal = new KeyValuePair<string, string>("str1", "helloworld");
             if (!objCurrent.Equals(keyVal))
             {
                 TestLibrary.TestFramework.LogError("001", "the ExpectResult is not the ActualResult");
                 retVal = false;
             }
         }
     }
     catch (Exception e)
     {
         TestLibrary.TestFramework.LogError("002", "Unexpect exception:" + e);
         retVal = false;
     }
     return retVal;
 }
 public bool PosTest2()
 {
     bool retVal = true;
     TestLibrary.TestFramework.BeginScenario("Invoke the method Reset in the IEnumerator 2");
     try
     {
         Dictionary<string, string> dictionary = new Dictionary<string, string>();
         dictionary.Add("str1", "helloworld");
         Dictionary<string, string>.Enumerator enumer = dictionary.GetEnumerator();
         IEnumerator iEnumer = (IEnumerator)enumer;
         while (iEnumer.MoveNext()) { }
         iEnumer.Reset();
         while (iEnumer.MoveNext())
         {
             KeyValuePair<string, string> keyVal1 = (KeyValuePair<string, string>)iEnumer.Current;
             if (keyVal1.Key != "str1" || keyVal1.Value != "helloworld")
             {
                 TestLibrary.TestFramework.LogError("001", "the ExpectResult is not the ActualResult");
                 retVal = false;
             }
         }
     }
     catch (Exception e)
     {
         TestLibrary.TestFramework.LogError("002", "Unexpect exception:" + e);
         retVal = false;
     }
     return retVal;
 }
 public bool PosTest2()
 {
     bool retVal = true;
     TestLibrary.TestFramework.BeginScenario("Return the property Current of in the Dictionary Enumerator 2");
     try
     {
         Dictionary<string, string> dictionary = new Dictionary<string, string>();
         dictionary.Add("str1", "helloworld");
         Dictionary<string, string>.Enumerator enumer = dictionary.GetEnumerator();
         if (enumer.MoveNext())
         {
             KeyValuePair<string, string> keyVal = enumer.Current;
             if (keyVal.Key != "str1" || keyVal.Value != "helloworld")
             {
                 TestLibrary.TestFramework.LogError("003", "the ExpectResult is not the ActualResult");
                 retVal = false;
             }
         }           
     }
     catch (Exception e)
     {
         TestLibrary.TestFramework.LogError("004", "Unexpect exception:" + e);
         retVal = false;
     }
     return retVal;
 }
 public bool PosTest2()
 {
     bool retVal = true;
     TestLibrary.TestFramework.BeginScenario("PosTest2:Invoke the method GetEnumerator in ValueCollection Generic IEnumerable 2");
     try
     {
         Dictionary<TestClass, TestClass> dic = new Dictionary<TestClass, TestClass>();
         TestClass TKey1 = new TestClass();
         TestClass TVal1 = new TestClass();
         TestClass TKey2 = new TestClass();
         TestClass TVal2 = new TestClass();
         dic.Add(TKey1, TVal1);
         dic.Add(TKey2, TVal2);
         IEnumerable<TestClass> ienumer = (IEnumerable<TestClass>)new Dictionary<TestClass, TestClass>.ValueCollection(dic);
         IEnumerator<TestClass> ienumerator = ienumer.GetEnumerator();
         Dictionary<TestClass, TestClass>.Enumerator dicEnumer = dic.GetEnumerator();
         while (ienumerator.MoveNext() && dicEnumer.MoveNext())
         {
             if (!ienumerator.Current.Equals(dicEnumer.Current.Value))
             {
                 TestLibrary.TestFramework.LogError("003", "the ExpecResult is not the ActualResult");
                 retVal = false;
             }
         }
     }
     catch (Exception e)
     {
         TestLibrary.TestFramework.LogError("004", "Unexpect exception:" + e);
         retVal = false;
     }
     return retVal;
 }
 public bool PosTest2()
 {
     bool retVal = true;
     TestLibrary.TestFramework.BeginScenario("Return the property get_Entry in the IDictionaryEnumerator 2");
     try
     {
         Dictionary<TestClass,TestClass> dictionary = new Dictionary<TestClass,TestClass>();
         TestClass Tkey1 = new TestClass();
         TestClass TVal1 = new TestClass();
         dictionary.Add(Tkey1,TVal1);
         Dictionary<TestClass,TestClass>.Enumerator enumer = dictionary.GetEnumerator();
         IDictionaryEnumerator idicEnumer = (IDictionaryEnumerator)enumer;
         if (idicEnumer.MoveNext())
         {
             DictionaryEntry entryVal = idicEnumer.Entry;
             if (entryVal.Key != Tkey1 || entryVal.Value != TVal1)
             {
                 TestLibrary.TestFramework.LogError("003", "the ExpectResult is not the ActualResult");
                 retVal = false;
             }
         }
     }
     catch (Exception e)
     {
         TestLibrary.TestFramework.LogError("004", "Unexpect exception:" + e);
         retVal = false;
     }
     return retVal;
 }
Example #17
0
    public int countBananaSplits(string[] ingredients)
    {
        Dictionary<string, int> dict = new Dictionary<string, int>();
        for (int i = 0; i < ingredients.Length; i++)
        {
            if (dict.ContainsKey(ingredients[i]))
            {
                dict[ingredients[i]]++;
            }
            else
            {
                dict.Add(ingredients[i], 1);
            }
        }

        if (!dict.ContainsKey("ice cream"))
        {
            return 0;
        }
        if (!dict.ContainsKey("banana"))
        {
            return 0;
        }

        int ret = 1;
        Dictionary<string, int>.Enumerator e = dict.GetEnumerator();
        while (e.MoveNext())
        {
            if (e.Current.Key != "ice cream" && e.Current.Key != "banana")
                ret *= (e.Current.Value + 1);
        }

        return dict["ice cream"]*dict["banana"]*(ret - 1);
    }
    public static void ShowSensorSelectionWindow(Vector2 nSize, Rect nPosition, VRPNDataObject nInFront)
    {
        size = nSize;
        pos = nPosition;
        inFront = nInFront;

        sensors = VRPNEditEditor.Instance.GetSensors(inFront.dataName, inFront.originalDataTime, inFront.dataDevice);
        disabledSensors = VRPNEditEditor.Instance.GetDisabledSensors(inFront.dataName, inFront.originalDataTime, inFront.dataDevice);
        states = new bool[sensors.Count];
        sensorsE = sensors.GetEnumerator();

        //Initial sensors state
        int numSensor = 0;
        while (sensorsE.MoveNext())
        {
            int test;
            if (disabledSensors.TryGetValue(sensorsE.Current.Key, out test))
            {
                states[numSensor] = false;
            }
            else
            {
                states[numSensor] = true;
            }
            numSensor++;
        }

        VRPNSensorSelectionWindow window = VRPNSensorSelectionWindow.CreateInstance<VRPNSensorSelectionWindow>();
        window.ShowAsDropDown(pos, size);
    }
Example #19
0
	public void ImportConditionTable( Dictionary< string /*Chapter*/ , string > _Set )
	{
		Dictionary<string,string>.Enumerator i = _Set.GetEnumerator() ;
		while( i.MoveNext() )
		{
			AddConditionTable( i.Current.Key , i.Current.Value ) ;
		}
	}
Example #20
0
        public JSONStructIterator(String szData)
        {
            m_object = (Dictionary<string, object>)JsonParser.JsonDecode(szData);

            m_enumStruct = m_object.GetEnumerator();
            if ( m_enumStruct.MoveNext() )
                m_strCurKey = m_enumStruct.Current.Key;
        }
Example #21
0
 public void Print(Dictionary<string, object> dic)
 {
     var enumer = dic.GetEnumerator();
     while (enumer.MoveNext())
     {
         Debug.Log(enumer.Current.Key + " : " + enumer.Current.Value);
     }
 }
Example #22
0
 public void GetEnumerator_KeyCollectionWithOneElementDictionary_NotNull()
 {
     var dictionary = new Dictionary<int, int>();
     dictionary.Add(1, 1);
     var keyCollection = new Dictionary<int, int>.KeyCollection(dictionary);
     //
     Assert.NotNull(keyCollection.GetEnumerator());
 }
	public void ImportStandardParameter( Dictionary< string , StandardParameter > _ParameterMap )
	{
		Dictionary< string , StandardParameter >.Enumerator i = _ParameterMap.GetEnumerator() ;
		while( i.MoveNext() )
		{
			AssignStandardParameter( i.Current.Key , i.Current.Value ) ;
		}
	}
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
        {
            if (pageState != null)
            {
                var enumerator = pageState.GetEnumerator();
                do
                {
                    var pair = enumerator.Current;
                    var control = Util.FindControl(this, pair.Key);
                    var textBox = control as TextBox;
                    if (textBox != null)
                    {
                        textBox.Text = pair.Value as String;
                        continue;
                    }
                    var comboBox = control as ComboBox;
                    if (comboBox != null)
                    {
                        if (pair.Key == this.comboBoxDevices1.Name)
                        {
                            this.previousSelectedDeviceId1 = pair.Value as String;
                        }
                        else if (pair.Key == this.comboBoxDevices2.Name)
                        {
                            this.previousSelectedDeviceId2 = pair.Value as String;
                        }
                        else
                        for (int j = 0; j < comboBox.Items.Count; j ++)
                        {
                            var comboBoxItem = comboBox.Items[j] as ComboBoxItem;
                            if (comboBoxItem.Content as String == pair.Value as String)
                            {
                                comboBox.SelectedIndex = j;
                                break;
                            }
                        }
                        continue;
                    }
                }
                while (enumerator.MoveNext());
            }

            // Dispose all devices which are used in Scenario1 to 3.
            UsbCdcControl.UsbDeviceList.Singleton.DisposeAll();

            foreach (var deviceList in UsbCdcControl.DeviceList.Instances)
            {
                foreach (var info in deviceList.Devices)
                {
                    this.OnDeviceAdded(this, new UsbDeviceInfo(info));
                }
            }
            UsbCdcControl.UsbDeviceList.Singleton.DeviceAdded += this.OnDeviceAdded;
            UsbCdcControl.UsbDeviceList.Singleton.DeviceRemoved += this.OnDeviceRemoved;

            this.buttonLoopbackTest.IsEnabled = false;
            this.buttonStopLoopback.IsEnabled = false;
        }
Example #25
0
		internal void FindJobDefinitionsByName(string[] names, Action<ScheduledJobDefinition> itemFound, bool writeErrorsAndWarnings = true)
		{
			HashSet<string> strs = new HashSet<string>(names);
			Dictionary<string, WildcardPattern> strs1 = new Dictionary<string, WildcardPattern>();
			string[] strArrays = names;
			for (int i = 0; i < (int)strArrays.Length; i++)
			{
				string str = strArrays[i];
				if (!strs1.ContainsKey(str))
				{
					strs1.Add(str, new WildcardPattern(str, WildcardOptions.IgnoreCase));
				}
			}
			Dictionary<string, Exception> strs2 = ScheduledJobDefinition.RefreshRepositoryFromStore((ScheduledJobDefinition definition) => {
				foreach (KeyValuePair<string, WildcardPattern> pattern in strs1)
				{
					if (!pattern.Value.IsMatch(definition.Name) || !this.ValidateJobDefinition(definition))
					{
						continue;
					}
					itemFound(definition);
					if (!strs.Contains(pattern.Key))
					{
						continue;
					}
					strs.Remove(pattern.Key);
				}
			}
			);
			foreach (KeyValuePair<string, Exception> keyValuePair in strs2)
		{
				Dictionary<string, WildcardPattern>.Enumerator enumerator = strs1.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						var keyValuePair1 = enumerator.Current;
						if (!keyValuePair1.Value.IsMatch(keyValuePair.Key))
						{
							continue;
						}
						this.HandleLoadError(keyValuePair.Key, keyValuePair.Value);
					}
				}
				finally
				{
					enumerator.Dispose();
				}
			}
			if (writeErrorsAndWarnings)
			{
				foreach (string str1 in strs)
				{
					this.WriteDefinitionNotFoundByNameError(str1);
				}
			}
		}
Example #26
0
 public void Dispose_OneElementDictionary_NotNull()
 {
     var dictionary = new Dictionary<int, int>();
     dictionary.Add(1, 1);
     var keyCollection = new Dictionary<int, int>.KeyCollection(dictionary);
     var enumerator = keyCollection.GetEnumerator();
     //
     enumerator.Dispose();
 }
Example #27
0
 public void MoveNext_OneElementDictionary_EqualsTrue()
 {
     var dictionary = new Dictionary<int, int>();
     dictionary.Add(1, 1);
     var keyCollection = new Dictionary<int, int>.KeyCollection(dictionary);
     var enumerator = keyCollection.GetEnumerator();
     //
     Assert.True(enumerator.MoveNext());
 }
Example #28
0
 public void getCurrent_OneElementDictionary_NotNull()
 {
     var dictionary = new Dictionary<int, int>();
     dictionary.Add(1, 1);
     var keyCollection = new Dictionary<int, int>.KeyCollection(dictionary);
     var enumerator = dictionary.GetEnumerator();
     enumerator.MoveNext();
     //
     Assert.NotNull(enumerator.Current);
 }
Example #29
0
 private String GetText(Dictionary<UInt32, ThreadStack> threadStacks)
 {
     Dictionary<UInt32, ThreadStack>.Enumerator enumer = threadStacks.GetEnumerator();
     if(enumer.MoveNext())
     {
         ThreadStack threadStack = enumer.Current.Value;
         return "AppDomain (" + r_manager.GetValue(threadStack.DomainId) + ") " + threadStack.DomainName;
     }
     return r_appDomainNode.Text;
 }
        //PROTOBUF
        public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command)
        {
            CommandInfo cmdInfo;
            try
            {
                cmdInfo = ParseCommand(command, clientManager);
            }
            catch (Exception exc)
            {
                if (!base.immatureId.Equals("-2"))
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID));
                return;
            }

            Cache cache = null;

            try
            {
                string server = ConnectionManager.ServerIpAddress;
                int port = ConnectionManager.ServerPort;

                Dictionary<string, int> runningServers = new Dictionary<string, int>();

                cache = CacheProvider.Provider.GetCacheInstanceIgnoreReplica(cmdInfo.CacheId);

                if (cache == null) throw new Exception("Cache is not registered");
                if (!cache.IsRunning) throw new Exception("Cache is not running");

                runningServers = cache.GetRunningServers(server, port);
                Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response();
                Alachisoft.NCache.Common.Protobuf.GetRunningServersResponse getRunningServerResponse = new Alachisoft.NCache.Common.Protobuf.GetRunningServersResponse();

                if (runningServers != null)
                {
                    Dictionary<string, int>.Enumerator ide = runningServers.GetEnumerator();
                    while (ide.MoveNext())
                    {
                        Common.Protobuf.KeyValuePair pair = new Common.Protobuf.KeyValuePair();
                        pair.key = ide.Current.Key;
                        pair.value = ide.Current.Value.ToString();
                        getRunningServerResponse.keyValuePair.Add(pair);
                    }
                }

                response.requestId = Convert.ToInt64(cmdInfo.RequestId);
                response.getRunningServer = getRunningServerResponse;
                response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.GET_RUNNING_SERVERS;

                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
            }
            catch (Exception exc)
            {
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID));
            }
        }