Exemplo n.º 1
0
        private static void SetCSRFToken(HttpWebRequest postReq)
        {
            var url = WebHelpers.GetSkylineLink(@"/project/home/begin.view?");

            var sessionCookies = new CookieContainer();

            try
            {
                var request = (HttpWebRequest)WebRequest.Create(url);
                request.Method          = @"GET";
                request.CookieContainer = sessionCookies;
                using (var response = (HttpWebResponse)request.GetResponse())
                {
                    postReq.CookieContainer = sessionCookies;
                    var csrf = response.Cookies[LABKEY_CSRF];
                    if (csrf != null)
                    {
                        // The server set a cookie called X-LABKEY-CSRF, get its value and add a header to the POST request
                        postReq.Headers.Add(LABKEY_CSRF, csrf.Value);
                    }
                    else
                    {
                        Console.WriteLine(@"CSRF token not found.");
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(@"Error establishing a session and getting a CSRF token: {0}", e);
            }
        }
Exemplo n.º 2
0
        private void SendErrorReportAttachment(string exceptionType, IEnumerable <Image> screenShots, byte[] skyFileBytes, bool isTest)
        {
            if (isTest) // We don't want to be submitting an exception every time the ReportErrorDlgTest is run.
            {
                DialogResult = DialogResult.OK;
                return;
            }

            string reportUrl = WebHelpers.GetSkylineLink(@"/announcements/home/issues/exceptions/insert.view");

            var nvc = new NameValueCollection
            {
                { @"title", PostTitle },
                { @"body", MessageBody },
                { @"fromDiscussion", @"false" },
                { @"allowMultipleDiscussions", @"false" },
                { @"rendererType", @"TEXT_WITH_LINKS" }
            };
            var files = new Dictionary <string, byte[]>();

            foreach (var screenShot in screenShots)
            {
                var memoryStream = new MemoryStream();
                screenShot.Save(memoryStream, ImageFormat.Jpeg);
                string name = @"Image-" + (files.Count + 1) + @".jpg";
                files.Add(name, memoryStream.ToArray());
            }

            if (skyFileBytes != null)
            {
                files.Add(@"skylineFile.sky", skyFileBytes);
            }

            HttpUploadFiles(reportUrl, @"image/jpeg", nvc, files);

            DialogResult = DialogResult.OK;
        }