private string DumpGraph(DirectedGraphImpl<string> gr) { StringBuilder sb = new StringBuilder(); foreach (string n in gr.Nodes) { sb.AppendFormat("({0} s:(", n); foreach (string i in gr.Successors(n)) { sb.AppendFormat("{0} ", i); } sb.Append(") p:( "); foreach (string p in gr.Predecessors(n)) { sb.AppendFormat("{0} ", p); } sb.Append(")) "); } return sb.ToString(); }
/// <summary> /// Returns a <see cref="T:System.String" /> that represents the current <see cref="T:System.Object" />. /// </summary> /// <param name="baseUrl"> The base URL. </param> /// <returns> A <see cref="T:System.String" /> that represents the current <see cref="T:System.Object" /> . </returns> public virtual String ToString(String baseUrl) { var sb = new StringBuilder(); foreach (var pair in _dictionary) { if (sb.Length > 0) sb.Append("&"); sb.AppendFormat("{0}={1}", pair.Key, pair.Value); } return baseUrl.IsNotNullOrEmpty() ? String.Concat(baseUrl, "?", sb.ToString()) : sb.ToString(); }
private string GenerateUsingClauseNamespaces() { System.StringBuilder returnValue = new System.StringBuilder(); foreach (var @namespace in this.namespaces.Distinct()) returnValue.AppendFormat("using {0};", @namespace); return returnValue; }
private string GenerateDbSets() { System.StringBuilder returnValue = new System.StringBuilder(); foreach (var dbSet in this.dbSets) { returnValue.AppendFormat("\t\t public DbSet<{0}> {1}", dbSet.Key.Name, dbSet.Value); returnValue.AppendLine(" { get; set; }"); returnValue.AppendLine(); } return returnValue; }
/// <summary> /// Overrides the Object.ToString() method to provide a text representation of /// a Matrix4. /// </summary> /// <returns>A string representation of a vector3.</returns> public override string ToString() { StringBuilder sb = new StringBuilder(); sb.AppendFormat(" | {0} {1} {2} {3} |\n", this.m00, this.m01, this.m02, this.m03); sb.AppendFormat(" | {0} {1} {2} {3} |\n", this.m10, this.m11, this.m12, this.m13); sb.AppendFormat(" | {0} {1} {2} {3} |\n", this.m20, this.m21, this.m22, this.m23); sb.AppendFormat(" | {0} {1} {2} {3} |\n", this.m30, this.m31, this.m32, this.m33); return sb.ToString(); }
public Client.Status Write (byte [] buffer) { uint bytesWritten = 0; #if LOG_IO StringBuilder sb = new StringBuilder("<- "); foreach(byte b in buffer) sb.AppendFormat(" {0:X2}", b); MainWindow.InvokeLog (sb.ToString()); #endif bool bResult = WriteFile (pipeHandle, buffer, (uint)buffer.Length, ref bytesWritten, 0); if (!bResult) { MainWindow.InvokeLog ("Communicator.Send() failed"); return Client.Status.Error; } wbytes += bytesWritten; Thread.Sleep (50); return Client.Status.Success; }
public Client.Status Read (byte [] buffer, ref uint count) { bool bResult = ReadFile (pipeHandle, buffer, (uint)buffer.Length, ref count, (uint)0); if (!bResult) { return Client.Status.Error; } rbytes += count; #if LOG_IO StringBuilder sb = new StringBuilder ("-> "); foreach (byte b in buffer) sb.AppendFormat (" {0:X2}", b); MainWindow.InvokeLog (sb.ToString ()); #endif return Client.Status.Success; }
/// <summary> /// This will return the root model content from the controller associated with a TreeElement /// </summary> /// <param name="t"></param> /// <returns></returns> protected RebelTreeResult GetRootResultFromTreeController(ITree t) { var tree = BackOfficeRequestContext.RegisteredComponents .TreeControllers.Where(x => x.Metadata.ComponentType.Equals(t.ControllerType)).SingleOrDefault(); if (tree != null) { using (var controller = tree.Value) { if (controller == null) { throw new TypeLoadException("Could not create controller: " + ControllerExtensions.GetControllerName(t.ControllerType)); } //proxy the request to the tree controller var rootNodeId = controller.GetRootNodeId(); //the result returned is the string response from the proxied request, now we need to change it to an RebelTreeResult var result = this.ProxyRequestToController( controller, x => x.Index(rootNodeId, new FormCollection()), tree.Metadata, BackOfficeRequestContext.Application.Settings.RebelPaths.BackOfficePath, "treeId"); return result.Result; } } // Give a descriptive error to help the poor sod who has to debug this with a custom tree var errorBuilder = new StringBuilder(); errorBuilder.AppendFormat("Tree {0} with alias {1} was requested, but its type wasn't registered at app startup.\n", t.ControllerType, t.ApplicationAlias); errorBuilder.AppendFormat("If the tree type is in a plugin assembly, check it is attributed with the {0}.\n", typeof(AssemblyContainsPluginsAttribute).Name); errorBuilder.Append("Here are the types that got registered:\n"); foreach (var treeController in BackOfficeRequestContext.RegisteredComponents .TreeControllers) { errorBuilder.AppendFormat("• {0} from Assembly {1} found in folder {2}\n", ControllerExtensions.GetControllerName(treeController.Metadata.ComponentType), treeController.Metadata.ComponentType.Assembly, treeController.Metadata.PluginDefinition.PackageFolderPath); } throw new TypeLoadException(errorBuilder.ToString()); }
private void LogKey(ConsoleKeyInfo key) { var x = ConsoleOutput.CursorLeft; var y = ConsoleOutput.CursorTop; var fgColor = ConsoleOutput.ForegroundColor; var bgColor = ConsoleOutput.BackgroundColor; try { ConsoleOutput.SetCursorPosition(0, 0); ConsoleOutput.ForegroundColor = ConsoleColor.Yellow; ConsoleOutput.BackgroundColor = ConsoleColor.DarkBlue; var builder = new StringBuilder(); builder.AppendFormat("[Key: {{{0, -12}}}] ", key.Key); if (char.IsControl(key.KeyChar)) { builder.AppendFormat("[Char: 0x{0:X}] ", (int)key.KeyChar); } else if (key.KeyChar != (char)0) { builder.AppendFormat("[Char: '{0}' : 0x{1:X}] ", key.KeyChar, (int)key.KeyChar); } var modifiers = (ConsoleModifiers)0; var translationModifiers = (ConsoleModifiers)0; var modifierNames = new List<string>(); if (key.Modifiers.HasFlag(ConsoleModifiers.Control)) { modifiers |= ConsoleModifiers.Control; modifierNames.Add("Ctrl"); } if (key.Modifiers.HasFlag(ConsoleModifiers.Alt)) { modifiers |= ConsoleModifiers.Alt; modifierNames.Add("Alt"); } if (key.Modifiers.HasFlag(ConsoleModifiers.Shift)) { modifiers |= ConsoleModifiers.Shift; translationModifiers |= ConsoleModifiers.Shift; } var translatedToChars = false; if (modifiers.HasFlag(ConsoleModifiers.Alt) || modifiers.HasFlag(ConsoleModifiers.Control)) { var chars = InputUtilities.GetChars(key.Key, translationModifiers); if (chars.Length > 0) { var charsAsString = new string(chars); builder.AppendFormat("[{0}+{1}]", string.Join("+", modifierNames), charsAsString); translatedToChars = true; } } if (!translatedToChars) { if (key.Modifiers.HasFlag(ConsoleModifiers.Shift)) modifierNames.Add("Shift"); if (modifierNames.Count > 0) { builder.AppendFormat("[{0}+{1}]", string.Join("+", modifierNames), key.Key); } } if (builder.Length < ConsoleOutput.BufferWidth) { builder.Append(new string(' ', ConsoleOutput.BufferWidth - builder.Length)); } ConsoleOutput.Write(builder.ToString()); } finally { ConsoleOutput.ForegroundColor = fgColor; ConsoleOutput.BackgroundColor = bgColor; ConsoleOutput.SetCursorPosition(x, y); } }
void AddFrames(StringBuilder sb, string newline, string unknown, StackTrace st) { for (int i = 0; i < st.FrameCount; i++) { StackFrame frame = st.GetFrame(i); if (i == 0) sb.AppendFormat(" {0} ", Locale.GetText("at")); else sb.Append(newline); if (frame.GetMethod() == null) { string internal_name = frame.GetInternalMethodName(); if (internal_name != null) sb.Append(internal_name); else sb.AppendFormat("<0x{0:x5}> {1}", frame.GetNativeOffset(), unknown); } else { GetFullNameForStackTrace(sb, frame.GetMethod()); if (frame.GetILOffset() == -1) sb.AppendFormat(" <0x{0:x5}> ", frame.GetNativeOffset()); else sb.AppendFormat(" [0x{0:x5}] ", frame.GetILOffset()); sb.AppendFormat("in {0}:{1} ", frame.GetSecureFileName(), frame.GetFileLineNumber()); } } }
public string Translate(string input, System.Globalization.CultureInfo sourceCulture, System.Globalization.CultureInfo targetCulture) { if (string.IsNullOrWhiteSpace(input)) throw new ArgumentNullException("input"); if (sourceCulture == null) throw new ArgumentNullException("sourceCulture"); if (targetCulture == null) throw new ArgumentNullException("targetCulture"); if (sourceCulture == targetCulture) throw new InvalidOperationException("The input does not require translation."); string returnValue = string.Empty; try { var result = this.translationHelper.TranslateThis(input, sourceCulture.TwoLetterISOLanguageName, targetCulture.TwoLetterISOLanguageName); returnValue = (result.Meanings.Count > 0 && result.Meanings.FirstOrDefault().Terms.Count > 0) ? result.Meanings.FirstOrDefault().Terms.FirstOrDefault() : result.TranslatedText; } catch(NullReferenceException) { try { string[] words = input.Split(' '); if (words.Length == 1) { returnValue = input; } else { System.StringBuilder sb = new System.StringBuilder(); foreach (string val in words) sb.AppendFormat("{0} ", this.Translate(val, sourceCulture, targetCulture)); returnValue = sb.ToString(); } } catch(NullReferenceException) { returnValue = input; } } return this.KeepCaseSentitivity(input, returnValue); }
protected override SecureMimeContext CreateContext () { var user = Environment.GetEnvironmentVariable ("USER"); var builder = new StringBuilder (); builder.Append ("server=localhost;"); builder.Append ("database=smime.npg;"); builder.AppendFormat ("user id={0}", user); var db = new NpgsqlCertificateDatabase (builder.ToString (), "no.secret"); return new DefaultSecureMimeContext (db); }
private void AddNumberCell( StringBuilder html, int value ) { html.Append( "<td>" ); if( value > 0 ) html.AppendFormat( "{0:N0}", value ); else html.Append( " " ); html.Append( "</td>" ); }
private void AddCell( StringBuilder html, string format, params object[] value ) { html.Append( "<td>" ); html.AppendFormat( format, value ); html.Append( "</td>" ); }