Esempio n. 1
0
        public async Task <IActionResult> OnGetAsync()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("/"));
            }

            var tokenData = await SmartMeOAuthConfiguration.GetAccessToken(HttpContext);

            return(await FolderApi.GetFolderAsync(tokenData.AccessToken, Id, new ResultHandler <SmartMeApiClient.Containers.Folder>
            {
                OnSuccess = (folder) =>
                {
                    Folder = folder;
                    return Page();
                },

                OnError = (errorType, errorMessage) =>
                {
                    if (errorType == ErrorType.Unauthorized)
                    {
                        errorMessage = $"Folder with Id '{Id}' does not exist";
                    }

                    return new RedirectResult("/Error?message=" + errorMessage);
                }
            }));
        }
Esempio n. 2
0
        public async Task <IActionResult> OnGetAsync()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("/"));
            }

            var tokenData = await SmartMeOAuthConfiguration.GetAccessToken(HttpContext);

            return(await ValuesApi.GetDeviceValuesInPastMultipleAsync(
                       tokenData.AccessToken,
                       Id,
                       DateFrom,
                       DateTo,
                       60,
                       new ResultHandler <List <DeviceValues> >
            {
                OnSuccess = (valuesList) =>
                {
                    ValuesList = valuesList;
                    return Page();
                },

                OnError = DefaultErrorHandler.Handle
            }));
        }
        public async Task <IActionResult> OnGetAsync()
        {
            if (User.Identity.IsAuthenticated)
            {
                var tokenData = await SmartMeOAuthConfiguration.GetAccessToken(HttpContext);

                if (string.IsNullOrEmpty(tokenData.AccessToken))
                {
                    // We don't have an access token, sign out
                    await HttpContext.SignOutAsync();

                    return(Redirect("/"));
                }

                // Test if access token is still valid else sign out and reload
                return(await DevicesApi.GetDevicesAsync(tokenData.AccessToken, new ResultHandler <List <Device> >
                {
                    OnError = (errorType, errorMessage) =>
                    {
                        HttpContext.SignOutAsync();
                        return Redirect("/");
                    }
                }));
            }

            return(Page());
        }
        public async Task <IActionResult> OnPostSwitchOffAsync(int action)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("/"));
            }

            var tokenData = await SmartMeOAuthConfiguration.GetAccessToken(HttpContext);

            return(await ActionsApi.RunActionsAsync(
                       tokenData.AccessToken,
                       new ActionToRun
            {
                DeviceID = Id,
                Actions = new List <ActionToRunItem>
                {
                    new ActionToRunItem(HexStringHelper.ByteArrayToString(ObisCodes.SmartMeSpecificPhaseSwitchL1), 0.0)
                }
            },
                       new ResultHandler <ActionToRun>
            {
                OnError = DefaultErrorHandler.Handle
            }
                       ));
        }
        public async Task <IActionResult> OnPostAsync(CustomDevice customDevice)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("/"));
            }

            var tokenData = await SmartMeOAuthConfiguration.GetAccessToken(HttpContext);

            return(await DevicesApi.AddCustomDeviceAsync(tokenData.AccessToken, customDevice, new ResultHandler <CustomDevice>
            {
                OnSuccess = (newCustomDevice) =>
                {
                    return Redirect("/Devices/AddCustomDeviceResult?id=" + newCustomDevice.Id);
                },

                OnError = DefaultErrorHandler.Handle
            }));
        }
        public async Task <IActionResult> OnGetAsync()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("/"));
            }

            var tokenData = await SmartMeOAuthConfiguration.GetAccessToken(HttpContext);

            return(await DevicesApi.GetSmartMeDeviceConfigurationAsync(tokenData.AccessToken, Id, new ResultHandler <SmartMeDeviceConfiguration>
            {
                OnSuccess = (deviceConfig) =>
                {
                    DeviceConfig = deviceConfig;
                    return Page();
                },

                OnError = DefaultErrorHandler.Handle
            }));
        }
        public async Task <IActionResult> OnPostAsync(CustomDevice customDevice)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("/"));
            }

            var tokenData = await SmartMeOAuthConfiguration.GetAccessToken(HttpContext);

            return(await DevicesApi.UpdateCustomDeviceAsync(tokenData.AccessToken, customDevice, new ResultHandler <CustomDevice>
            {
                OnSuccess = (empty) =>
                {
                    // Trigger another GET to show the updated custom device
                    return Redirect("/Devices/UpdateCustomDevice");
                },

                OnError = DefaultErrorHandler.Handle
            }));
        }
        public async Task <IActionResult> OnGetAsync()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("/"));
            }

            var tokenData = await SmartMeOAuthConfiguration.GetAccessToken(HttpContext);

            return(await FolderApi.GetMeterFolderInformationAsync(tokenData.AccessToken, Id, new ResultHandler <MeterFolderInformation>
            {
                OnSuccess = (info) =>
                {
                    Info = info;
                    return Page();
                },

                OnError = DefaultErrorHandler.Handle
            }));
        }
        public async Task <IActionResult> OnGetAsync()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("/"));
            }

            var tokenData = await SmartMeOAuthConfiguration.GetAccessToken(HttpContext);

            return(await DevicesApi.GetDevicesAsync(tokenData.AccessToken, MeterSubType.MeterSubTypeHeat, new ResultHandler <List <Device> >
            {
                OnSuccess = (devices) =>
                {
                    Devices = devices;
                    return Page();
                },

                OnError = DefaultErrorHandler.Handle
            }));
        }
        public async Task <IActionResult> OnGetAsync()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("/"));
            }

            var tokenData = await SmartMeOAuthConfiguration.GetAccessToken(HttpContext);

            return(await ValuesApi.GetMeterValuesAsync(tokenData.AccessToken, Id, Date, new ResultHandler <MeterValues>
            {
                OnSuccess = (values) =>
                {
                    Values = values;
                    return Page();
                },

                OnError = DefaultErrorHandler.Handle
            }));
        }
Esempio n. 11
0
        public async Task <IActionResult> OnPostAsync(SmartMeDeviceConfiguration config)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("/"));
            }

            var tokenData = await SmartMeOAuthConfiguration.GetAccessToken(HttpContext);

            return(await DevicesApi.SetSmartMeDeviceConfigurationAsync(tokenData.AccessToken, config, new ResultHandler <SmartMeDeviceConfiguration>
            {
                OnSuccess = (empty) =>
                {
                    // Trigger another GET to show the updated SmartMeDeviceConfiguration
                    return Redirect("/Devices/SetSmartMeDeviceConfiguration");
                },

                OnError = DefaultErrorHandler.Handle
            }));
        }
Esempio n. 12
0
        public async Task <IActionResult> OnGetAsync()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("/"));
            }

            var tokenData = await SmartMeOAuthConfiguration.GetAccessToken(HttpContext);

            return(await ActionsApi.GetActionsAsync(tokenData.AccessToken, Id, new ResultHandler <List <SmartMeApiClient.Containers.Action> >
            {
                OnSuccess = (actions) =>
                {
                    Actions = actions;
                    return Page();
                },

                OnError = DefaultErrorHandler.Handle
            }));
        }
        public async Task <IActionResult> OnGetAsync(Guid id)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("/"));
            }

            var tokenData = await SmartMeOAuthConfiguration.GetAccessToken(HttpContext);

            return(await DevicesApi.GetCustomDeviceAsync(tokenData.AccessToken, id, new ResultHandler <CustomDevice>
            {
                OnSuccess = (customDevice) =>
                {
                    CustomDevice = customDevice;
                    return Page();
                },

                OnError = DefaultErrorHandler.Handle
            }));
        }
Esempio n. 14
0
        public async Task <IActionResult> OnPostAsync(MeterFolderInformationToSet infoToSet)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("/"));
            }

            var tokenData = await SmartMeOAuthConfiguration.GetAccessToken(HttpContext);

            return(await FolderApi.SetMeterFolderInformationAsync(
                       tokenData.AccessToken,
                       infoToSet,
                       new ResultHandler <MeterFolderInformationToSet>
            {
                OnSuccess = (empty) =>
                {
                    // Trigger another GET to show the updated MeterFolderInformation
                    return Redirect("/Folder/GetMeterFolderInformation");
                },

                OnError = DefaultErrorHandler.Handle
            }
                       ));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Redirect("/"));
            }

            var tokenData = await SmartMeOAuthConfiguration.GetAccessToken(HttpContext);

            var telegram = new byte[] { 0x68, 0x7A, 0x7A, 0x68, 0x08, 0x00, 0x72, 0x71, 0x76, 0x22, 0x15, 0xEE, 0x4D, 0x19, 0x04, 0x15, 0x00, 0x00, 0x00, 0x04, 0x06, 0x00, 0x00, 0x00, 0x00, 0x84, 0x0A, 0x06, 0x00, 0x00, 0x00, 0x00, 0x04, 0x14, 0x0B, 0x00, 0x00, 0x00, 0x84, 0x0A, 0x14, 0x00, 0x00, 0x00, 0x00, 0x0B, 0xFD, 0x0F, 0x00, 0x03, 0x01, 0x0A, 0xFD, 0x0D, 0x00, 0x11, 0x05, 0xFF, 0x01, 0xF2, 0x4E, 0x2E, 0x3C, 0x05, 0xFF, 0x02, 0x85, 0xDA, 0x50, 0x3F, 0x0C, 0x78, 0x71, 0x76, 0x22, 0x15, 0x04, 0x6D, 0x2F, 0x0B, 0xDB, 0x18, 0x82, 0x0A, 0x6C, 0xE1, 0xF1, 0x05, 0x5B, 0x00, 0x9A, 0xB8, 0x41, 0x05, 0x5F, 0x80, 0x00, 0xB2, 0x41, 0x05, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x05, 0x2B, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0x2B, 0x00, 0x03, 0x22, 0x29, 0x02, 0x00, 0x02, 0xFF, 0x2C, 0x00, 0x00, 0x1F, 0x59, 0x16 };

            return(await MBusApi.SendTelegramAsync(
                       tokenData.AccessToken,
                       new MBusData
            {
                Date = DateTime.UtcNow,
                Telegram = BitConverter.ToString(telegram).Replace("-", "")
            },
                       new ResultHandler <MBusData>
            {
                OnError = DefaultErrorHandler.Handle
            }
                       ));
        }