public IActionResult InsertLog([FromBody] LogDeviceModel data)
        {
            DpOperations db     = new DpOperations();
            var          device = db.Device.GetApiAccessAndSecretKeyDevice(data.apiAccessKey, data.apiSecretKey);

            if (device != null && data.errorList != null)
            {
                foreach (var item in data.errorList)
                {
                    db.Log.InsertLog(new DevicePlanLog
                    {
                        CreatedDate    = DateTime.Now,
                        Description    = item,
                        DeviceId       = device.Id,
                        DevicePlanId   = data.devicePlanId,
                        OrganizationId = device.OrganizationId
                    });
                }
            }
            return(Ok());
        }
        public void SendFile(string model)
        {
            BackupLog bc              = new BackupLog();
            string    localDirectory  = "";
            string    remoteDirectory = "";
            string    devicePlanId    = "";
            dynamic   platformDetail  = JObject.Parse(model);

            localDirectory          = platformDetail.localDirectory;
            remoteDirectory         = platformDetail.remoteDirectory;
            devicePlanId            = platformDetail.devicePlanId;
            bc.DevicePlanId         = Convert.ToInt32(devicePlanId);
            bc.CreateDirectoryCount = 0;
            bc.CreateFileCount      = 0;
            bc.FailedCount          = 0;
            bc.ProccessCount        = 0;
            bc.TotalSize            = 0;
            bc.DeletedCount         = 0;
            bc.UpdatedCount         = 0;
            DbOperations db = new DbOperations();

            IPlatform platf = null;

            if (platformDetail.planType.ToString() == "1")
            {
                DriveService s        = new Google.Apis.Drive.v3.DriveService();
                var          services = new DriveService(new BaseClientService.Initializer()
                {
                    ApiKey          = platformDetail.googleApiCode, // from https://console.developers.google.com (Public API access)
                    ApplicationName = "ECloud Backup",
                });

                platf = new PlatformGoogle(s, platformDetail.googleAccessToken.ToString(), platformDetail.googleApiCode.ToString(), Common.ConvertDatabaseDateTime(platformDetail.googleTokenExpired.ToString()));
            }
            else if (platformDetail.planType.ToString() == "2")
            {
                platf = new AmazonS3(platformDetail.apiAccessKey.ToString(), platformDetail.apiSecretKey.ToString(), platformDetail.region.ToString());
            }

            DateTime dtStartBackup = DateTime.Now;

            SendBackupDirectory(localDirectory, remoteDirectory, db, Convert.ToInt32(devicePlanId), platf, bc);

            var           list      = db.GetErrorFileList(Convert.ToInt32(devicePlanId), dtStartBackup);
            List <string> errorList = new List <string>();

            foreach (var k in list)
            {
                errorList.Add(k.FullName + " - " + k.ErrorMessage);
            }

            LogDeviceModel mdl = new LogDeviceModel
            {
                apiAccessKey = bc.apiAccessKey,
                apiSecretKey = bc.apiSecretKey,
                cpuId        = bc.cpuId,
                deviceId     = bc.deviceId,
                devicePlanId = Convert.ToInt32(devicePlanId),
                diskVolume   = bc.diskVolume,
                errorList    = errorList,
                macAddress   = bc.macAddress
            };


            IRestRequest request = new RestRequest("api/device/deviceplanid/{deviceplanid}/finish", Method.POST);

            request.RequestFormat = RestSharp.DataFormat.Json;
            request.AddParameter("deviceplanid", devicePlanId, ParameterType.UrlSegment);
            request.AddBody(bc);
            TaskCompletionSource <IRestResponse> taskCompletion = new TaskCompletionSource <IRestResponse>();
            RestRequestAsyncHandle handle   = client.ExecuteAsync(request, r => { taskCompletion.SetResult(r); });
            IRestResponse          response = taskCompletion.Task.Result;



            IRestRequest request1 = new RestRequest("api/device/log", Method.POST);

            request1.RequestFormat = RestSharp.DataFormat.Json;
            request1.AddBody(mdl);
            TaskCompletionSource <IRestResponse> taskCompletion1 = new TaskCompletionSource <IRestResponse>();
            RestRequestAsyncHandle handle1   = client.ExecuteAsync(request1, r => { taskCompletion1.SetResult(r); });
            IRestResponse          response1 = taskCompletion1.Task.Result;
        }