private void Consumer_onMessageReceived(byte[] message)
        {
            string returnText = System.Text.Encoding.UTF8.GetString(message);


            //CheckCpuSpeed();

            string[]   deviceInfo = Common.SecurityKey().Split('|');
            CheckModel model      = new CheckModel();
            var        result     = Common.ApiAndSecretKey();

            model.apiAccessKey = result.Key;
            model.apiSecretKey = result.Value;
            model.cpuId        = deviceInfo[0];
            model.diskVolume   = deviceInfo[1];

            model.macAddress = deviceInfo[2];



            IRestRequest request = new RestRequest("api/device/decrpyt?message={message}", Method.POST);

            request.RequestFormat = RestSharp.DataFormat.Json;
            request.AddParameter("message", returnText, ParameterType.UrlSegment);
            request.AddBody(model);
            TaskCompletionSource <IRestResponse> taskCompletion = new TaskCompletionSource <IRestResponse>();
            RestRequestAsyncHandle handle   = client.ExecuteAsync(request, r => { taskCompletion.SetResult(r); });
            IRestResponse          response = taskCompletion.Task.Result;
            string messageBody = response.Content;

            messageBody = messageBody.Replace("\"", "");
            WriteError(messageBody);

            if (messageBody.StartsWith("C|"))
            {
                Thread thFile = new Thread(SendCheckOnline);
                thFile.Start();
            }
            else if (messageBody.StartsWith("F|"))
            {
                Thread thFile = new Thread(() => SendFileList(messageBody.Split('|')[2]));
                thFile.Start();
            }
            else if (!messageBody.StartsWith("C|") && !messageBody.StartsWith("F|"))
            {
                Thread thBackup = new Thread(() => SendFile(messageBody));
                thBackup.Start();
            }
        }
        private void SendFileList(string directory)
        {
            WriteError("StartFileList");

            List <string> directoryList = new List <string>();

            if (String.IsNullOrEmpty(directory))
            {
                DriveInfo[] allDrives = DriveInfo.GetDrives();
                foreach (DriveInfo d in allDrives)
                {
                    directoryList.Add(d.Name);
                }
            }
            else
            {
                directory = directory.Replace(@"\\", @"\");
                foreach (var item in Directory.GetDirectories(directory))
                {
                    directoryList.Add(item);
                }
            }

            string[]   deviceInfo = Common.SecurityKey().Split('|');
            CheckModel model      = new CheckModel();
            var        result     = Common.ApiAndSecretKey();

            model.apiAccessKey = result.Key;
            model.apiSecretKey = result.Value;
            model.cpuId        = deviceInfo[0];
            model.diskVolume   = deviceInfo[1];
            model.macAddress   = deviceInfo[2];
            //if (!String.IsNullOrEmpty(directory))
            model.subDirectory     = directory;
            model.directoryListing = directoryList;


            WriteError("EndFileList Count : " + directoryList.Count);



            IRestRequest request = new RestRequest("api/device/filelist", Method.POST);

            request.RequestFormat = RestSharp.DataFormat.Json;
            request.AddBody(model);
            TaskCompletionSource <IRestResponse> taskCompletion = new TaskCompletionSource <IRestResponse>();
            RestRequestAsyncHandle handle   = client.ExecuteAsync(request, r => { taskCompletion.SetResult(r); });
            IRestResponse          response = taskCompletion.Task.Result;
        }
        private void SendCheckOnline()
        {
            string[]   deviceInfo = Common.SecurityKey().Split('|');
            CheckModel model      = new CheckModel();
            var        result     = Common.ApiAndSecretKey();

            model.apiAccessKey = result.Key;
            model.apiSecretKey = result.Value;
            model.cpuId        = deviceInfo[0];
            model.diskVolume   = deviceInfo[1];
            model.macAddress   = deviceInfo[2];



            IRestRequest request = new RestRequest("api/device/check", Method.POST);

            request.RequestFormat = RestSharp.DataFormat.Json;
            request.AddBody(model);
            TaskCompletionSource <IRestResponse> taskCompletion = new TaskCompletionSource <IRestResponse>();
            RestRequestAsyncHandle handle   = client.ExecuteAsync(request, r => { taskCompletion.SetResult(r); });
            IRestResponse          response = taskCompletion.Task.Result;
        }
        private TokenResponse ResetGoogleToken(int devicePlanId)
        {
            string[]   deviceInfo = Common.SecurityKey().Split('|');
            CheckModel model      = new CheckModel();
            var        result     = Common.ApiAndSecretKey();

            model.apiAccessKey = result.Key;
            model.apiSecretKey = result.Value;
            model.cpuId        = deviceInfo[0];
            model.diskVolume   = deviceInfo[1];
            model.macAddress   = deviceInfo[2];


            IRestRequest request = new RestRequest("api/device/deviceplan/{devicePlanId}/resettoken", Method.POST);

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

            return(JsonConvert.DeserializeObject <TokenResponse>(response.Content));
        }