示例#1
0
        private void Download(object o)
        {
            string[] s1 = o as string[];

            ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return(true); };

            var webRequest = System.Net.WebRequest.Create(new Uri(new Uri(Properties.Settings.Default.Url), s1[1])) as HttpWebRequest;

            if (webRequest != null)
            {
                webRequest.Method          = "GET";
                webRequest.CookieContainer = new CookieContainer();
                webRequest.CookieContainer.Add(new Cookie("token", token[0], "/", new Uri(Properties.Settings.Default.Url).Host));
                webRequest.CookieContainer.Add(new Cookie(token[2], token[1], "/", new Uri(Properties.Settings.Default.Url).Host));
                webRequest.ServicePoint.Expect100Continue = false;
            }

            HttpWebResponse resp      = (HttpWebResponse)webRequest.GetResponse();
            Stream          resStream = resp.GetResponseStream();
            FileStream      fs        = File.Create(s1[0]);

            resStream.CopyTo(fs);
            fs.Close();

            this.Invoke(new Action(() =>
            {
                progressBar1.Value = 100;
                progressBar1.Style = ProgressBarStyle.Blocks;
                try
                {
                    Globals.ThisAddIn.Application.Documents.Open(filename);
                    Globals.ThisAddIn.Application.DocumentBeforeClose += Application_DocumentBeforeClose;
                    WordSaveHandler wsh         = new WordSaveHandler(Globals.ThisAddIn.Application);
                    wsh.AfterSaveEvent         += wsh_AfterSaveEvent;
                    wsh.AfterUiSaveEvent       += wsh_AfterUiSaveEvent;
                    Globals.ThisAddIn.Shutdown += ThisAddIn_Shutdown;
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                Close();
            }));
        }
示例#2
0
        private void CheckFile(object o)
        {
            string[] os = o as string[];
            ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return(true); };
            string ret = string.Empty;

            path = path.Replace('\\', '/');
            string p2         = path + (path.EndsWith("/") ? "" : "/") + os[0] + "." + (os[1] == "0" ? "docx" : "dotx");
            var    webRequest = System.Net.WebRequest.Create(new Uri(new Uri(Properties.Settings.Default.Url), "./api/myfiles/exists/" + p2 + "?" + DateTime.Now.Ticks)) as HttpWebRequest;

            if (webRequest != null)
            {
                webRequest.Method          = "GET";
                webRequest.CookieContainer = new CookieContainer();
                webRequest.CookieContainer.Add(new Cookie("token", token[0], "/", new Uri(Properties.Settings.Default.Url).Host));
                webRequest.CookieContainer.Add(new Cookie(token[2], token[1], "/", new Uri(Properties.Settings.Default.Url).Host));
                webRequest.ServicePoint.Expect100Continue = false;
                webRequest.Timeout = 20000;

                webRequest.ContentType = "application/json";
            }

            HttpWebResponse resp      = (HttpWebResponse)webRequest.GetResponse();
            Stream          resStream = resp.GetResponseStream();
            StreamReader    reader    = new StreamReader(resStream);

            ret = reader.ReadToEnd();
            if (ret != null || ret != string.Empty)
            {
                JSONProperties p = Newtonsoft.Json.JsonConvert.DeserializeObject <JSONProperties>(ret);
                if (p.Name == null || MessageBox.Show("Do you want to overwrite this file?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                {
                    this.BeginInvoke(new Action(() =>
                    {
                        filename = System.IO.Path.Combine(System.IO.Path.GetTempPath(), os[0] + "." + (os[1] == "0" ? "docx" : "dotx"));
                        path     = "./api/myfiles-upload/" + path + (path.EndsWith("/") ? "" : "/") + os[0] + "." + (os[1] == "0" ? "docx" : "dotx");
                        Globals.ThisAddIn.Application.DocumentBeforeClose += Application_DocumentBeforeClose;
                        WordSaveHandler wsh         = new WordSaveHandler(Globals.ThisAddIn.Application);
                        wsh.AfterSaveEvent         += wsh_AfterSaveEvent;
                        wsh.AfterUiSaveEvent       += wsh_AfterUiSaveEvent;
                        Globals.ThisAddIn.Shutdown += ThisAddIn_Shutdown;
                        Globals.ThisAddIn.Application.ActiveDocument.SaveAs2(filename, AddToRecentFiles: false);
                        SaveAsd = false;
                        Close();
                    }));
                }
                else
                {
                    this.BeginInvoke(new Action(() =>
                    {
                        button1.Enabled    = button2.Enabled = listView1.Enabled = true;
                        progressBar1.Value = 0;
                        progressBar1.Style = ProgressBarStyle.Blocks;
                    }));
                }
            }
            else
            {
                MessageBox.Show("Error loading", "Error reading response from HAP+ Server", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }