private void RemoveNodeButton(ToolStripItem nodeButton) { StringCollection toolBarNodes = Properties.Settings.Default.ToolBarNodes; string typeName = (nodeButton.Tag as Type).Name; if (toolBarNodes != null && toolBarNodes.Contains(typeName)) { toolBarNodes.Remove(typeName); toolStrip1.Items.Remove(nodeButton); } }
public static void RemoveSymbolLibrary(Project project, string symbolLibraryNameWithExtesion) { Masterdata masterdata = new Masterdata(); StringCollection newMasterdatas = new StringCollection(); StringCollection projectMasterdatas = masterdata.get_ProjectEntries(project); if (projectMasterdatas.Contains(symbolLibraryNameWithExtesion)) { newMasterdatas.Remove(symbolLibraryNameWithExtesion); } }
/// <summary> /// This returns a StringCollection with the names of recently used settings /// for the given report /// /// </summary> /// <returns>the list of names of recently used settings, which exist at the moment /// </returns> public StringCollection GetRecentlyUsedSettings() { StringCollection ReturnValue; String SettingName; StringCollection AvailableSettings; System.Int32 Counter; ReturnValue = new StringCollection(); if (("RptStg" + FReportName).Length > 32) { throw new Exception(String.Format("Report name ({0}) is too long for the settings", FReportName)); } // get names of recently used settings from the database ReturnValue = StringHelper.StrSplit(TUserDefaults.GetStringDefault("RptStg" + FReportName, ""), ","); // remove settings that are not available anymore AvailableSettings = GetAvailableSettings(); Counter = 0; while (Counter < ReturnValue.Count) { SettingName = ReturnValue[Counter]; if (!AvailableSettings.Contains(SettingName)) { ReturnValue.Remove(SettingName); } else { Counter = Counter + 1; } } // we might to fill up with reports from the directory, that have not been used yet Counter = 0; while ((Counter < AvailableSettings.Count) && (ReturnValue.Count < MAX_NUMBER_OF_RECENT_SETTINGS)) { SettingName = AvailableSettings[Counter]; if (!ReturnValue.Contains(SettingName)) { ReturnValue.Add(SettingName); } Counter = Counter + 1; } return(ReturnValue); }
private void btnRemoveBookmark_Click(object sender, EventArgs e) { StringCollection sc = MangaRipper.Properties.Settings.Default.Bookmark; if (sc != null) { sc.Remove(cbTitleUrl.Text); MangaRipper.Properties.Settings.Default.Bookmark = sc; LoadBookmark(); } }
public static void ClassNotInTheme() { IKBService kbserv = UIServices.KB; string title = "KBDoctor - Class not in Theme"; string outputFile = Functions.CreateOutputFile(kbserv, title); //IOutputService output = CommonServices.Output; KBDoctorOutput.StartSection(title); KBDoctorXMLWriter writer = new KBDoctorXMLWriter(outputFile, Encoding.UTF8); writer.AddHeader(title); writer.AddTableHeader(new string[] { "Object", "Class", "Error" }); //Cargo todas las clases de todos los theme de la KB. StringCollection ThemeClasses = LoadThemeClasses(); StringCollection UsedClasses = LoadUsedClasses(); foreach (string sd in UsedClasses) { if (!ThemeClasses.Contains(sd)) { writer.AddTableData(new string[] { "", sd, "Application Class not in theme" }); KBDoctorOutput.Message("Application Class not in theme " + sd); } else { ThemeClasses.Remove(sd); } } writer.AddTableData(new string[] { "-----------------", "--------------", "---" }); foreach (string ss in ThemeClasses) { if (!UsedClasses.Contains(ss)) { writer.AddTableData(new string[] { "", ss, "Class not referenced" }); KBDoctorOutput.Message("Class not referenced in application " + ss); } } writer.AddTableData(new string[] { "-------", "-----------------", "--------------" }); writer.AddFooter(); writer.Close(); KBDoctorOutput.EndSection(title, true); KBDoctorHelper.ShowKBDoctorResults(outputFile); }
public static void RemoveTest(StringCollection collection, string[] data) { Assert.All(data, element => { Assert.True(collection.Contains(element)); Assert.True(((IList)collection).Contains(element)); collection.Remove(element); Assert.False(collection.Contains(element)); Assert.False(((IList)collection).Contains(element)); }); Assert.Equal(0, collection.Count); }
public void RemoveShouldRemove() { //arrange var collection = new StringCollection(); //act collection.Add("abc"); collection.Remove("abc"); //assert Assert.True(collection.IsEmpty()); }
/// <summary> /// Export the specified tracks to a given directory using the specified encoder. /// </summary> /// <param name="tracks"></param> /// <param name="encoder"></param> /// <param name="location"></param> /// <param name="createSubdir"></param> public void Export( PersistentIDCollection list, Encoder encoder, string playlistFormat, string location, bool createSubdirectories) { lock (sync) { disabled.Add(Resx.I_ScanDuplicates); disabled.Add(Resx.I_ScanFileWatch); disabled.Add(Resx.I_ScanMaintenance); } string pathFormat = null; if (createSubdirectories) { pathFormat = PathHelper.GetPathFormat(ExportScanner.DefaultPathFormat); } IScanner scanner = new ExportScanner( controller, catalog, list, encoder, playlistFormat, location, pathFormat, false); scanner.Completed = (Action) delegate { lock (sync) { disabled.Remove(Resx.I_ScanDuplicates); disabled.Remove(Resx.I_ScanFileWatch); disabled.Remove(Resx.I_ScanMaintenance); } }; AddScanner(scanner, ExportScannerPriority); }
/// <summary> /// Handles the RowUpdating event of the grid control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewUpdateEventArgs"/> instance containing the event data.</param> void grid_RowUpdating(object sender, GridViewUpdateEventArgs e) { string service = grid.DataKeys[e.RowIndex].Value.ToString(); TextBox textbox = (TextBox)grid.Rows[e.RowIndex].FindControl("txtName"); StringCollection col = BlogService.LoadPingServices(); col.Remove(service); col.Add(textbox.Text); BlogService.SavePingServices(col); Response.Redirect(Request.RawUrl); }
public StringCollection Replace(StringCollection src) { var preReturn = src.Cast <String>().ToList(); var spBody = preReturn.Last(); // Where(s => s.Split('\n').Count() > 0).FirstOrDefault(s => s.StartsWith(create, true, CultureInfo.InvariantCulture)); var createStart = spBody.IndexOf(ReplaceText, StringComparison.InvariantCultureIgnoreCase); var removedCreate = spBody.Remove(createStart, ReplaceText.Length); var addedAlter = removedCreate.Insert(createStart, ReplacedText); src.Remove(spBody); src.Add(addedAlter); return(src); }
public void OpenRecentFile(string location) { if (!File.Exists(location)) { _recentFiles.RemoveAt(GetIndex(location)); _recentFilesInSettings.Remove(location); _messageBoxService.ShowMessageBox("File does not exist.", "PMML Validator", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Exclamation); return; } _tabViewModelManager.CreateNewTabForRecentFile(location); }
private void btnDel_Click(object sender, EventArgs e) { if (lstName.SelectedItems.Count > 0) { string strSelected = lstName.SelectedItem.ToString(); if (lstName.Items.Contains(strSelected)) { Form1.names.Remove(strSelected); lstName.Items.Remove(strSelected); tmps.Remove(strSelected); } } }
private void permanentlyDeleteButton_Click(object sender, EventArgs e) { if (MessageBox.Show(rs.GetString("deletePermanentlyYesNoMsg"), rs.GetString("deleteTitle"), MessageBoxButtons.YesNo) == DialogResult.Yes) { int count = 0; for (int i = packageListDataGridView.Rows.Count - 1; i >= 0; i--) { bool delete = (bool)packageListDataGridView.Rows[i].Cells["selectedProductColumn"].Value; if (delete == true) { ppda.permanentlyDelete((string)packageListDataGridView.Rows[i].Cells["packageIdColumn"].Value, conn); showedDeletedAlertPackage.Remove((string)packageListDataGridView.Rows[i].Cells["packageIdColumn"].Value); setting.Save(); showedStockAlertPackage.Remove((string)packageListDataGridView.Rows[i].Cells["packageIdColumn"].Value); setting.Save(); packageListDataGridView.Rows.Remove(packageListDataGridView.Rows[i]); count++; } } if (count == 0) { MessageBox.Show(rs.GetString("selectProcuctDeletedMsg"), "", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { if (packageListDataGridView.Rows.Count > 0) { permanentlyDeleteButton.Enabled = true; recoverButton.Enabled = true; deselectAllButton.Enabled = true; selectAllButton.Enabled = true; } else { permanentlyDeleteButton.Enabled = false; recoverButton.Enabled = false; deselectAllButton.Enabled = false; selectAllButton.Enabled = false; } packageListDataGridView.ClearSelection(); productList = null; productList = ppda.getAllDeletedProductPackages(Language.getLanguageCode(), conn); MessageBox.Show(rs.GetString("deletePermanentlyMsg")); } } }
public void RefreshCachedReports(string CompanyNameShort) { Common.LogWriter.Instance.WriteEventLogEntry("Start RefreshCachedReports: " + CompanyNameShort); lock (this) { // check if already being handled if (_refreshCachedRequests.Contains(CompanyNameShort)) { return; } _refreshCachedRequests.Add(CompanyNameShort); } int count = 0; try { FI.Common.DataAccess.IUsersDA userDao = DataAccessFactory.Instance.GetUsersDA(); FI.Common.DataAccess.IOlapReportsDA rptDao = DataAccessFactory.Instance.GetOlapReportsDA(); decimal companyId = userDao.GetCompanyIdByShortName(CompanyNameShort); if (companyId <= 0) { return; } Common.Data.FIDataTable tbl = rptDao.GetCashedReportsToRefresh(companyId); if (tbl != null) { foreach (DataRow row in tbl.Rows) { User usr = new User((decimal)row["user_id"], false); OlapReport rpt = usr.ReportSystem.GetReport((decimal)row["rpt_id"], typeof(OlapReport), true) as OlapReport; rpt.Execute(); count++; } } } catch (Exception exc) { Common.LogWriter.Instance.WriteEventLogEntry(exc); throw exc; } finally { _refreshCachedRequests.Remove(CompanyNameShort); Common.LogWriter.Instance.WriteEventLogEntry(string.Format("End RefreshCachedReports: Company={0}, Count={1}", CompanyNameShort, count)); } }
private void buttonRemoveTag_Click(object sender, EventArgs e) { var selectedTag = listBoxTags.SelectedItem.ToString(); if (tags.Contains(selectedTag)) { tags.Remove(selectedTag); } Properties.Settings.Default.Tags = tags; Properties.Settings.Default.Save(); FillListBoxTags(); }
private void updateButton_Click(object sender, EventArgs e) { bool isInputCorrect = this.isInputCorrect(); if (isInputCorrect) { Bottle b = pbda.getOneProductBottleByID(bottleIdTextBox.Text, Language.getLanguageCode(), conn); b.setProductNameEnUs(englishNameTextBox.Text); b.setProductNameZhHant(tChineseNameTextBox.Text); b.setDescriptionEnUs(engDescTextBox.Text); b.setDescriptionZhHant(tChiDescTextBox.Text); b.setPhoto(productPhotoBox.Image); b.setSupplierID(supplierID); b.setQtyInStock(Convert.ToInt32(quantityTextBox.Text)); b.setPrice(Convert.ToInt32(priceTextBox.Text)); b.setBottleCapacity(Convert.ToInt32(capacityTextBox.Text)); int i = pbda.update(b, conn); if (i > 0) { foreach (DataGridViewRow row in bottleListDataGridView.Rows) { if (bottleIdTextBox.Text.Equals(row.Cells["bottleIdColumn"].Value.ToString())) { row.Cells["engNameColumn"].Value = englishNameTextBox.Text; row.Cells["tChiNameColumn"].Value = tChineseNameTextBox.Text; row.Cells["engDescriptionColumn"].Value = engDescTextBox.Text; row.Cells["tChiDescriptionColumn"].Value = tChiDescTextBox.Text; row.Cells["capacityColumn"].Value = capacityTextBox.Text + " " + rs.GetString("mlText"); row.Cells["quantityColumn"].Value = quantityTextBox.Text; row.Cells["priceColumn"].Value = rs.GetString("hkdText") + priceTextBox.Text; } } showedStockAlertBottle.Remove(b.getProductID()); setting.Save(); productList.Clear(); productList = null; productList = pbda.findProductBottlesBySupplierID(supplierID, Language.getLanguageCode(), conn); MessageBox.Show(rs.GetString("updateProductSuccessMsg")); } else { MessageBox.Show(rs.GetString("updateProductFailMsg"), rs.GetString("errorText"), MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// add new value of combobox to the user defaults, or move existing value to the front; /// limits the number of values to MAX_COMBOBOX_HISTORY /// </summary> /// <param name="Sender"></param> /// <param name="e"></param> public void AddComboBoxHistory(System.Object Sender, TAcceptNewEntryEventArgs e) { string keyName = "CmbHistory" + ((Control)Sender).Name; StringCollection values = StringHelper.StrSplit(TUserDefaults.GetStringDefault(keyName, ""), ","); values.Remove(e.ItemString); values.Insert(0, e.ItemString); while (values.Count > MAX_COMBOBOX_HISTORY) { values.RemoveAt(values.Count - 1); } TUserDefaults.SetDefault(keyName, StringHelper.StrMerge(values, ',')); }
private void btnGO_Click(object sender, EventArgs e) { if (!tmrDisplay.Enabled) { tmrDisplay.Enabled = true; //btnConfig.Enabled = false; return; } if (names.Count > 0) { tmrDisplay.Enabled = false; names.Remove(lblName.Text); } }
/// <summary> /// store information about the recent opened file /// </summary> /// <param name="fileDirector">file Directory</param> public static void AddRecentFile(string fileDirector) { StringCollection files = GetRecentFiles(); if (files.Contains(fileDirector)) { files.Remove(fileDirector); } files.Insert(0, fileDirector); if (files.Count > MAX_FILE) { files.RemoveAt(files.Count - 1); } Properties.Settings.Default.Save(); }
private void updateButton_Click(object sender, EventArgs e) { bool isInputCorrect = this.isInputCorrect(); if (isInputCorrect) { Perfume p = ppda.getOneProductPerfumeByID(perfumeIdTextBox.Text, Language.getLanguageCode(), conn); p.setProductNameEnUs(englishNameTextBox.Text.Trim()); p.setProductNameZhHant(tChineseNameTextBox.Text.Trim()); p.setDescriptionEnUs(engDescTextBox.Text.Trim()); p.setDescriptionZhHant(tChiDescTextBox.Text.Trim()); p.setPhoto(productPhotoBox.Image); p.setSupplierID(supplierID); p.setQtyInStock(int.Parse(quantityTextBox.Text.Trim())); p.setPrice(int.Parse(priceTextBox.Text.Trim())); p.setCategoryCode(categoryComboBox.SelectedValue.ToString()); int i = ppda.update(p, conn); if (i > 0) { foreach (DataGridViewRow row in perfumeListDataGridView.Rows) { if (perfumeIdTextBox.Text.Equals(row.Cells["perfumeIdColumn"].Value.ToString())) { row.Cells["engNameColumn"].Value = englishNameTextBox.Text; row.Cells["tChiNameColumn"].Value = tChineseNameTextBox.Text; row.Cells["engDescriptionColumn"].Value = engDescTextBox.Text; row.Cells["tChiDescriptionColumn"].Value = tChiDescTextBox.Text; row.Cells["quantityColumn"].Value = quantityTextBox.Text + " " + rs.GetString("mlText"); row.Cells["priceColumn"].Value = rs.GetString("hkdText") + priceTextBox.Text; } } showedStockAlertPerfume.Remove(p.getProductID()); setting.Save(); productList.Clear(); productList = null; productList = ppda.findProductPerfumeBySupplierID(supplierID, Language.getLanguageCode(), conn); MessageBox.Show(rs.GetString("updateProductSuccessMsg")); } else { MessageBox.Show(rs.GetString("updateProductFailMsg"), rs.GetString("errorText"), MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
protected virtual void Dispose(bool disposing) { lock (_lockedFiles) { if (_fullPath == null) { return; } _lockedFiles.Remove(_fullPath); if (OS.Log.IsInfoEnabled) { OS.Log.LogInfo("Unlocking file '{0}'.".InvariantFormat(_fullPath)); } _fullPath = null; } }
/// <summary> /// Adds a string to the list and positions it in the recent list /// </summary> /// <param name="text">The string that should be added</param> public void AddString(string text) { if (m_List.Contains(text)) { m_List.Remove(text); m_List.Insert(0, text); } else { if (m_List.Count == m_Capacity) { m_List.RemoveAt(m_List.Count - 1); } m_List.Insert(0, text); } }
private void AddFilesToMru(string filename) { StringCollection strings = Settings.Default.FileHistory; if (strings.Contains(filename)) { strings.Remove(filename); } strings.Insert(0, filename); if (strings.Count > maxMru) { strings.RemoveAt(20); } Settings.Default.Save(); }
public static void MergeRecentFiles(StringCollection collection) { var toRemove = new List <string>(); foreach (string f in collection) { if (!System.IO.File.Exists(f)) { toRemove.Add(f); } } foreach (string f in toRemove) { collection.Remove(f); } }
static void Main(string[] args) { StringCollection strcol = new StringCollection(); strcol.Add("Chetan Bhagat"); strcol.Add("Prem Chand"); strcol.Add("Prem Chand"); strcol.Add("Ruskin Bond"); strcol.Add("Durjoy Dutt"); Console.WriteLine("The Elements of the StringCollection is---------"); foreach (var item in strcol) { Console.WriteLine(item); } Console.WriteLine("Checking weather David Eagleman element is present in the StringCollection:{0}", strcol.Contains("David Eagleman")); string[] str = new string[strcol.Count]; Console.WriteLine("Copying the above StringCollection list to string array--------------"); strcol.CopyTo(str, 0); Console.WriteLine("Printing the copied list into the array"); foreach (var index in str) { Console.WriteLine(index); } Console.WriteLine("Checking the index of the element : {0} ", strcol.IndexOf("Chetan Bhagat")); strcol.Insert(4, "David Eagleman"); Console.WriteLine("Printing the list after inserting the new value"); foreach (var item1 in strcol) { Console.WriteLine(item1); } strcol.Remove("Prem Chand"); Console.WriteLine("List of the elements after removing----------"); foreach (var item2 in strcol) { Console.WriteLine(item2); } Console.WriteLine("Removing element from the index value--------"); strcol.RemoveAt(3); Console.WriteLine("Elements list after removing values from index 3"); foreach (var item3 in strcol) { Console.WriteLine(item3); } Console.Read(); }
private bool UpdateIds(StringCollection ids, DataTable table, UpdateMode mode) { bool updated = false; if (mode == UpdateMode.New && ids.Count > 0) { ids.Clear(); updated = true; } foreach (DataRow row in table.Rows) { if (!row.IsNull(0)) { string value = row[0].ToString(); if (mode == UpdateMode.Remove) { if (ids.IndexOf(value) >= 0) { ids.Remove(value); updated = true; } } else { if (mode == UpdateMode.Add) { if (ids.IndexOf(value) < 0) { ids.Add(value); updated = true; } } else { ids.Add(value); updated = true; } } } } return(updated); }
/// <summary> /// write the namespace for an interface /// this includes all the interfaces in this namespace /// it calls itself recursively for sub namespaces /// </summary> private void WriteNamespace( ProcessTemplate AMainTemplate, String ParentNamespace, String ParentInterfaceName, TNamespace tn, TNamespace sn, SortedList <string, TNamespace> children, SortedList InterfaceNames, List <CSParser> ACSFiles) { WriteInterface( AMainTemplate, ParentNamespace, ParentInterfaceName, "I" + ParentInterfaceName + "Namespace", tn, sn, children, InterfaceNames, ACSFiles); StringCollection InterfacesInNamespace = GetInterfacesInNamespace(ParentNamespace, InterfaceNames); // has been written already; we want to keep the order of the interfaces this way InterfacesInNamespace.Remove("I" + ParentInterfaceName + "Namespace"); foreach (String InterfaceName in InterfacesInNamespace) { WriteInterface( AMainTemplate, ParentNamespace, ParentInterfaceName, InterfaceName, tn, sn, children, InterfaceNames, ACSFiles); } foreach (TNamespace child in children.Values) { WriteNamespace( AMainTemplate, ParentNamespace + "." + child.Name, ParentInterfaceName + child.Name, tn, child, child.Children, InterfaceNames, ACSFiles); } }
/// <summary> /// Update the MRU list with the specified project filename by /// adding it to the list or making it the most recently used. /// </summary> protected void UpdateMostRecentUsedList(string fsmFile) { StringCollection mruList = Settings.Default.MruList; fsmFile = Path.GetFullPath(fsmFile); if (mruList.Contains(fsmFile)) { mruList.Remove(fsmFile); } mruList.Insert(0, fsmFile); while (mruList.Count > 10) { mruList.RemoveAt(9); } }
/// <summary> /// Update the MRU list with the specified project filename by /// adding it to the list or making it the most recently used. /// </summary> private static void UpdateMruList(string projectFile) { StringCollection mruList = Settings.Default.MruList; projectFile = Path.GetFullPath(projectFile); if (mruList.Contains(projectFile)) { mruList.Remove(projectFile); } mruList.Insert(0, projectFile); while (mruList.Count > 10) { mruList.RemoveAt(9); } }
protected override Dictionary <string, Dictionary <string, object> > GetArtifactsWithDefaultAction(Application application) { Dictionary <string, Dictionary <string, object> > artifacts = new Dictionary <string, Dictionary <string, object> >(); StringCollection referencedAppNames = new StringCollection(); GetAllReferencedAppsRecursive(application, referencedAppNames); referencedAppNames.Remove(application.Name); foreach (string appName in referencedAppNames) { Dictionary <string, object> metadata = new Dictionary <string, object>(); metadata[ActionMetadataKey] = _defaultAction; artifacts[appName] = metadata; } return(artifacts); }
private void PrepareIds(out StringCollection targetIds, out StringCollection filteredIds, out StringCollection selectionIds) { targetIds = _appState.TargetIds.Clone(); selectionIds = _appState.SelectionIds.Clone(); // segregate the target IDs that pass through the query from // those that do not if (String.IsNullOrEmpty(_appState.Query)) { filteredIds = new StringCollection(); } else { Configuration config = AppContext.GetConfiguration(); Configuration.QueryRow query = config.Query.FindByQueryID(_appState.Query); using (OleDbCommand command = query.GetDatabaseCommand()) { command.Parameters[0].Value = _appState.TargetIds.Join(","); if (command.Parameters.Count > 1) { command.Parameters[1].Value = AppUser.GetRole(); } using (OleDbDataReader reader = command.ExecuteReader()) { int mapIdColumn = reader.GetOrdinal("MapID"); filteredIds = targetIds; targetIds = new StringCollection(); while (reader.Read()) { if (!reader.IsDBNull(mapIdColumn)) { string mapId = reader.GetValue(mapIdColumn).ToString(); filteredIds.Remove(mapId); if (!targetIds.Contains(mapId)) { targetIds.Add(mapId); } } } } command.Connection.Dispose(); } } if (targetIds.Count > 0) { // remove the active ID from the targets if (_appState.ActiveMapId.Length > 0) { targetIds.Remove(_appState.ActiveMapId); } // remove the selection IDs from the targets if necessary if (_appState.TargetLayer == _appState.SelectionLayer && _appState.SelectionIds.Count > 0) { if (_appState.ActiveMapId.Length > 0) { selectionIds.Remove(_appState.ActiveMapId); } foreach (string selectionId in _appState.SelectionIds) { targetIds.Remove(selectionId); } } } }
public static void Remove_DuplicateTest(StringCollection collection, string[] data) { // Only the first element will be removed. string[] first = data.Distinct().ToArray(); Assert.All(first, element => { Assert.True(collection.Contains(element)); Assert.True(((IList)collection).Contains(element)); collection.Remove(element); Assert.True(collection.Contains(element)); Assert.True(((IList)collection).Contains(element)); }); Assert.Equal(data.Length - first.Length, collection.Count); for (int i = first.Length; i < data.Length; i++) { string element = data[i]; Assert.True(collection.Contains(element)); Assert.True(((IList)collection).Contains(element)); collection.Remove(element); bool stillPresent = i < data.Length - first.Length; Assert.Equal(stillPresent, collection.Contains(element)); Assert.Equal(stillPresent, ((IList)collection).Contains(element)); } Assert.Equal(0, collection.Count); }
public static void Remove_NotPresentTest(StringCollection collection, string[] data) { collection.Remove(ElementNotPresent); Assert.Equal(data.Length, collection.Count); ((IList)collection).Remove(ElementNotPresent); Assert.Equal(data.Length, collection.Count); }
public static void RemoveTest(StringCollection collection, string[] data) { Assert.All(data, element => { Assert.True(collection.Contains(element)); Assert.True(((IList)collection).Contains(element)); collection.Remove(element); Assert.False(collection.Contains(element)); Assert.False(((IList)collection).Contains(element)); }); Assert.Equal(0, collection.Count); }
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() }; int cnt = 0; try { intl = new IntlStrings(); Console.WriteLine("--- create collection ---"); strLoc = "Loc_001oo"; iCountTestcases++; sc = new StringCollection(); Console.WriteLine("1. Remove() from empty collection"); for (int i = 0; i < values.Length; i++) { iCountTestcases++; sc.Remove(values[i]); if (sc.Count != 0) { iCountErrors++; Console.WriteLine("Err_0001_{0}, Remove changed Count for empty collection", i); } } Console.WriteLine("2. add simple strings and test Remove()"); strLoc = "Loc_002oo"; 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); } for (int i = 0; i < values.Length; i++) { iCountTestcases++; if (!sc.Contains(values[i])) { iCountErrors++; Console.WriteLine("Err_0002_{0}b, doesn't contain {0} item", i); } cnt = sc.Count; iCountTestcases++; sc.Remove(values[i]); if (sc.Count != cnt - 1) { iCountErrors++; Console.WriteLine("Err_0002_{0}c, didn't remove anything", i); } if (sc.Contains(values[i])) { iCountErrors++; Console.WriteLine("Err_0002_{0}d, removed wrong item", i); } } Console.WriteLine("3. add intl strings and test Remove()"); strLoc = "Loc_003oo"; string [] intlValues = new string [values.Length]; for (int i = 0; i < values.Length; i++) { string val = intl.GetString(MAX_LEN, true, true, true); while (Array.IndexOf(intlValues, val) != -1 ) val = intl.GetString(MAX_LEN, true, true, true); intlValues[i] = val; } int len = values.Length; Boolean caseInsensitive = false; for (int i = 0; i < len; i++) { if(intlValues[i].Length!=0 && intlValues[i].ToLower()==intlValues[i].ToUpper()) caseInsensitive = true; } iCountTestcases++; sc.Clear(); sc.AddRange(intlValues); if ( sc.Count != intlValues.Length ) { iCountErrors++; Console.WriteLine("Err_0003a, count is {0} instead of {1}", sc.Count, intlValues.Length); } for (int i = 0; i < intlValues.Length; i++) { iCountTestcases++; if (!sc.Contains(intlValues[i])) { iCountErrors++; Console.WriteLine("Err_0002_{0}b, doesn't contain {0} item", i); } cnt = sc.Count; iCountTestcases++; sc.Remove(intlValues[i]); if (sc.Count != cnt - 1) { iCountErrors++; Console.WriteLine("Err_0002_{0}c, didn't remove anything", i); } if (sc.Contains(intlValues[i])) { iCountErrors++; Console.WriteLine("Err_0002_{0}d, removed wrong item", i); } } Console.WriteLine("4. duplicate strings "); strLoc = "Loc_004oo"; iCountTestcases++; sc.Clear(); string intlStr = intlValues[0]; sc.Add(intlStr); sc.AddRange(values); sc.AddRange(intlValues); cnt = values.Length + 1 + intlValues.Length; if (sc.Count != cnt) { iCountErrors++; Console.WriteLine("Err_0004a, count is {1} instead of {2}", sc.Count, cnt); } iCountTestcases++; if (sc.IndexOf(intlStr) != 0) { iCountErrors++; Console.WriteLine("Err_0004b, IndexOf returned {0} instead of {1}", sc.IndexOf(intlStr), 0); } iCountTestcases++; sc.Remove(intlStr); if (!sc.Contains(intlStr)) { iCountErrors++; Console.WriteLine("Err_0004c, removed both duplicates"); } if (sc.IndexOf(intlStr) != values.Length) { iCountErrors++; Console.WriteLine("Err_0004d, IndexOf returned {0} instead of {1}", sc.IndexOf(intlStr), values.Length); } for (int i = 0; i < values.Length; i++) { if (sc.IndexOf(values[i]) != i) { iCountErrors++; Console.WriteLine("Err_0004e_{0}, IndexOf {0} item returned {1} ", i, sc.IndexOf(values[i])); } if (sc.IndexOf(intlValues[i]) != i+values.Length) { iCountErrors++; Console.WriteLine("Err_0004f_{0}, IndexOf {1} item returned {2} ", i, i+values.Length, sc.IndexOf(intlValues[i])); } } Console.WriteLine("5. Case sensitivity"); strLoc = "Loc_005oo"; iCountTestcases++; sc.Clear(); sc.Add(intlStr.ToUpper()); sc.AddRange(values); sc.Add(intlStr.ToLower()); cnt = values.Length + 2; if (sc.Count != cnt) { iCountErrors++; Console.WriteLine("Err_0005a, count is {1} instead of {2} ", sc.Count, cnt); } intlStr = intlStr.ToLower(); iCountTestcases++; Console.WriteLine(" - remove lowercase" ); cnt = sc.Count; sc.Remove(intlStr); if (sc.Count != cnt-1) { iCountErrors++; Console.WriteLine("Err_0005b, didn't remove anything"); } if (!caseInsensitive && sc.Contains(intlStr)) { iCountErrors++; Console.WriteLine("Err_0005c, didn't remove lowercase "); } if (!sc.Contains(intlValues[0].ToUpper())) { iCountErrors++; Console.WriteLine("Err_0005d, removed uppercase "); } Console.WriteLine("6. Remove() non-existing item"); strLoc = "Loc_006oo"; iCountTestcases++; sc.Clear(); sc.AddRange(values); cnt = values.Length; if (sc.Count != cnt) { iCountErrors++; Console.WriteLine("Err_0006a, count is {1} instead of {2} ", sc.Count, cnt); } intlStr = "Hello"; iCountTestcases++; cnt = sc.Count; sc.Remove(intlStr); if (sc.Count != cnt) { iCountErrors++; Console.WriteLine("Err_0005b, removed something"); } } 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; } }
private bool UpdateIds(StringCollection ids, DataTable table, UpdateMode mode) { bool updated = false; if (mode == UpdateMode.New && ids.Count > 0) { ids.Clear(); updated = true; } foreach (DataRow row in table.Rows) { if (!row.IsNull(0)) { string value = row[0].ToString(); if (mode == UpdateMode.Remove) { if (ids.IndexOf(value) >= 0) { ids.Remove(value); updated = true; } } else { if (mode == UpdateMode.Add) { if (ids.IndexOf(value) < 0) { ids.Add(value); updated = true; } } else { ids.Add(value); updated = true; } } } } return updated; }