Beispiel #1
0
        private async Task <ReqResult> GetModelResult()
        {
            ObjectValue v = await Connection.GetObjectValueByID(RootID);

            Calc_Model model = v.ToObject <Calc_Model>() ?? new Calc_Model();

            ObjectRef[] objects = model.GetAllCalculations().SelectMany(GetObjects).Distinct().ToArray();
            ObjectInfos infos;

            try {
                infos = await Connection.GetObjectsByID(objects);
            }
            catch (Exception) {
                infos = new ObjectInfos(objects.Length);
                for (int i = 0; i < objects.Length; ++i)
                {
                    ObjectRef obj = objects[i];
                    try {
                        infos.Add(await Connection.GetObjectByID(obj));
                    }
                    catch (Exception) {
                        infos.Add(new ObjectInfo(obj, "???", "???"));
                    }
                }
            }

            var objectInfos = new List <ObjInfo>();

            foreach (ObjectInfo info in infos)
            {
                var numericVariables = info.Variables.Where(IsNumericBoolOrStruct).Select(v => v.Name).ToArray();
                objectInfos.Add(new ObjInfo()
                {
                    ID        = info.ID.ToEncodedString(),
                    Name      = info.Name,
                    Variables = numericVariables
                });
            }

            var mods = await Connection.GetModules();

            List <VariableValue> variables = await Connection.ReadAllVariablesOfObjectTree(RootID);

            var changes = VarValsToEventEntries(variables);

            DataValue resGetAdapterInfo = await Connection.CallMethod(moduleID, "GetAdapterInfo");

            AdapterInfo[] adapterTypesInfo = resGetAdapterInfo.Object <AdapterInfo[]>() ?? new AdapterInfo[0];

            var res = new {
                model       = model,
                objectInfos = objectInfos,
                moduleInfos = mods.Select(m => new {
                    ID   = m.ID,
                    Name = m.Name
                }).ToArray(),
                variableValues   = changes,
                adapterTypesInfo = adapterTypesInfo,
            };

            return(ReqResult.OK(res, ignoreShouldSerializeMembers: true));
        }