private Directives GutsDirectives() { var patch = new Directives().Add("items"); var knowledge = this.memory.Contents().Knowledge(this.name.AsString()); new Each <string>( (key) => patch .Add("item") .Add("name") .Set(key.Substring((this.name.AsString() + "/").Length)) .Up() .Add("size") .Set( new LengthOf( this.memory .Contents() .Bytes(key, () => new byte[0]) ).Value() ) .Up() .Up(), knowledge ).Invoke(); return(patch); }
public void AddDirective(IDirective directive) { if (Directives == null) { Directives = new List <IDirective>(); } Directives.Add(directive); }
/// <summary> /// Adds the specified directive to the plan. /// </summary> /// <param name="directive">The directive.</param> public void Add(IDirective directive) { Ensure.ArgumentNotNull(directive, "directive"); var constructorInjectionDirective = directive as ConstructorInjectionDirective; if (constructorInjectionDirective != null) { ConstructorInjectionDirectives.Add(constructorInjectionDirective); } Directives.Add(directive); }
static Beboputer() { //find instructions and directives List <Type> directives = Assembly.GetAssembly(typeof(Directive)).GetTypes().Where(type => type.IsSubclassOf(typeof(Directive))).ToList <Type>(); foreach (Type directive in directives) { MnemonicAttribute ma = (MnemonicAttribute)Attribute.GetCustomAttribute(directive, typeof(MnemonicAttribute)); string mnemonic = directive.Name; if (ma != null) { mnemonic = ma.Mnemonic; } Directives.Add(mnemonic, directive); } List <Type> instructions = Assembly.GetAssembly(typeof(Instruction)).GetTypes().Where(type => type.IsSubclassOf(typeof(Instruction))).ToList <Type>(); foreach (Type instruction in instructions) { MnemonicAttribute ma = (MnemonicAttribute)Attribute.GetCustomAttribute(instruction, typeof(MnemonicAttribute)); string mnemonic = instruction.Name; if (ma != null) { mnemonic = ma.Mnemonic; } Instructions.Add(mnemonic, instruction); //opcodes OpcodeAttribute[] oas = (OpcodeAttribute[])Attribute.GetCustomAttributes(instruction, typeof(OpcodeAttribute)); foreach (OpcodeAttribute oa in oas) { string key = mnemonic + "_" + Enum.GetName(typeof(AddressingModes), oa.AddressingMode); if (Beboputer.Opcodes.ContainsKey(key)) { throw new InvalidOperationException("opcode key {" + key + "} already exists"); } Beboputer.Opcodes.Add(key, oa.Opcode); } } }
public void ConvertsToString() { Directives dirs = new Directives(); for (int idx = 0; idx < 10; ++idx) { dirs.Add("HELLO"); } var xml = dirs.ToString(); Assert.True( new Regex("ADD \"HELLO\";").Matches(xml).Count == 10 ); }
/// <inheritdoc /> protected override void InitializeLayout() { if (Fields.Count == 0) { Fields.Add(new W3CExtendedLogField() { Name = "date", Layout = "${date:universalTime=true:format=yyyy-MM-dd}" }); Fields.Add(new W3CExtendedLogField() { Name = "time", Layout = @"${date:universalTime=true:format=HH\:mm\:ss}" }); Fields.Add(new W3CExtendedLogField() { Name = "c-ip", Layout = "${aspnet-request-ip}" }); Fields.Add(new W3CExtendedLogField() { Name = "cs-username", Layout = "${aspnet-user-identity}" }); Fields.Add(new W3CExtendedLogField() { Name = "s-computername", Layout = "${machinename}" }); Fields.Add(new W3CExtendedLogField() { Name = "cs-method", Layout = "${aspnet-request-method}" }); Fields.Add(new W3CExtendedLogField() { Name = "cs-uri-stem", Layout = "${aspnet-request-url:includeScheme=false:includeHost=false}" }); Fields.Add(new W3CExtendedLogField() { Name = "cs-uri-query", Layout = "${aspnet-request-url:includeScheme=false:includeHost=false:includePath=false:includeQueryString=true}" }); Fields.Add(new W3CExtendedLogField() { Name = "sc-status", Layout = "${aspnet-response-statuscode}" }); Fields.Add(new W3CExtendedLogField() { Name = "sc-bytes", Layout = "${aspnet-response-contentlength}" }); Fields.Add(new W3CExtendedLogField() { Name = "cs-bytes", Layout = "${aspnet-request-contentlength}" }); Fields.Add(new W3CExtendedLogField() { Name = "time-taken", Layout = "${aspnet-request-duration}" }); Fields.Add(new W3CExtendedLogField() { Name = "cs-host", Layout = "${aspnet-request-url:includeScheme=false:includeHost=true:includePath=false}" }); Fields.Add(new W3CExtendedLogField() { Name = "cs(User-Agent)", Layout = "${aspnet-request-useragent}" }); } if (Directives.Count == 0) { Directives.Add(new W3CExtendedLogField() { Name = "Software", Layout = "Microsoft Internet Information Server" }); Directives.Add(new W3CExtendedLogField() { Name = "Version", Layout = "1.0" }); Directives.Add(new W3CExtendedLogField() { Name = "Start-Date", Layout = @"${date:universalTime=true:format=yyyy-MM-dd HH\:mm\:ss}" }); } base.InitializeLayout(); }
/// <summary> /// /// </summary> /// <returns></returns> public IEnumerator <IDirective> GetEnumerator() { var dirs = new Directives(); var node = this.node.Value(); if (node.NodeType == XmlNodeType.Element) { var elmnt = node as XElement; dirs.Add(elmnt.Name); foreach (XAttribute attr in elmnt.Attributes()) { dirs.Attr(attr.Name, attr.Value); } } var ctn = node as XContainer; //@TODO: Add failing for null var containsElement = new Contains <XmlNodeType>( new Mapped <XNode, XmlNodeType>( xnode => xnode.NodeType, ctn.Nodes() ), XmlNodeType.Element ).Value(); foreach (XNode child in ctn.Nodes()) { switch (child.NodeType) { case XmlNodeType.Text: if (!containsElement) { dirs.Set((child as XText).Value); } break; case XmlNodeType.CDATA: if (!containsElement) { dirs.Set((child as XCData).Value); } break; case XmlNodeType.Element: dirs.Append(new CopyOfDirective(child)).Up(); break; case XmlNodeType.ProcessingInstruction: dirs.Pi((child as XProcessingInstruction).Target, (child as XProcessingInstruction).Data); break; case XmlNodeType.Attribute: case XmlNodeType.Comment: case XmlNodeType.Document: case XmlNodeType.DocumentFragment: case XmlNodeType.DocumentType: break; default: throw new ArgumentException($"unsupported type {child.NodeType} of node {child.ToString()}"); } } return(dirs.GetEnumerator()); }
/// <summary> /// Adds the specified directive to the plan. /// </summary> /// <param name="directive">The directive.</param> public void Add(IDirective directive) { Ensure.ArgumentNotNull(directive, "directive"); Directives.Add(directive); }