/// <summary> /// Adds the relevant details of a claim as a row in the table passed in. /// </summary> /// <param name="claim">The claim to be described.</param> /// <param name="table">The table to add a row to.</param> private void AddClaimRow(IClaimsIdentity claimsId, Table table) { TableHeaderCell thc1 = new TableHeaderCell(); thc1.Text = "Claim Type"; TableHeaderCell thc2 = new TableHeaderCell(); thc2.Text = "Claim Value"; TableHeaderCell thc3 = new TableHeaderCell(); thc3.Text = "Value Type"; TableHeaderCell thc4 = new TableHeaderCell(); thc4.Text = "Subject Name"; TableHeaderCell thc5 = new TableHeaderCell(); thc5.Text = "Issuer Name"; // Add the needed columns to the table TableHeaderRow th = new TableHeaderRow(); th.Controls.Add(thc1); th.Controls.Add(thc2); th.Controls.Add(thc3); th.Controls.Add(thc4); th.Controls.Add(thc5); th.BorderWidth = 1; th.BorderColor = System.Drawing.Color.Chocolate; table.Controls.Add(th); //Populate the table with claims information // Show the ones that are expected claims StringCollection collClaims = new StringCollection(); collClaims.AddRange(ExpectedClaims); foreach (Claim claim in claimsId.Claims) { // Validate whether the claim is what we expect // if not, disregard that to show in the claims table if (collClaims.Contains(claim.ClaimType)) { WriteClaim(claim, table); } } // Set table properties for easy reading table.BorderWidth = 1; table.Font.Name = "Franklin Gothic Book"; table.Font.Size = 10; table.CellPadding = 3; table.CellSpacing = 3; table.BorderColor = System.Drawing.Color.Chocolate; }
/// <summary> /// Gets the user messages from the given exception. /// </summary> /// <param name="ex"></param> /// <returns></returns> public static string[] GetUserMessages(Exception ex) { if (ex == null) { return new string[] { "No error messages were returned." } } ; // walk... StringCollection messages = new StringCollection(); Exception scan = ex; while (scan != null) { // are we? if (scan is IUserMessages) { messages.AddRange(((IUserMessages)scan).GetUserMessages()); } // next... scan = scan.InnerException; } // do we have any? if not build one string that expresses the stack... if (messages.Count == 0) { scan = ex; while (scan != null) { StringBuilder builder = new StringBuilder(); for (int index = 0; index < messages.Count; index++) { builder.Append(" "); } // next... builder.Append(scan.Message); // add... messages.Add(builder.ToString()); // next... scan = scan.InnerException; } } // return... string[] results = new string[messages.Count]; for (int index = 0; index < messages.Count; index++) { results[index] = messages[index]; } // return... return(results); } }
public override ApplicationRecordDataType GetApplication( NodeId applicationId ) { base.GetApplication(applicationId); string id = OpcVaultClientHelper.GetServiceIdFromNodeId(applicationId, NamespaceIndex); ApplicationRecordApiModel result; try { result = _opcVaultServiceClient.GetApplication(id); } catch { return(null); } var names = new List <LocalizedText>(); foreach (var applicationName in result.ApplicationNames) { names.Add(new LocalizedText(applicationName.Locale, applicationName.Text)); } StringCollection discoveryUrls = null; var endpoints = result.DiscoveryUrls; if (endpoints != null) { discoveryUrls = new StringCollection(); foreach (var endpoint in endpoints) { discoveryUrls.Add(endpoint); } } var capabilities = new StringCollection(); if (!String.IsNullOrWhiteSpace(result.ServerCapabilities)) { capabilities.AddRange(result.ServerCapabilities.Split(',')); } NodeId appNodeId = OpcVaultClientHelper.GetNodeIdFromServiceId(result.ApplicationId, NamespaceIndex); return(new ApplicationRecordDataType() { ApplicationId = appNodeId, ApplicationUri = result.ApplicationUri, ApplicationType = (ApplicationType)result.ApplicationType, ApplicationNames = new LocalizedTextCollection(names), ProductUri = result.ProductUri, DiscoveryUrls = discoveryUrls, ServerCapabilities = capabilities }); }
public void Connect() { if (Connection != null) { if (Connection.State != ConnectionState.Open) { Connection.Open(); return; } } else { if (string.IsNullOrEmpty(ConnectionString)) { throw new InvalidOperationException("You must set a connection object or specify a connection string before calling Connect."); } StringCollection stringCollection = new StringCollection(); stringCollection.AddRange(new string[] { "ARITHABORT", "ANSI_NULLS", "ANSI_WARNINGS", "ARITHIGNORE", "ANSI_DEFAULTS", "ANSI_NULL_DFLT_OFF", "ANSI_NULL_DFLT_ON", "ANSI_PADDING", "ANSI_WARNINGS" }); StringBuilder sqlSetStringBuilder = new StringBuilder(); StringBuilder connectionStringBuilder = new StringBuilder(); Hashtable hashtable = ParseConfigString(ConnectionString); foreach (object obj in hashtable.Keys) { string text = (string)obj; if (stringCollection.Contains(text.Trim().ToUpper())) { sqlSetStringBuilder.AppendFormat("SET {0} {1};", text, hashtable[text]); } else if (text.Trim().Length > 0) { connectionStringBuilder.AppendFormat("{0}={1};", text, hashtable[text]); } } Connection = new SqlConnection(connectionStringBuilder.ToString()); Connection.Open(); if (sqlSetStringBuilder.Length > 0) { IDbCommand command = Connection.CreateCommand(); command.CommandTimeout = CommandTimeout; command.CommandText = sqlSetStringBuilder.ToString(); command.CommandType = CommandType.Text; command.ExecuteNonQuery(); command.Dispose(); return; } } }
public void Connect() { if (_connection != null) { if (_connection.State != ConnectionState.Open) { _connection.Open(); } } else { if (_connectionString != String.Empty) { StringCollection initKeys = new StringCollection(); // ToDo - Figure this out initKeys.AddRange(new string[] { "ARITHABORT", "ANSI_NULLS", "ANSI_WARNINGS", "ARITHIGNORE", "ANSI_DEFAULTS", "ANSI_NULL_DFLT_OFF", "ANSI_NULL_DFLT_ON", "ANSI_PADDING", "ANSI_WARNINGS" }); StringBuilder initStatements = new StringBuilder(); StringBuilder connectionString = new StringBuilder(); Hashtable attribs = this.ParseConfigString(_connectionString); foreach (string key in attribs.Keys) { if (initKeys.Contains(key.Trim().ToUpper())) { initStatements.AppendFormat("SET {0} {1};", key, attribs[key]); } else if (key.Trim().Length > 0) { connectionString.AppendFormat("{0}={1};", key, attribs[key]); } } _connection = new SAConnection(connectionString.ToString()); _connection.Open(); if (initStatements.Length > 0) { SACommand cmd = new SACommand(); cmd.CommandTimeout = this.CommandTimeout; cmd.CommandText = initStatements.ToString(); cmd.Connection = _connection; cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); cmd.Dispose(); } } else { throw new InvalidOperationException( "You must set a connection object or specify a connection string before calling Connect."); } } }
// ヘッダを分析し、Dictionary<string, string> に格納 public static Dictionary <string, string> Parse(string header) { StringCollection line = new StringCollection(); Dictionary <string, string> sd = new Dictionary <string, string>(); line.AddRange(Regex.Split(header, "\r\n")); Match m = Regex.Match(line[0], @"^(.+)\s+(.+)/(\d\.\d)$"); Match n = Regex.Match(line[0], @"^(.+)/(\d\.\d)\s+(\d{3})\s+(.+)$"); if (m.Success) { // REQUEST - e.g.: "^(GET String) (SHIORI)/(2.5)$" sd["_COMMANDLINE_"] = line[0]; sd["_METHOD_"] = m.Groups[1].Value; sd["_PROTOCOL_"] = m.Groups[2].Value; sd["_VERSION_"] = m.Groups[3].Value; } else if (n.Success) { // RESPONSE - e.g.: "^(SHIORI)/(3.0) (204) (No Content)$" sd["_STATUSLINE_"] = line[0]; sd["_PROTOCOL_"] = n.Groups[1].Value; sd["_VERSION_"] = n.Groups[2].Value; sd["_STATUS_"] = n.Groups[3].Value; sd["_STRING_"] = n.Groups[4].Value; } line.RemoveAt(0); // コマンドライン削除 // SSTP の Entry, IfGhost - Script は例外にならざるを得ないので、このような処理になった // その他の方法論としては、レスポンス格納用の変数をさらにネストするか、 // 行単位で保持するか、独自の管理クラスを作るか、 // そもそも帰ってきた値を変数としてキープしておくのをやめるか、等々 // int e = 0; // Entryキー用カウンタ // int i = 0; // IfGhost 用カウンタ // int s = 0; // Script 用カウンタ // Regex re = new Regex(@"^Entry\s*:\s*(.+)\s*$", RegexOptions.Compiled); // Regex ri = new Regex(@"^IfGhost\s*:\s*(.+)\s*$", RegexOptions.Compiled); // Regex rs = new Regex(@"^Script\s*:\s*(.+)\s*$", RegexOptions.Compiled); // Regex rg = new Regex(@"^GhostEx\s*:\s*(.+)\s*$", RegexOptions.Compiled); // Regex rb = new Regex(@"^X-Bottle-IfGhost\s*:\s*(.+)\s*$", RegexOptions.Compiled); // ボトル拡張 for (int j = 0; j < line.Count; ++j) { m = Protocol.rGeneralEntry.Match(line[j]); if (m.Success) { // e.g.: "^Value: \0\s[10]Hello, World!\e" sd[m.Groups[1].Value] = m.Groups[2].Value.Trim(); // } else if (re.Match(c).Success) { // "Entry: SAKURA script" // sd["Entry" + e++] = re.Match(c).Groups[1].Value; // } else if (ri.Match(c).Success) { // "IfGhost: Ghost name(s)" // sd["IfGhost" + i++] = ri.Match(c).Groups[1].Value; // } else if (rs.Match(c).Success) { // "Script: SAKURA script" // sd["GhostEx" + s++] = rs.Match(c).Groups[1].Value; // } else if (rg.Match(c).Success) { // "GhostEx: Ghost name" // sd["Script" + s++] = rg.Match(c).Groups[1].Value; // } else if (rb.Match(c).Success) { // "X-Bottle-IfGhost: Ghost name" // sd["X-Bottle-IfGhost"] = rb.Match(c).Groups[1].Value; } } return(sd); }
private void ReadQueryStrings(HttpContext context) { try { webUrl = context.Request.QueryString["webUrl"]; string listIdString = context.Request.QueryString["listId"] ?? String.Empty; string itemIdsString = context.Request.QueryString["itemIds"] ?? String.Empty; fileName = context.Request.QueryString["fileName"] ?? String.Empty; if (!String.IsNullOrEmpty(listIdString)) { listId = new Guid(listIdString); } else { throw new Exception("Invalid List ID"); } if (!String.IsNullOrEmpty(itemIdsString)) { char[] splitters = new char[] { '|' }; StringCollection itemIdStrings = new StringCollection(); itemIds = new List <int>(); itemIdStrings.AddRange(itemIdsString.Split(splitters, StringSplitOptions.RemoveEmptyEntries)); foreach (String itemIdString in itemIdStrings) { itemIds.Add(Int32.Parse(itemIdString)); } } else { throw new Exception("Invalid Item ID(s)"); } if (String.IsNullOrEmpty(webUrl)) { throw new Exception("Invalid Web Url"); } if (String.IsNullOrEmpty(fileName)) { fileName = "Assets.zip"; } else if (!fileName.EndsWith(".zip", StringComparison.InvariantCultureIgnoreCase)) { fileName = fileName + ".zip"; } } catch (Exception e) { throw new Exception("An error occurred while reading the query string parameters", e); } }
public void Add(string[] filePaths) { if (filePaths.Any(string.IsNullOrEmpty)) { throw new ArgumentException(nameof(filePaths)); } _playlist.AddRange(filePaths); }
void loadMedics() { IniFile ini = new IniFile(ClassSql.MMS_Path); string a = ini.IniReadValue("MEDICAL", "PEME_Physician"); string b = ini.IniReadValue("MEDICAL", "PEME MedicalDirector"); string c = ini.IniReadValue("MEDICAL", "MedTech"); string d = ini.IniReadValue("MEDICAL", "Pathologist"); string e = ini.IniReadValue("MEDICAL", "Xray_Radiologist"); string f = ini.IniReadValue("MEDICAL", "Medical_Director"); string g = ini.IniReadValue("MEDICAL", "HIV_Exam_physician"); string h = ini.IniReadValue("MEDICAL", "Psychometrician"); string i = ini.IniReadValue("MEDICAL", "Psychologist"); string j = ini.IniReadValue("MEDICAL", "XRAY_TECH"); string k = ini.IniReadValue("MEDICAL", "medtech1_Name"); string l = ini.IniReadValue("MEDICAL", "medtech2_Name"); string aa = ini.IniReadValue("MEDICAL", "PEME_Physician_license"); string bb = ini.IniReadValue("MEDICAL", "PEME MedicalDirector_license"); string cc = ini.IniReadValue("MEDICAL", "MedTech_license"); string dd = ini.IniReadValue("MEDICAL", "Pathologist_license"); string ee = ini.IniReadValue("MEDICAL", "Xray Radiologist_license"); string ff = ini.IniReadValue("MEDICAL", "Medical Director_license"); string gg = ini.IniReadValue("MEDICAL", "HIV_Exam_physician_license"); string hh = ini.IniReadValue("MEDICAL", "Psychometrician_license"); string ii = ini.IniReadValue("MEDICAL", "Psychologist_license"); string jj = ini.IniReadValue("MEDICAL", "XRAYTECH_LICENSE"); string kk = ini.IniReadValue("MEDICAL", "medtech1_Lic"); string ll = ini.IniReadValue("MEDICAL", "medtech2_Lic"); StringCollection Names = new StringCollection(); StringCollection License = new StringCollection(); string[] row = new string[] { a, b, c, d, e, f, g, h, i, j, k, l }; string[] lics = new string[] { aa, bb, cc, dd, ee, ff, gg, hh, ii, jj, kk, ll }; Names.AddRange(row); License.AddRange(lics); foreach (string name in Names) { dg_medics.Rows.Add(name); } dg_medics.Rows[0].Cells[1].Value = aa; dg_medics.Rows[1].Cells[1].Value = bb; dg_medics.Rows[2].Cells[1].Value = cc; dg_medics.Rows[3].Cells[1].Value = dd; dg_medics.Rows[4].Cells[1].Value = ee; dg_medics.Rows[5].Cells[1].Value = ff; dg_medics.Rows[6].Cells[1].Value = gg; dg_medics.Rows[7].Cells[1].Value = hh; dg_medics.Rows[8].Cells[1].Value = ii; dg_medics.Rows[9].Cells[1].Value = jj; dg_medics.Rows[10].Cells[1].Value = kk; dg_medics.Rows[11].Cells[1].Value = ll; }
/// <summary> /// Creates a shallow copy of the specified <see cref="StringCollection" />. /// </summary> /// <param name="stringCollection">The <see cref="StringCollection" /> that should be copied.</param> /// <returns> /// A shallow copy of the specified <see cref="StringCollection" />. /// </returns> private static StringCollection Clone(StringCollection stringCollection) { string[] strings = new string[stringCollection.Count]; stringCollection.CopyTo(strings, 0); StringCollection clone = new StringCollection(); clone.AddRange(strings); return(clone); }
protected void BuildPropertySet(Type p, StringCollection propertySet) { if (TypeToLdapPropListMap[this.MappingTableIndex].ContainsKey(p)) { Debug.Assert(TypeToLdapPropListMap[this.MappingTableIndex].ContainsKey(p)); string[] props = new string[TypeToLdapPropListMap[this.MappingTableIndex][p].Count]; TypeToLdapPropListMap[this.MappingTableIndex][p].CopyTo(props, 0); propertySet.AddRange(props); } else { Type baseType; if (p.IsSubclassOf(typeof(UserPrincipal))) { baseType = typeof(UserPrincipal); } else if (p.IsSubclassOf(typeof(GroupPrincipal))) { baseType = typeof(GroupPrincipal); } else if (p.IsSubclassOf(typeof(ComputerPrincipal))) { baseType = typeof(ComputerPrincipal); } else if (p.IsSubclassOf(typeof(AuthenticablePrincipal))) { baseType = typeof(AuthenticablePrincipal); } else { baseType = typeof(Principal); } Hashtable propertyList = new Hashtable(); // Load the properties for the base types... foreach (string s in TypeToLdapPropListMap[this.MappingTableIndex][baseType]) { if (!propertyList.Contains(s)) { propertyList.Add(s, s); } } // Reflect the properties off the extension class and add them to the list. BuildExtensionPropertyList(propertyList, p); foreach (string property in propertyList.Values) { propertySet.Add(property); } // Cache the list for this property type so we don't need to reflect again in the future. this.AddPropertySetToTypePropListMap(p, propertySet); } }
public void LecturaCorrectaStringCollection() { StringCollection collection = new StringCollection(); collection.AddRange(new[] { "pepe , Venus", "lola, Marte" }); int rangoLista = 2; Assert.AreEqual(rangoLista, collection.Count); }
internal static StringCollection ToSC(IEnumerable <string> e) { var sc = new StringCollection(); if (e != null) { sc.AddRange(e.ToArray()); } return(sc); }
public Trigger(Trigger basedOn) : base(basedOn) { _updateEventColumns = new StringCollection(this); _updateEventColumns.AddRange(basedOn.UpdateEventColumns); _tableSchema = basedOn.TableSchema; _tableName = basedOn.TableName; _definition = basedOn.Definition; //_oldDefinition = _definition; }
private void AutoCompleteForm_VisibleChanged(object sender, System.EventArgs e) { ArrayList _items = new ArrayList(items); _items.Sort(new CaseInsensitiveComparer()); items = new StringCollection(); items.AddRange((string[])_items.ToArray(typeof(string))); columnHeader1.Width = lstCompleteItems.Width - SystemInformation.VerticalScrollBarWidth; }
private static StringCollection GetCompleteLibraryPaths(StringCollection userLibraryPaths) { StringCollection strings = new StringCollection(); strings.Add(Environment.CurrentDirectory); strings.Add(TrimDirectorySeparatorChar(RuntimeEnvironment.GetRuntimeDirectory())); string[] array = new string[userLibraryPaths.Count]; userLibraryPaths.CopyTo(array, 0); strings.AddRange(array); string environmentVariable = Environment.GetEnvironmentVariable("LIB"); if ((environmentVariable != null) && (environmentVariable.Length > 0)) { string[] strArray2 = Environment.GetEnvironmentVariable("LIB").Split(new char[] { ',', ';' }); strings.AddRange(strArray2); } return(strings); }
/// <summary> /// Recurses the directories. /// </summary> /// <param name="path">The path.</param> /// <param name="pattern">The pattern.</param> /// <param name="recurse">if set to <c>true</c> [recurse].</param> /// <param name="useRegex">if set to <c>true</c> [use regex].</param> private void RecurseDirectories(string path, string pattern, bool recurse, bool useRegex) { try { string[] files; if (!useRegex) { files = Directory.GetFiles(path, pattern); if (files != null) { m_Files.AddRange(files); // foreach (string file in files) // { // Console.WriteLine(file); // } } else { return; } } else { Match match; files = Directory.GetFiles(path); foreach (string file in files) { match = m_Regex.Match(file); if (match.Success) { m_Files.Add(file); } } } if (recurse) { string[] dirs = Directory.GetDirectories(path); if (dirs != null && dirs.Length > 0) { foreach (string str in dirs) { RecurseDirectories(Helper.NormalizePath(str), pattern, recurse, useRegex); } } } } catch (DirectoryNotFoundException) { return; } catch (ArgumentException) { return; } }
/// <summary> /// /// </summary> /// <param name="parameterNames">comma-delimited names</param> public MethodParameterJsCodeAttribute(string parameterNames) { _pnames = parameterNames; if (parameterNames != null) { _names = new StringCollection(); _names.AddRange(parameterNames.Split(',')); } }
private void AutoCompleteForm_VisibleChanged(object sender, System.EventArgs e) { ArrayList items = new ArrayList(mItems); items.Sort(new CaseInsensitiveComparer()); mItems = new StringCollection(); mItems.AddRange((string[])items.ToArray(typeof(string))); columnHeader1.Width = lstCompleteItems.Width - 20; }
/// <summary> /// Initializes a new instance of the FileHeader class. /// </summary> /// <param name="headerText"> /// The header text. /// </param> /// <param name="tokens"> /// The collection of tokens in the header. /// </param> /// <param name="parent"> /// The parent of the header. /// </param> internal FileHeader(string headerText, CsTokenList tokens, Reference <ICodePart> parent) { Param.AssertNotNull(headerText, "headerText"); Param.AssertNotNull(tokens, "tokens"); Param.AssertNotNull(parent, "parent"); this.headerText = headerText; this.tokens = tokens; this.parent = parent; this.location = this.tokens.First != null?CsToken.JoinLocations(this.tokens.First, this.tokens.Last) : CodeLocation.Empty; // Attempt to load this into an Xml document. try { if (this.headerText.Length > 0) { this.headerXml = string.Format(CultureInfo.InvariantCulture, "<root>{0}</root>", HtmlEncode(this.headerText)); XmlDocument doc = new XmlDocument(); doc.LoadXml(this.headerXml); // Check whether the header has the autogenerated tag. if (doc.DocumentElement != null) { XmlNode node = doc.DocumentElement["autogenerated"]; if (node != null) { // Set this as generated code. this.generated = true; } else { node = doc.DocumentElement["auto-generated"]; if (node != null) { // Set this as generated code. this.generated = true; } } StringCollection unstyledElements = new StringCollection(); unstyledElements.AddRange(new[] { "unstyled", "stylecopoff", "nostyle" }); XmlNodeList childNodes = doc.DocumentElement.ChildNodes; if (childNodes.Cast <XmlNode>().Any(xmlNode => unstyledElements.Contains(xmlNode.Name.ToLowerInvariant()))) { this.UnStyled = true; } } } } catch (XmlException) { } }
protected void ProcessView(object modelHost, SPList targetList, ListViewDefinition viewModel) { var currentView = targetList.Views.FindByName(viewModel.Title); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = currentView, ObjectType = typeof(SPView), ObjectDefinition = viewModel, ModelHost = modelHost }); if (currentView == null) { var viewFields = new StringCollection(); viewFields.AddRange(viewModel.Fields.ToArray()); // TODO, handle personal view creation currentView = targetList.Views.Add(viewModel.Title, viewFields, viewModel.Query, (uint)viewModel.RowLimit, viewModel.IsPaged, viewModel.IsDefault); } // viewModel.InvokeOnDeployingModelEvents<ListViewDefinition, SPView>(currentView); // if any fields specified, overwrite if (viewModel.Fields.Any()) { currentView.ViewFields.DeleteAll(); foreach (var viewField in viewModel.Fields) { currentView.ViewFields.Add(viewField); } } // viewModel.InvokeOnModelUpdatedEvents<ListViewDefinition, SPView>(currentView); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = currentView, ObjectType = typeof(SPView), ObjectDefinition = viewModel, ModelHost = modelHost }); currentView.Update(); }
public void Test06_NullStringArray() { StringCollection collectionTest = new StringCollection(); collectionTest.Add("collection"); collectionTest.Add("with"); collectionTest.Add("strings"); Assert.ThrowsException <ArgumentNullException>(() => collectionTest.AddRange(strings: default(string[]))); }
public void Test02_NullStringCollectionReference() { StringCollection collectionTest = default; StringCollection collection2 = new StringCollection(); collection2.Add("init"); Assert.ThrowsException <ArgumentNullException>(() => collectionTest.AddRange(collection2)); }
public static StringCollection ToStringCollection(this IEnumerable <String> enumberable) { List <String> list = new List <String>(enumberable); StringCollection collection = new StringCollection(); collection.AddRange(list.ToArray()); return(collection); }
public static void CountTest(StringCollection collection, string[] data) { Assert.Equal(data.Length, collection.Count); collection.Clear(); Assert.Equal(0, collection.Count); collection.Add("one"); Assert.Equal(1, collection.Count); collection.AddRange(data); Assert.Equal(1 + data.Length, collection.Count); }
public async Task InjectFilesAsync(params string[] files) { clipboardCopyInterceptor.SkipNext(); var collection = new StringCollection(); collection.AddRange(files); WindowsClipboard.SetFileDropList(collection); }
public bool TerminateProjects() // ... when ending the program { StringCollection collection = new StringCollection(); collection.AddRange(RecentProjects.ToArray()); Properties.Settings.Default.RecentProjects = collection; Properties.Settings.Default.Save(); return(abortOperation()); }
/// <summary> /// /// </summary> /// <param name="language"></param> /// <param name="version"></param> public static void LoadPhpbbFileList(string language, ModVersion version) { PhpbbFileList.Clear(); if (version.Major == 2 && version.Minor == 0) { PhpbbFileList.AddRange(OpenTextFile(Path.Combine(domain.BaseDirectory, "files.txt")).Replace("\r\n", "\n").Split('\n')); } else if (version.Major == 3 && version.Minor == 0) { PhpbbFileList.AddRange(OpenTextFile(Path.Combine(domain.BaseDirectory, "files_3.0.txt")).Replace("\r\n", "\n").Split('\n')); } if (language != "english") { for (int i = 0; i < PhpbbFileList.Count; i++) { PhpbbFileList[i] = PhpbbFileList[i].Replace("english", language); } } }
public virtual StringCollection GetFileDropList() { StringCollection retVal = new StringCollection(); if (GetData(DataFormats.FileDrop, true) is string[] strings) { retVal.AddRange(strings); } return(retVal); }
public StringCollection Save() { StringCollection saveCol = new StringCollection(); string[] strs = new string[history.Count]; history.Values.CopyTo(strs, 0); saveCol.AddRange(strs); return(saveCol); }
public static StringCollection FromString(string value, char separator) { StringCollection col = new StringCollection(); if (value.Length > 0) { col.AddRange(value.Split(separator)); } return col; }
public StringCollection Clone() { StringCollection c = new StringCollection(); if (Count > 0) { string[] strings = new string[Count]; CopyTo(strings, 0); c.AddRange(strings); } return c; }
}/// <summary> /// Data used for testing with RemoveAt. /// </summary> /// Format is: /// 1. initial Collection /// 2. internal data /// 3. location to remove (0, count / 2, count) /// <returns>Row of data</returns> public static IEnumerable<object[]> RemoveAt_Data() { foreach (object[] data in StringCollection_Data().Concat(StringCollection_Duplicates_Data())) { string[] d = (string[])(data[1]); if (d.Length > 0) { foreach (int location in new[] { 0, d.Length / 2, d.Length - 1 }.Distinct()) { StringCollection initial = new StringCollection(); initial.AddRange(d); yield return new object[] { initial, d, location }; } } } }
/// <summary> /// Data used for testing with Insert. /// </summary> /// Format is: /// 1. initial Collection /// 2. internal data /// 3. data to insert (ElementNotPresent or null) /// 4. location to insert (0, count / 2, count) /// <returns>Row of data</returns> public static IEnumerable<object[]> Insert_Data() { foreach (object[] data in StringCollection_Data().Concat(StringCollection_Duplicates_Data())) { string[] d = (string[])(data[1]); foreach (string element in new[] { ElementNotPresent, null }) { foreach (int location in new[] { 0, d.Length / 2, d.Length }.Distinct()) { StringCollection initial = new StringCollection(); initial.AddRange(d); yield return new object[] { initial, d, element, location }; } } } }/// <summary>
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. Check for empty collection"); for (int i = 0; i < values.Length; i++) { iCountTestcases++; if (sc.IndexOf(values[i]) != -1) { iCountErrors++; Console.WriteLine("Err_0001_{0}, returned {1} for empty collection", i, sc.IndexOf(values[i])); } } Console.WriteLine("2. add simple strings and verify IndexOf()"); strLoc = "Loc_002oo"; iCountTestcases++; cnt = sc.Count; 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.IndexOf(values[i]) != i) { iCountErrors++; Console.WriteLine("Err_0002_{0}b, IndexOf returned {1} instead of {0}", i, sc.IndexOf(values[i])); } } Console.WriteLine("3. add intl strings and verify IndexOf()"); 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++; cnt = sc.Count; sc.AddRange(intlValues); if ( sc.Count != (cnt + intlValues.Length) ) { iCountErrors++; Console.WriteLine("Err_0003a, count is {0} instead of {1}", sc.Count, cnt + intlValues.Length); } for (int i = 0; i < intlValues.Length; i++) { iCountTestcases++; if (sc.IndexOf(intlValues[i]) != values.Length + i) { iCountErrors++; Console.WriteLine("Err_0003_{0}b, IndexOf returned {1} instead of {2}", i, sc.IndexOf(intlValues[i]), values.Length + 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.Clear(); sc.AddRange(values); sc.AddRange(intlValues); sc.Add(intlStr); cnt = values.Length + 1 + intlValues.Length; if (sc.Count != cnt) { iCountErrors++; Console.WriteLine("Err_0004c, count is {1} instead of {2}", sc.Count, cnt); } iCountTestcases++; if (sc.IndexOf(intlStr) != values.Length) { iCountErrors++; Console.WriteLine("Err_0004b, IndexOf returned {0} instead of {1}", sc.IndexOf(intlStr), values.Length); } Console.WriteLine("5. Case sensitivity"); strLoc = "Loc_005oo"; iCountTestcases++; sc.Clear(); sc.Add(intlValues[0].ToUpper()); sc.AddRange(values); sc.Add(intlValues[0].ToLower()); cnt = values.Length + 2; if (sc.Count != cnt) { iCountErrors++; Console.WriteLine("Err_0005, count is {1} instead of {2} ", sc.Count, cnt); } intlStr = intlValues[0].ToLower(); iCountTestcases++; Console.WriteLine(" - look for lowercase" ); if (!caseInsensitive && (sc.IndexOf(intlStr) != values.Length + 1)) { iCountErrors++; Console.WriteLine("Err_0005a, IndexOf() returned {0} instead of {1} ", sc.IndexOf(intlStr), values.Length + 1); } } 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; } }
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. add simple strings"); iCountTestcases++; cnt = sc.Count; sc.AddRange(values); if (sc.Count != values.Length) { iCountErrors++; Console.WriteLine("Err_0001, count is {0} instead of {1}", sc.Count, values.Length); } Console.WriteLine("2. verify that collection contains all added items"); strLoc = "Loc_002oo"; for (int i = 0; i < values.Length; i++) { iCountTestcases++; if (!sc.Contains(values[i])) { iCountErrors++; Console.WriteLine("Err_0002_{0}, collection doesn't contain new item", i); } } Console.WriteLine("3. add intl strings"); 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; } strLoc = "Loc_003oo"; cnt = sc.Count; Console.WriteLine(" initial number of items: " + cnt); iCountTestcases++; sc.AddRange(intlValues); if (sc.Count != (cnt + intlValues.Length)) { iCountErrors++; Console.WriteLine("Err_0003, count is {0} instead of {1}", sc.Count, cnt + intlValues.Length); } Console.WriteLine("4. verify that collection contains all added items"); strLoc = "Loc_004oo"; for (int i = 0; i < intlValues.Length; i++) { iCountTestcases++; iCountTestcases++; if (!sc.Contains(intlValues[i])) { iCountErrors++; Console.WriteLine("Err_0004_{0}, collection doesn't contain new item", i); } } Console.WriteLine("5. add empty range"); strLoc = "Loc_005oo"; iCountTestcases++; cnt = sc.Count; string [] empty = {}; sc.AddRange(empty); if (sc.Count != cnt) { iCountErrors++; Console.WriteLine("Err_0005, count is {0} instead of {1}", sc.Count, cnt); } } 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 void CommonConstructor(Ektron.Cms.Controls.Menu menuObject, Ektron.Cms.Common.EkEnumeration.CMSMenuItemType targettype, CMSIDTypes.menuitem_id targetid) { this.menu_id_val = new CMSIDTypes.menu_id(menuObject.DefaultMenuID); this.targettype_val = targettype; this.targetid_val = targetid; MenuObj_val = menuObject; // Test for standard menu XML xpaths XmlNodeList xnl; StringCollection strcolValidationPaths = new StringCollection(); string[] strarrValidationPaths = new string[] { "/MenuDataResult", "/MenuDataResult/Item", "/MenuDataResult/Item/Item" }; strcolValidationPaths.AddRange(strarrValidationPaths); foreach (string strValidationPath in strcolValidationPaths) { xnl = MenuObj_val.XmlDoc.SelectNodes(strValidationPath); if (xnl.Count <= 0) { TargetNotInMenuException ex = new TargetNotInMenuException(this.GetType().ToString() + ": CMS returns invalid menu data. XPath \"" + strValidationPath + "\" is missing from the XML returned for menu_id " + MenuObj_val.DefaultMenuID.ToString() + ". This may indicate that no menu with ID " + MenuObj_val.DefaultMenuID.ToString() + " exists."); ex.Source = ExceptionSource; throw (ex); } } string menuTargetXPath = "/descendant::Item[child::ItemID=\'" + targetid.val.ToString() + "\' and ItemType=\'" + targettype.ToString() + "\']"; xnl = MenuObj_val.XmlDoc.SelectNodes(menuTargetXPath); if (xnl.Count > 0) // Test to ensure that the target item exists in the menu { TargetCrumb_val = xnl[0]; } else { TargetNotInMenuException ex = new TargetNotInMenuException(this.GetType().ToString() + ": Item ID " + targetid.val.ToString() + ", Type \"" + targettype.ToString() + "\" does not exist in menu_id " + MenuObj_val.DefaultMenuID.ToString()); ex.Source = ExceptionSource; throw (ex); } string menuAncestorsXPath = "(" + menuTargetXPath + "/ancestor::Item[ItemType=\'" + Ektron.Cms.Common.EkEnumeration.CMSMenuItemType.Submenu.ToString() + "\'])|(" + menuTargetXPath + ")"; TierCrumb_val = MenuObj_val.XmlDoc.SelectNodes(menuAncestorsXPath); TierCrumb_idx = new XMLNodeListIndexer(TierCrumb_val); XmlNode xn; Ektron.Cms.Common.EkEnumeration.CMSMenuItemType xn_ItemType; int xn_ItemID; string tierXPath; int TierListLength; if (targettype == Ektron.Cms.Common.EkEnumeration.CMSMenuItemType.Submenu) { //If target is a submenu we'll grab the children TierListLength = TierCrumb_val.Count; } else { TierListLength = TierCrumb_val.Count - 1; } TierList_val = new XmlNodeList[TierListLength + 1]; for (int I = 0; I <= (TierListLength); I++) { if (I == 0) { xn = TierCrumb_val[0]; xn_ItemType = (Ektron.Cms.Common.EkEnumeration.CMSMenuItemType)(Enum.Parse(typeof(Ektron.Cms.Common.EkEnumeration.CMSMenuItemType), xn.SelectSingleNode("ItemType").InnerText)); xn_ItemID = int.Parse(xn.SelectSingleNode("ItemID").InnerText); tierXPath = "/descendant::Item[child::ItemID=\'" + xn_ItemID.ToString() + "\' and ItemType=\'" + xn_ItemType.ToString() + "\']"; } else if (TierCrumb_val.Count > 0) { xn = TierCrumb_val[I - 1]; xn_ItemType = (Ektron.Cms.Common.EkEnumeration.CMSMenuItemType)(Enum.Parse(typeof(Ektron.Cms.Common.EkEnumeration.CMSMenuItemType), xn.SelectSingleNode("ItemType").InnerText)); xn_ItemID = int.Parse((string)(xn.SelectSingleNode("ItemID").InnerText)); tierXPath = "/descendant::Item[child::ItemID=\'" + xn_ItemID.ToString() + "\' and ItemType=\'" + xn_ItemType.ToString() + "\']/child::Menu/child::Item"; break; } else { xn = TierCrumb_val[I]; xn_ItemType = (Ektron.Cms.Common.EkEnumeration.CMSMenuItemType)(Enum.Parse(typeof(Ektron.Cms.Common.EkEnumeration.CMSMenuItemType), xn.SelectSingleNode("ItemType").InnerText)); xn_ItemID = int.Parse(xn.SelectSingleNode("ItemID").InnerText); tierXPath = "/descendant::Item[child::ItemID=\'" + xn_ItemID.ToString() + "\' and ItemType=\'" + xn_ItemType.ToString() + "\']/parent::Menu/child::Item"; } xnl = MenuObj_val.XmlDoc.SelectNodes(tierXPath); TierList_val.SetValue(xnl, I); } IsInitialized = true; }
/// /// Removes stop words from the text. /// public static string RemoveStopWords(string inputText) { inputText = inputText .Replace("\\", string.Empty) .Replace("|", string.Empty) .Replace("(", string.Empty) .Replace(")", string.Empty) .Replace("[", string.Empty) .Replace("]", string.Empty) .Replace("*", string.Empty) .Replace("?", string.Empty) .Replace("}", string.Empty) .Replace("{", string.Empty) .Replace("^", string.Empty) .Replace("+", string.Empty); // transform given text into array of words char[] wordSeparators = new char[] { ' ', '\n', '\r', ',', ';', '.', '!', '?', '-', ' ', '"', '\'' }; string[] words = inputText.Split(wordSeparators, StringSplitOptions.RemoveEmptyEntries); // Create and initializes a new StringCollection. StringCollection myStopWordsCol = new StringCollection(); // Add a range of elements from an array to the end of the StringCollection. myStopWordsCol.AddRange(stopWordsArrary); StringBuilder sb = new StringBuilder(); for (int i = 0; i < words.Length; i++) { string word = words[i].ToLowerInvariant().Trim(); if (word.Length > 1 && !myStopWordsCol.Contains(word)) sb.Append(word + " "); } return sb.ToString(); }
public static void CountTest(StringCollection collection, string[] data) { Assert.Equal(data.Length, collection.Count); collection.Clear(); Assert.Equal(0, collection.Count); collection.Add("one"); Assert.Equal(1, collection.Count); collection.AddRange(data); Assert.Equal(1 + data.Length, collection.Count); }
public static void AddRange_NullTest(StringCollection collection, string[] data) { Assert.Throws<ArgumentNullException>("value", () => collection.AddRange(null)); }
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; } }
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; } }
public void PrintStringAtPos(string str, int pagenum, int col, int row, int maxlength = 100, int maxrows = 1) { if (String.IsNullOrWhiteSpace(str)) return; // replace Euro with "{" {backspace} "=" as the best approximation i've come up with... // unforunately the Euro currency came along after the printer's ROM... "{=" seemed to look the best out of various potential combinations, e.g. (=, C=, C: str = str.Replace("€", "{\x08="); //wordwrap logic... if (str.Length > maxlength && Math.Abs(maxrows) > 1) { var lines = new StringCollection(); //first check if text already has hard coded carriage returns in it and just assume those have been formatted properly if (str.Contains("\n")) lines.AddRange(str.Split('\n')); else { //otherwise dive into word wrap logic... //regex from here: http://regexlib.com/%28A%28EUjmatMAbqeJAVntKDWeVsP5A_5Xg2Q0u9xwCAHWWstjGAsCMb9Bvt6wVbYw4T-qTSvJU4RyVpn50P4Nci6N1vvxBArnwgO_k8F_3qJa5EdPPrrHHjp02XUS30FiGt4NNIFU8ZEynWmDksDVFHsuXNjDJ4ZS2saCasmnMl03WWfEW6uh7-BNkiTj0JD4Jypu0%29%29/REDetails.aspx?regexp_id=470 //grabs the 'maxlength' of chars it can, breaking on whitespace, period or dash var wordWrapRegex = new Regex(@"^[\s\S]{1," + maxlength.ToString(CultureInfo.InvariantCulture) + @"}([\s\.\-]|$)", RegexOptions.Singleline | RegexOptions.ExplicitCapture); while (lines.Count < Math.Abs(maxrows)) { Match result = wordWrapRegex.Match(str); if (!result.Success) break; lines.Add(result.Value.TrimEnd()); str = str.Left(-result.Value.Length); //negative Left "slices" x chars off the left and returns the remainder } //if we bailed out because we couldn't wordwrap anything in, just include the chopped text so at least it's visible if (lines.Count < Math.Abs(maxrows) && str.Length > 0) lines.Add(str.Left(maxlength)); } //negative maxrows means word wrap from the top of the block defined by row-lines.count //e.g. when you're printing an NF1, Field 11 (the NF2 value box) has a "DO NOT GO OVER 2500" phrase that wraps within that space, //so you want to "back up" to the top of the allocated text space and wrap down from there... //conversely, when printing the flat NF2 dollar value, you want it to go right on the specified row at the bottom of the space if (maxrows < 0) row = row - lines.Count + 1; foreach (var line in lines) PrintBytesAtPos(CP437GetBytes(line), pagenum, col, row++); } else //otherwise just print the maxlength of single line PrintBytesAtPos(CP437GetBytes(str.Left(maxlength)), pagenum, col, row); }
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() }; string[] destination; int cnt = 0; try { intl = new IntlStrings(); Console.WriteLine("--- create collection ---"); strLoc = "Loc_001oo"; iCountTestcases++; sc = new StringCollection(); Console.WriteLine("1. Copy empty collection into empty array"); iCountTestcases++; destination = new string[values.Length]; for (int i = 0; i < values.Length; i++) { destination[i] = ""; } sc.CopyTo(destination, 0); if( destination.Length != values.Length) { iCountErrors++; Console.WriteLine("Err_0001a, altered array after copying empty collection"); } if (destination.Length == values.Length) { for (int i = 0; i < values.Length; i++) { iCountTestcases++; if (String.Compare(destination[i], "", false) != 0) { iCountErrors++; Console.WriteLine("Err_0001_{0}b, item = \"{1}\" insteead of \"{2}\" after copying empty collection", i, destination[i], ""); } } } Console.WriteLine("2. Copy empty collection into non-empty array"); iCountTestcases++; destination = values; sc.CopyTo(destination, 0); if( destination.Length != values.Length) { iCountErrors++; Console.WriteLine("Err_0002a, altered array after copying empty collection"); } if (destination.Length == values.Length) { for (int i = 0; i < values.Length; i++) { iCountTestcases++; if (String.Compare(destination[i], values[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_0002_{0}b, altered item {0} after copying empty collection", i); } } } Console.WriteLine("3. add simple strings and CopyTo([], 0)"); strLoc = "Loc_003oo"; iCountTestcases++; cnt = sc.Count; sc.AddRange(values); if (sc.Count != values.Length) { iCountErrors++; Console.WriteLine("Err_0003a, count is {0} instead of {1}", sc.Count, values.Length); } destination = new string[values.Length]; sc.CopyTo(destination, 0); for (int i = 0; i < values.Length; i++) { iCountTestcases++; if ( String.Compare(sc[i], destination[i], false) != 0 ) { iCountErrors++; Console.WriteLine("Err_0003_{0}b, copied \"{1}\" instead of \"{2}\"", i, destination[i], sc[i]); } } Console.WriteLine("4. add simple strings and CopyTo([], {0})", values.Length); sc.Clear(); strLoc = "Loc_004oo"; iCountTestcases++; cnt = sc.Count; sc.AddRange(values); if (sc.Count != values.Length) { iCountErrors++; Console.WriteLine("Err_0003a, count is {0} instead of {1}", sc.Count, values.Length); } destination = new string[values.Length * 2]; sc.CopyTo(destination, values.Length); for (int i = 0; i < values.Length; i++) { iCountTestcases++; if ( String.Compare(sc[i], destination[i+values.Length], false) != 0 ) { iCountErrors++; Console.WriteLine("Err_0003_{0}b, copied \"{1}\" instead of \"{2}\"", i, destination[i+values.Length], sc[i]); } } Console.WriteLine("5. add intl strings and CopyTo([], 0)"); strLoc = "Loc_005oo"; iCountTestcases++; 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; } iCountTestcases++; sc.Clear(); sc.AddRange(intlValues); if ( sc.Count != (intlValues.Length) ) { iCountErrors++; Console.WriteLine("Err_0005a, count is {0} instead of {1}", sc.Count, intlValues.Length); } destination = new string[intlValues.Length]; sc.CopyTo(destination, 0); for (int i = 0; i < intlValues.Length; i++) { iCountTestcases++; if ( String.Compare(sc[i], destination[i], false) != 0 ) { iCountErrors++; Console.WriteLine("Err_0005_{0}b, copied \"{1}\" instead of \"{2}\"", i, destination[i], sc[i]); } } Console.WriteLine("6. add intl strings and CopyTo([], {0})", intlValues.Length); strLoc = "Loc_006oo"; iCountTestcases++; sc.Clear(); sc.AddRange(intlValues); if ( sc.Count != (intlValues.Length) ) { iCountErrors++; Console.WriteLine("Err_0006a, count is {0} instead of {1}", sc.Count, intlValues.Length); } destination = new string[intlValues.Length*2]; sc.CopyTo(destination, intlValues.Length); for (int i = 0; i < intlValues.Length; i++) { iCountTestcases++; if ( String.Compare(sc[i], destination[i+intlValues.Length], false) != 0 ) { iCountErrors++; Console.WriteLine("Err_0006_{0}b, copied \"{1}\" instead of \"{2}\"", i, destination[i+intlValues.Length], sc[i]); } } Console.WriteLine("7. CopyTo(null, int)"); strLoc = "Loc_007oo"; iCountTestcases++; sc.Clear(); sc.AddRange(values); if ( sc.Count != (intlValues.Length) ) { iCountErrors++; Console.WriteLine("Err_0007a, count is {0} instead of {1}", sc.Count, intlValues.Length); } destination = null; try { sc.CopyTo(destination, 0); iCountErrors++; Console.WriteLine("Err_0007b: no exception "); } catch (ArgumentNullException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0007c, unexpected exception: {0}", e.ToString()); } Console.WriteLine("8. CopyTo(string[], -1)"); strLoc = "Loc_008oo"; iCountTestcases++; if (sc.Count != values.Length ) { sc.Clear(); sc.AddRange(values); if ( sc.Count != (intlValues.Length) ) { iCountErrors++; Console.WriteLine("Err_0008a, count is {0} instead of {1}", sc.Count, intlValues.Length); } } destination = new string[values.Length]; try { sc.CopyTo(destination, -1); iCountErrors++; Console.WriteLine("Err_0008b: no exception "); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0008c, unexpected exception: {0}", e.ToString()); } Console.WriteLine("9. CopyTo(string[], upperBound+1)"); strLoc = "Loc_009oo"; iCountTestcases++; if (sc.Count != values.Length ) { sc.Clear(); sc.AddRange(values); if ( sc.Count != (intlValues.Length) ) { iCountErrors++; Console.WriteLine("Err_0009a, count is {0} instead of {1}", sc.Count, intlValues.Length); } } destination = new string[values.Length]; try { sc.CopyTo(destination, values.Length); iCountErrors++; Console.WriteLine("Err_0009b: no exception "); } catch (ArgumentException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0009c, unexpected exception: {0}", e.ToString()); } Console.WriteLine("10. CopyTo(string[], upperBound+2)"); strLoc = "Loc_010oo"; iCountTestcases++; if (sc.Count != values.Length ) { sc.Clear(); sc.AddRange(values); if ( sc.Count != (intlValues.Length+1) ) { iCountErrors++; Console.WriteLine("Err_0010a, count is {0} instead of {1}", sc.Count, intlValues.Length); } } destination = new string[values.Length]; try { sc.CopyTo(destination, values.Length); iCountErrors++; Console.WriteLine("Err_0010b: no exception "); } catch (ArgumentException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0009c, unexpected exception: {0}", e.ToString()); } Console.WriteLine("11. CopyTo(string[], not_enough_space)"); strLoc = "Loc_011oo"; iCountTestcases++; if (sc.Count != values.Length ) { sc.Clear(); sc.AddRange(values); if ( sc.Count != (intlValues.Length) ) { iCountErrors++; Console.WriteLine("Err_0011a, count is {0} instead of {1}", sc.Count, intlValues.Length); } } destination = new string[values.Length]; try { sc.CopyTo(destination, values.Length / 2); iCountErrors++; Console.WriteLine("Err_0011b: no exception "); } catch (ArgumentException ex) { Console.WriteLine(" Expected exception: {0}", ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0011c, 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; } }
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 itm; 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. get Item from empty collection"); Console.WriteLine(" (-1)th"); strLoc = "Loc_001oo"; iCountTestcases++; try { itm = sc[-1]; iCountErrors++; Console.WriteLine("Err_0001a, no exception"); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine(" expected exception: " + ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0001b, unexpected exception: {0}", e.ToString()); } Console.WriteLine(" 0th"); iCountTestcases++; try { itm = sc[0]; iCountErrors++; Console.WriteLine("Err_0001c, no exception"); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine(" expected exception: " + ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0001d, unexpected exception: {0}", e.ToString()); } Console.WriteLine("2. Get Item on collection with simple strings"); strLoc = "Loc_002oo"; sc.Clear(); iCountTestcases++; 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 (String.Compare(sc[i], values[i], false) != 0) { iCountErrors++; Console.WriteLine("Err_0002_{0}b, returned {1} instead of {2}", i, sc[i], values[i]); } } Console.WriteLine("3. get Item on collection with intl strings"); 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++; int cnt = sc.Count; sc.AddRange(intlValues); if ( sc.Count != (cnt + intlValues.Length) ) { iCountErrors++; Console.WriteLine("Err_0003a, count is {0} instead of {1}", sc.Count, cnt + intlValues.Length); } cnt = values.Length; for (int i = cnt; i < cnt + intlValues.Length; i++) { iCountTestcases++; if (String.Compare(sc[i], intlValues[i-cnt], false) != 0) { iCountErrors++; Console.WriteLine("Err_0003_{0}b, returned {1} instead of {2}", i, sc[i], intlValues[i-cnt]); } } Console.WriteLine("4. case sensitivity"); strLoc = "Loc_004oo"; string intlStr = intlValues[0]; intlStr = intlStr.ToUpper(); sc.Clear(); sc.Add(intlStr); iCountTestcases++; if ( sc.Count != 1 ) { iCountErrors++; Console.WriteLine("Err_0004a, count is {0} instead of 1", sc.Count); } iCountTestcases++; if (!caseInsensitive && (String.Compare(sc[0], intlValues[0].ToLower(), false) == 0)) { iCountErrors++; Console.WriteLine("Err_0004b, returned unexpected result: {0} when should have return all upper", sc[0]); } iCountTestcases++; if (String.Compare(sc[0], intlStr, false) != 0) { iCountErrors++; Console.WriteLine("Err_0004c, returned {0} instead of {1}", sc[0], intlStr); } Console.WriteLine("4. get [-1]"); sc.Clear(); sc.AddRange(intlValues); Console.WriteLine(" collection contains {0} items", sc.Count); strLoc = "Loc_004oo"; iCountTestcases++; try { itm = sc[-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. get [Count]"); strLoc = "Loc_005oo"; iCountTestcases++; try { itm = sc[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. get [Count + 1]"); strLoc = "Loc_006oo"; iCountTestcases++; try { itm = sc[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; } }
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 itm; 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. set Item on empty collection"); Console.WriteLine(" (-1)th"); strLoc = "Loc_001oo"; itm = intl.GetString(MAX_LEN, true, true, true); iCountTestcases++; try { sc[-1] = itm; iCountErrors++; Console.WriteLine("Err_0001a, no exception"); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine(" expected exception: " + ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0001b, unexpected exception: {0}", e.ToString()); } Console.WriteLine(" 0th to string"); iCountTestcases++; try { sc[0] = itm; iCountErrors++; Console.WriteLine("Err_0001c, no exception"); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine(" expected exception: " + ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0001d, unexpected exception: {0}", e.ToString()); } Console.WriteLine(" 0th to null"); iCountTestcases++; try { sc[0] = null; iCountErrors++; Console.WriteLine("Err_0001e, no exception"); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine(" expected exception: " + ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0001f, unexpected exception: {0}", e.ToString()); } Console.WriteLine("2. set Item on collection with simple strings"); strLoc = "Loc_002oo"; sc.Clear(); iCountTestcases++; sc.AddRange(values); int cnt = values.Length; if (sc.Count != cnt) { iCountErrors++; Console.WriteLine("Err_0002a, count is {0} instead of {1}", sc.Count, cnt); } for (int i = 0; i < cnt; i++) { iCountTestcases++; sc[i] = values[cnt-i-1]; if (String.Compare(sc[i], values[cnt-i-1], false) != 0) { iCountErrors++; Console.WriteLine("Err_0002_{0}b, value is {1} instead of {2}", i, sc[i], values[cnt-i-1]); } } Console.WriteLine("3. get Item on collection with intl strings"); 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(); cnt = intlValues.Length; 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 = cnt; i < cnt; i++) { iCountTestcases++; sc[i] = intlValues[cnt-i-1]; iCountTestcases++; if (String.Compare(sc[i], intlValues[cnt-i-1], false) != 0) { iCountErrors++; Console.WriteLine("Err_0003_{0}b, actual item is {1} instead of {2}", i, sc[i], intlValues[cnt-i-1]); } } Console.WriteLine("4. case sensitivity"); strLoc = "Loc_004oo"; string intlStrUpper = intlValues[0]; intlStrUpper = intlStrUpper.ToUpper(); string intlStrLower = intlStrUpper.ToLower(); sc.Clear(); sc.AddRange(values); sc.Add(intlStrUpper); iCountTestcases++; if ( sc.Count != values.Length + 1 ) { iCountErrors++; Console.WriteLine("Err_0004a, count is {0} instead of {1}", sc.Count, values.Length + 1); } sc[0] = intlStrLower; iCountTestcases++; if (!caseInsensitive && (String.Compare(sc[0], intlStrUpper, false) == 0)) { iCountErrors++; Console.WriteLine("Err_0004b, set to uppercase when should have to lower"); } iCountTestcases++; if (String.Compare(sc[0], intlStrLower, false) != 0) { iCountErrors++; Console.WriteLine("Err_0004c, disn't set to lower"); } sc[sc.Count - 1] = intlStrLower; iCountTestcases++; if (!caseInsensitive && (String.Compare(sc[sc.Count - 1], intlStrUpper, false) == 0)) { iCountErrors++; Console.WriteLine("Err_0004b, didn't set from uppercase to lowercase "); } iCountTestcases++; if (String.Compare(sc[sc.Count - 1], intlStrLower, false) != 0) { iCountErrors++; Console.WriteLine("Err_0004c, disn't set to lower"); } Console.WriteLine("5. set to null"); strLoc = "Loc_005oo"; if (sc.Count < 1) sc.AddRange(values); int ind = sc.Count / 2; sc[ind] = null; iCountTestcases++; if (sc[ind] != null) { iCountErrors++; Console.WriteLine("Err_0005a, failed to set to null"); } iCountTestcases++; if (!sc.Contains(null)) { iCountErrors++; Console.WriteLine("Err_0005b, Contains() didn't return truw for null"); } iCountTestcases++; if (sc.IndexOf(null) != ind) { iCountErrors++; Console.WriteLine("Err_0005c, IndexOf() returned {0} instead of {1}", sc.IndexOf(null), ind); } Console.WriteLine("6. set [-1] to string"); sc.Clear(); sc.AddRange(intlValues); Console.WriteLine(" collection contains {0} items", sc.Count); strLoc = "Loc_006oo"; iCountTestcases++; try { sc[-1] = intlStrUpper; 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()); } Console.WriteLine("7. set [Count] to string"); strLoc = "Loc_007oo"; iCountTestcases++; try { sc[sc.Count] = intlStrUpper; iCountErrors++; Console.WriteLine("Err_0007a, no exception"); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine(" expected exception: " + ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0007b, unexpected exception: {0}", e.ToString()); } Console.WriteLine("8. set (Count + 1) to string"); strLoc = "Loc_008oo"; iCountTestcases++; try { sc[sc.Count + 1] = intlStrUpper; iCountErrors++; Console.WriteLine("Err_0008a, no exception"); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine(" expected exception: " + ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0008b, unexpected exception: {0}", e.ToString()); } Console.WriteLine("9. set [Count] to null"); strLoc = "Loc_009oo"; iCountTestcases++; try { sc[sc.Count] = null; iCountErrors++; Console.WriteLine("Err_0009a, no exception"); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine(" expected exception: " + ex.Message); } catch (Exception e) { iCountErrors++; Console.WriteLine("Err_0009b, 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; } }
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> /// Build sample item specifics /// </summary> /// <returns>ItemSpecifics object</returns> static NameValueListTypeCollection buildItemSpecifics() { //create the content of item specifics NameValueListTypeCollection nvCollection = new NameValueListTypeCollection(); NameValueListType nv1 = new NameValueListType(); nv1.Name = "Platform"; StringCollection nv1Col = new StringCollection(); String[] strArr1 = new string[] { "Microsoft Xbox 360" }; nv1Col.AddRange(strArr1); nv1.Value = nv1Col; NameValueListType nv2 = new NameValueListType(); nv2.Name = "Genre"; StringCollection nv2Col = new StringCollection(); String[] strArr2 = new string[] { "Simulation" }; nv2Col.AddRange(strArr2); nv2.Value = nv2Col; nvCollection.Add(nv1); nvCollection.Add(nv2); return nvCollection; }
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. Count on empty collection"); iCountTestcases++; if (sc.Count != 0) { iCountErrors++; Console.WriteLine("Err_0001, returned {0} for empty collection", sc.Count); } Console.WriteLine("2. add simple strings and verify Count"); 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); } iCountTestcases++; sc.Clear(); sc.AddRange(values); if (sc.Count != values.Length) { iCountErrors++; Console.WriteLine("Err_0002b, count is {0} instead of {1}", sc.Count, values.Length); } Console.WriteLine("3. add intl strings and verify Count"); 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; } 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); } iCountTestcases++; sc.Clear(); sc.AddRange(intlValues); if ( sc.Count != intlValues.Length ) { iCountErrors++; Console.WriteLine("Err_0003b, count is {0} instead of {1}", sc.Count, intlValues.Length); } } 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; } }
// Retrieve values from the configuration file, or if the setting does not exist in the file, // retrieve the value from the application's default configuration private object GetSetting(SettingsProperty setProp) { object retVal; try { // Search for the specific settings node we are looking for in the configuration file. // If it exists, return the InnerText or InnerXML of its first child node, depending on the setting type. // If the setting is serialized as a string, return the text stored in the config if (setProp.SerializeAs.ToString() == "String") { return XMLConfig.SelectSingleNode("//setting[@name='" + setProp.Name + "']").FirstChild.InnerText; } // If the setting is stored as XML, deserialize it and return the proper object. This only supports // StringCollections at the moment - I will likely add other types as I use them in applications. else { string settingType = setProp.PropertyType.ToString(); string xmlData = XMLConfig.SelectSingleNode("//setting[@name='" + setProp.Name + "']").FirstChild.InnerXml; XmlSerializer xs = new XmlSerializer(typeof(string[])); string[] data = (string[])xs.Deserialize(new XmlTextReader(xmlData, XmlNodeType.Element, null)); switch (settingType) { case "System.Collections.Specialized.StringCollection": StringCollection sc = new StringCollection(); sc.AddRange(data); return sc; default: return ""; } } } catch (Exception) { // Check to see if a default value is defined by the application. // If so, return that value, using the same rules for settings stored as Strings and XML as above if ((setProp.DefaultValue != null)) { if (setProp.SerializeAs.ToString() == "String") { retVal = setProp.DefaultValue.ToString(); } else { string settingType = setProp.PropertyType.ToString(); string xmlData = setProp.DefaultValue.ToString(); XmlSerializer xs = new XmlSerializer(typeof(string[])); string[] data = (string[])xs.Deserialize(new XmlTextReader(xmlData, XmlNodeType.Element, null)); switch (settingType) { case "System.Collections.Specialized.StringCollection": StringCollection sc = new StringCollection(); sc.AddRange(data); return sc; default: return ""; } } } else { retVal = ""; } } return retVal; }
public static void AddRangeTest(StringCollection collection, string[] data) { StringCollection added = new StringCollection(); added.AddRange(data); Assert.Equal(collection, added); added.AddRange(new string[] { /*empty*/}); Assert.Equal(collection, added); }
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; 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. IsSynchronized on empty collection"); iCountTestcases++; if (sc.IsSynchronized) { iCountErrors++; Console.WriteLine("Err_0001, returned true for empty collection"); } Console.WriteLine("2. IsSynchronized for filled collection"); 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); } iCountTestcases++; if (sc.IsSynchronized) { iCountErrors++; Console.WriteLine("Err_0002b, returned true for filled collection"); } } 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> /// Returns an array with all countries /// </summary> public static StringCollection GetCountries() { StringCollection countries = new StringCollection(); countries.AddRange(_countries); return countries; }
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 implemented to handle properties related to VEvent items /// </summary> /// <param name="propertyName">The name of the property</param> /// <param name="parameters">A string collection containing the parameters and their values. If empty, /// there are no parameters.</param> /// <param name="propertyValue">The value of the property.</param> protected virtual void VEventParser(string propertyName, StringCollection parameters, string propertyValue) { StringCollection sc; string[] parts, parms; int idx; // The last entry is always CustomProperty so scan for length minus one for(idx = 0; idx < ntvEvent.Length - 1; idx++) if(ntvEvent[idx].IsMatch(propertyName)) break; // An opening BEGIN:VEVENT property must have been seen if(vEvent == null) throw new PDIParserException(this.LineNumber, LR.GetString("ExParseNoBeginProp", "BEGIN:VEVENT", propertyName)); // Handle or create the property switch(ntvEvent[idx].EnumValue) { case PropertyType.Begin: // Handle nested objects priorState.Push(currentState); // Is it an alarm? if(String.Compare(propertyValue.Trim(), "VALARM", StringComparison.OrdinalIgnoreCase) == 0) { vAlarm = new VAlarm(); vEvent.Alarms.Add(vAlarm); currentState = VCalendarParserState.VAlarm; } else { // Unknown/custom object currentState = VCalendarParserState.Custom; CustomObjectParser(propertyName, parameters, propertyValue); } break; case PropertyType.End: // For this, the value must be VEVENT if(String.Compare(propertyValue.Trim(), "VEVENT", StringComparison.OrdinalIgnoreCase) != 0) throw new PDIParserException(this.LineNumber, LR.GetString("ExParseUnrecognizedTagValue", ntvEvent[idx].Name, propertyValue)); // The event is added to the collection when created so we don't have to rely on an END tag // to add it. vEvent = null; currentState = priorState.Pop(); break; case PropertyType.Class: vEvent.Classification.EncodedValue = propertyValue; break; case PropertyType.Categories: // If this is seen more than once, just add the new stuff to the existing property CategoriesProperty cp = new CategoriesProperty(); cp.DeserializeParameters(parameters); cp.EncodedValue = propertyValue; foreach(string s in cp.Categories) vEvent.Categories.Categories.Add(s); break; case PropertyType.Resources: // If this is seen more than once, just add the new stuff to the existing property ResourcesProperty rp = new ResourcesProperty(); rp.DeserializeParameters(parameters); rp.EncodedValue = propertyValue; foreach(string s in rp.Resources) vEvent.Resources.Resources.Add(s); break; case PropertyType.Url: vEvent.Url.DeserializeParameters(parameters); vEvent.Url.EncodedValue = propertyValue; break; case PropertyType.UniqueId: vEvent.UniqueId.EncodedValue = propertyValue; break; case PropertyType.LastModified: vEvent.LastModified.DeserializeParameters(parameters); vEvent.LastModified.EncodedValue = propertyValue; break; case PropertyType.GeographicPosition: vEvent.GeographicPosition.EncodedValue = propertyValue; break; case PropertyType.DateCreated: vEvent.DateCreated.DeserializeParameters(parameters); vEvent.DateCreated.EncodedValue = propertyValue; break; case PropertyType.StartDateTime: vEvent.StartDateTime.DeserializeParameters(parameters); vEvent.StartDateTime.EncodedValue = propertyValue; break; case PropertyType.EndDateTime: vEvent.EndDateTime.DeserializeParameters(parameters); vEvent.EndDateTime.EncodedValue = propertyValue; break; case PropertyType.TimeStamp: vEvent.TimeStamp.DeserializeParameters(parameters); vEvent.TimeStamp.EncodedValue = propertyValue; break; case PropertyType.Summary: vEvent.Summary.DeserializeParameters(parameters); vEvent.Summary.EncodedValue = propertyValue; break; case PropertyType.Description: vEvent.Description.DeserializeParameters(parameters); vEvent.Description.EncodedValue = propertyValue; break; case PropertyType.Location: vEvent.Location.DeserializeParameters(parameters); vEvent.Location.EncodedValue = propertyValue; break; case PropertyType.Priority: vEvent.Priority.DeserializeParameters(parameters); vEvent.Priority.EncodedValue = propertyValue; break; case PropertyType.Sequence: vEvent.Sequence.DeserializeParameters(parameters); vEvent.Sequence.EncodedValue = propertyValue; break; case PropertyType.Transparency: vEvent.Transparency.DeserializeParameters(parameters); vEvent.Transparency.EncodedValue = propertyValue; break; case PropertyType.RecurrenceCount: vEvent.RecurrenceCount.DeserializeParameters(parameters); vEvent.RecurrenceCount.EncodedValue = propertyValue; break; case PropertyType.Comment: // If this is seen more than once, just add the new stuff to the existing property if(vEvent.Comment.Value != null) { vEvent.Comment.EncodedValue += "\r\n"; vEvent.Comment.EncodedValue += propertyValue; } else { vEvent.Comment.DeserializeParameters(parameters); vEvent.Comment.EncodedValue = propertyValue; } break; case PropertyType.Contact: ContactProperty c = new ContactProperty(); c.DeserializeParameters(parameters); c.EncodedValue = propertyValue; vEvent.Contacts.Add(c); break; case PropertyType.Organizer: vEvent.Organizer.DeserializeParameters(parameters); vEvent.Organizer.EncodedValue = propertyValue; break; case PropertyType.Attendee: AttendeeProperty ap = new AttendeeProperty(); ap.DeserializeParameters(parameters); ap.EncodedValue = propertyValue; vEvent.Attendees.Add(ap); break; case PropertyType.RelatedTo: RelatedToProperty rt = new RelatedToProperty(); rt.DeserializeParameters(parameters); rt.EncodedValue = propertyValue; vEvent.RelatedTo.Add(rt); break; case PropertyType.Attachment: AttachProperty att = new AttachProperty(); att.DeserializeParameters(parameters); att.EncodedValue = propertyValue; vEvent.Attachments.Add(att); break; case PropertyType.RecurrenceId: vEvent.RecurrenceId.DeserializeParameters(parameters); vEvent.RecurrenceId.EncodedValue = propertyValue; break; case PropertyType.Status: vEvent.Status.DeserializeParameters(parameters); vEvent.Status.EncodedValue = propertyValue; break; case PropertyType.RequestStatus: RequestStatusProperty rs = new RequestStatusProperty(); rs.DeserializeParameters(parameters); rs.EncodedValue = propertyValue; vEvent.RequestStatuses.Add(rs); break; case PropertyType.Duration: vEvent.Duration.DeserializeParameters(parameters); vEvent.Duration.EncodedValue = propertyValue; break; case PropertyType.AudioAlarm: case PropertyType.DisplayAlarm: case PropertyType.EMailAlarm: case PropertyType.ProcedureAlarm: // These are converted to a VAlarm object vAlarm = new VAlarm(); ParseVCalendarAlarm(ntvEvent[idx].EnumValue, parameters, propertyValue); vEvent.Alarms.Add(vAlarm); vAlarm = null; break; case PropertyType.RecurrenceRule: RRuleProperty rr = new RRuleProperty(); rr.DeserializeParameters(parameters); rr.EncodedValue = propertyValue; vEvent.RecurrenceRules.Add(rr); break; case PropertyType.RecurDate: // There may be more than one date in the value. If so, split them into separate ones. This // makes it easier to manage. They'll get written back out as individual properties but // that's okay. parts = propertyValue.Split(',', ';'); // It's important that we retain the same parameters for each one parms = new string[parameters.Count]; parameters.CopyTo(parms, 0); foreach(string s in parts) { sc = new StringCollection(); sc.AddRange(parms); RDateProperty rd = new RDateProperty(); rd.DeserializeParameters(sc); rd.EncodedValue = s; vEvent.RecurDates.Add(rd); } break; case PropertyType.ExceptionRule: ExRuleProperty er = new ExRuleProperty(); er.DeserializeParameters(parameters); er.EncodedValue = propertyValue; vEvent.ExceptionRules.Add(er); break; case PropertyType.ExceptionDate: // There may be more than one date in the value. If so, split them into separate ones. This // makes it easier to manage. They'll get written back out as individual properties but // that's okay. parts = propertyValue.Split(',', ';'); // It's important that we retain the same parameters for each one parms = new string[parameters.Count]; parameters.CopyTo(parms, 0); foreach(string s in parts) { sc = new StringCollection(); sc.AddRange(parms); ExDateProperty ed = new ExDateProperty(); ed.DeserializeParameters(sc); ed.EncodedValue = s; vEvent.ExceptionDates.Add(ed); } break; case PropertyType.ExcludeStartDateTime: // This is a custom property not defined by the spec vEvent.ExcludeStartDateTime = (propertyValue[0] == '1'); break; default: // Anything else is a custom property CustomProperty cust = new CustomProperty(propertyName); cust.DeserializeParameters(parameters); cust.EncodedValue = propertyValue; vEvent.CustomProperties.Add(cust); break; } }
public static void SyncRootTest(StringCollection collection, string[] data) { object syncRoot = collection.SyncRoot; Assert.NotNull(syncRoot); Assert.IsType<object>(syncRoot); Assert.Same(syncRoot, collection.SyncRoot); Assert.NotSame(syncRoot, new StringCollection().SyncRoot); StringCollection other = new StringCollection(); other.AddRange(data); Assert.NotSame(syncRoot, other.SyncRoot); }
private static object[] ConstructRow(string[] data) { if (data.Contains(ElementNotPresent)) throw new ArgumentException("Do not include \"" + ElementNotPresent + "\" in data."); StringCollection col = new StringCollection(); col.AddRange(data); return new object[] { col, data }; }
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; StringCollection sc1; object root; object root1; 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(); sc1 = new StringCollection(); Console.WriteLine(" toString: " + sc.SyncRoot.ToString()); Console.WriteLine("1. SyncRoot for empty collection"); Console.WriteLine(" - roots of two different collections"); iCountTestcases++; root = sc.SyncRoot; root1 = sc1.SyncRoot; if ( root.Equals(root1) ) { iCountErrors++; Console.WriteLine("Err_0001a, roots of two different collections are equal"); } Console.WriteLine(" - roots of the same collection"); iCountTestcases++; root1 = sc.SyncRoot; if ( !root.Equals(root1) ) { iCountErrors++; Console.WriteLine("Err_0001b, roots for one collections are not equal"); } Console.WriteLine("2. SyncRoot for filled collection"); iCountTestcases++; sc.AddRange(values); sc1.AddRange(values); root = sc.SyncRoot; root1 = sc1.SyncRoot; Console.WriteLine(" - roots of two different collections"); if ( root.Equals(root1) ) { iCountErrors++; Console.WriteLine("Err_0002a, roots of two different collections are equal"); } Console.WriteLine(" - roots of the same collection"); iCountTestcases++; root1 = sc.SyncRoot; if ( !root.Equals(root1) ) { iCountErrors++; Console.WriteLine("Err_0002b, roots for one collections are not equal"); } Console.WriteLine("3. SyncRoot vs StringCollection"); iCountTestcases++; root = sc.SyncRoot; string str = root.ToString(); if ( str.IndexOf("StringCollection", 0) == -1 ) { iCountErrors++; Console.WriteLine("Err_0003, root.ToString() doesn't contain \"StringCollection\""); } } 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 implemented to handle properties related to observance rule items in VTimeZone objects /// </summary> /// <param name="propertyName">The name of the property.</param> /// <param name="parameters">A string collection containing the parameters and their values. If empty, /// there are no parameters.</param> /// <param name="propertyValue">The value of the property.</param> protected virtual void ObservanceRuleParser(string propertyName, StringCollection parameters, string propertyValue) { StringCollection sc; string[] parts, parms; int idx; // The last entry is always CustomProperty so scan for length minus one for(idx = 0; idx < ntvORule.Length - 1; idx++) if(ntvORule[idx].IsMatch(propertyName)) break; // An opening BEGIN:STANDARD or BEGIN:DAYLIGHT property must have been seen. if(obsRule == null) throw new PDIParserException(this.LineNumber, LR.GetString("ExParseNoBeginProp", "BEGIN:STANDARD/BEGIN:DAYLIGHT", propertyName)); // Handle or create the property switch(ntvORule[idx].EnumValue) { case PropertyType.Begin: // Handle unknown nested objects priorState.Push(currentState); currentState = VCalendarParserState.Custom; CustomObjectParser(propertyName, parameters, propertyValue); break; case PropertyType.End: // For this, the value must be STANDARD or DAYLIGHT depending on the rule type if((obsRule.RuleType == ObservanceRuleType.Standard && String.Compare(propertyValue.Trim(), "STANDARD", StringComparison.OrdinalIgnoreCase) != 0) || (obsRule.RuleType == ObservanceRuleType.Daylight && String.Compare(propertyValue.Trim(), "DAYLIGHT", StringComparison.OrdinalIgnoreCase) != 0)) { throw new PDIParserException(this.LineNumber, LR.GetString("ExParseUnrecognizedTagValue", ntvORule[idx].Name, propertyValue)); } // The rule is added to the collection when created so we don't have to rely on an END tag to // add it. obsRule = null; currentState = priorState.Pop(); break; case PropertyType.StartDateTime: obsRule.StartDateTime.DeserializeParameters(parameters); obsRule.StartDateTime.EncodedValue = propertyValue; break; case PropertyType.TimeZoneOffsetFrom: obsRule.OffsetFrom.DeserializeParameters(parameters); obsRule.OffsetFrom.EncodedValue = propertyValue; break; case PropertyType.TimeZoneOffsetTo: obsRule.OffsetTo.DeserializeParameters(parameters); obsRule.OffsetTo.EncodedValue = propertyValue; break; case PropertyType.Comment: // If this is seen more than once, just add the new stuff to the existing property if(obsRule.Comment.Value != null) { obsRule.Comment.EncodedValue += "\r\n"; obsRule.Comment.EncodedValue += propertyValue; } else { obsRule.Comment.DeserializeParameters(parameters); obsRule.Comment.EncodedValue = propertyValue; } break; case PropertyType.RecurrenceRule: RRuleProperty rr = new RRuleProperty(); rr.DeserializeParameters(parameters); rr.EncodedValue = propertyValue; obsRule.RecurrenceRules.Add(rr); break; case PropertyType.RecurDate: // There may be more than one date in the value. If so, split them into separate ones. This // makes it easier to manage. They'll get written back out as individual properties but // that's okay. parts = propertyValue.Split(',', ';'); // It's important that we retain the same parameters for each one parms = new string[parameters.Count]; parameters.CopyTo(parms, 0); foreach(string s in parts) { sc = new StringCollection(); sc.AddRange(parms); RDateProperty rd = new RDateProperty(); rd.DeserializeParameters(sc); rd.EncodedValue = s; obsRule.RecurDates.Add(rd); } break; case PropertyType.TimeZoneName: TimeZoneNameProperty tzn = new TimeZoneNameProperty(); tzn.DeserializeParameters(parameters); tzn.EncodedValue = propertyValue; obsRule.TimeZoneNames.Add(tzn); break; default: // Anything else is a custom property CustomProperty cust = new CustomProperty(propertyName); cust.DeserializeParameters(parameters); cust.EncodedValue = propertyValue; obsRule.CustomProperties.Add(cust); break; } }
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; }