public void addTo(Context context)
        {
            var vd = new VariableDefinition(V_MODTIME, VFT_MODTIME, true, true, "Modification Times", null);

            vd.setGetter(new DelegatedVariableGetter((con, def, caller, request) => tooOldModifications()));
            vd.setSetter(new DelegatedVariableSetter((con, def, caller, request, value) => { }));
            context.addVariableDefinition(vd);
        }
Exemplo n.º 2
0
        private void addSettingsVariable(Context context)
        {
            var vd = new VariableDefinition(V_SETTINGS, VFT_SETTINGS, true, true, "Just Settings",
                                            ContextUtils.GROUP_REMOTE);

            vd.setGetter(new DelegatedVariableGetter((con, def, caller, request) => settings));
            vd.setSetter(new DelegatedVariableSetter((con, def, caller, request, value) =>
            {
                settings = value;
                notifyPropertyChanged("stringValue");
            }));
            context.addVariableDefinition(vd);
        }
        private void InitializeAgentContext()
        {
            var context = _agent.getContext();

            Console.Out.WriteLine("=== Reinitializing Agent Context");

            var performanceSettingsVariableDefinition = new VariableDefinition(
                V_PERFORMANCE_TESTING,
                VFT_PERFORMANCE_TESTING, true, true, "Performance Testing",
                ContextUtils.GROUP_REMOTE);

            performanceSettingsVariableDefinition.setGetter(new DelegatedVariableGetter((con, def, caller, request) => this.PerformanceSettings));
            performanceSettingsVariableDefinition.setSetter(new DelegatedVariableSetter((con, def, caller, request, value) => { this.PerformanceSettings = value; }));
            context.addVariableDefinition(performanceSettingsVariableDefinition);
        }
Exemplo n.º 4
0
        private static void initializeAgentContext(AgentContext context)
        {
            string login    = "******";
            string password = "******";

            VariableDefinition vd = new VariableDefinition("currentUser_login", singleString, true, false, "Имя пользователя", ContextUtils.GROUP_REMOTE);

            vd.setGetter(new DelegatedVariableGetter((con, def, caller, request) => authData));
            vd.setSetter(new DelegatedVariableSetter((con, def, caller, request, value) => { authData = value; }));
            vd.setGroup(ContextUtils.createGroup(ContextUtils.GROUP_REMOTE, "Учетные данные"));
            context.addVariableDefinition(vd);

            vd = new VariableDefinition("currentUser_pswd", singleString, true, false, "Пароль", ContextUtils.GROUP_REMOTE);
            vd.setGetter(new DelegatedVariableGetter((con, def, caller, request) => authData2));
            vd.setSetter(new DelegatedVariableSetter((con, def, caller, request, value) => { authData2 = value; }));
            vd.setGroup(ContextUtils.createGroup(ContextUtils.GROUP_REMOTE, "Учетные данные"));
            context.addVariableDefinition(vd);

            vd = new VariableDefinition("user_list", VTF_USERS, true, false, "Список пользователей", ContextUtils.GROUP_REMOTE);
            vd.setGetter(new DelegatedVariableGetter((con, def, caller, request) => VDT_USERS));
            vd.setSetter(new DelegatedVariableSetter((con, def, caller, request, value) => { VDT_USERS = value; }));
            vd.setGroup(ContextUtils.createGroup(ContextUtils.GROUP_REMOTE, "Данные с сервера"));
            context.addVariableDefinition(vd);

            vd = new VariableDefinition("device_list", VTF_DEVICES, true, false, "Список устройств", ContextUtils.GROUP_REMOTE);
            vd.setGetter(new DelegatedVariableGetter((con, def, caller, request) => VDT_DEVICES));
            vd.setSetter(new DelegatedVariableSetter((con, def, caller, request, value) => { VDT_DEVICES = value; }));
            vd.setGroup(ContextUtils.createGroup(ContextUtils.GROUP_REMOTE, "Данные с сервера"));
            context.addVariableDefinition(vd);

            Task <AuthResponse> signin = Connect(login, password);

            signin.Wait();
            if (signin.Result.status)
            {
                var records = new DataTable(singleString);
                records.addRecord().addString(login);
                context.setVariable("currentUser_login", records);

                records = new DataTable(singleString);
                records.addRecord().addString(password);
                context.setVariable("currentUser_pswd", records);
            }

            Task <UserListResponse> getUserList = GetUserList();

            getUserList.Wait();
            if (getUserList.Result.status && getUserList.Result.user_list != null)
            {
                var records = new DataTable(VTF_USERS);
                foreach (var user in getUserList.Result.user_list)
                {
                    records.addRecord().addString(user.login).addString(user.device_access);
                }
                context.setVariable("user_list", records);
            }

            Task <DeviceListResponse> getDevList = GetDeviceList();

            getDevList.Wait();
            var recordsdev = new DataTable(VTF_DEVICES);

            if (getDevList.Result.status && getDevList.Result.devices_list != null)
            {
                foreach (var device in getDevList.Result.devices_list)
                {
                    if (device.devEui == "323632317D37590E")
                    {
                        // запрос архива данных
                        Task <DataDeviceResponse> getDataArchive = GetDataFromDevice(device.devEui);
                        getDataArchive.Wait();
                        var dataDevice      = getDataArchive.Result.data_list;
                        var dataTableDevice = new DataTable(VTF_DATADEVICES);
                        foreach (var x in dataDevice)
                        {
                            var packet = DataPacket.Parse(x.data);
                            dataTableDevice.addRecord().addInt(packet.type).addInt(packet.charge).addDate(packet.dateTime).addInt(packet.temperature).addInt(packet.input1).addInt(packet.input2).addInt(packet.input3).addInt(packet.input4);
                        }

                        // добавляем всю информацию
                        recordsdev.addRecord().addString(device.devEui).addString(device.devName).addString(device.devType == null ? " " : device.devType).addDataTable(dataTableDevice);
                    }
                }
                context.setVariable("device_list", recordsdev);
            }

            var ed = new EventDefinition(E_EVENT, EFT_EVENT, "Agent Event", ContextUtils.GROUP_REMOTE);

            context.addEventDefinition(ed);

            context.addEventListener(E_EVENT, new DefaultContextEventListener <CallerController <CallerData> >(
                                         (anEvent) =>
            {
                Console.Out.WriteLine(("User has confirmed event with data: " + anEvent.ToString()));
            }));

            DataTable records2 = new DataTable(EFT_EVENT);

            records2.addRecord().addFloat((float)15);
            context.fireEvent(E_EVENT, EventLevel.INFO, records2 /*(float)(random.Next() * 1000000)*/);
            //context.start();
        }
Exemplo n.º 5
0
        private static void initializeAgentContext(Context context)
        {
            var random = new Random();
            var vd     = new VariableDefinition(V_SETTING, VFT_SETTING, true, true, "Tabular Setting",
                                                ContextUtils.GROUP_REMOTE);

            vd.setGetter(new DelegatedVariableGetter((con, def, caller, request) => setting));
            vd.setSetter(new DelegatedVariableSetter((con, def, caller, request, value) => { setting = value; }));
            context.addVariableDefinition(vd);

            vd = new VariableDefinition(V_PERIOD, VFT_PERIOD, true, true, "Event Generation Period",
                                        ContextUtils.GROUP_REMOTE);
            vd.setGetter(
                new DelegatedVariableGetter(
                    (con, def, caller, request) => new DataRecord(VFT_PERIOD).addLong(period).wrap()));
            vd.setSetter(
                new DelegatedVariableSetter(
                    (con, def, caller, request, value) => { period = value.rec().getLong(VF_PERIOD_PERIOD); }));
            context.addVariableDefinition(vd);
            var fd = new FunctionDefinition(F_OPERATION, FIFT_OPERATION, FOFT_OPERATION, "Agent Operation",
                                            ContextUtils.GROUP_REMOTE);

            fd.setImplementation(new DelegatedFunctionImplementation((con, def, caller, request, parameters) =>
            {
                var limit = parameters.rec().getInt(FIF_OPERATION_LIMIT);
                return(new DataRecord(def.getOutputFormat()).addInt(random.Next() * limit).wrap());
            }));
            context.addFunctionDefinition(fd);

            var ed = new EventDefinition(E_EVENT, EFT_EVENT, "Agent Event", ContextUtils.GROUP_REMOTE);

            context.addEventDefinition(ed);

            context.addEventListener(AgentContext.E_EVENT_CONFIRMED, new DefaultContextEventListener <CallerController <CallerData> >(
                                         (anEvent) =>
            {
                Console.Out.WriteLine(("Server has confirmed event with ID: " + anEvent.getData().rec().getLong(AgentContext.EF_EVENT_CONFIRMED_ID)));
            }));

            context.addEventListener(AgentContext.E_EVENT_ACKNOWLEDGED, new DefaultContextEventListener <CallerController <CallerData> >(
                                         (anEvent) =>
            {
                Console.Out.WriteLine(("User has confirmed event with data: " + anEvent.ToString()));
            }));

            //// For assets adding you should create DataTable with AgentContext.FOFT_ASSET format, add addVariableDefinition with AgentContext.V_ASSETS name and getter for it with created DataTable.
            //// You can add assets by adding records to created DataTable for previous step. For example:

            //var assetDataTable = new DataTable(AgentContext.FOFT_ASSET, false);
            //var assetVariable = new VariableDefinition(AgentContext.V_ASSETS, AgentContext.FOFT_ASSET, true, false, null);
            //assetVariable.setGetter(new DelegatedVariableGetter((con, def, caller, request) => assetDataTable));
            //context.addVariableDefinition(assetVariable);

            //var assetSub = new DataRecord(AgentContext.FOFT_ASSET);
            //assetSub.setValue(0, "Test Subasset"); //id
            //assetSub.setValue(1, "Test Subasset"); //dexscription
            //assetSub.setValue(2, true); // enable
            //assetSub.setValue(3, null); //subset

            //var assetRoot = new DataRecord(AgentContext.FOFT_ASSET);
            //assetRoot.setValue(0, "Test Asset"); // id
            //assetRoot.setValue(1, "Test Asset"); // description
            //assetRoot.setValue(2, true); // enable
            //assetRoot.setValue(3, new DataTable(assetSub)); // subasset

            //assetDataTable.addRecord(assetRoot);

            //// If we add some assets here, we'll need to make sure group of all entities is remote|assetId|subassetID [|...].
            //// Entity group can then be constructed via ContextUtils.createGroup(ContextUtils.GROUP_REMOTE, "Test Asset") ContextUtils.createGroup(ContextUtils.GROUP_REMOTE, "Test Asset", "Test Subasset")
            //// For example:

            //var variableExample = new VariableDefinition(V_SETTING, VFT_SETTING, true, true, "Test Variable", ContextUtils.createGroup(ContextUtils.GROUP_REMOTE, "Test Asset"));
        }