/// <summary> /// Generate extra three routing for specified url {store}/url, {store}/{language}/url, {language}/url, url /// </summary> /// <param name="routes"></param> /// <param name="name"></param> /// <param name="url"></param> /// <param name="defaults"></param> /// <param name="constraints"></param> /// <param name="routeFactory"></param> public static void MapLocalizedStorefrontRoute(this RouteCollection routes, string name, string url, object defaults, object constraints, Func<string, Route> routeFactory) { var languageConstrain = @"[a-z]{2}-[A-Z]{2}"; var languageWithStoreRoute = routeFactory(@"{store}/{language}/" + url); languageWithStoreRoute.Defaults = new RouteValueDictionary(defaults); languageWithStoreRoute.Constraints = new RouteValueDictionary(constraints); languageWithStoreRoute.DataTokens = new RouteValueDictionary(); languageWithStoreRoute.Constraints.Add("language", languageConstrain); routes.Add(name + "StoreWithLang", languageWithStoreRoute); var languageRoute = routeFactory(@"{language}/" + url); languageRoute.Defaults = new RouteValueDictionary(defaults); languageRoute.Constraints = new RouteValueDictionary(constraints); languageRoute.DataTokens = new RouteValueDictionary(); languageRoute.Constraints.Add("language", languageConstrain); routes.Add(name + "Lang", languageRoute); var storeRoute = routeFactory(@"{store}/" + url); storeRoute.Defaults = new RouteValueDictionary(defaults); storeRoute.Constraints = new RouteValueDictionary(constraints); storeRoute.DataTokens = new RouteValueDictionary(); routes.Add(name + "Store", storeRoute); var route = routeFactory(url); route.Defaults = new RouteValueDictionary(defaults); route.Constraints = new RouteValueDictionary(constraints); route.DataTokens = new RouteValueDictionary(); routes.Add(name, route); }
public static void AddLabeledSlider(this Menu menu, string name, string displayName, string[] values, int defaultValue = 0) { var slider = menu.Add(name, new Slider(displayName, defaultValue, 0, values.Length - 1)); var text = menu.Add(name + "label", new Label(values[slider.CurrentValue])); slider.OnValueChange += delegate { text.DisplayName = values[slider.CurrentValue]; }; }
public static void JumblistMapRoute( this RouteCollection routes, string name, string url, object defaults, string[] namespaces, object constraints ) { if ( routes == null ) throw new ArgumentNullException( "routes" ); if ( url == null ) throw new ArgumentNullException( "url" ); var route = new JumblistRoute( url, new MvcRouteHandler() ) { Defaults = new RouteValueDictionary( defaults ), Constraints = new RouteValueDictionary( constraints ), DataTokens = new RouteValueDictionary() }; if ( (namespaces != null) && (namespaces.Length > 0) ) { route.DataTokens["Namespaces"] = namespaces; } if ( String.IsNullOrEmpty( name ) ) routes.Add( route ); else routes.Add( name, route ); }
private static void AddProperty(this IDictionary<string, object> parms, PropertyInfo p, object o, string prefix = "") { object value = p.GetValue(o); // filter out sentinals values for unitialized search fields if (value != null && !value.Equals(0) && !value.Equals(DateTime.MinValue)) { // if the property is a string just add it if (value is string) parms.Add(prefix + p.Name, value); // value types else if (value.GetType().GetTypeInfo().IsValueType) { // serialize dates in the correct format if (value is DateTime) parms.Add(prefix + p.Name, ((DateTime)value).ToString("yyyy-MM-dd")); else parms.Add(prefix + p.Name, value); } // the property is a list in which case search on the first item's value - committee_ids is an example else if (value is IList<string> && ((IList<string>)value).Count > 0) parms.Add(prefix + p.Name, ((IList<string>)value)[0]); // the property is marked as searchable but is a sub ojbect - recurse adding // this property name as a prefix (history.house_passage_result is an example) else parms.AddProperties(value, p.Name + "."); } }
/// <summary> /// Creates a direct or symbolic reference with the specified name and target /// </summary> /// <param name = "name">The name of the reference to create.</param> /// <param name = "canonicalRefNameOrObjectish">The target which can be either the canonical name of a reference or a revparse spec.</param> /// <param name = "allowOverwrite">True to allow silent overwriting a potentially existing reference, false otherwise.</param> /// <param name = "refsColl">The <see cref="ReferenceCollection"/> being worked with.</param> /// <param name="logMessage">The optional message to log in the <see cref="ReflogCollection"/> when adding the <see cref="Reference"/></param> /// <returns>A new <see cref = "Reference" />.</returns> public static Reference Add(this ReferenceCollection refsColl, string name, string canonicalRefNameOrObjectish, bool allowOverwrite = false, string logMessage = null) { Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(canonicalRefNameOrObjectish, "canonicalRefNameOrObjectish"); Reference reference; RefState refState = TryResolveReference(out reference, refsColl, canonicalRefNameOrObjectish); var gitObject = refsColl.repo.Lookup(canonicalRefNameOrObjectish, Core.GitObjectType.Any, LookUpOptions.None); if (refState == RefState.Exists) { return refsColl.Add(name, reference, allowOverwrite, logMessage); } if (refState == RefState.DoesNotExistButLooksValid && gitObject == null) { using (ReferenceSafeHandle handle = Proxy.git_reference_symbolic_create(refsColl.repo.Handle, name, canonicalRefNameOrObjectish, allowOverwrite)) { return Reference.BuildFromPtr<Reference>(handle, refsColl.repo); } } Ensure.GitObjectIsNotNull(gitObject, canonicalRefNameOrObjectish); return refsColl.Add(name, gitObject.Id, allowOverwrite, logMessage); }
public static void Compare(this Collection<Client> Collection, IEnumerable<Client> Items) { if (Items.Count() > 0) { Collection<Client> Temporary = new Collection<Client>(); foreach (Client c in Collection) { Temporary.Add(c); } Collection.Clear(); // Remove our items bool bHasItems = (Temporary.Count() > 0) ? true : false; foreach (Client c in Items) // For each item in our enumeration { if (bHasItems) // If our current collection has any items { foreach (Client e in Temporary) // For each item in our temporary collection { if (c.Id == e.Id) // If the Id is the same as the id in our items collection Collection.Add(c); // Add to the current collection } } else // If we have no items in our collection Collection.Add(c); // Add all the items to our collection } } }
public static CreateProject AddAspNetStart(this CreateProject project, bool full) { string appStartUpTemplate = Resources.AspNet.Startup .Replace("[{namespace}]", $"{project.Parameter.ProjectName}"); appStartUpTemplate = appStartUpTemplate .Replace("[{factoryUsing}]", !full ? string.Empty : $"using {project.Parameter.SolutionParam.SolutionName}.Business.Factory;") .Replace("[{factoryInit}]", !full ? string.Empty : "Register.Do(appSettings.UnitTest);") .Replace("[{name}]", GetSafeName(project.Parameter.SolutionParam.SolutionName)); string appProgramTemplate = Resources.AspNet.Program .Replace("[{namespace}]", $"{project.Parameter.ProjectName}"); string appControllerTemplate = Resources.AspNet.HomeController .Replace("[{namespace}]", $"{project.Parameter.ProjectName}.Controllers"); CreateFile appStartUp = new CreateFile(new CreateFileParam(project.Parameter, "Code", "Startup.cs") { Template = appStartUpTemplate }); project.Add(appStartUp); CreateFile appProgram = new CreateFile(new CreateFileParam(project.Parameter, "Code", "Program.cs") { Template = appProgramTemplate }); project.Add(appProgram); CreateFile appController = new CreateFile(new CreateFileParam(project.Parameter, "Controllers", "HomeController.cs") { Template = appControllerTemplate }); project.Add(appController); return project; }
/// <summary> /// Creates a direct or symbolic reference with the specified name and target /// </summary> /// <param name="refsColl">The <see cref="ReferenceCollection"/> being worked with.</param> /// <param name="name">The name of the reference to create.</param> /// <param name="canonicalRefNameOrObjectish">The target which can be either the canonical name of a reference or a revparse spec.</param> /// <param name="signature">The identity used for updating the reflog</param> /// <param name="logMessage">The optional message to log in the <see cref="ReflogCollection"/> when adding the <see cref="Reference"/></param> /// <param name="allowOverwrite">True to allow silent overwriting a potentially existing reference, false otherwise.</param> /// <returns>A new <see cref="Reference"/>.</returns> public static Reference Add(this ReferenceCollection refsColl, string name, string canonicalRefNameOrObjectish, Signature signature, string logMessage, bool allowOverwrite = false) { Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(canonicalRefNameOrObjectish, "canonicalRefNameOrObjectish"); Reference reference; RefState refState = TryResolveReference(out reference, refsColl, canonicalRefNameOrObjectish); var gitObject = refsColl.repo.Lookup(canonicalRefNameOrObjectish, GitObjectType.Any, LookUpOptions.None); if (refState == RefState.Exists) { return refsColl.Add(name, reference, signature, logMessage, allowOverwrite); } if (refState == RefState.DoesNotExistButLooksValid && gitObject == null) { using (ReferenceSafeHandle handle = Proxy.git_reference_symbolic_create(refsColl.repo.Handle, name, canonicalRefNameOrObjectish, allowOverwrite, signature.OrDefault(refsColl.repo.Config), logMessage)) { return Reference.BuildFromPtr<Reference>(handle, refsColl.repo); } } Ensure.GitObjectIsNotNull(gitObject, canonicalRefNameOrObjectish); if (logMessage == null) { logMessage = string.Format("{0}: Created from {1}", name.LooksLikeLocalBranch() ? "branch" : "reference", canonicalRefNameOrObjectish); } refsColl.EnsureHasLog(name); return refsColl.Add(name, gitObject.Id, signature, logMessage, allowOverwrite); }
public static IServiceCollection AddChiLocalization(this IServiceCollection services, string path) { services.Add(new ServiceDescriptor( typeof(IGettextProcessor), sp => new DefaultGettextProcessor(path), ServiceLifetime.Singleton )); services.Add(new ServiceDescriptor( typeof(IStringLocalizerFactory), typeof(GettextStringLocalizerFactory), ServiceLifetime.Singleton )); services.Add(new ServiceDescriptor( typeof(IStringLocalizer), typeof(GettextStringLocalizer), ServiceLifetime.Transient )); services.Add(new ServiceDescriptor( typeof(IStringLocalizer<>), typeof(StringLocalizer<>), ServiceLifetime.Transient )); return services; }
private static void addSkillSheit(this Menu m, string slot, int dh = 70, int minh = 1, int maxh = 100, int dm = 30, int minm = 1, int maxm = 100) { m.Add(slot+".Enabled", new CheckBox("Use " + slot)); m.Add(slot + ".Hitchance", new Slider("Min Hitchance {0}%", dh, minh, maxh)); m.Add(slot + ".Mana", new Slider("Min Mana to use {0}%", dm, minm, maxm)); }
/// <summary> /// Add the -target option to the given tool arguments builder. /// </summary> internal static void AddTarget(this List<string> builder) { #if BB builder.Add(ToolOptions.Target.AsArg()); builder.Add("BlackBerry"); #endif }
public static void CompleteResolution(this KAOSView view) { foreach (var resolution in view.Resolutions().ToArray()) { view.Add (view.ParentModel.Elements.Single (x => x.Identifier == resolution.ResolvingGoalIdentifier)); view.Add (view.ParentModel.Elements.Single (x => x.Identifier == resolution.ObstacleIdentifier)); } }
public static void If(this Collection<Instruction> ins, Action<Collection<Instruction>> condition, Action<Collection<Instruction>> thenStatement, Action<Collection<Instruction>> elseStatement) { var ifEnd = Instruction.Create(OpCodes.Nop); var ifElse = Instruction.Create(OpCodes.Nop); condition(ins); if (ins[ins.Count - 1].OpCode == OpCodes.Ceq) { ins[ins.Count - 1] = Instruction.Create(OpCodes.Bne_Un, ifElse); } else { ins.Add(Instruction.Create(OpCodes.Brfalse, ifElse)); } thenStatement(ins); ins.Add(Instruction.Create(OpCodes.Br, ifEnd)); ins.Add(ifElse); elseStatement(ins); ins.Add(ifEnd); }
public static void Apply(this CssStyleCollection style, PrintSetting setting) { if (setting == null) return; if (string.IsNullOrEmpty(setting.Top)) { style.Remove("top"); } else { style.Add("top", setting.Top); } if (string.IsNullOrEmpty(setting.Left)) { style.Remove("left"); } else { style.Add("left", setting.Left); } if (string.IsNullOrEmpty(setting.Font)) { style.Remove("font"); } else { style.Add("font", setting.Font); } if (string.IsNullOrEmpty(setting.Size)) { style.Remove("font-size"); } else { style.Add("font-size", setting.Size); } if (string.IsNullOrEmpty(setting.Width)) { style.Remove("width"); } else { style.Add("width", setting.Width); } if (string.IsNullOrEmpty(setting.Height)) { style.Remove("height"); } else { style.Add("height", setting.Height); } }
public static void Add(this ImmutableArray<NavInfoNode>.Builder builder, string name, _LIB_LISTTYPE type, bool expandDottedNames) { if (name == null) { return; } if (expandDottedNames) { const char separator = '.'; var start = 0; var separatorPos = name.IndexOf(separator, start); while (separatorPos >= 0) { builder.Add(name.Substring(start, separatorPos - start), type); start = separatorPos + 1; separatorPos = name.IndexOf(separator, start); } if (start < name.Length) { builder.Add(name.Substring(start), type); } } else { builder.Add(name, type); } }
// register A - initially loaded with a // register B - initially loaded with b // register C - initially 0, exactly one bit wider than A, stores overflow bit // register N - initially loaded with N // after computation in register B: (a+b) mod N // other registers dont change their states // register B must be exactly one bit wider than A to store carry bit // register B must be exactly one bit wider than N to store carry bit // registers A, N must be the same length // Insecure version: registers widths etc. are not checked public static void AddModulo( this QuantumComputer comp, Register a, Register b, Register c, Register N, ulong valueN) { RegisterRef carry = b[b.Width - 1]; RegisterRef overflow = c[c.Width - 1]; comp.Add(a, b, c); comp.InverseAdd(N, b, c); comp.SigmaX(carry); comp.CNot(overflow, carry); comp.SigmaX(carry); //resetting N comp.LoadNumber(N, valueN, overflow); comp.Add(N, b, c); // now we have [(a+b) mod N] in B register // next steps lead to recover the initial state of registers N and overflow bit //setting N back comp.LoadNumber(N, valueN, overflow); comp.InverseAdd(a, b, c); comp.CNot(overflow, carry); comp.Add(a, b, c); }
public static void SetDefaultBundle(this BundleCollection bundles) { #region CSS Bundle var defaultCSSs = new Bundle("~/Content/themes/base/css/css", new CssMinify()); //main CSS defaultCSSs.AddFile("~/Content/themes/base/css/main.css"); //bootstarp CSS files defaultCSSs.AddFile("~/Content/themes/base/css/bootstrap.css"); defaultCSSs.AddFile("~/Content/themes/base/css/bootstrap-responsive.css"); //CSS file for bootstrap-datepicker defaultCSSs.AddFile("~/Content/themes/base/css/datepicker.css"); bundles.Add(defaultCSSs); #endregion #region JavaScript Bundle var defaultJSs = new Bundle("~/Content/themes/base/js/js", new JsMinify()); //load jQuery library defaultJSs.AddFile("~/Content/themes/base/js/jquery-1.7.2.min.js"); //bootstrap JS files defaultJSs.AddFile("~/Content/themes/base/js/bootstrap.js"); //bootstrap-datepicker defaultJSs.AddFile("~/Content/themes/base/js/bootstrap-datepicker.js"); bundles.Add(defaultJSs); #endregion }
public static bool AddAndWait(this Fiber fiber, Action operation, TimeSpan timeout) { var @event = new ManualResetEvent(false); fiber.Add(() => { try { operation(); } finally { @event.Set(); } }); bool completed = @event.WaitOne(timeout); fiber.Add(() => { var disposable = @event as IDisposable; disposable.Dispose(); }); return completed; }
/// <summary> /// Create code to box the given source value into the given type. /// </summary> public static RLRange Box(this IRLBuilder builder, ISourceLocation sequencePoint, RegisterSpec source, XTypeReference type, DexTargetPackage targetPackage, IRegisterAllocator frame) { if (type.IsPrimitive) { if (type.IsByte()) builder.Add(sequencePoint, RCode.Int_to_byte, source.Register, source.Register); else if (type.IsUInt16()) builder.Add(sequencePoint, RCode.Int_to_short, source.Register, source.Register); // Call appropriate valueOf method var boxedType = type.Module.TypeSystem.Object; var r = frame.AllocateTemp(boxedType.GetReference(targetPackage)); var call = builder.Add(sequencePoint, RCode.Invoke_static, type.GetBoxValueOfMethod(), source.Registers); var last = builder.Add(sequencePoint, RCode.Move_result_object, r); return new RLRange(call, last, r); } if (type.IsGenericParameter) { var nop = builder.Add(sequencePoint, RCode.Nop); return new RLRange(nop, source); } XTypeDefinition typeDef ; if (type.TryResolve(out typeDef) && (typeDef.IsEnum)) { // Call appropriate valueOf method /*var boxedType = type.Module.TypeSystem.Object; var r = frame.AllocateTemp(boxedType.GetReference(target, nsConverter)); var call = builder.Add(sequencePoint, RCode.Invoke_static, typeDef.GetEnumUnderlyingType().GetBoxValueOfMethod(), source.Registers); var last = builder.Add(sequencePoint, RCode.Move_result_object, r); return new RLRange(call, last, r);*/ } // Just cast var checkCast = builder.Add(sequencePoint, RCode.Check_cast, type.GetReference(targetPackage), source); return new RLRange(checkCast, source); }
/// <summary> /// Adds a disposable to the CompositeDisposable or disposes the disposable if the CompositeDisposable is disposed. /// </summary> public static void Add(this CompositeDisposable self, IDisposable disposable1, IDisposable disposable2, IDisposable disposable3, IDisposable disposable4) { self.Add(disposable1); self.Add(disposable2); self.Add(disposable3); self.Add(disposable4); }
public static void MapRouteLowercase(this RouteCollection routes, string name, string url, object defaults, object constraints) { if (routes == null) { throw new ArgumentNullException("routes"); } if (url == null) { throw new ArgumentNullException("url"); } object route = new LowercaseRouteHelper(url, new MvcRouteHandler()) { Defaults = new RouteValueDictionary(defaults), Constraints = new RouteValueDictionary(constraints) }; if (String.IsNullOrEmpty(name)) { routes.Add(route as RouteBase); } else { routes.Add(name, route as RouteBase); } }
private static void AddResources(this ResourceDictionary resourceDictionary, Color color, string name) { resourceDictionary.Add(name.GetHighlightColorName(), color.CalculateHighlightColor()); resourceDictionary.Add(name.GetAccentColorName(), color); resourceDictionary.Add(name.GetHighlightBrushName(), new SolidColorBrush((Color) resourceDictionary[name.GetHighlightColorName()])); resourceDictionary.Add(name.GetAccentBrushName(), new SolidColorBrush((Color) resourceDictionary[name.GetAccentColorName()])); }
private static void Add(this IProfileRegistry registry, IServiceRegistry serviceRegistry) { registry.Add(serviceRegistry.TypeRegistrations); registry.Add(serviceRegistry.CollectionTypeRegistrations); registry.Add(serviceRegistry.InstanceRegistrations); }
public static void AddLine(this Paragraph p, string s, Font font) { if (s.HasValue()) { if (p.Content.Length > 0) p.Add("\n"); p.Add(new Chunk(s, font)); } }
public static void Add(this SolutionFileDesigner that, SolutionFileDesignerHTMLElementTabs e) { that.Add(e.HTMLDesignerTab); that.Add(e.HTMLSourceTab); that.Content.Add(e.HTMLDesignerContent); that.Content.Add(e.HTMLSourceView.Container); }
public static void CompleteObstacleAgentAssignments(this KAOSView view) { foreach (var aa in view.ObstacleAgentAssignments().ToArray()) { view.Add (view.ParentModel.Elements.Single (x => x.Identifier == aa.ObstacleIdentifier)); foreach (var agentIdentifier in aa.AgentIdentifiers) { view.Add (view.ParentModel.Elements.Single (x => x.Identifier == agentIdentifier)); } } }
public static void BranchShort(this List<object> codeList, Code op, int label) { Debug.Assert((codeList.Count() - label) < SByte.MaxValue); // +2, op code + address code, as backward jump start from first byte of the end of branch command with address var address = (byte) -(codeList.Count() - label + 2); codeList.Add(op); codeList.Add(address); }
public static void AddInOrder(this ObservableCollection<TaskView> list, TaskView item) { list.Add(item); var order = list.OrderByDescending(elem => elem.ViewModel.SeverityValue).ToList(); list.Clear(); order.ForEach(orderItem => list.Add(orderItem)); }
/// <summary> /// Adds the fields of the <see cref="DbFeature"/> class that should be stored to the provided index stores. /// </summary> /// <param name="stores">The stores to which the fields should be added.</param> public static void AddDbFeatureStoredFields(this IDictionary<Expression<Func<DbFeature, object>>, FieldStorage> stores) { // Store the product so it can be used to create the top menu stores.Add(feature => feature.Product, FieldStorage.Yes); // Store the three fields that are used to create the menu stores.Add(feature => feature.Group, FieldStorage.Yes); stores.Add(feature => feature.Title, FieldStorage.Yes); stores.Add(feature => feature.ParentTitle, FieldStorage.Yes); }
public static DynamicParameters AddUserInfo(this DynamicParameters parameters, User userInfo) { parameters.Add("@Email", userInfo.Email); parameters.Add("@FirstName", userInfo.FirstName); parameters.Add("@LastName", userInfo.LastName); parameters.Add("@TotalResponses", userInfo.TotalResponses); parameters.Add("@Ip", userInfo.Ip); return parameters; }