Esempio n. 1
0
        private void bt_RunCMD_Click(object sender, EventArgs e)
        {
            var client   = new RestClient(iCrt_01.Properties.Resources.CBMasServer);
            var cmd_body = new CBLRCmd();

            cmd_body.name    = "create process";
            cmd_body._object = tb_CommandLine.Text;
            //Execute a command using LR REST Api.
            var request_put = new RestRequest(Method.POST);

            request_put.AddHeader("X-Auth-Token", iCrt_01.Properties.Resources.CBApiKey);
            request_put.Resource = "/v1/cblr/session/" + sessionID + "/command";

            var body = JsonConvert.SerializeObject(cmd_body);

            request_put.AddParameter("application/json", body, ParameterType.RequestBody);
            var response_put = client.Execute <List <CBLRCmd> >(request_put);

            foreach (CBLRCmd item in response_put.Data)
            {
                cmd_status = item.status;
                cmd_id     = item.id;
            }
        }
Esempio n. 2
0
        private async void bt_Upload_Click(object sender, EventArgs e)
        {
            //Step one is to get the file to the CB server.
            //This needs to be done ASYNC.
            var client = new RestClient(iCrt_01.Properties.Resources.CBMasServer);

            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                Stream reader   = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);
                var    filepath = openFileDialog1.FileName;
                var    filename = openFileDialog1.SafeFileName;

                var request = new RestRequest(Method.POST);
                request.AddHeader("X-Auth-Token", iCrt_01.Properties.Resources.CBApiKey);
                request.AddHeader("Content-Type", "multipart/form-data");
                request.Resource = "/v1/cblr/session/" + sessionID + "/file";
                request.AlwaysMultipartFormData = true;
                byte[] data = new byte[reader.Length];
                reader.Read(data, 0, (int)reader.Length);

                request.AddFile("file", data, filename);
                var response = await client.ExecuteTaskAsync <List <CBLRFile> >(request);

                //wait for response back from the server that the file uploaded... sadly no progress % returned.
                if (response.ResponseStatus == ResponseStatus.Completed)
                {
                    foreach (CBLRFile item in response.Data)
                    {
                        fileID = item.id;
                    }
                }
                lbl_FS_Status.Text = "File Uploaded to server. File ID:" + fileID;
            }

            //If all has gone well we now have a fileID that we can use to PUT the file on the LR machine.

            var put_cmd     = new CBLRCmd();
            var request_put = new RestRequest(Method.POST);

            request_put.AddHeader("X-Auth-Token", iCrt_01.Properties.Resources.CBApiKey);
            request_put.Resource = "/v1/cblr/session/" + sessionID + "/command";

            put_cmd.name    = "put file";
            put_cmd.file_id = fileID;
            put_cmd._object = openFileDialog1.SafeFileName;

            string body = JsonConvert.SerializeObject(put_cmd);

            request_put.RequestFormat = DataFormat.Json;
            request_put.AddParameter("application/json", body, ParameterType.RequestBody);
            var response_put = client.Execute <List <CBLRCmd> >(request_put);

            foreach (CBLRCmd item in response_put.Data)
            {
                cmd_status = item.status;
                cmd_id     = item.id;
            }
            //The response back from the server is instant in this case but is always "pending"
            //Need to bug the server while we're waiting for that status to come back.
            while (cmd_status == "pending")
            {
                var request_check = new RestRequest();
                request_check.AddHeader("X-Auth-Token", iCrt_01.Properties.Resources.CBApiKey);
                request_check.Resource = "/v1/cblr/session/" + sessionID + "/command";
                var response_check = client.Execute <List <CBLRCmd> >(request_check);
                foreach (CBLRCmd item in response_check.Data)
                {
                    cmd_status = item.status;
                    //cmd_id = item.id;
                }
            }

            lbl_FS_Status.Text = "File uploaded to endpoint.";
        }