예제 #1
0
파일: DOCQRclient.cs 프로젝트: DOCQR/revit
        /// <summary>
        /// send the model information to the web server
        /// </summary>
        /// <param name="filePath">Full File Path</param>
        /// <param name="projectName">Project Name</param>
        /// <param name="modelName">Model Name</param>
        /// <returns></returns>
        public string SendModelInfo(Project proj, string filePath)
        {
            if (IsDummy)
            {
                System.Threading.Thread.Sleep(5000);
                return Guid.NewGuid().ToString();
            }

            //FileStream fileStream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);               // read the json file
            //using (BinaryReader binaryReader = new BinaryReader(fileStream))
            {

                byte[] jsonFile = File.ReadAllBytes(filePath); //binaryReader.ReadBytes((int)fileStream.Length);                                           // conver the file to byte array
                RestRequest request = new RestRequest("/views/"+proj.id + "/" + ModelID, Method.POST);        // GET URL FROM WEB SERVER

                System.Diagnostics.Debug.WriteLine("Uploading file to DOCQR: " + jsonFile.Length + " bytes");
                //request.AddParameter("user", _token);                                                                       // add parameters to send to web server
                //request.AddParameter("modelName", this.ModelID);
                ////request.AddParameter("projectName", projectName);
                //request.AddParameter("jsonFileName", filePath);

                request.AddParameter("Content-Type", "application/stream");                                                 // stream the json file to the body
                request.AddParameter("Content-Length", jsonFile.LongLength);
                request.AddParameter("jsonFile", jsonFile, ParameterType.RequestBody);
                request.Timeout = 1000 * 60 * 60;                                                                           // set up a time out

                IRestResponse responce = client.Execute(request);                                                           // execute the request

                if (responce.StatusCode == System.Net.HttpStatusCode.OK)                                                    // if the responce was OK
                {
                    return responce.Content.TrimStart('"').TrimEnd('"');                                                                                // return the data (list of project names)
                }
                else
                {
                    throw new Exception("Unable to send model " + responce.StatusCode, new Exception(responce.Content));
                }
            }
        }
예제 #2
0
 private void button1_Click(object sender, EventArgs e)
 {
     SelectedProject = this.comboBox1.SelectedItem as Project;
     this.DialogResult = DialogResult.OK;
     this.Close();
 }