private static bool CheckFileNameUsingPaths(string fileName, StringCollection paths, out string fullFileName)
        {
            fullFileName = null;
            string   str  = fileName.Trim(new char[] { '"' });
            FileInfo info = new FileInfo(str);

            if (str.Length != info.Name.Length)
            {
                if (info.Exists)
                {
                    fullFileName = info.FullName;
                }
                return(info.Exists);
            }
            using (StringEnumerator enumerator = paths.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    string   str3  = enumerator.Current + Path.DirectorySeparatorChar + str;
                    FileInfo info2 = new FileInfo(str3);
                    if (info2.Exists)
                    {
                        fullFileName = str3;
                        return(true);
                    }
                }
            }
            return(false);
        }
Beispiel #2
0
        private void ProcessRemoteUrls(DiscoveryClientProtocol client, StringCollection urls, XmlSchemas schemas,
                                       ServiceDescriptionCollection descriptions)
        {
            StringEnumerator enumerator = urls.GetEnumerator();

            while (enumerator.MoveNext())
            {
                string current = enumerator.Current;
                try
                {
                    DiscoveryDocument document = client.DiscoverAny(current);
                    client.ResolveAll();
                }
                catch (Exception exception)
                {
                    throw new InvalidOperationException("General Error " + current, exception);
                }
            }
            IDictionaryEnumerator enumerator2 = client.Documents.GetEnumerator();

            while (enumerator2.MoveNext())
            {
                var entry = (DictionaryEntry)enumerator2.Current;
                AddDocument((string)entry.Key, entry.Value, schemas, descriptions);
            }
        }
        static void Main()
        {
            StringCollection mySEnum = new StringCollection();

            mySEnum.Add("This");
            mySEnum.Add("is");
            mySEnum.Add("String");
            mySEnum.Add("Enumerator");
            mySEnum.Add("Demo");


            // Enumerates the elements in the StringCollection.
            StringEnumerator myEnumerator = mySEnum.GetEnumerator();

            while (myEnumerator.MoveNext())
            {
                Console.WriteLine("{0}", myEnumerator.Current);
            }
            Console.WriteLine();

            //// Resets the enumerator and displays the first element again.
            myEnumerator.Reset();
            if (myEnumerator.MoveNext())
            {
                Console.WriteLine("The first element is {0}.", myEnumerator.Current);
            }
        }
Beispiel #4
0
        public void analyzeShortTermMemory()
        {
            purifyBotsMind();
            StringCollection sc = null;

            sc = new StringCollection();
            botsMemory.Clear();
            if (fullPathName == "")
            {
                sc = readBrainFile();
            }
            else
            {
                sc = readBrainFile(fullPathName);
            }
            StringEnumerator ii = sc.GetEnumerator();

            while (ii.MoveNext())
            {
                if (!botsMemory.Contains(parseForThoughts(ii.Current)))
                {
                    botsMemory.Add(parseForThoughts(ii.Current), parseForWords(ii.Current));
                }
            }
            memorySize = botsMemory.Count;
            return;
        }
Beispiel #5
0
        public string GetValidMCode(string actCode)
        {
            ActivationCodeInfo V_0 = this.ExtractActivationCode(actCode); // 提取激活码

            StringCollection V_1 = GetMacAddressStrs();                   // 获取本机网卡MAC地址

            StringEnumerator V_4 = V_1.GetEnumerator();

            try
            {
                while (V_4.MoveNext())
                {
                    string V_2 = V_4.Current;
                    if (V_2.Equals(V_0.Mac))
                    {
                        string V_3 = V_0.Mac;
                        return(V_3);
                    }
                }
            }
            finally
            {
                if (V_4 is IDisposable)
                {
                    ((IDisposable)V_4).Dispose();
                }
            }

            return(string.Empty);
        }
        public string M59(string sMessage)
        {
            string strRdo = "";

            try
            {
                if (Session["MessagesSession"] == null)
                {
                    MessagesSession msgSession = new MessagesSession();
                    Session["MessagesSession"] = msgSession;
                }

                IRecvMessage msg = null;
                msg         = MessageFactory.GetReceivedMessage(sMessage);
                msg.Session = ((MessagesSession)Session["MessagesSession"]);


                StringCollection sc = msg.Process();

                System.Collections.Specialized.StringEnumerator myEnumerator = sc.GetEnumerator();
                while (myEnumerator.MoveNext())
                {
                    strRdo += myEnumerator.Current + "\n";
                }
            }
            catch (Exception e)
            {
                strRdo = e.ToString();
            }

            return(strRdo);
        }
        public DesignDataSetSource(MapCore mapCore, object originalDataSource)
        {
            StringCollection dataSourceDataMembers = DataBindingHelper.GetDataSourceDataMembers(originalDataSource);
            StringEnumerator enumerator            = dataSourceDataMembers.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    string    current   = enumerator.Current;
                    DataTable dataTable = new DataTable(current)
                    {
                        Locale = CultureInfo.CurrentCulture
                    };
                    DataBindingHelper.InitDesignDataTable(originalDataSource, current, dataTable);
                    base.Tables.Add(dataTable);
                }
            }
            finally
            {
                IDisposable disposable = enumerator as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
        }
Beispiel #8
0
        private static System.Reflection.Assembly AssemblyResolver(object sender, ResolveEventArgs args)
        {
            char[] chArray2 = new char[1] {
                ','
            };
            char[] chArray1 = chArray2;
            string text1    = args.Name.Split(chArray1)[0];

            StringEnumerator enumerator1 = HintDirectories.GetEnumerator();

            while (enumerator1.MoveNext())
            {
                string text2 = enumerator1.Current;
                string text3 = Path.Combine(text2, string.Format("{0}.dll", text1));
                if (File.Exists(text3))
                {
                    return(Assembly.LoadFrom(text3));
                }
                text3 = Path.Combine(text2, string.Format("{0}.exe", text1));
                if (File.Exists(text3))
                {
                    return(Assembly.LoadFrom(text3));
                }
            }
            return(null);
        }
Beispiel #9
0
        public static void GetEnumerator_ModifiedCollectionTest(StringCollection collection, string[] data)
        {
            StringEnumerator enumerator = collection.GetEnumerator();

            Assert.NotNull(enumerator);
            if (data.Length > 0)
            {
                Assert.True(enumerator.MoveNext());
                string current = enumerator.Current;
                Assert.Equal(data[0], current);
                collection.RemoveAt(0);
                if (data.Length > 1 && data[0] != data[1])
                {
                    Assert.NotEqual(current, collection[0]);
                }
                Assert.Equal(current, enumerator.Current);
                Assert.Throws <InvalidOperationException>(() => enumerator.MoveNext());
                Assert.Throws <InvalidOperationException>(() => enumerator.Reset());
            }
            else
            {
                collection.Add("newValue");
                Assert.Throws <InvalidOperationException>(() => enumerator.MoveNext());
            }
        }
Beispiel #10
0
        private void ProcessLocalPaths(DiscoveryClientProtocol client, StringCollection localPaths, XmlSchemas schemas,
                                       ServiceDescriptionCollection descriptions)
        {
            StringEnumerator enumerator = localPaths.GetEnumerator();

            while (enumerator.MoveNext())
            {
                string current   = enumerator.Current;
                string extension = Path.GetExtension(current);
                if (string.Compare(extension, ".discomap", true) == 0)
                {
                    client.ReadAll(current);
                }
                else
                {
                    object document = null;
                    if (string.Compare(extension, ".wsdl", true) == 0)
                    {
                        document = ReadLocalDocument(false, current);
                    }
                    else
                    {
                        if (string.Compare(extension, ".xsd", true) != 0)
                        {
                            throw new InvalidOperationException("Unknown file type " + current);
                        }
                        document = ReadLocalDocument(true, current);
                    }
                    if (document != null)
                    {
                        AddDocument(current, document, schemas, descriptions);
                    }
                }
            }
        }
Beispiel #11
0
        private SvnLookOutputParser(StringCollection infoLines, StringCollection changedLines, StringCollection diffLines)
        {
            StringEnumerator strings = infoLines.GetEnumerator();

            strings.MoveNext();              // move to first
            strings.MoveNext();              // skip first
            FindAuthor(strings);
            FindTimestamp(strings);
            FindLogMessageSize(strings);
            FindLogMessage(strings);

            strings = changedLines.GetEnumerator();
            bool hasMoreLines = SkipBlanks(strings);

            if (!hasMoreLines)
            {
                throw new ArgumentException("Unexpected: no changes recorded, aborting fatally");
            }

            FindChanges(strings);

            if (diffLines != null && diffLines.Count > 0)
            {
                strings      = diffLines.GetEnumerator();
                hasMoreLines = SkipBlanks(strings);

                if (hasMoreLines)
                {
                    FillDiffCollection(strings);
                }
            }
        }
        static void Main()
        {
            StringCollection scol = new StringCollection();

            scol.Add("Tiger");
            scol.Add("Lion");
            scol.Add("Cheetah");
            scol.Add("Panther");
            scol.Add("Lynx");


            Console.WriteLine("Printing the Elements");
            foreach (var item in scol)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("****************************************");
            Console.WriteLine("Printing Elements using the GetEnumerator Method");

            StringEnumerator se = scol.GetEnumerator();


            while (se.MoveNext())
            {
                Console.WriteLine(se.Current);
            }
            se.Reset();
        }
 public static string ReplaceStrUseSC(string originalStr, StringCollection sc)
 {
     if (!string.IsNullOrEmpty(originalStr))
     {
         StringEnumerator enumerator = sc.GetEnumerator();
         try
         {
             while (enumerator.MoveNext())
             {
                 string current = enumerator.Current;
                 originalStr = Regex.Replace(originalStr, current, "*".PadLeft(current.Length, '*'), RegexOptions.IgnoreCase);
             }
             return(originalStr);
         }
         finally
         {
             IDisposable disposable = enumerator as IDisposable;
             if (disposable != null)
             {
                 disposable.Dispose();
             }
         }
     }
     return(string.Empty);
 }
Beispiel #14
0
    // Uses the enumerator.
    // NOTE: The foreach statement is the preferred way of enumerating the contents of a collection.
    public static void PrintValues2(StringCollection myCol)
    {
        StringEnumerator myEnumerator = myCol.GetEnumerator();

        while (myEnumerator.MoveNext())
        {
            Console.WriteLine("   {0}", myEnumerator.Current);
        }
        Console.WriteLine();
    }
Beispiel #15
0
        /// <summary>
        /// Get an enumerator that represents the key/value pairs of this configuration
        /// </summary>
        /// <returns>an IEnumerator object to enumerate through this configuration</returns>
        public IEnumerator GetEnumerator()
        {
            StringCollection stringCollection = new StringCollection();

            foreach (string allKey in this._cfg.AppSettings.Settings.AllKeys)
            {
                string str = allKey + ": " + this._cfg.AppSettings.Settings[allKey].Value;
                stringCollection.Add(str);
            }

            return((IEnumerator)stringCollection.GetEnumerator());
        }
        void OnVerbDisplayFileName(IntPtr hWnd)
        {
            //System.Windows.Forms.MessageBox.Show(
            //    "COUNT=\r\n\r\n" +this.selectedFiles.Count,
            //    "FileContextMenuExt");

            try
            {
                //  Type typINVOKECOMMANDINFO = Type.GetType("UofShellExt.INVOKECOMMANDINFO");
                ////  INVOKECOMMANDINFO ici = (INVOKECOMMANDINFO)Marshal.PtrToStructure(pici, typINVOKECOMMANDINFO);
                //  switch (ici.verb)
                //  {
                //      case 0:
                // Open a file for arguments passing
                // MessageBox.Show("invokecommand 0");
                string       argFileName   = Path.GetTempFileName();
                FileStream   argFileStream = File.Open(argFileName, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
                StreamWriter argFileWriter = new StreamWriter(argFileStream);

                // System.Windows.Forms.MessageBox.Show("argFileName="+argFileName);

                // Write All arguments
                argFileWriter.WriteLine("OoxToUof");
                argFileWriter.WriteLine(selectedFiles.Count);
                //  argFileWriter.WriteLine("1");
                // argFileWriter.WriteLine(m_fileName.Length.ToString());
                StringEnumerator se = selectedFiles.GetEnumerator();
                while (se.MoveNext())
                {
                    argFileWriter.WriteLine(se.Current);
                }


                //  argFileWriter.WriteLine(this.selectedFile);
                // Close the File
                argFileWriter.Close();
                argFileStream.Close();

                // Start the standalone converter
                // Argument 1: Conversion Argument File Name
                // Argument 2: The name of the mutex for sync the file
                System.Diagnostics.Process.Start(typeof(UofStdConverter.Program).Assembly.Location, "\"" + argFileName + "\"");

                //            break;
                //        case 1:
                //            MessageBox.Show("invokecommand 1");
                //            break;
                //    }
            }
            catch (Exception)
            {
            }
        }
Beispiel #17
0
 private void AppendSwitchFileCollection(StringWriter writer, string name, StringCollection collection)
 {
     if (collection != null)
     {
         StringEnumerator enumerator = collection.GetEnumerator();
         while (enumerator.MoveNext())
         {
             string item = enumerator.Current;
             AppendSwitchFileIfNotNull(writer, name, item);
         }
     }
 }
Beispiel #18
0
        /// <summary>
        /// Get an enumerator that represents the key/value pairs of this configuration
        /// </summary>
        /// <returns>an IEnumerator object to enumerate through this configuration</returns>
        public IEnumerator GetEnumerator()
        {
            var strCol = new StringCollection();

            foreach (string cfgElement in _cfg.AppSettings.Settings.AllKeys)
            {
                string configLine = cfgElement + ": " + _cfg.AppSettings.Settings[cfgElement].Value;

                strCol.Add(configLine);
            }

            return((IEnumerator)strCol.GetEnumerator());
        }
Beispiel #19
0
 private bool FindUser(StringCollection users, string principal)
 {
     using (StringEnumerator enumerator = users.GetEnumerator())
     {
         while (enumerator.MoveNext())
         {
             if (string.Equals(enumerator.Current, principal, StringComparison.OrdinalIgnoreCase))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Beispiel #20
0
        public static string DecimalBinario(double d)
        {
            int              cociente;
            string           numero      = string.Empty;
            StringCollection restos      = new StringCollection();
            bool             isNumber    = int.TryParse(d.ToString(), out cociente);
            int              rescociente = 0;

            if (isNumber)
            {
                if (cociente == 0)
                {
                    restos.Add("0");
                }
                else
                {
                    //guardo en la coleccion los restos
                    while (cociente >= 2)
                    {
                        rescociente = cociente % 2;
                        restos.Add((rescociente).ToString());
                        cociente = cociente / 2;
                    }
                    restos.Add("1");
                }


                //recorro el stringCollection de atras para adelante
                StringEnumerator eRestos = restos.GetEnumerator();
                int      i   = restos.Count - 1;
                string[] ret = new string[i + 1];

                //dejo los items en mi array
                while (eRestos.MoveNext())
                {
                    ret[i] = eRestos.Current;
                    i--;
                }

                numero = string.Empty;
                //ahora devuelvo el numero convertido a binario
                for (int j = 0; j < ret.Length; j++)
                {
                    numero += ret[j];
                }
            }

            return(isNumber ? numero : "Valor Inválido");
        }
Beispiel #21
0
        private static void ResolveServerParameters(IParametersTranslator paramsTranslator, NameValueCollection allParametersCollection, NameValueCollection rsParameters, NameValueCollection rcParameters, NameValueCollection dsuParameters, NameValueCollection dspParameters, NameValueCollection reportParameters, out Hashtable reverseLookup, out ExternalItemPath itemPath)
        {
            reverseLookup = new Hashtable();
            itemPath      = null;
            StringCollection stringCollection = new StringCollection();

            for (int i = 0; i < allParametersCollection.Count; i++)
            {
                string key = allParametersCollection.GetKey(i);
                if (key != null && StringComparer.OrdinalIgnoreCase.Compare(key, "rs:StoredParametersID") == 0)
                {
                    string text = allParametersCollection[i];
                    NameValueCollection nameValueCollection = default(NameValueCollection);
                    paramsTranslator.GetParamsInstance(text, out itemPath, out nameValueCollection);
                    if (nameValueCollection == null)
                    {
                        throw new StoredParameterNotFoundException(text.MarkAsPrivate());
                    }
                    reverseLookup.Add(new ReportParameterCollection(nameValueCollection), text);
                    stringCollection.Add(key);
                    foreach (string item in nameValueCollection)
                    {
                        string[] values = nameValueCollection.GetValues(item);
                        if (!RSRequestParameters.TryToAddToCollection(item, values, "rs:", false, rsParameters) && !RSRequestParameters.TryToAddToCollection(item, values, "rc:", false, rcParameters) && !RSRequestParameters.TryToAddToCollection(item, values, "dsu:", false, dsuParameters) && !RSRequestParameters.TryToAddToCollection(item, values, "dsp:", false, dspParameters))
                        {
                            RSRequestParameters.TryToAddToCollection(item, values, "", true, reportParameters);
                        }
                    }
                }
            }
            StringEnumerator enumerator2 = stringCollection.GetEnumerator();

            try
            {
                while (enumerator2.MoveNext())
                {
                    string current = enumerator2.Current;
                    allParametersCollection.Remove(current);
                }
            }
            finally
            {
                IDisposable disposable = enumerator2 as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
        }
Beispiel #22
0
        public static string ConvertCollectionInString(StringCollection collection)
        {
            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }
            StringEnumerator se   = collection.GetEnumerator();
            List <string>    data = new List <string>();

            while (se.MoveNext())
            {
                data.Add(se.Current);
            }
            return(string.Join(DEFAULT_DATA_SEPARATOR.ToString(), data.ToArray()));
        }
Beispiel #23
0
        private static void DumpHashtable(Hashtable ht)
        {
            foreach (DictionaryEntry entry in ht)
            {
                Console.Write("  {0}:\t", entry.Key);

                StringCollection sc           = (StringCollection)entry.Value;
                StringEnumerator scEnumerator = sc.GetEnumerator();
                while (scEnumerator.MoveNext())
                {
                    Console.Write("{0}, ", scEnumerator.Current);
                }

                Console.WriteLine();
            }
        }
Beispiel #24
0
 public static Entry For(StringCollection strings)
 {
     if (strings == null)
     {
         return(new NullEntry());
     }
     else
     {
         ArrayEntry arrayEntry         = new ArrayEntry();
         StringCollection.Enumerator e = strings.GetEnumerator();
         while (e.MoveNext())
         {
             arrayEntry.Add(For(e.Current));
         }
         return(arrayEntry);
     }
 }
Beispiel #25
0
        private static void ResolveServerParameters(IParametersTranslator paramsTranslator, NameValueCollection allParametersCollection, NameValueCollection rsParameters, NameValueCollection rcParameters, NameValueCollection dsuParameters, NameValueCollection dspParameters, NameValueCollection reportParameters, out Hashtable reverseLookup, out ExternalItemPath itemPath)
        {
            reverseLookup = new Hashtable();
            itemPath      = null;
            StringCollection stringCollection = new StringCollection();

            for (int i = 0; i < allParametersCollection.Count; i++)
            {
                string key = allParametersCollection.GetKey(i);
                if (key == null || StringComparer.OrdinalIgnoreCase.Compare(key, "rs:StoredParametersID") != 0)
                {
                    continue;
                }
                string text = allParametersCollection[i];
                paramsTranslator.GetParamsInstance(text, out itemPath, out NameValueCollection parameters);
                if (parameters == null)
                {
                    throw new StoredParameterNotFoundException(text.MarkAsPrivate());
                }
                reverseLookup.Add(new ReportParameterCollection(parameters), text);
                stringCollection.Add(key);
                foreach (string item in parameters)
                {
                    string[] values = parameters.GetValues(item);
                    if (!TryToAddToCollection(item, values, "rs:", allowMultiValue: false, rsParameters) && !TryToAddToCollection(item, values, "rc:", allowMultiValue: false, rcParameters) && !TryToAddToCollection(item, values, "dsu:", allowMultiValue: false, dsuParameters) && !TryToAddToCollection(item, values, "dsp:", allowMultiValue: false, dspParameters))
                    {
                        TryToAddToCollection(item, values, "", allowMultiValue: true, reportParameters);
                    }
                }
            }
            StringEnumerator enumerator2 = stringCollection.GetEnumerator();

            try
            {
                while (enumerator2.MoveNext())
                {
                    string current = enumerator2.Current;
                    allParametersCollection.Remove(current);
                }
            }
            finally
            {
                (enumerator2 as IDisposable)?.Dispose();
            }
        }
Beispiel #26
0
        /// <summary>
        /// Searches the StringCollection for the item's imagepath
        /// </summary>
        /// <param name="key">SL created key representing the Folder or Item</param>
        /// <param name="stringc">StringCollection of the current ImageLog file</param>
        /// <returns></returns>
        public static string Findfilepath(string key, StringCollection stringc)
        {
            string path = "";
            //Look for the entire line
            StringEnumerator SCE = stringc.GetEnumerator();

            while (SCE.MoveNext())
            {
                if (SCE.Current.Contains(key))
                {
                    path = SCE.Current;
                }
            }

            path = path.Substring(path.IndexOf(","), path.Length).Trim();

            return(path);
        }
Beispiel #27
0
        public bool ValidateLicense(string actCode, out int pws, bool onRegister)
        {
            pws = 0;

            // 校验激活码
            if (!this.ValidateSegment5(actCode, onRegister))
            {
                return(false);
            }

            // 提取激活码
            ActivationCodeInfo V_0 = this.ExtractActivationCode(actCode);

            // 授权人数
            pws = V_0.NumberOfPowerUsers;

            // 本机网卡MAC地址
            StringCollection V_1 = GetMacAddressStrs(); // 0B

            StringEnumerator V_4 = V_1.GetEnumerator();

            // 如果激活码中的MAC地址包含本机MAC地址,则验证通过
            try
            {
                while (V_4.MoveNext())
                {
                    string V_2 = V_4.Current;
                    if (V_2.Equals(V_0.Mac))
                    {
                        bool V_3 = true;
                        return(V_3);
                    }
                }
            }
            finally
            {
                if (V_4 is IDisposable)
                {
                    ((IDisposable)V_4).Dispose();
                }
            }
            return(false);
        }
        public override int GetHashCode()
        {
            int num = 0;
            StringCollection stringCollection = new StringCollection();

            for (int i = 0; i < this.Count; i++)
            {
                string key = this.GetKey(i);
                stringCollection.Add(key);
                string[] values = this.GetValues(i);
                if (values != null)
                {
                    string[] array = values;
                    foreach (string text in array)
                    {
                        if (text != null)
                        {
                            stringCollection.Add(text);
                        }
                    }
                }
            }
            StringEnumerator enumerator = stringCollection.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    string current = enumerator.Current;
                    num ^= current.GetHashCode();
                }
                return(num);
            }
            finally
            {
                IDisposable disposable = enumerator as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
        }
Beispiel #29
0
        static void Main()
        {
            StringCollection sl = new StringCollection();

            sl.Add("apples");
            sl.Add("banana");
            sl.Add("oranges");
            sl.Add("kiwi");
            sl.Add("Guvva");
            sl.Add("grapes");
            StringEnumerator sd = sl.GetEnumerator();

            while (sd.MoveNext())
            {
                Console.WriteLine(sd.Current);
            }
            Console.WriteLine("count is:{0}", sl.Count);
            Console.WriteLine("-----------------------using count property--------------");
            Console.WriteLine("count is: {0}", sl.Count);
            Console.WriteLine("Is synchrozied or not :{0}", sl.IsSynchronized);

            Console.WriteLine("list is readonly property ?:{0}", sl.IsReadOnly);
            Console.WriteLine("-----------------------using Remove method-----------------");
            String[] myArr1 = new String[] { "A", "B", "C", "D", "E" };
            //Console.WriteLine(  "Range:{0}", sl.AddRange(myArr1));
            sl.Remove("apples");
            Console.WriteLine("After removing---------------");
            foreach (var v in sl)
            {
                Console.WriteLine(v);
            }
            String[] myArr = new String[] { "A", "B", "C", "D", "E" };


            sl.AddRange(myArr);


            foreach (Object obj in sl)
            {
                Console.WriteLine("{0}", obj);
            }
        }
        static void Main()
        {
            StringCollection sc = new StringCollection();

            sc.Add("red");
            sc.Add("blue");
            sc.Add("green");
            sc.Add("yellow");
            sc.Add("brown");

            StringEnumerator en = sc.GetEnumerator();

            Console.WriteLine("---move next method---");

            while (en.MoveNext())
            {
                Console.WriteLine(en.Current);
            }
            en.Reset();
        }
Beispiel #31
0
 public virtual bool runTest()
 {
     Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
     int iCountErrors = 0;
     int iCountTestcases = 0;
     String strLoc = "Loc_000oo";
     StringCollection sc; 
     StringEnumerator en; 
     string curr;        
     string [] values = 
     {
         "a",
         "aa",
         "",
         " ",
         "text",
         "     spaces",
         "1",
         "$%^#",
         "2222222222222222222222222",
         System.DateTime.Today.ToString(),
         Int32.MaxValue.ToString()
     };
     try
     {
         Console.WriteLine("--- create collection ---");
         strLoc = "Loc_001oo"; 
         iCountTestcases++;
         sc = new StringCollection();
         Console.WriteLine("1. Enumerator for empty collection");
         Console.WriteLine("     - get type");
         iCountTestcases++;
         en = sc.GetEnumerator();
         string type = en.GetType().ToString();
         if ( type.IndexOf("StringEnumerator", 0) == 0 ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001a, type is not StringEnumerator");
         }
         Console.WriteLine("     - MoveNext");
         iCountTestcases++;
         bool res = en.MoveNext();
         if ( res ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001b, MoveNext returned true");
         }
         Console.WriteLine("     - Current");
         iCountTestcases++;
         try 
         {
             curr = en.Current;
             iCountErrors++;
             Console.WriteLine("Err_0001c, no exception");
         }
         catch (InvalidOperationException ex) 
         {
             Console.WriteLine("  expected exception: " + ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001d, unexpected exception: {0}", e.ToString());
         }
         Console.WriteLine("     - Add item to the collection");
         iCountTestcases++;
         int cnt = sc.Count;
         sc.Add(values[0]);
         if ( sc.Count != 1) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001e, failed to add item");
         }
         Console.WriteLine("     - MoveNext on modified collection");
         try 
         {
             res = en.MoveNext();
             iCountErrors++;
             Console.WriteLine("Err_0001f, no exception");
         }
         catch (InvalidOperationException ex) 
         {
             Console.WriteLine("  expected exception: " + ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001g, unexpected exception: {0}", e.ToString());
         }
         Console.WriteLine("2. Enumerator for filled collection");
         strLoc = "Loc_002oo"; 
         iCountTestcases++;
         sc.AddRange(values);
         Console.WriteLine("     - get type");
         iCountTestcases++;
         en = sc.GetEnumerator();
         type = en.GetType().ToString();
         if ( type.IndexOf("StringEnumerator", 0) == 0 ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002a, type is not StringEnumerator");
         }
         Console.WriteLine("     - MoveNext and Current within collection");
         for (int i = 0; i < sc.Count; i++) 
         {
             iCountTestcases++;
             res = en.MoveNext();
             if ( !res ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002b_{0}, MoveNext returned false", i);
             }
             iCountTestcases++;
             curr = en.Current;
             if (String.Compare(curr, sc[i], false) != 0 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002c_{0}, Current returned \"{1}\" instead of \"{2}\"", i, curr, sc[i]);
             }
             iCountTestcases++;
             string curr1 = en.Current;
             if (String.Compare(curr, curr1, false) != 0 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002d_{0}, second call of Current returned different result", i);
             }
         }
         res = en.MoveNext();
         Console.WriteLine("     - MoveNext outside of the collection");
         iCountTestcases++;
         res = en.MoveNext();
         if ( res ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002e, MoveNext returned true");
         }
         Console.WriteLine("     - Current outside of the collection");
         iCountTestcases++;
         try 
         {
             curr = en.Current;
             iCountErrors++;
             Console.WriteLine("Err_0002f, no exception");
         }
         catch (InvalidOperationException ex) 
         {
             Console.WriteLine("  expected exception: " + ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002g, unexpected exception: {0}", e.ToString());
         }
         Console.WriteLine("     - Reset");
         iCountTestcases++;
         en.Reset();
         Console.WriteLine("     - get Current after Reset");
         iCountTestcases++;
         try 
         {
             curr = en.Current;
             iCountErrors++;
             Console.WriteLine("Err_0002h, no exception");
         }
         catch (InvalidOperationException ex) 
         {
             Console.WriteLine("  expected exception: " + ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002j, unexpected exception: {0}", e.ToString());
         }
         Console.WriteLine("3. Enumerator and modified collection in the middle of enumeration");
         strLoc = "Loc_003oo"; 
         iCountTestcases++;
         if (sc.Count < 1)
             sc.AddRange(values);
         iCountTestcases++;
         en = sc.GetEnumerator();
         Console.WriteLine("     - Enumerate to the middle of the collection");
         for (int i = 0; i < sc.Count / 2; i++) 
         {
             iCountTestcases++;
             res = en.MoveNext();
             if (!res) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0003a_{0}, MoveNext returned false", i);
             }
         }
         Console.WriteLine("     - modify collection");
         cnt = sc.Count;
         curr = en.Current;
         iCountTestcases++;
         sc.RemoveAt(0);
         if ( sc.Count != cnt - 1 ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0003b, didn't remove 0-item");
         }
         Console.WriteLine("     - get Current");
         iCountTestcases++;
         if (String.Compare(curr, en.Current) != 0 ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0003c, current returned {0} instead of {1}", en.Current, curr);
         }
         Console.WriteLine("     - call MoveNext");
         iCountTestcases++;
         try 
         {
             res = en.MoveNext();
             iCountErrors++;
             Console.WriteLine("Err_0003d, no exception");
         }
         catch (InvalidOperationException ex) 
         {
             Console.WriteLine("  expected exception: " + ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0003e, unexpected exception: {0}", e.ToString());
         }
         Console.WriteLine("4. Enumerator and collection modified after enumeration");
         strLoc = "Loc_004oo"; 
         iCountTestcases++;
         if (sc.Count < 1)
             sc.AddRange(values);
         iCountTestcases++;
         en = sc.GetEnumerator();
         Console.WriteLine("     - Enumerate through the collection");
         for (int i = 0; i < sc.Count; i++) 
         {
             iCountTestcases++;
             res = en.MoveNext();
             if (!res) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0004a_{0}, MoveNext returned false", i);
             }
         }
         Console.WriteLine("     - modify collection");
         cnt = sc.Count;
         curr = en.Current;
         iCountTestcases++;
         sc.RemoveAt(0);
         if ( sc.Count != cnt - 1 ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0004b, didn't remove 0-item");
         }   
         Console.WriteLine("     - get Current");
         iCountTestcases++;
         if (String.Compare(curr, en.Current) != 0 ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0004c, current returned {0} instead of {1}", en.Current, curr);
         }   
         Console.WriteLine("     - call MoveNext");
         iCountTestcases++;
         try 
         {
             res = en.MoveNext();
             iCountErrors++;
             Console.WriteLine("Err_0004f, no exception");
         }
         catch (InvalidOperationException ex) 
         {
             Console.WriteLine("  expected exception: " + ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0004g, unexpected exception: {0}", e.ToString());
         }
     } 
     catch (Exception exc_general ) 
     {
         ++iCountErrors;
         Console.WriteLine (s_strTFAbbrev + " : Error Err_general!  strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString());
     }
     if ( iCountErrors == 0 )
     {
         Console.WriteLine( "Pass.   "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
         return true;
     }
     else
     {
         Console.WriteLine("Fail!   "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
         return false;
     }
 }
Beispiel #32
0
 public static void GetEnumerator_ModifiedCollectionTest(StringCollection collection, string[] data)
 {
     StringEnumerator enumerator = collection.GetEnumerator();
     Assert.NotNull(enumerator);
     if (data.Length > 0)
     {
         Assert.True(enumerator.MoveNext());
         string current = enumerator.Current;
         Assert.Equal(data[0], current);
         collection.RemoveAt(0);
         if (data.Length > 1 && data[0] != data[1])
         {
             Assert.NotEqual(current, collection[0]);
         }
         Assert.Equal(current, enumerator.Current);
         Assert.Throws<InvalidOperationException>(() => enumerator.MoveNext());
         Assert.Throws<InvalidOperationException>(() => enumerator.Reset());
     }
     else
     {
         collection.Add("newValue");
         Assert.Throws<InvalidOperationException>(() => enumerator.MoveNext());
     }
 }
Beispiel #33
0
        public static void GetEnumeratorTest(StringCollection collection, string[] data)
        {
            bool repeat = true;
            StringEnumerator enumerator = collection.GetEnumerator();
            Assert.NotNull(enumerator);
            while (repeat)
            {
                Assert.Throws<InvalidOperationException>(() => enumerator.Current);
                foreach (string element in data)
                {
                    Assert.True(enumerator.MoveNext());
                    Assert.Equal(element, enumerator.Current);
                    Assert.Equal(element, enumerator.Current);
                }
                Assert.False(enumerator.MoveNext());
                Assert.Throws<InvalidOperationException>(() => enumerator.Current);
                Assert.False(enumerator.MoveNext());

                enumerator.Reset();
                enumerator.Reset();
                repeat = false;
            }
        }
 public virtual bool runTest()
 {
     Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
     int iCountErrors = 0;
     int iCountTestcases = 0;
     String strLoc = "Loc_000oo";
     StringCollection sc; 
     StringEnumerator en; 
     string curr;        
     bool res;           
     string [] values = 
     {
         "a",
         "aa",
         "",
         " ",
         "text",
         "     spaces",
         "1",
         "$%^#",
         "2222222222222222222222222",
         System.DateTime.Today.ToString(),
         Int32.MaxValue.ToString()
     };
     try
     {
         Console.WriteLine("--- create collection ---");
         strLoc = "Loc_001oo"; 
         iCountTestcases++;
         sc = new StringCollection();
         Console.WriteLine("1. Reset() on empty collection");
         Console.WriteLine("     - Reset()");
         iCountTestcases++;
         en = sc.GetEnumerator();
         try 
         {
             en.Reset();
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001a, unexpected exception: " + e.ToString());
         }
         Console.WriteLine("     - Current");
         iCountTestcases++;
         try 
         {
             curr = en.Current;
             iCountErrors++;
             Console.WriteLine("Err_0001b, no exception");
         }
         catch (InvalidOperationException ex) 
         {
             Console.WriteLine("  expected exception: " + ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001c, unexpected exception: {0}", e.ToString());
         }
         Console.WriteLine("     - Add item to the collection");
         iCountTestcases++;
         int cnt = sc.Count;
         sc.Add(values[0]);
         if ( sc.Count != 1) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001d, failed to add item");
         }
         Console.WriteLine("     - Reset() on modified collection");
         try 
         {
             en.Reset();
             iCountErrors++;
             Console.WriteLine("Err_0001e, no exception");
         }
         catch (InvalidOperationException ex) 
         {
             Console.WriteLine("  expected exception: " + ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001f, unexpected exception: {0}", e.ToString());
         }
         Console.WriteLine("2. Reset() on filled collection");
         strLoc = "Loc_002oo"; 
         iCountTestcases++;
         sc.AddRange(values);
         en = sc.GetEnumerator();
         Console.WriteLine("     - Reset() after Reset()");
         iCountTestcases++;
         try 
         {
             en.Reset();
             en.Reset();
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002a, unexpected exception: " + e.ToString());
         }
         Console.WriteLine("     - Reset() after 0th item ");
         iCountTestcases++;
         if (!en.MoveNext()) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002b, MoveNext() returned false");
         }
         iCountTestcases++;
         curr = en.Current;
         if (String.Compare(curr, values[0], false) != 0) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002c, Current returned wrong value");
         }
         en.Reset();
         if (!en.MoveNext()) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002d, MoveNext() returned false");
         }
         iCountTestcases++;
         if (String.Compare(en.Current, curr, false) != 0) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002e, Current returned wrong value");
         }
         int ind = sc.Count / 2;
         Console.WriteLine("     - Reset() after {0} item ", ind);
         en.Reset();
         for (int i = 0; i < ind + 1; i++) 
         {
             iCountTestcases++;
             res = en.MoveNext();
             if ( !res ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002f_{0}, MoveNext returned false", i);
             }
             iCountTestcases++;
             curr = en.Current;
             if (String.Compare(curr, sc[i], false) != 0 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002g_{0}, Current returned \"{1}\" instead of \"{2}\"", i, curr, sc[i]);
             }
             iCountTestcases++;
             string curr1 = en.Current;
             if (String.Compare(curr, curr1, false) != 0 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002h_{0}, second call of Current returned different result", i);
             }
         }
         en.Reset();
         if (!en.MoveNext()) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002i, MoveNext() returned false");
         }
         iCountTestcases++;
         if (String.Compare(en.Current, sc[0], false) != 0) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002j, Current returned wrong value");
         }
         ind = sc.Count;
         Console.WriteLine("     - Reset() after {0} item ", ind-1);
         en.Reset();
         for (int i = 0; i < ind; i++) 
         {
             iCountTestcases++;
             res = en.MoveNext();
             if ( !res ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002k_{0}, MoveNext returned false", i);
             }
             iCountTestcases++;
             curr = en.Current;
             if (String.Compare(curr, sc[i], false) != 0 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002l_{0}, Current returned \"{1}\" instead of \"{2}\"", i, curr, sc[i]);
             }
             iCountTestcases++;
             string curr1 = en.Current;
             if (String.Compare(curr, curr1, false) != 0 ) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002m_{0}, second call of Current returned different result", i);
             }
         }
         en.Reset();
         if (!en.MoveNext()) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002n, MoveNext() returned false");
         }
         iCountTestcases++;
         if (String.Compare(en.Current, sc[0], false) != 0) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002o, Current returned wrong value");
         }
         en.Reset();
         Console.WriteLine("     - Reset() after enumerated beyond the last item");
         for (int i = 0; i < ind; i++) 
         {
             res = en.MoveNext();
         }
         res = en.MoveNext();
         iCountTestcases++;
         res = en.MoveNext();
         if ( res ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002p, MoveNext returned true");
         }
         en.Reset();
         if (!en.MoveNext()) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002q, MoveNext() returned false");
         }
         iCountTestcases++;
         if (String.Compare(en.Current, sc[0], false) != 0) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002r, Current returned wrong value");
         }
         Console.WriteLine("     - Current after Reset()");
         iCountTestcases++;
         en.Reset();
         try 
         {
             curr = en.Current;
             iCountErrors++;
             Console.WriteLine("Err_0002s, no exception");
         }
         catch (InvalidOperationException ex) 
         {
             Console.WriteLine("  expected exception: " + ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002t, unexpected exception: {0}", e.ToString());
         }
         Console.WriteLine("3. Reset() modified collection in process of enumeration");
         strLoc = "Loc_003oo"; 
         iCountTestcases++;
         if (sc.Count < 1)
             sc.AddRange(values);
         iCountTestcases++;
         en = sc.GetEnumerator();
         Console.WriteLine("     - Reset() for init position of the enumerator");
         sc.RemoveAt(0);
         iCountTestcases++;
         try 
         {
             en.Reset();
             iCountErrors++;
             Console.WriteLine("Err_0003a, no exception");
         }
         catch (InvalidOperationException ex) 
         {
             Console.WriteLine("  expected exception: " + ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0003b, unexpected exception: {0}", e.ToString());
         }
         en = sc.GetEnumerator();
         Console.WriteLine("     - Enumerate to the middle of the collection and Reset()");
         for (int i = 0; i < sc.Count / 2; i++) 
         {
             iCountTestcases++;
             res = en.MoveNext();
         }
         Console.WriteLine("     - modify collection");
         curr = en.Current;
         iCountTestcases++;
         sc.RemoveAt(0);
         Console.WriteLine("     - get Current");
         iCountTestcases++;
         if (String.Compare(curr, en.Current) != 0 ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0003c, current returned {0} instead of {1}", en.Current, curr);
         }
         Console.WriteLine("     - call Reset()");
         iCountTestcases++;
         try 
         {
             en.Reset();
             iCountErrors++;
             Console.WriteLine("Err_0003d, no exception");
         }
         catch (InvalidOperationException ex) 
         {
             Console.WriteLine("  expected exception: " + ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0003e, unexpected exception: {0}", e.ToString());
         }
         en = sc.GetEnumerator();
         Console.WriteLine("     - Enumerate to end of the collection and Reset()");
         for (int i = 0; i < sc.Count; i++) 
         {
             iCountTestcases++;
             res = en.MoveNext();
         }
         Console.WriteLine("     - modify collection");
         iCountTestcases++;
         sc.RemoveAt(0);
         Console.WriteLine("     - call Reset()");
         iCountTestcases++;
         try 
         {
             en.Reset();
             iCountErrors++;
             Console.WriteLine("Err_0003f, no exception");
         }
         catch (InvalidOperationException ex) 
         {
             Console.WriteLine("  expected exception: " + ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0003g, unexpected exception: {0}", e.ToString());
         }
         Console.WriteLine("4. Reset() after enumerating beyond the end");
         strLoc = "Loc_004oo"; 
         iCountTestcases++;
         if (sc.Count < 1)
             sc.AddRange(values);
         iCountTestcases++;
         en = sc.GetEnumerator();
         Console.WriteLine("     - Enumerate through the collection");
         for (int i = 0; i < sc.Count; i++) 
         {
             iCountTestcases++;
             res = en.MoveNext();
         }
         Console.WriteLine("     - Enumerate beyond the end");
         res = en.MoveNext();              
         if ( res ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0004a, MoveNext returned true after moving beyond the end");
         }   
         Console.WriteLine("     - modify collection");
         cnt = sc.Count;
         iCountTestcases++;
         sc.RemoveAt(0);
         if ( sc.Count != cnt - 1 ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0004b, didn't remove 0-item");
         }   
         Console.WriteLine("     - call Reset()");
         iCountTestcases++;
         try 
         {
             en.Reset();
             iCountErrors++;
             Console.WriteLine("Err_0004c, no exception");
         }
         catch (InvalidOperationException ex) 
         {
             Console.WriteLine("  expected exception: " + ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0004d, unexpected exception: {0}", e.ToString());
         }
     } 
     catch (Exception exc_general ) 
     {
         ++iCountErrors;
         Console.WriteLine (s_strTFAbbrev + " : Error Err_general!  strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString());
     }
     if ( iCountErrors == 0 )
     {
         Console.WriteLine( "Pass.   "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
         return true;
     }
     else
     {
         Console.WriteLine("Fail!   "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
         return false;
     }
 }