Exemplo n.º 1
0
        /// <summary>
        /// Set Device Type and start the proper firmware
        /// </summary>
        /// <param name="requestSetDeviceType"></param>
        /// <returns></returns>
        public async Task <ResultCommand> SetDeviceType(RequestCommandSetDeviceType requestSetDeviceType)
        {
            var resultSetDeviceType = await _streamClient.SendCommand <RequestCommandSetDeviceType, ResultCommand>
                                          (CommandsEnum.SetDeviceType, requestSetDeviceType, Common.Helpers.SharedConstants.DEFAULT_ENCRYPTION_KEY);

            return(resultSetDeviceType);
        }
Exemplo n.º 2
0
 public Task <ResultCommand> SetDeviceType(RequestCommandSetDeviceType setDeviceTypeCommand)
 {
     return(Task.FromResult(new ResultCommand()
     {
         IsSuccess = true
     }));
 }
Exemplo n.º 3
0
        public async Task <ResultCommand> SetDeviceType(RequestCommandSetDeviceType requestDeviceType)
        {
            try
            {
                var apps = await LoadFirmwares();

                //Find the app
                var app = apps.FirstOrDefault(p => p.PackageFullName.ToLower().StartsWith(requestDeviceType.DeviceType.ToLower()));
                if (app == null)
                {
                    DebugHelper.LogError($"Package starting with {requestDeviceType.DeviceType} not found.");
                    return(ResultCommand.CreateFailedCommand($"Error SetDeviceType: Package starting with {requestDeviceType.DeviceType} not found."));
                }

                //Deactivate all other firmwares at startup
                foreach (var appToStop in apps)
                {
                    if (appToStop.IsStartup)
                    {
                        if (!await PortalApiHelper.SetStartupForHeadlessApp(false, appToStop.PackageFullName))
                        {
                            DebugHelper.LogError($"Error while turning off run at startup for App {appToStop.PackageFullName}");
                        }
                    }
                    if (!await PortalApiHelper.StopHeadlessApp(appToStop.PackageFullName))
                    {
                        DebugHelper.LogError($"Error while stopping App {appToStop.PackageFullName}");
                    }
                }

                //Start our firmware and set to run
                if (!await PortalApiHelper.StartHeadlessApp(app.PackageFullName))
                {
                    DebugHelper.LogError($"Error while starting App {app.PackageFullName}");
                    return(ResultCommand.CreateFailedCommand($"Error SetDeviceType: Error while starting App {app.PackageFullName}"));
                }

                if (!await PortalApiHelper.SetStartupForHeadlessApp(true, app.PackageFullName))
                {
                    DebugHelper.LogError($"Error while turning on run at startup for App {app.PackageFullName}");
                    return(ResultCommand.CreateFailedCommand($"Error SetDeviceType: Error while turning on run at startup for App {app.PackageFullName}"));
                }

                return(ResultCommand.CreateSuccessCommand());
            }
            catch (Exception e)
            {
                DebugHelper.LogError($"Error SetDeviceType: {e.Message}.");
                return(ResultCommand.CreateFailedCommand($"Error SetDeviceType: {e.Message}."));
            }
        }
Exemplo n.º 4
0
        public async Task <ResultCommand> SetDeviceType(RequestCommandSetDeviceType requestSetDeviceType)
        {
            RestRequest request = await PrepareQuery("SetDeviceType", Method.POST);

            request.AddParameter("application/json", JsonConvert.SerializeObject(requestSetDeviceType), ParameterType.RequestBody);
            var queryResult = await _client.ExecuteTaskAsync <Command>(request);

            if (queryResult.IsSuccessful)
            {
                return(GetResultCommand <ResultCommand>(queryResult.Data));
            }
            else
            {
                Debug.WriteLine($"SetDeviceType: {queryResult.StatusCode}");
            }
            return(ResultCommand.CreateFailedCommand <ResultCommand>($"SetDeviceType: {queryResult.StatusCode}"));
        }
        public async Task <ResultCommand> SetDeviceType(RequestCommandSetDeviceType setDeviceTypeCommand)
        {
            try
            {
                var request     = PrepareRequest("/SetDeviceType", Method.POST, setDeviceTypeCommand);
                var queryResult = await client.ExecutePostTaskAsync <ResultCommand>(request);

                if (queryResult.IsSuccessful)
                {
                    return(queryResult.Data);
                }

                return(null);
            }
            catch (Exception e)
            {
                logger.Log(e);
                return(null);
            }
        }