public override bool Render(IInternalContextAdapter context, TextWriter writer, INode node) { bool result; object obj; if (!this.AssertArgument(node)) { result = false; } else if (!this.AssertNodeHasValue(node, context, out obj)) { result = false; } else { string arg = obj.ToString(); this.AssertTemplateStack(context); Resource.Resource currentResource = context.CurrentResource; string encoding; if (currentResource != null) { encoding = currentResource.Encoding; } else { encoding = (string)this.rsvc.GetProperty("input.encoding"); } Template template = this.GetTemplate(arg, encoding, context); result = (template != null && this.RenderTemplate(template, arg, writer, context)); } return(result); }
public Resource.Resource Load(string name, Resource.ResourceManager content) { try { if (name.IndexOf('.') < 0) { name += ".BMP"; } System.IO.Stream stream = FileSystem.Open(name); BitmapSurface surface = new BitmapSurface(stream, BitmapSurface.SourceType.Unknown, true); Resource.Resource resource = RendererManager.CurrentRenderer.CreateTexture(name, surface, true, true); stream.Close(); return(resource); } catch (System.IO.FileNotFoundException) { Logger.WriteError("Unable to find texture: {0}", name); return(RendererManager.CurrentRenderer.ErrorTexture); } }
private int GetHarvest(Settlement.Settlement settlement, Resource.Resource resource, double rate, Settler.Settler worker) { var efficiency = BuildingEfficiency(settlement, resource, worker) * WorkerEfficiency(worker); var guaranteedHarvest = (int)(rate * efficiency); var uncertainHarvest = guaranteedHarvest - rate * efficiency; return(guaranteedHarvest + (new Random().NextDouble() < uncertainHarvest ? 1 : 0)); }
/// <summary> /// iterates through the argument list and renders every /// argument that is appropriate. Any non appropriate /// arguments are logged, but render() continues. /// </summary> public override bool Render(IInternalContextAdapter context, TextWriter writer, INode node) { // did we get an argument? if (!AssertArgument(node)) { return(false); } // does it have a value? If you have a null reference, then no. Object value; if (!AssertNodeHasValue(node, context, out value)) { return(false); } // get the path String arg = value.ToString(); AssertTemplateStack(context); Resource.Resource current = context.CurrentResource; // get the resource, and assume that we use the encoding of the current template // the 'current resource' can be null if we are processing a stream.... String encoding; if (current == null) { encoding = (String)runtimeServices.GetProperty(RuntimeConstants.INPUT_ENCODING); } else { encoding = current.Encoding; } // now use the Runtime resource loader to get the template Template t = null; t = GetTemplate(arg, encoding, context); if (t == null) { return(false); } // and render it if (!RenderTemplate(t, arg, writer, context)) { return(false); } return(true); }
public IDictionary<string, IResource> Get() { var tryToPingGoogle = new Resource.Resource(new List<ICall>() { new Call.Call() { Method = Method.GET, Name = "Ping Google", Url = "http://google.com", Validation = new HttpStatusCodeIsOK() }, new Call.Call() { Method = Method.GET, Name = "Failed Ping Google", Url = "http://google.coxm", Validation = new HttpStatusCodeIsOK() }, new Call.Call() { Method = Method.GET, Name = "Valid but never called Ping Google", Url = "http://google.com", Validation = new HttpStatusCodeIsOK() } }, "Chained up GETs for Ping Google"); var tryToPing7D = new Resource.Resource(new List<ICall>() { new Call.Call() { Method = Method.GET, Name = "Call status...", Url = "http://api.7digital.com/1.2/status?oauth_consumer_key=YOUR_KEY_HERE", Validation = new HttpStatusCodeIsOK() } }, "Get 7d API current time"); return new Dictionary<string, IResource> { {tryToPingGoogle.Name,tryToPingGoogle}, {tryToPing7D.Name, tryToPing7D} }; }
/// <summary> /// does the actual rendering of the included file /// </summary> /// <param name="node">AST argument of type StringLiteral or Reference</param> /// <param name="context">valid context so we can render References</param> /// <param name="writer">output Writer</param> /// <returns>boolean success or failure. failures are logged</returns> private bool RenderOutput(INode node, IInternalContextAdapter context, TextWriter writer) { if (node == null) { runtimeServices.Error("#include() error : null argument"); return(false); } // does it have a value? If you have a null reference, then no. Object val = node.Value(context); if (val == null) { runtimeServices.Error("#include() error : null argument"); return(false); } // get the path String arg = val.ToString(); Resource.Resource resource = null; Resource.Resource current = context.CurrentResource; try { // get the resource, and assume that we use the encoding of the current template // the 'current resource' can be null if we are processing a stream.... String encoding; if (current == null) { encoding = (String)runtimeServices.GetProperty(RuntimeConstants.INPUT_ENCODING); } else { encoding = current.Encoding; } resource = runtimeServices.GetContent(arg, encoding); } catch (ResourceNotFoundException) { // the arg wasn't found. Note it and throw runtimeServices.Error( string.Format("#include(): cannot find resource '{0}', called from template {1} at ({2}, {3})", arg, context.CurrentTemplateName, Line, Column)); throw; } catch (System.Exception e) { runtimeServices.Error( string.Format("#include(): arg = '{0}', called from template {1} at ({2}, {3}) : {4}", arg, context.CurrentTemplateName, Line, Column, e)); } if (resource == null) { return(false); } writer.Write((String)resource.Data); return(true); }
public virtual double BuildingEfficiency(Settlement.Settlement settlement, Resource.Resource resource, Settler.Settler worker) { return(1.0); }
private bool RenderOutput(INode node, IInternalContextAdapter context, TextWriter writer) { bool result; if (node == null) { this.rsvc.Error("#include() error : null argument"); result = false; } else { object obj = node.Value(context); if (obj == null) { this.rsvc.Error("#include() error : null argument"); result = false; } else { string text = obj.ToString(); Resource.Resource resource = null; Resource.Resource currentResource = context.CurrentResource; try { string encoding; if (currentResource != null) { encoding = currentResource.Encoding; } else { encoding = (string)this.rsvc.GetProperty("input.encoding"); } resource = this.rsvc.GetContent(text, encoding); } catch (ResourceNotFoundException) { this.rsvc.Error(string.Concat(new object[] { "#include(): cannot find resource '", text, "', called from template ", context.CurrentTemplateName, " at (", base.Line, ", ", base.Column, ")" })); throw; } catch (System.Exception ex) { this.rsvc.Error(string.Concat(new object[] { "#include(): arg = '", text, "', called from template ", context.CurrentTemplateName, " at (", base.Line, ", ", base.Column, ") : ", ex })); } if (resource == null) { result = false; } else { writer.Write((string)resource.Data); result = true; } } } return(result); }
public override double BuildingEfficiency(Settlement.Settlement settlement, Resource.Resource resource, Settler.Settler worker) { return(1); }