}// IntersectCollections static internal StringCollection CondIntersectCollections(ref StringCollection sc1, ref StringCollection sc2, ref StringCollection sc3) { StringCollection scOutput = new StringCollection(); int iLen = sc1.Count; for (int i = 0; i < iLen; i++) { // Clean up our String Collection a little bit if (sc1[i].Equals("")) { sc1.RemoveAt(i); i--; iLen--; } else { int iIndexInSecond = sc2.IndexOf(sc1[i]); if (iIndexInSecond != -1 && !sc3.Contains(sc1[i])) { scOutput.Add(sc1[i]); // Pull this string out of the two string collections sc1.RemoveAt(i); sc2.RemoveAt(iIndexInSecond); // Set the counters so we won't be lost i--; iLen--; } } } return(scOutput); }// IntersectCollections
/// <summary> /// Load the list of recent files from disk. /// </summary> public static void LoadRecentFiles() { if (File.Exists(RecentFilesFilePath)) { // Load the Recent Files from disk XmlSerializer ser = new XmlSerializer(typeof(StringCollection)); using (TextReader reader = new StreamReader(RecentFilesFilePath)) { recentFiles = (StringCollection)ser.Deserialize(reader); } // Remove files from the Recent Files list that no longer exists. for (int i = 0; i < recentFiles.Count; i++) { if (!File.Exists(recentFiles[i])) { recentFiles.RemoveAt(i); } } // Only keep the 5 most recent files, trim the rest. while (recentFiles.Count > NumberOfRecentFiles) { recentFiles.RemoveAt(NumberOfRecentFiles); } } }
public void AddFile(string strFilename) { // Does the file already exist in the list? int nIndex = 0; int nFound = -1; foreach (string s in m_files) { if (s == strFilename) { nFound = nIndex; } nIndex++; } if (nFound != -1) { m_files.RemoveAt(nFound); } // Add file to top of list. m_files.Insert(0, strFilename); // Remove files from bottom if we have too many. if (m_files.Count > MaxRecentFiles) { m_files.RemoveAt(MaxRecentFiles); } BuildRecentMenu(); Properties.Settings.Default.RecentFiles = m_files; Properties.Settings.Default.Save(); }
/// <summary> /// This is overridden to provide custom handling of the CONTEXT parameter /// </summary> /// <param name="parameters">The parameters for the property</param> public override void DeserializeParameters(StringCollection parameters) { if (parameters == null || parameters.Count == 0) { return; } for (int paramIdx = 0; paramIdx < parameters.Count; paramIdx++) { if (String.Compare(parameters[paramIdx], "CONTEXT=", StringComparison.OrdinalIgnoreCase) == 0) { // Remove the parameter name parameters.RemoveAt(paramIdx); if (paramIdx < parameters.Count) { this.Context = parameters[paramIdx]; // As above, remove the value parameters.RemoveAt(paramIdx); } break; } } // Let the base class handle all other parameters base.DeserializeParameters(parameters); }
//no usado //public void llenarMinusculas() //{ // for (int i = 97; i <= 109; i++) // { // char key = (char)i; // char value = (char)(i + 13); // minusculasReemplazar.Add(key, value); // } //} ////no usado //public StringCollection buscarMinisculas(StringCollection minusculasActuales) //{ // for (int i = 0; i < producciones.Count; i++) // { // if (producciones[i].Length > 1) // { // for (int j = 0; j < producciones[i].Length; j++) // { // if (isSmallLetter(producciones[i][j]) && !minusculasActuales.Contains(producciones[i][j] + "")) // { // minusculasActuales.Add(producciones[i][j] + ""); // } // } // } // } // return minusculasActuales; //} /** * Metodo usado para eliminar las producciones no alcanzables */ public void removerProduccion(String eliminar) { for (int i = 0; i < producciones.Count; i++) { if (producciones[i].Contains(eliminar)) { producciones.RemoveAt(i); } } }
/// <summary> /// This is overridden to provide custom handling of the FBTYPE parameter /// </summary> /// <param name="parameters">The parameters for the property</param> public override void DeserializeParameters(StringCollection parameters) { string type; if (parameters == null || parameters.Count == 0) { return; } for (int paramIdx = 0; paramIdx < parameters.Count; paramIdx++) { if (String.Compare(parameters[paramIdx], "FBTYPE=", StringComparison.OrdinalIgnoreCase) == 0) { // Remove the parameter name parameters.RemoveAt(paramIdx); if (paramIdx < parameters.Count) { type = parameters[paramIdx].Trim().ToUpperInvariant(); switch (type) { case "FREE": this.FreeBusyType = FreeBusyType.Free; break; case "BUSY": this.FreeBusyType = FreeBusyType.Busy; break; case "BUSY-UNAVAILABLE": this.FreeBusyType = FreeBusyType.BusyUnavailable; break; case "BUSY-TENTATIVE": this.FreeBusyType = FreeBusyType.BusyTentative; break; default: this.OtherType = parameters[paramIdx]; break; } // As above, remove the value parameters.RemoveAt(paramIdx); } break; } } // Let the base class handle all other parameters base.DeserializeParameters(parameters); }
static string[] EvalDirForCLR(string dir, bool bSubdirs, bool bOutputToConsole, bool forNgen) { StringCollection sc = new StringCollection(); StringCollection files = new StringCollection(); try { files.AddRange(Directory.GetFiles(dir, "*.exe")); files.AddRange(Directory.GetFiles(dir, "*.dll")); } catch { } foreach (string file in files) { if (EvalFileForCLR(file, bOutputToConsole)) { sc.Add(file); } } if (bSubdirs) { string[] subfolders = new string[] {}; try { subfolders = Directory.GetDirectories(dir); } catch { } foreach (string sf in subfolders) { sc.AddRange(Program.EvalDirForCLR(sf, bSubdirs, true, forNgen)); if (forNgen) { for (int f = sc.Count - 1; f >= 0; f--) { if ((new DirectoryInfo(sc[f])).Attributes == FileAttributes.Hidden) { Console.WriteLine("Removing hidden directory " + sc[f]); sc.RemoveAt(f); } else if (sc[f].ToLower().StartsWith(Environment.GetEnvironmentVariable("windir").ToLower() + "\\assembly") || sc[f].ToLower().StartsWith(Environment.GetEnvironmentVariable("windir").ToLower() + "\\microsoft.net") || sc[f].ToLower().Contains("$recycle")) { Console.WriteLine("Removing system resource " + sc[f]); sc.RemoveAt(f); } } } } } string[] ret = new string[sc.Count]; sc.CopyTo(ret, 0); return(ret); }
private string[] ResolvePath(string path, bool ignoreMask) { if (path == null) { throw new ArgumentNullException("path"); } // if(path.Trim() == "") // throw new ArgumentException("Path is empty."); if (!path.Trim().StartsWith("\\")) { path = current.ToString() + '\\' + path; } StringCollection sa = new StringCollection(path.Split('\\')); char[] invalidChars = new char[] { '\\', '/', ':', '*', '?', '\"', '<', '>', '|' }; if (ignoreMask) { invalidChars = new char[] { '\\', '/', ':', '\"', '<', '>', '|' } } ; for (int i = 0; i < sa.Count;) { if (sa[i].Trim() == "") { sa.RemoveAt(i); } else if (sa[i].Trim() == ".") { sa.RemoveAt(i); } else if (sa[i].Trim() == "..") { sa.RemoveAt(i--); if (i >= 0) { sa.RemoveAt(i); } } else { sa[i] = sa[i].Trim(); if (sa[i].Length > 255) { throw new PathTooLongException("File or directory name is too long."); } if (sa[i++].IndexOfAny(invalidChars) >= 0) { throw new ArgumentException("Path name contains invalid characters."); } } } return(sa.ToArray()); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Removes non existant paths from the MRU list. /// </summary> /// ------------------------------------------------------------------------------------ private static void RemoveStalePaths() { if (s_paths.Count > 0) { for (int i = s_paths.Count - 1; i >= 0; i--) { if (!File.Exists(s_paths[i])) { s_paths.RemoveAt(i); } } } }
/// <summary> /// This is overridden to provide custom handling of the TYPE parameter /// </summary> /// <param name="parameters">The parameters for the property</param> public override void DeserializeParameters(StringCollection parameters) { int idx; if (parameters == null || parameters.Count == 0) { return; } for (int paramIdx = 0; paramIdx < parameters.Count; paramIdx++) { for (idx = 0; idx < ntv.Length; idx++) { if (ntv[idx].IsMatch(parameters[paramIdx])) { break; } } if (idx == ntv.Length) { // If it was a parameter name, skip the value too if (parameters[paramIdx].EndsWith("=", StringComparison.Ordinal)) { paramIdx++; } continue; // Not a sound parameter } // Parameters may appear as a pair (name followed by value) or by value alone if (!ntv[idx].IsParameterValue) { // Remove the TYPE parameter name so that the base class won't put it in the custom // parameters. We'll skip this one and decode the parameter value. parameters.RemoveAt(paramIdx); } else { this.SoundType = parameters[paramIdx]; // As above, remove the value parameters.RemoveAt(paramIdx); } paramIdx--; } // Let the base class handle all other parameters base.DeserializeParameters(parameters); }
private void buttonSaveToList_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxAccountName.Text)) { MessageBox.Show("The account name cannot be empty."); return; } CredentialsEntry myCredentials = new CredentialsEntry(textBoxAccountName.Text, textBoxAccountKey.Text, textBoxBlobKey.Text, textBoxDescription.Text, radioButtonPartner.Checked.ToString(), radioButtonOther.Checked.ToString(), textBoxAPIServer.Text, textBoxScope.Text, textBoxACSBaseAddress.Text, textBoxAzureEndpoint.Text, textBoxManagementPortal.Text); if (CredentialsList == null) { CredentialsList = new StringCollection(); } //let's find if the account name is already in the list int foundindex = -1; for (int i = 0; i < CredentialsList.Count; i += CredentialsEntry.StringsCount) { if (CredentialsList[i] == textBoxAccountName.Text) { foundindex = i; break; } } if (foundindex == -1) // not found { CredentialsList.AddRange(myCredentials.ToArray()); Properties.Settings.Default.LoginList = CredentialsList; Program.SaveAndProtectUserConfig(); listBoxAcounts.Items.Add(myCredentials.AccountName); } else { //found, let's update the entry et insert the new data for (int i = 0; i < CredentialsEntry.StringsCount; i++) { CredentialsList.RemoveAt(foundindex); } for (int i = 0; i < CredentialsEntry.StringsCount; i++) { CredentialsList.Insert(foundindex + i, myCredentials.ToArray().Skip(i).Take(1).FirstOrDefault()); } Properties.Settings.Default.LoginList = CredentialsList; Program.SaveAndProtectUserConfig(); } }
public static StringCollection Fix(StringCollection path) { if (path.Count == 0) { return(path); } StringCollection strings = new StringCollection(); for (int i = 0; i < path.Count; i++) { string str = path[i]; if (str == Separator) { if ((i == 0) || ((strings.Count > 0) && (strings[strings.Count - 1] != Separator))) { strings.Add(str); } } else if (str == "..") { if (strings.Count == 1) { throw new ArgumentException("Cannot change up a directory from the root"); } if ((strings.Count >= 2) && (strings[strings.Count - 2] != "..")) { strings.RemoveAt(strings.Count - 1); strings.RemoveAt(strings.Count - 1); } else { strings.Add(str); } } else if ((str != "") && (str != ".")) { strings.Add(str); } } while ((strings.Count > 1) && (strings[strings.Count - 1] == Separator)) { strings.RemoveAt(strings.Count - 1); } if (strings.Count == 0) { strings.Add("."); } return(strings); }
/// <summary> /// This is overridden to provide custom handling of the RELTYPE parameter /// </summary> /// <param name="parameters">The parameters for the property</param> public override void DeserializeParameters(StringCollection parameters) { string type; if (parameters == null || parameters.Count == 0) { return; } for (int paramIdx = 0; paramIdx < parameters.Count; paramIdx++) { if (String.Compare(parameters[paramIdx], "RELTYPE=", StringComparison.OrdinalIgnoreCase) == 0) { // Remove the parameter name parameters.RemoveAt(paramIdx); if (paramIdx < parameters.Count) { type = parameters[paramIdx].Trim().ToUpperInvariant(); switch (type) { case "PARENT": this.RelationshipType = RelationshipType.Parent; break; case "CHILD": this.RelationshipType = RelationshipType.Child; break; case "SIBLING": this.RelationshipType = RelationshipType.Sibling; break; default: this.OtherRelationship = parameters[paramIdx]; break; } // As above, remove the value parameters.RemoveAt(paramIdx); } break; } } // Let the base class handle all other parameters base.DeserializeParameters(parameters); }
/// <summary> /// 加载最近打开的文件 /// </summary> public void LoadRecentFiles() { RecentFiles = _fileService.ReadStringCollectionFromXML(RECENT_FILES_FILE_PATH); for (int i = 0; i < RecentFiles.Count; i++) { if (!_fileService.IsExistFile(RecentFiles[i])) { RecentFiles.RemoveAt(i); } } while (RecentFiles.Count > 3) { RecentFiles.RemoveAt(3); } }
private void RemoveHeaderTrailer(StringCollection header) { while ((header.Count > 0) && StringUtils.IsEmpty(header[header.Count - 1])) { header.RemoveAt(header.Count - 1); } }
/// <summary> /// Забирает сообщение из очереди для автоответчика /// </summary> /// <returns></returns> internal static string GetAnswer() { if (Critical || (DateTime.Now.Subtract(LastChanged).TotalSeconds < 3)) { return(string.Empty); } if (AnswersCollection.SyncRoot != null) { lock (AnswersCollection.SyncRoot) { if (AnswersCollection.Count == 0) { return(string.Empty); } var message = AnswersCollection[0]; AnswersCollection.RemoveAt(0); LastChanged = DateTime.Now; return(message); } } return(string.Empty); }
private void RemoveChild(object sender, RoutedEventArgs args) { if (_dataSource.Count > 0) { _dataSource.RemoveAt(0); } }
/// <summary> /// Overridden StringConverter function: Returns the standard values that the dropdown should have /// </summary> /// <param name="context">The descriptor context</param> /// <returns>Collection of standard values</returns> public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { StringCollection classNames = EditorManager.EngineManager.TypeManager_GetClassNamesDerivedFrom("VPostProcessingTemplateBase"); classNames.RemoveAt(0); // remove the first class (not instancable base class) return(new StandardValuesCollection(classNames)); }
public void handleMapcycle(ComboBox comboBox) { StringCollection s = new StringCollection(); try { for (int i = 0; i < Properties.Settings.Default.mapcycle.Count; i++) { bool Contains = comboBox.Items.Contains(Properties.Settings.Default.mapcycle[i]); if (!Contains) { comboBox.Items.Add(Properties.Settings.Default.mapcycle[i]); } } var uniques = Properties.Settings.Default.mapcycle.Cast <IEnumerable>(); var unique = uniques.Distinct(); foreach (var x in unique) { s.Add(x.ToString()); } if (s.Count > 23) { s.RemoveAt(22); } Properties.Settings.Default.mapcycle = s; } catch (Exception) { Properties.Settings.Default.mapcycle = s; } }
static void Main(string[] args) { StringCollection str = new StringCollection(); str.Add("Bringal"); str.Add("Bottle_Gaurd"); str.Add("Cauliflower"); str.Add("Cabbage"); str.Add("Okra"); Console.WriteLine("The Elements of the StringCollection is---------"); foreach (var item in str) { Console.WriteLine(item); } Console.WriteLine("Copying the above StringCollection list to string array--------------"); string[] str1 = new string[str.Count]; str.CopyTo(str1, 0); Console.WriteLine("Printing the copied list into the array"); foreach (var i in str) { Console.WriteLine(i); } Console.WriteLine("Checking weather Tomato element is present in the StringCollection:{0}", str.Contains("Tomato")); Console.WriteLine("Checking the index of the element : {0} ", str.IndexOf("Cauliflower")); str.Insert(4, "Tomato"); Console.WriteLine("Printing the list after inserting the new value"); foreach (var item1 in str) { Console.WriteLine(item1); } str.Remove("Bringal"); Console.WriteLine("List of the elements after removing----------"); foreach (var item2 in str) { Console.WriteLine(item2); } Console.WriteLine("Removing element from the index value--------"); str.RemoveAt(3); Console.WriteLine("Elements list after removing values from index 3"); foreach (var item3 in str) { Console.WriteLine(item3); } Console.Read(); }
private void btnRename_Click(object sender, EventArgs e) { List <Exception> exceptions = new List <Exception>(); int renamed = 0; foreach (EpisodeEntry item in episodes) { if (item.PerformRename()) { if (item.Moved) { renamed++; } } else { exceptions.Add(item.MoveException); } } StringBuilder sb = new StringBuilder(); if (renamed == 1) { sb.Append("One file has"); } else { sb.AppendFormat("{0} files have", renamed); } sb.AppendLine(" been renamed."); string series = Path.GetFileName(txtEpisodeFolder.Text); history.Remove(series); history.Add(series); while (history.Count > 20) { history.RemoveAt(0); } if (exceptions.Count > 0) { sb.AppendLine("One or more errors occurred while renaming the files:"); foreach (Exception ex in exceptions) { sb.AppendLine(ex.Message); } MessageBox.Show(sb.ToString(), "Finished", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { episodes.Clear(); InvalidateFilenames(); btnReadFiles.PerformClick(); ShowToast(sb.ToString()); } }
public void AddToHistory(string data, int positiondiff) { /* * // BUG: this code doesnt work well * // _History.Count-1 is the last entry, which should be always empty * if ((_History.Count > 1) && * (data == _History[_History.Count-2])) { * // don't add the same value * return; * } */ _History.Insert(_History.Count - 1, data); #if LOG4NET _Logger.Debug("added: '" + data + "' to history"); #endif if (_History.Count > Settings.CommandHistorySize) { _History.RemoveAt(0); } else { _HistoryPosition += positiondiff; } }
public void Delete(string path, bool recursive) { DirInfo di = FindInfo(path); if (di == null) { throw new FileNotFoundException(string.Format("Could not find file '{0}'.", path)); } if (di.ToString() == "\\") { if (!recursive) { throw new IOException("The archive root cannot be deleted."); } StringCollection sa = new StringCollection(GetDirectories("\\")); sa.AddRange(GetFiles("\\")); foreach (string s in sa) { Delete("\\" + s, true); } } else if (di is FileInfo) { entries.Remove(di); FileInfo fi = (FileInfo)di; lock (stream) { foreach (int i in fi.seq) { stream.Position = GetOffset(i); bw.Write((short)-1); bw.Write(new byte[BLOCK_SIZE - 2]); } } } else { StringCollection sa = new StringCollection(GetDirectories(di.ToString())); sa.AddRange(GetFiles(di.ToString())); if (recursive) { foreach (string s in sa) { Delete(di.ToString() + '\\' + s, true); } } else if (sa.Count > 0) { throw new IOException("Directory is not empty."); } entries.Remove(di); if (di == current) { sa = new StringCollection(ResolvePath(di.ToString())); sa.RemoveAt(sa.Count - 1); current = FindInfo("\\" + string.Join("\\", sa.ToArray())); } } UpdateDirs(); }
void IDisposable.Dispose() { while (_stack.Count > _previousCount) { _stack.RemoveAt(_stack.Count - 1); } }
public static StringCollection GetRestOfTheLineInStringCollection(string line) { //Execute keyword handling //Declare a StringCollection to hold the matches StringCollection resultList = new StringCollection(); //Define a Regex to parse the input Regex parseWords = new Regex(@"(\S+)"); //Define a Match to handle the results from Regex Match match = parseWords.Match(line); //Add every match from Regex to the StringCollection while (match.Success) { //Only add the result if it is not a white space or null if (!string.IsNullOrEmpty(match.Value)) { resultList.Add(match.Value); } match = match.NextMatch(); } //Remove the keyword from the results resultList.RemoveAt(0); return(resultList); }
/// <summary> /// Load the last used project on startup /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void MainForm_Load(object sender, EventArgs e) { StringCollection mruList = Settings.Default.MruList; int idx = 0; // Set the verbose logging option miVerboseLogging.Checked = Settings.Default.VerboseLogging; // Create the MRU on first use if (mruList == null) { Settings.Default.MruList = new StringCollection(); } else { // Get rid of projects that no longer exist while (idx < mruList.Count) { if (!File.Exists(mruList[idx])) { mruList.RemoveAt(idx); } else { idx++; } } if (mruList.Count != 0) { project.LoadProject(mruList[0]); } } }
public static void Main() { // Creates and initializes a new StringCollection. StringCollection myCol = new StringCollection(); String[] myArr = new String[] { "RED", "orange", "yellow", "RED", "green", "blue", "RED", "indigo", "violet", "RED" }; myCol.AddRange(myArr); Console.WriteLine("Initial contents of the StringCollection:"); PrintValues(myCol); // Removes one element from the StringCollection. myCol.Remove("yellow"); Console.WriteLine("After removing \"yellow\":"); PrintValues(myCol); // Removes all occurrences of a value from the StringCollection. int i = myCol.IndexOf("RED"); while (i > -1) { myCol.RemoveAt(i); i = myCol.IndexOf("RED"); } Console.WriteLine("After removing all occurrences of \"RED\":"); PrintValues(myCol); // Clears the entire collection. myCol.Clear(); Console.WriteLine("After clearing the collection:"); PrintValues(myCol); }
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()); } }
public void Move(string path, string dest) { DirInfo d1 = FindInfo(path), d2 = FindInfo(dest); if (d1 == null) { throw new FileNotFoundException(string.Format("Could not find file '{0}'.", path)); } if (d2 == null) { StringCollection sa = new StringCollection(ResolvePath(dest)); string s = sa[sa.Count - 1]; sa.RemoveAt(sa.Count - 1); d2 = FindInfo("\\" + string.Join("\\", sa.ToArray())); if (d2 == null) { throw new FileNotFoundException(string.Format("Could not find file '{0}'.", dest)); } d1.Name = s; } else if (d2 is FileInfo) { throw new IOException("A file or folder with this name already exists."); } d1.Parent = d2.Index; if (d1 == current) { StringCollection sa = new StringCollection(ResolvePath(d1.ToString())); sa.RemoveAt(sa.Count - 1); current = FindInfo("\\" + string.Join("\\", sa.ToArray())); } }
/// <summary> /// Removes the schemas from the schema manager. /// </summary> void RemoveUserSchemas() { while (removedSchemaNamespaces.Count > 0) { XmlSchemaManager.RemoveUserSchema(removedSchemaNamespaces[0]); removedSchemaNamespaces.RemoveAt(0); } }
/// <summary> /// This is overridden to provide custom handling of the CONTEXT parameter /// </summary> /// <param name="parameters">The parameters for the property</param> public override void DeserializeParameters(StringCollection parameters) { if(parameters == null || parameters.Count == 0) return; for(int paramIdx = 0; paramIdx < parameters.Count; paramIdx++) if(String.Compare(parameters[paramIdx], "CONTEXT=", StringComparison.OrdinalIgnoreCase) == 0) { // Remove the parameter name parameters.RemoveAt(paramIdx); if(paramIdx < parameters.Count) { this.Context = parameters[paramIdx]; // As above, remove the value parameters.RemoveAt(paramIdx); } break; } // Let the base class handle all other parameters base.DeserializeParameters(parameters); }
public static void RemoveAt_ArgumentInvalidTest(StringCollection collection, string[] data) { Assert.Throws<ArgumentOutOfRangeException>(() => collection.RemoveAt(-1)); Assert.Throws<ArgumentOutOfRangeException>(() => collection.RemoveAt(data.Length)); }
private void deleteBookmark(int num) { StringCollection sc = new StringCollection(); FileStream aFile = new FileStream(bookmarkFile, FileMode.Open); StreamReader sr = new StreamReader(aFile); string strLine = sr.ReadLine(); while(strLine != null) { sc.Add(strLine); strLine = sr.ReadLine(); } sr.Close(); aFile.Close(); if (num - 1 > -1) { sc.RemoveAt(num - 1); String[] bookmarks = new String[sc.Count]; sc.CopyTo(bookmarks, 0); File.WriteAllLines(bookmarkFile, bookmarks); } }
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()); } }
public static void RemoveAtTest(StringCollection collection, string[] data, int location) { collection.RemoveAt(location); Assert.Equal(data.Length - 1, collection.Count); for (int i = 0; i < data.Length - 1; i++) { if (i < location) { Assert.Equal(data[i], collection[i]); } else if (i >= location) { Assert.Equal(data[i + 1], collection[i]); } } }
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; } }
/// <summary> /// This is overridden to provide custom handling of the FBTYPE parameter /// </summary> /// <param name="parameters">The parameters for the property</param> public override void DeserializeParameters(StringCollection parameters) { string type; if(parameters == null || parameters.Count == 0) return; for(int paramIdx = 0; paramIdx < parameters.Count; paramIdx++) if(String.Compare(parameters[paramIdx], "FBTYPE=", StringComparison.OrdinalIgnoreCase) == 0) { // Remove the parameter name parameters.RemoveAt(paramIdx); if(paramIdx < parameters.Count) { type = parameters[paramIdx].Trim().ToUpperInvariant(); switch(type) { case "FREE": this.FreeBusyType = FreeBusyType.Free; break; case "BUSY": this.FreeBusyType = FreeBusyType.Busy; break; case "BUSY-UNAVAILABLE": this.FreeBusyType = FreeBusyType.BusyUnavailable; break; case "BUSY-TENTATIVE": this.FreeBusyType = FreeBusyType.BusyTentative; break; default: this.OtherType = parameters[paramIdx]; break; } // As above, remove the value parameters.RemoveAt(paramIdx); } break; } // Let the base class handle all other parameters base.DeserializeParameters(parameters); }
/// <summary> /// This is overridden to provide custom handling of the TYPE parameter /// </summary> /// <param name="parameters">The parameters for the property</param> public override void DeserializeParameters(StringCollection parameters) { int idx; if(parameters == null || parameters.Count == 0) return; for(int paramIdx = 0; paramIdx < parameters.Count; paramIdx++) { for(idx = 0; idx < ntv.Length; idx++) if(ntv[idx].IsMatch(parameters[paramIdx])) break; if(idx == ntv.Length) { // If it was a parameter name, skip the value too if(parameters[paramIdx].EndsWith("=", StringComparison.Ordinal)) paramIdx++; continue; // Not a photo parameter } // Parameters may appear as a pair (name followed by value) or by value alone if(!ntv[idx].IsParameterValue) { // Remove the TYPE parameter name so that the base class won't put it in the custom // parameters. We'll skip this one and decode the parameter value. parameters.RemoveAt(paramIdx); } else { this.ImageType = parameters[paramIdx]; // As above, remove the value parameters.RemoveAt(paramIdx); } paramIdx--; } // Let the base class handle all other parameters base.DeserializeParameters(parameters); }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; IntlStrings intl; String strLoc = "Loc_000oo"; StringCollection sc; string [] values = { "", " ", "a", "aa", "text", " spaces", "1", "$%^#", "2222222222222222222222222", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; try { intl = new IntlStrings(); Console.WriteLine("--- create collection ---"); strLoc = "Loc_001oo"; iCountTestcases++; sc = new StringCollection(); Console.WriteLine("1. RemoveAt() from empty collection"); iCountTestcases++; if (sc.Count > 0) sc.Clear(); try { sc.RemoveAt(0); iCountErrors++; Console.WriteLine("Err_0001_{0}a, no exception"); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine(" expected exception: " + ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0001_{0}b, unexpected exception: " + e.ToString()); } Console.WriteLine("2. RemoveAt() on filled collection"); strLoc = "Loc_002oo"; Console.WriteLine(" - at the beginning"); iCountTestcases++; sc.Clear(); sc.AddRange(values); if (sc.Count != values.Length) { iCountErrors++; Console.WriteLine("Err_0002a, count is {0} instead of {1}", sc.Count, values.Length); } iCountTestcases++; sc.RemoveAt(0); if (sc.Count != values.Length - 1) { iCountErrors++; Console.WriteLine("Err_0002b, Count returned {0} instead of {1}", sc.Count, values.Length - 1); } iCountTestcases++; if (sc.Contains(values[0])) { iCountErrors++; Console.WriteLine("Err_0002c, removed wrong item"); } for (int i = 0; i < values.Length; i++) { iCountTestcases++; if (sc.IndexOf(values[i]) != i-1) { iCountErrors++; Console.WriteLine("Err_0002_{0}d, IndexOf returned {1} instead of {2}", i, sc.IndexOf(values[i]), i-1); } } Console.WriteLine(" - at the end"); iCountTestcases++; sc.Clear(); sc.AddRange(values); if (sc.Count != values.Length) { iCountErrors++; Console.WriteLine("Err_0002e, count is {0} instead of {1}", sc.Count, values.Length); } iCountTestcases++; sc.RemoveAt(values.Length-1); if (sc.Count != values.Length - 1) { iCountErrors++; Console.WriteLine("Err_0002f, Count returned {0} instead of {1}", sc.Count, values.Length - 1); } iCountTestcases++; if (sc.Contains(values[values.Length - 1])) { iCountErrors++; Console.WriteLine("Err_0002g, removed wrong item"); } for (int i = 0; i < values.Length-1; i++) { iCountTestcases++; if (sc.IndexOf(values[i]) != i) { iCountErrors++; Console.WriteLine("Err_0002_{0}h, IndexOf returned {1} instead of {2}", i, sc.IndexOf(values[i]), i); } } Console.WriteLine(" - at the middle"); iCountTestcases++; sc.Clear(); sc.AddRange(values); if (sc.Count != values.Length) { iCountErrors++; Console.WriteLine("Err_0002i, count is {0} instead of {1}", sc.Count, values.Length); } iCountTestcases++; sc.RemoveAt(values.Length/2); if (sc.Count != values.Length - 1) { iCountErrors++; Console.WriteLine("Err_0002j, Count returned {0} instead of {1}", sc.Count, values.Length - 1); } iCountTestcases++; if (sc.Contains(values[values.Length/2])) { iCountErrors++; Console.WriteLine("Err_0002g, removed wrong item"); } for (int i = 0; i < values.Length; i++) { iCountTestcases++; int expected = i; if (i == values.Length / 2) expected = -1; else if (i > values.Length / 2) expected = i-1; if (sc.IndexOf(values[i]) != expected) { iCountErrors++; Console.WriteLine("Err_0002_{0}k, IndexOf returned {1} instead of {2}", i, sc.IndexOf(values[i]), expected); } } Console.WriteLine("3. RemoveAt() on collection with duplicate strings "); strLoc = "Loc_003oo"; iCountTestcases++; sc.Clear(); string intlStr = intl.GetString(MAX_LEN, true, true, true); sc.Add(intlStr); sc.AddRange(values); sc.Add(intlStr); if (sc.Count != values.Length + 2) { iCountErrors++; Console.WriteLine("Err_0003a, count is {1} instead of {2}", sc.Count, values.Length + 2); } iCountTestcases++; sc.RemoveAt(values.Length + 1); if (!sc.Contains(intlStr)) { iCountErrors++; Console.WriteLine("Err_0003b, removed both duplicates"); } if (sc.IndexOf(intlStr) != 0) { iCountErrors++; Console.WriteLine("Err_0003c, removed 1st instance"); } Console.WriteLine("4. RemoveAt(-1)"); strLoc = "Loc_004oo"; iCountTestcases++; sc.Clear(); sc.AddRange(values); try { sc.RemoveAt(-1); iCountErrors++; Console.WriteLine("Err_0004a, no exception"); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine(" expected exception: " + ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0004b, unexpected exception: {0}", e.ToString()); } Console.WriteLine("5. RemoveAt(Count)"); strLoc = "Loc_005oo"; iCountTestcases++; sc.Clear(); sc.AddRange(values); try { sc.RemoveAt(sc.Count); iCountErrors++; Console.WriteLine("Err_0005a, no exception"); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine(" expected exception: " + ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0005b, unexpected exception: {0}", e.ToString()); } Console.WriteLine("6. RemoveAt(Count+1)"); strLoc = "Loc_006oo"; iCountTestcases++; sc.Clear(); sc.AddRange(values); try { sc.RemoveAt(sc.Count+1); iCountErrors++; Console.WriteLine("Err_0006a, no exception"); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine(" expected exception: " + ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0006b, 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; } }
/// <summary> /// This is overridden to provide custom handling of the extra parameters /// </summary> /// <param name="parameters">The parameters for the property.</param> public override void DeserializeParameters(StringCollection parameters) { string[] delVals, memberVals; string tempVal; int idx; if(parameters == null || parameters.Count == 0) return; for(int paramIdx = 0; paramIdx < parameters.Count; paramIdx++) { for(idx = 0; idx < ntv.Length; idx++) if(ntv[idx].IsMatch(parameters[paramIdx])) break; if(idx == ntv.Length) { // If it was a parameter name, skip the value too if(parameters[paramIdx].EndsWith("=", StringComparison.Ordinal)) paramIdx++; continue; // Not an attendee parameter } // Parameters may appear as a pair (name followed by value) or by value alone switch(ntv[idx].EnumValue) { case ParameterType.Role: if(!ntv[idx].IsParameterValue) parameters.RemoveAt(paramIdx); if(paramIdx < parameters.Count) role = parameters[paramIdx]; break; case ParameterType.Rsvp: if(!ntv[idx].IsParameterValue) parameters.RemoveAt(paramIdx); if(paramIdx < parameters.Count) { tempVal = parameters[paramIdx].Trim(); rsvp = (String.Compare(tempVal, "YES", StringComparison.OrdinalIgnoreCase) == 0 || String.Compare(tempVal, "TRUE", StringComparison.OrdinalIgnoreCase) == 0); } break; case ParameterType.Expect: if(!ntv[idx].IsParameterValue) parameters.RemoveAt(paramIdx); if(paramIdx < parameters.Count) expect = parameters[paramIdx]; break; case ParameterType.CalendarUserType: if(!ntv[idx].IsParameterValue) parameters.RemoveAt(paramIdx); if(paramIdx < parameters.Count) cuType = parameters[paramIdx]; break; case ParameterType.DelegatedFrom: if(!ntv[idx].IsParameterValue) parameters.RemoveAt(paramIdx); if(paramIdx < parameters.Count) { delVals = parameters[paramIdx].Split(','); delFrom.Clear(); foreach(string s in delVals) { tempVal = s.Trim(); if(tempVal.Length > 0) delFrom.Add(tempVal); } } break; case ParameterType.DelegatedTo: if(!ntv[idx].IsParameterValue) parameters.RemoveAt(paramIdx); if(paramIdx < parameters.Count) { delVals = parameters[paramIdx].Split(','); delTo.Clear(); foreach(string s in delVals) { tempVal = s.Trim(); if(tempVal.Length > 0) delTo.Add(tempVal); } } break; case ParameterType.Member: if(!ntv[idx].IsParameterValue) parameters.RemoveAt(paramIdx); if(paramIdx < parameters.Count) { memberVals = parameters[paramIdx].Split(','); member.Clear(); foreach(string s in memberVals) { tempVal = s.Trim(); if(tempVal.Length > 0) member.Add(tempVal); } } break; case ParameterType.Status: if(!ntv[idx].IsParameterValue) parameters.RemoveAt(paramIdx); if(paramIdx < parameters.Count) status = parameters[paramIdx]; break; } parameters.RemoveAt(paramIdx); paramIdx--; } // Let the base class handle all other parameters base.DeserializeParameters(parameters); }
private static Dictionary<String, StringCollection> LayersFromString(string value) { Dictionary<String, StringCollection> dict = new Dictionary<String, StringCollection>(); if (value.Length > 0) { string[] layers = value.Split(Separator2); for (int i = 0; i < layers.Length; ++i) { StringCollection values = new StringCollection(); values.AddRange(layers[i].Split(Separator3)); string key = values[0]; values.RemoveAt(0); dict.Add(key, values); } } return dict; }
//===================================================================== /// <summary> /// Load the grid with the specified calendar items /// </summary> private void LoadGridWithItems() { int gridIdx = dgvCalendar.CurrentCellAddress.Y; VCalendar.TimeZones.Sort(true); dgvCalendar.DataSource = null; // Get just the time zones used? if(chkLimitToCalendar.Checked) { // Get just the time zones used StringCollection timeZonesUsed = new StringCollection(); if(vCal != null) { vCal.TimeZonesUsed(timeZonesUsed); // Remove entries that don't exist for(int idx = 0; idx < timeZonesUsed.Count; idx++) if(VCalendar.TimeZones[timeZonesUsed[idx]] == null) { timeZonesUsed.RemoveAt(idx); idx--; } } // Add each instance to a temporary collection and bind it to the grid timeZones.Clear(); foreach(string timeZoneId in timeZonesUsed) timeZones.Add(VCalendar.TimeZones[timeZoneId]); dgvCalendar.DataSource = timeZones; } else dgvCalendar.DataSource = VCalendar.TimeZones; // Enable or disable the buttons based on the vCard count btnEdit.Enabled = btnDelete.Enabled = (dgvCalendar.RowCount != 0); // Stay on the last item selected if(gridIdx > -1 && gridIdx < dgvCalendar.RowCount) dgvCalendar.CurrentCell = dgvCalendar[0, gridIdx]; }
/// <summary> /// This is overridden to provide custom handling of the TYPE parameter /// </summary> /// <param name="parameters">The parameters for the property</param> public override void DeserializeParameters(StringCollection parameters) { string[] types; int idx, subIdx; if(parameters == null || parameters.Count == 0) return; EMailTypes et = EMailTypes.None; for(int paramIdx = 0; paramIdx < parameters.Count; paramIdx++) { for(idx = 0; idx < ntv.Length; idx++) if(ntv[idx].IsMatch(parameters[paramIdx])) break; if(idx == ntv.Length) { // If it was a parameter name, skip the value too if(parameters[paramIdx].EndsWith("=", StringComparison.Ordinal)) paramIdx++; continue; // Not an e-mail parameter } // Parameters may appear as a pair (name followed by value) or by value alone if(!ntv[idx].IsParameterValue && paramIdx < parameters.Count - 1) { // Remove the TYPE parameter name so that the base class won't put it in the custom // parameters. We'll skip this one and decode the parameter value. parameters.RemoveAt(paramIdx); // If the values contain a comma, split it on the comma and parse the types (i.e. vCard 3.0 // spec). If not, just continue and handle it as normal. if(reSplit.IsMatch(parameters[paramIdx])) { types = reSplit.Split(parameters[paramIdx]); foreach(string s in types) { for(subIdx = 1; subIdx < ntv.Length; subIdx++) if(ntv[subIdx].IsMatch(s)) break; // Unrecognized ones are ignored if(subIdx < ntv.Length) et |= ntv[subIdx].EnumValue; } parameters.RemoveAt(paramIdx); } } else { et |= ntv[idx].EnumValue; // As above, remove the value parameters.RemoveAt(paramIdx); } paramIdx--; } if(et != EMailTypes.None) this.EMailTypes = et; // Let the base class handle all other parameters base.DeserializeParameters(parameters); }
/// <summary> /// This is overridden to provide custom handling of the RELTYPE parameter /// </summary> /// <param name="parameters">The parameters for the property</param> public override void DeserializeParameters(StringCollection parameters) { string type; if(parameters == null || parameters.Count == 0) return; for(int paramIdx = 0; paramIdx < parameters.Count; paramIdx++) if(String.Compare(parameters[paramIdx], "RELTYPE=", StringComparison.OrdinalIgnoreCase) == 0) { // Remove the parameter name parameters.RemoveAt(paramIdx); if(paramIdx < parameters.Count) { type = parameters[paramIdx].Trim().ToUpperInvariant(); switch(type) { case "PARENT": this.RelationshipType = RelationshipType.Parent; break; case "CHILD": this.RelationshipType = RelationshipType.Child; break; case "SIBLING": this.RelationshipType = RelationshipType.Sibling; break; default: this.OtherRelationship = parameters[paramIdx]; break; } // As above, remove the value parameters.RemoveAt(paramIdx); } break; } // Let the base class handle all other parameters base.DeserializeParameters(parameters); }
/// <summary> /// This is overridden to provide custom handling of the extra parameters /// </summary> /// <param name="parameters">The parameters for the property</param> public override void DeserializeParameters(StringCollection parameters) { if(parameters == null || parameters.Count == 0) return; for(int paramIdx = 0; paramIdx < parameters.Count; paramIdx++) { if(String.Compare(parameters[paramIdx], "CN=", StringComparison.OrdinalIgnoreCase) == 0) { // Remove the parameter name parameters.RemoveAt(paramIdx); if(paramIdx < parameters.Count) { this.CommonName = parameters[paramIdx]; // As above, remove the value parameters.RemoveAt(paramIdx); } } else if(String.Compare(parameters[paramIdx], "DIR=", StringComparison.OrdinalIgnoreCase) == 0) { parameters.RemoveAt(paramIdx); if(paramIdx < parameters.Count) { this.DirectoryEntry = parameters[paramIdx]; parameters.RemoveAt(paramIdx); } } else if(String.Compare(parameters[paramIdx], "SENT-BY=", StringComparison.OrdinalIgnoreCase) == 0) { parameters.RemoveAt(paramIdx); if(paramIdx < parameters.Count) { this.SentBy = parameters[paramIdx]; parameters.RemoveAt(paramIdx); } } } // Let the base class handle all other parameters base.DeserializeParameters(parameters); }
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; } }