Inheritance: ResolveValue
コード例 #1
0
ファイル: WebServer.cs プロジェクト: CivilPol/SRS
 private string RenderTemplate(List<Service> services)
 {
     using (
         StreamReader template = new StreamReader(new FileStream("Resources\\services.cottle", FileMode.Open),
                                                  Encoding.UTF8))
     {
         try
         {
             Document document = new Document(template);
             Scope scope = new Scope();
             CommonFunctions.Assign(scope);
             scope["services"] = new ReflectionValue(services);
             return document.Render(scope);
         }
         catch (Exception)
         {
             Console.WriteLine("Error rendering template");
         }
     }
     return "Error rendering template";
 }
コード例 #2
0
        // Create Cottle variables from the EDDI information
        private Dictionary<string, Cottle.Value> createVariables(Event theEvent = null)
        {
            Dictionary<string, Cottle.Value> dict = new Dictionary<string, Cottle.Value>();

            if (EDDI.Instance.Cmdr != null)
            {
                dict["cmdr"] = new ReflectionValue(EDDI.Instance.Cmdr);
            }

            if (EDDI.Instance.Ship != null)
            {
                dict["ship"] = new ReflectionValue(EDDI.Instance.Ship);
            }

            if (EDDI.Instance.HomeStarSystem != null)
            {
                dict["homesystem"] = new ReflectionValue(EDDI.Instance.HomeStarSystem);
            }

            if (EDDI.Instance.HomeStation != null)
            {
                dict["homestation"] = new ReflectionValue(EDDI.Instance.HomeStation);
            }

            if (EDDI.Instance.CurrentStarSystem != null)
            {
                dict["system"] = new ReflectionValue(EDDI.Instance.CurrentStarSystem);
            }

            if (EDDI.Instance.LastStarSystem != null)
            {
                dict["lastsystem"] = new ReflectionValue(EDDI.Instance.LastStarSystem);
            }

            if (EDDI.Instance.CurrentStation != null)
            {
                dict["station"] = new ReflectionValue(EDDI.Instance.CurrentStation);
            }

            if (theEvent != null)
            {
                dict["event"] = new ReflectionValue(theEvent);
            }

            return dict;
        }