Exemplo n.º 1
0
 private static VariableRef MakeVarRefFromAddress(string address, string moduleID)
 {
     try {
         string[]? arr = StdJson.ObjectFromString <string[]>(address);
         if (arr != null && arr.Length == 2 && arr[0].Length > 0 && arr[1].Length > 0)
         {
             return(VariableRef.Make(moduleID, arr[0], arr[1]));
         }
     }
     catch (Exception) {}
     return(VariableRef.Make(moduleID, address, "Value"));
 }
Exemplo n.º 2
0
        protected virtual T DeserializeModelFromString(string model)
        {
            string m = model.TrimStart();

            if (m.StartsWith("<"))
            {
                modelFormat = ModelFormat.XML;
                return(Xml.FromXmlString <T>(model));
            }
            else if (m.StartsWith("{"))
            {
                modelFormat = ModelFormat.JSON;
                return(StdJson.ObjectFromString <T>(model) ?? new T());
            }
            else
            {
                throw new Exception($"Unknown file format for {modelFileName}: expected XML or JSON");
            }
        }
Exemplo n.º 3
0
        public async Task <ReqResult> UiReq_ConfigPageDuplicate(string pageID, string newPageID, string title)
        {
            CheckActivePage(pageID);

            string pageCopy = StdJson.ObjectToString(activePage !.Page);
            var    page     = StdJson.ObjectFromString <Page>(pageCopy) !;

            page.ID   = newPageID;
            page.Name = title;

            var pages = configuration.Pages.ToList();

            pages.Add(page);
            configuration.Pages = pages.ToArray();

            Pages[page.ID] = new PageState(page, Connection, widgetTypes, this);

            DataValue newViewConfig = DataValue.FromObject(configuration, indented: true);
            await Context.SaveViewConfiguration(newViewConfig);

            return(ReqResult.OK(configuration.Pages));
        }