static string GetData (string propertyName) { Text.StringBuilder ThemeName = new Text.StringBuilder (260); Text.StringBuilder ColorName = new Text.StringBuilder (260); Text.StringBuilder SizeName = new Text.StringBuilder (260); UXTheme.GetCurrentThemeName (ThemeName, ThemeName.Capacity, ColorName, ColorName.Capacity, SizeName, SizeName.Capacity); Text.StringBuilder PropertyValue = new Text.StringBuilder (260); UXTheme.GetThemeDocumentationProperty (ThemeName.ToString(), propertyName, PropertyValue, PropertyValue.Capacity); return PropertyValue.ToString (); }
/// <summary> /// This method is added to be backward compatible with V1 hosts w.r.t /// new PromptForChoice method added in PowerShell V2. /// </summary> /// <param name="caption"></param> /// <param name="message"></param> /// <param name="choices"></param> /// <param name="defaultChoices"></param> /// <returns></returns> /// <exception cref="ArgumentException"> /// 1. Choices is null. /// 2. Choices.Count = 0 /// 3. DefaultChoice is either less than 0 or greater than Choices.Count /// </exception> private Collection<int> EmulatePromptForMultipleChoice(string caption, string message, Collection<ChoiceDescription> choices, IEnumerable<int> defaultChoices) { Dbg.Assert(null != _externalUI, "externalUI cannot be null."); if (choices == null) { throw PSTraceSource.NewArgumentNullException("choices"); } if (choices.Count == 0) { throw PSTraceSource.NewArgumentException("choices", InternalHostUserInterfaceStrings.EmptyChoicesError, "choices"); } Dictionary<int, bool> defaultChoiceKeys = new Dictionary<int, bool>(); if (null != defaultChoices) { foreach (int defaultChoice in defaultChoices) { if ((defaultChoice < 0) || (defaultChoice >= choices.Count)) { throw PSTraceSource.NewArgumentOutOfRangeException("defaultChoice", defaultChoice, InternalHostUserInterfaceStrings.InvalidDefaultChoiceForMultipleSelection, "defaultChoice", "choices", defaultChoice); } if (!defaultChoiceKeys.ContainsKey(defaultChoice)) { defaultChoiceKeys.Add(defaultChoice, true); } } } // Construct the caption + message + list of choices + default choices Text.StringBuilder choicesMessage = new Text.StringBuilder(); char newLine = '\n'; if (!string.IsNullOrEmpty(caption)) { choicesMessage.Append(caption); choicesMessage.Append(newLine); } if (!string.IsNullOrEmpty(message)) { choicesMessage.Append(message); choicesMessage.Append(newLine); } string[,] hotkeysAndPlainLabels = null; HostUIHelperMethods.BuildHotkeysAndPlainLabels(choices, out hotkeysAndPlainLabels); string choiceTemplate = "[{0}] {1} "; for (int i = 0; i < hotkeysAndPlainLabels.GetLength(1); ++i) { string choice = String.Format( Globalization.CultureInfo.InvariantCulture, choiceTemplate, hotkeysAndPlainLabels[0, i], hotkeysAndPlainLabels[1, i]); choicesMessage.Append(choice); choicesMessage.Append(newLine); } // default choices string defaultPrompt = ""; if (defaultChoiceKeys.Count > 0) { string prepend = ""; Text.StringBuilder defaultChoicesBuilder = new Text.StringBuilder(); foreach (int defaultChoice in defaultChoiceKeys.Keys) { string defaultStr = hotkeysAndPlainLabels[0, defaultChoice]; if (string.IsNullOrEmpty(defaultStr)) { defaultStr = hotkeysAndPlainLabels[1, defaultChoice]; } defaultChoicesBuilder.Append(string.Format(Globalization.CultureInfo.InvariantCulture, "{0}{1}", prepend, defaultStr)); prepend = ","; } string defaultChoicesStr = defaultChoicesBuilder.ToString(); if (defaultChoiceKeys.Count == 1) { defaultPrompt = StringUtil.Format(InternalHostUserInterfaceStrings.DefaultChoice, defaultChoicesStr); } else { defaultPrompt = StringUtil.Format(InternalHostUserInterfaceStrings.DefaultChoicesForMultipleChoices, defaultChoicesStr); } } string messageToBeDisplayed = choicesMessage.ToString() + defaultPrompt + newLine; // read choices from the user Collection<int> result = new Collection<int>(); int choicesSelected = 0; do { string choiceMsg = StringUtil.Format(InternalHostUserInterfaceStrings.ChoiceMessage, choicesSelected); messageToBeDisplayed += choiceMsg; _externalUI.WriteLine(messageToBeDisplayed); string response = _externalUI.ReadLine(); // they just hit enter if (response.Length == 0) { // this may happen when // 1. user wants to go with the defaults // 2. user selected some choices and wanted those // choices to be picked. // user did not pick up any choices..choose the default if ((result.Count == 0) && (defaultChoiceKeys.Keys.Count >= 0)) { // if there's a default, pick that one. foreach (int defaultChoice in defaultChoiceKeys.Keys) { result.Add(defaultChoice); } } // allow for no choice selection. break; } int choicePicked = HostUIHelperMethods.DetermineChoicePicked(response.Trim(), choices, hotkeysAndPlainLabels); if (choicePicked >= 0) { result.Add(choicePicked); choicesSelected++; } // reset messageToBeDisplayed messageToBeDisplayed = ""; } while (true); return result; }
public int UxThemeGetThemeString (IntPtr hTheme, int iPartId, int iStateId, StringProperty prop, out string result) { Text.StringBuilder sb = new Text.StringBuilder (255); int hresult = UXTheme.GetThemeString (hTheme, iPartId, iStateId, (int)prop, sb, sb.Capacity); result = sb.ToString (); return hresult; }
/// <summary> /// /// </summary> /// <param name="isCapabilityWorkflow"> /// This boolean is used to suppress common workflow parameters (or) display /// them separately towards the end /// </param> /// <returns></returns> internal string ToString(bool isCapabilityWorkflow) { Text.StringBuilder result = new Text.StringBuilder(); GenerateParametersInDisplayOrder(isCapabilityWorkflow, parameter => AppendFormatCommandParameterInfo(parameter, ref result), delegate (string str) { if (result.Length > 0) { result.Append(" "); } result.Append("["); result.Append(str); result.Append("]"); }); return result.ToString(); }
private string BuildStackTrace(string trace) { var items = trace.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); var newStackTrace = new Text.StringBuilder(); var found = false; foreach (var item in items) { // Only include lines that has files in the source code if (item.Contains(":")) { if (item.Contains("System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()")) { // Stacktrace from here on will be added by the CLR break; } if (found) { newStackTrace.Append(Environment.NewLine); } found = true; newStackTrace.Append(item); } else if (found) { break; } } var result = newStackTrace.ToString(); return result; }
/// <summary> /// This method is added to be backward compatible with V1 hosts w.r.t /// new PromptForChoice method added in PowerShell V2. /// </summary> /// <param name="caption"></param> /// <param name="message"></param> /// <param name="choices"></param> /// <param name="defaultChoices"></param> /// <returns></returns> /// <exception cref="ArgumentException"> /// 1. Choices is null. /// 2. Choices.Count = 0 /// 3. DefaultChoice is either less than 0 or greater than Choices.Count /// </exception> private Collection <int> EmulatePromptForMultipleChoice(string caption, string message, Collection <ChoiceDescription> choices, IEnumerable <int> defaultChoices) { Dbg.Assert(_externalUI != null, "externalUI cannot be null."); if (choices == null) { throw PSTraceSource.NewArgumentNullException("choices"); } if (choices.Count == 0) { throw PSTraceSource.NewArgumentException("choices", InternalHostUserInterfaceStrings.EmptyChoicesError, "choices"); } Dictionary <int, bool> defaultChoiceKeys = new Dictionary <int, bool>(); if (defaultChoices != null) { foreach (int defaultChoice in defaultChoices) { if ((defaultChoice < 0) || (defaultChoice >= choices.Count)) { throw PSTraceSource.NewArgumentOutOfRangeException("defaultChoice", defaultChoice, InternalHostUserInterfaceStrings.InvalidDefaultChoiceForMultipleSelection, "defaultChoice", "choices", defaultChoice); } defaultChoiceKeys.TryAdd(defaultChoice, true); } } // Construct the caption + message + list of choices + default choices Text.StringBuilder choicesMessage = new Text.StringBuilder(); char newLine = '\n'; if (!string.IsNullOrEmpty(caption)) { choicesMessage.Append(caption); choicesMessage.Append(newLine); } if (!string.IsNullOrEmpty(message)) { choicesMessage.Append(message); choicesMessage.Append(newLine); } string[,] hotkeysAndPlainLabels = null; HostUIHelperMethods.BuildHotkeysAndPlainLabels(choices, out hotkeysAndPlainLabels); string choiceTemplate = "[{0}] {1} "; for (int i = 0; i < hotkeysAndPlainLabels.GetLength(1); ++i) { string choice = string.Format( Globalization.CultureInfo.InvariantCulture, choiceTemplate, hotkeysAndPlainLabels[0, i], hotkeysAndPlainLabels[1, i]); choicesMessage.Append(choice); choicesMessage.Append(newLine); } // default choices string defaultPrompt = string.Empty; if (defaultChoiceKeys.Count > 0) { string prepend = string.Empty; Text.StringBuilder defaultChoicesBuilder = new Text.StringBuilder(); foreach (int defaultChoice in defaultChoiceKeys.Keys) { string defaultStr = hotkeysAndPlainLabels[0, defaultChoice]; if (string.IsNullOrEmpty(defaultStr)) { defaultStr = hotkeysAndPlainLabels[1, defaultChoice]; } defaultChoicesBuilder.Append(string.Format(Globalization.CultureInfo.InvariantCulture, "{0}{1}", prepend, defaultStr)); prepend = ","; } string defaultChoicesStr = defaultChoicesBuilder.ToString(); if (defaultChoiceKeys.Count == 1) { defaultPrompt = StringUtil.Format(InternalHostUserInterfaceStrings.DefaultChoice, defaultChoicesStr); } else { defaultPrompt = StringUtil.Format(InternalHostUserInterfaceStrings.DefaultChoicesForMultipleChoices, defaultChoicesStr); } } string messageToBeDisplayed = choicesMessage.ToString() + defaultPrompt + newLine; // read choices from the user Collection <int> result = new Collection <int>(); int choicesSelected = 0; do { string choiceMsg = StringUtil.Format(InternalHostUserInterfaceStrings.ChoiceMessage, choicesSelected); messageToBeDisplayed += choiceMsg; _externalUI.WriteLine(messageToBeDisplayed); string response = _externalUI.ReadLine(); // they just hit enter if (response.Length == 0) { // this may happen when // 1. user wants to go with the defaults // 2. user selected some choices and wanted those // choices to be picked. // user did not pick up any choices..choose the default if ((result.Count == 0) && (defaultChoiceKeys.Keys.Count >= 0)) { // if there's a default, pick that one. foreach (int defaultChoice in defaultChoiceKeys.Keys) { result.Add(defaultChoice); } } // allow for no choice selection. break; } int choicePicked = HostUIHelperMethods.DetermineChoicePicked(response.Trim(), choices, hotkeysAndPlainLabels); if (choicePicked >= 0) { result.Add(choicePicked); choicesSelected++; } // reset messageToBeDisplayed messageToBeDisplayed = string.Empty; } while (true); return(result); }
/// <summary> /// Constructs a string of the choices and their hotkeys. /// </summary> /// <param name="choices"></param> /// <param name="hotkeysAndPlainLabels"></param> /// <exception cref="ArgumentException"> /// 1. Cannot process the hot key because a question mark ("?") cannot be used as a hot key. /// </exception> internal static void BuildHotkeysAndPlainLabels(Collection<ChoiceDescription> choices, out string[,] hotkeysAndPlainLabels) { // we will allocate the result array hotkeysAndPlainLabels = new string[2, choices.Count]; for (int i = 0; i < choices.Count; ++i) { #region SplitLabel hotkeysAndPlainLabels[0, i] = string.Empty; int andPos = choices[i].Label.IndexOf('&'); if (andPos >= 0) { Text.StringBuilder splitLabel = new Text.StringBuilder(choices[i].Label.Substring(0, andPos), choices[i].Label.Length); if (andPos + 1 < choices[i].Label.Length) { splitLabel.Append(choices[i].Label.Substring(andPos + 1)); hotkeysAndPlainLabels[0, i] = CultureInfo.CurrentCulture.TextInfo.ToUpper(choices[i].Label.Substring(andPos + 1, 1).Trim()); } hotkeysAndPlainLabels[1, i] = splitLabel.ToString().Trim(); } else { hotkeysAndPlainLabels[1, i] = choices[i].Label; } #endregion SplitLabel // ? is not localizable if (string.Compare(hotkeysAndPlainLabels[0, i], "?", StringComparison.Ordinal) == 0) { Exception e = PSTraceSource.NewArgumentException( String.Format(Globalization.CultureInfo.InvariantCulture, "choices[{0}].Label", i), InternalHostUserInterfaceStrings.InvalidChoiceHotKeyError); throw e; } } }
/// <summary> /// Computes a name from a text label by removing all spaces and non-alphanumeric characters. /// </summary> private string NameFromText(string text, Type itemType, INameCreationService nameCreationService, bool adjustCapitalization) { string baseName; // for separators, name them ToolStripSeparator... if (text == "-") { baseName = "toolStripSeparator"; } else { string nameSuffix = itemType.Name; // remove all the non letter and number characters. Append length of "MenuItem" Text.StringBuilder name = new Text.StringBuilder(text.Length + nameSuffix.Length); bool firstCharSeen = false; for (int i = 0; i < text.Length; i++) { char c = text[i]; if (char.IsLetterOrDigit(c)) { if (!firstCharSeen) { c = char.ToLower(c, CultureInfo.CurrentCulture); firstCharSeen = true; } name.Append(c); } } name.Append(nameSuffix); baseName = name.ToString(); if (adjustCapitalization) { string nameOfRandomItem = ToolStripDesigner.NameFromText(null, typeof(ToolStripMenuItem), _designer.Component.Site); if (!string.IsNullOrEmpty(nameOfRandomItem) && char.IsUpper(nameOfRandomItem[0])) { baseName = char.ToUpper(baseName[0], CultureInfo.InvariantCulture) + baseName.Substring(1); } } } // see if this name matches another one in the container.. object existingComponent = _host.Container.Components[baseName]; if (existingComponent is null) { if (!nameCreationService.IsValidName(baseName)) { // we don't have a name collision but this still isn't a valid name...something is wrong and we can't make a valid identifier out of this so bail. return(nameCreationService.CreateName(_host.Container, itemType)); } else { return(baseName); } } else { // start appending numbers. string newName = baseName; for (int indexer = 1; !nameCreationService.IsValidName(newName); indexer++) { newName = baseName + indexer.ToString(CultureInfo.InvariantCulture); } return(newName); } }
public extern static Int32 GetThemeFilename(IntPtr hTheme, int iPartId, int iStateId, int iPropId, [MarshalAs(UnmanagedType.LPWStr)] Text.StringBuilder themeFileName, int themeFileNameLength);
public void CreateTable(SQLiteTable table) { StringBuilder sb = new Text.StringBuilder(); sb.Append("create table if not exists `"); sb.Append(table.TableName); sb.AppendLine("`("); bool firstRecord = true; foreach (SQLiteColumn col in table.Columns) { if (col.ColumnName.Trim().Length == 0) { throw new Exception("Column name cannot be blank."); } if (firstRecord) { firstRecord = false; } else { sb.AppendLine(","); } sb.Append(col.ColumnName); sb.Append(" "); if (col.AutoIncrement) { sb.Append("integer primary key autoincrement"); continue; } switch (col.ColDataType) { case ColType.Text: sb.Append("text"); break; case ColType.Integer: sb.Append("integer"); break; case ColType.Decimal: sb.Append("decimal"); break; case ColType.DateTime: sb.Append("datetime"); break; case ColType.BLOB: sb.Append("blob"); break; } if (col.PrimaryKey) { sb.Append(" primary key"); } if (col.NotNull) { sb.Append(" not null"); } if (col.DefaultValue.Length > 0) { sb.Append(" default "); if (col.DefaultValue.Contains(" ") || col.ColDataType == ColType.Text || col.ColDataType == ColType.DateTime) { sb.Append("'"); sb.Append(col.DefaultValue); sb.Append("'"); } else { sb.Append(col.DefaultValue); } } if (col.Unique) { sb.Append(" unique"); } } sb.AppendLine(");"); cmd.CommandText = sb.ToString(); cmd.ExecuteNonQuery(); }
private static void AppendFormatCommandParameterInfo(CommandParameterInfo parameter, Text.StringBuilder result) { if (result.Length > 0) { // Add a space between parameters result.Append(" "); } if (parameter.ParameterType == typeof(SwitchParameter)) { result.AppendFormat(CultureInfo.InvariantCulture, parameter.IsMandatory ? "-{0}" : "[-{0}]", parameter.Name); } else { string parameterTypeString = GetParameterTypeString(parameter.ParameterType, parameter.Attributes); if (parameter.IsMandatory) { result.AppendFormat(CultureInfo.InvariantCulture, parameter.Position != int.MinValue ? "[-{0}] <{1}>" : "-{0} <{1}>", parameter.Name, parameterTypeString); } else { result.AppendFormat(CultureInfo.InvariantCulture, parameter.Position != int.MinValue ? "[[-{0}] <{1}>]" : "[-{0} <{1}>]", parameter.Name, parameterTypeString); } } }
private string FixUpStatementExtent(int startColNum, string stateExtentText) { Text.StringBuilder sb = new Text.StringBuilder(); sb.Append(' ', startColNum); sb.Append(stateExtentText); return sb.ToString(); }
/// <summary> /// Returns error context in the format [[errorContextInfo, ]line ddd, column ddd]. /// Returns empty string if errorPosition is less than 0 and errorContextInfo is not specified. /// </summary> internal static string FormatErrorContext( string commandText, int errorPosition, string errorContextInfo, bool loadErrorContextInfoFromResource, out int lineNumber, out int columnNumber) { Debug.Assert(errorPosition > -1, "position in input stream cannot be < 0"); Debug.Assert(errorPosition <= commandText.Length, "position in input stream cannot be greater than query text size"); if (loadErrorContextInfoFromResource) { errorContextInfo = !String.IsNullOrEmpty(errorContextInfo) ? EntityRes.GetString(errorContextInfo) : String.Empty; } // // Replace control chars and newLines for single representation characters // StringBuilder sb = new StringBuilder(commandText.Length); for (int i = 0; i < commandText.Length; i++) { Char c = commandText[i]; if (CqlLexer.IsNewLine(c)) { c = '\n'; } else if ((Char.IsControl(c) || Char.IsWhiteSpace(c)) && ('\r' != c)) { c = ' '; } sb.Append(c); } commandText = sb.ToString().TrimEnd(new char[] { '\n' }); // // Compute line and column // string[] queryLines = commandText.Split(new char[] { '\n' }, StringSplitOptions.None); for (lineNumber = 0, columnNumber = errorPosition; lineNumber < queryLines.Length && columnNumber > queryLines[lineNumber].Length; columnNumber -= (queryLines[lineNumber].Length + 1), ++lineNumber) { ; } ++lineNumber; // switch lineNum and colNum to 1-based indexes ++columnNumber; // // Error context format: "[errorContextInfo,] line ddd, column ddd" // sb = new Text.StringBuilder(); if (!String.IsNullOrEmpty(errorContextInfo)) { sb.AppendFormat(CultureInfo.CurrentCulture, "{0}, ", errorContextInfo); } if (errorPosition >= 0) { sb.AppendFormat(CultureInfo.CurrentCulture, "{0} {1}, {2} {3}", System.Data.Entity.Strings.LocalizedLine, lineNumber, System.Data.Entity.Strings.LocalizedColumn, columnNumber); } return(sb.ToString()); }
static public extern int GetCurrentThemeName( Text.StringBuilder pszThemeFileName, int dwMaxNameChars, Text.StringBuilder pszColorBuff, int cchMaxColorChars, Text.StringBuilder pszSizeBuff, int cchMaxSizeChars);