예제 #1
0
        private void meetingRoomUpload()
        {
            try
            {
                FileStream fs   = new FileStream(filePath, FileMode.Open, FileAccess.Read);
                byte[]     data = new byte[fs.Length];
                fs.Read(data, 0, data.Length);
                fs.Close();

                Dictionary <string, object> postParameters = new Dictionary <string, object>
                {
                    { "room", room },
                    { "file", new FormUpload.FileParameter(data, filePath) },
                    { "jsessionId", jsessionId }
                };

                const string userAgent = "Mazio";

                Cookie cookie = new Cookie("JSESSIONID", jsessionId, "/", url.Substring(0, url.LastIndexOf("/")));

                HttpWebResponse webResponse = FormUpload.MultipartFormDataPost(url, userAgent, postParameters, cookie);

                // Process response
                StreamReader responseReader = new StreamReader(webResponse.GetResponseStream());
                responseReader.ReadToEnd();
                webResponse.Close();
                Invoke(new MethodInvoker(delegate
                {
                    uploadLog.Text += "Done. Result is " + webResponse.StatusCode + "\r\n";
                }));
            }
            catch (Exception e)
            {
                Debug.Write(e.StackTrace);
                Invoke(new MethodInvoker(delegate
                {
                    uploadLog.Text += "Failed: " + e.Message + "\r\n";
                }));
            }

            Invoke(new MethodInvoker(delegate
            {
                buttonCancel.Enabled = true;
                buttonCancel.Text    = "Close";
            }));
        }
예제 #2
0
        private void jiraUploadByPost()
        {
            try {
                JiraSoapServiceService service = new JiraSoapServiceService {
                    Url = serverUrl + "/rpc/soap/jirasoapservice-v2"
                };
                string tok = null;

                if (issueId == null)
                {
                    tok = service.login(userLogin, userPassword);

                    RemoteIssue issue = service.getIssue(tok, issueKey);
                    issueId = issue.id;
                }

                FileStream fs   = new FileStream(path, FileMode.Open, FileAccess.Read);
                byte[]     data = new byte[fs.Length];
                fs.Read(data, 0, data.Length);
                fs.Close();

                Dictionary <string, object> postParameters = new Dictionary <string, object>
                {
                    { "filename.1", new FormUpload.FileParameter(data, name, getMimeType(name)) },
                };

                const string userAgent = "Mazio";

                string postUrl =
                    serverUrl + "/secure/AttachFile.jspa?id=" + issueId
                    + (jSessionId == null
                        ? ("&os_username="******"&os_password="******"");

                HttpWebResponse webResponse;
                if (jSessionId != null)
                {
                    Cookie cookie = new Cookie("JSESSIONID", jSessionId, "/jira", serverUrl.Substring(0, serverUrl.LastIndexOf("/")));
                    webResponse = FormUpload.MultipartFormDataPost(postUrl, userAgent, postParameters, cookie);
                }
                else
                {
                    webResponse = FormUpload.MultipartFormDataPost(postUrl, userAgent, postParameters);
                }

                StreamReader responseReader = new StreamReader(webResponse.GetResponseStream());
#pragma warning disable 168
                string result = responseReader.ReadToEnd();
#pragma warning restore 168
                webResponse.Close();

                if (token != null && !string.IsNullOrEmpty(comment))
                {
                    service.addComment(tok, issueKey, new RemoteComment {
                        body = comment
                    });
                }

                Invoke(new MethodInvoker(delegate { uploadLog.Text += "Done. See " + serverUrl + "/browse/" + issueKey + "\r\n"; }));
            } catch (Exception e) {
                Debug.Write(e.StackTrace);
                Invoke(new MethodInvoker(delegate { uploadLog.Text += "Failed: " + e.Message + "\r\n"; }));
            }
            done = true;

            Invoke(new MethodInvoker(delegate {
                saveLastUsed();
                buttonCancel.Enabled = true;
                buttonCancel.Text    = "Close";
            }));
        }