private void PublishArticle(DekiCommunicator dc, MohawkCollege.EHR.gpmr.Pipeline.Renderer.Deki.Article.Article a, string path, Dictionary <string, String> properties) { // Clean article to remove .html string Html = a.Content.Replace(".deki\"", "\""); Html = Html.Replace(".deki#", "#"); Html = Html.Replace("\"~/", string.Format("\"{0}/", path)); // Publish away! path = path.Replace("/", "%2f"); // Try twice to publish for (int i = 0; i < 5; i++) { try { dc.Publish(Html, string.Format("{0}%2f{1}", path, a.Url.Replace("/", "%2f")), a.Title); foreach (var kv in properties) { try { dc.PublishProperty(kv.Key, kv.Value, string.Format("{0}%2f{1}", path, a.Url.Replace("/", "%2f"))); } catch { } // Don't care if properties are not published } // Throttling is required to allow time for the MySQL server in deki to catch-up with the // GPMR process. This is needed because the MySQL server on Deki-Hayes can become bogged // down when submitting massive amounts of content. Thread.Sleep(250); break; } catch (Exception e) { System.Diagnostics.Trace.WriteLine(string.Format("{0}, retrying publish operation for {1}", e.Message, a.Title), "warn"); } } System.Diagnostics.Trace.Write(".", "information"); if (a.Children != null) { foreach (Article.Article ca in a.Children) { PublishArticle(dc, ca, path, properties); } } }
private void Publish(ArticleCollection acoll) { Dictionary <string, StringCollection> parameters = hostContext.Data["CommandParameters"] as Dictionary <string, StringCollection>; string url, path, user, password; Dictionary <String, String> properties = new Dictionary <string, string>(); try { url = parameters["deki-url"][0]; path = parameters["deki-path"][0]; user = parameters["deki-user"][0]; password = parameters.ContainsKey("deki-password") ? parameters["deki-password"][0] : null; if (password == null) { Console.Write(string.Format("deki: {0}'s password:"******"Publishing to deki server:\r\n\tServer:{0}\r\n\tRoot:{1}\r\n\tUser:{2}\r\n\tPassword:{3}", url, path, user, new string('*', password.Length)), "information"); if (parameters.ContainsKey("deki-prop")) { foreach (string kv in parameters["deki-prop"]) { string[] kvData = kv.Split('='); properties.Add(kvData[0], kvData.Length == 2 ? kvData[1] : ""); } } } catch (Exception) { throw new InvalidOperationException("Can't publish, not enough information provided"); } System.Diagnostics.Trace.Write("Requesting a session...", "debug"); DekiCommunicator dc = new DekiCommunicator(); dc.Address = url; bool ignoreSSL = false; ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(delegate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors sslPolicyErrors) { if (sslPolicyErrors == SslPolicyErrors.None || ignoreSSL) { return(true); } Console.Write("deki: {0}\r\nWould you like to ignore this and attempt a re-connect? (y/n)", sslPolicyErrors); ignoreSSL = (Console.ReadLine().StartsWith("y")); return(ignoreSSL); }); // Request a session for (int i = 0; i < 2; i++) { dc.Authenticate(user, password); if (dc.State == DekiCommunicator.DekiCommState.Authenticated) { System.Diagnostics.Trace.WriteLine("ok", "debug"); break; } else { Console.Write("deki: Could not get a session ({0})\r\n", dc.State); Console.Write(string.Format("deki: {0}'s password:"******"Publishing Documents.", "debug"); try { foreach (Article.Article a in acoll) { PublishArticle(dc, a, path, properties); } System.Diagnostics.Trace.WriteLine("Success", "debug"); } catch (Exception e) { System.Diagnostics.Trace.WriteLine("Fail", "debug"); System.Diagnostics.Trace.WriteLine("Could not publish documents", "error"); System.Diagnostics.Trace.WriteLine(e.ToString(), "error"); //throw new Exception("Could not publish documents", e); } }