private void WriteToRichBox(string s, bool bClear) { object sender = System.Threading.Thread.CurrentThread; RichBoxArgs a = new RichBoxArgs(s, bClear); WriteToRichBox(sender, a); }
void WriteToRichBox(object sender, RichBoxArgs e) { if (this.InvokeRequired == false) { if (e.clear) { richTextBox1.Clear(); } richTextBox1.AppendText(e.stringToWrite); // Scroll to end of text richTextBox1.SelectionLength = 0; richTextBox1.SelectionStart = richTextBox1.Text.Length; richTextBox1.ScrollToCaret(); if (_cancelPressed) { e.Cancel = true; } if (e.Cancel || e.Completed) { this._cancelPressed = false; this.Cancel.Enabled = false; this.btnUpload.Enabled = true; this.btnDownloadSkin.Enabled = true; this.Connect.Enabled = true; this.btnDownloadAllSkins.Enabled = true; this.btnClearTemplates.Enabled = true; } WriteToLogFile(e.stringToWrite); } else { WriteToRichBoxHandler writeToBox = new WriteToRichBoxHandler(WriteToRichBox); Invoke(writeToBox, new object[] { sender, e }); } }
private void ClearTemplates(ServerDetails details) { object sender = System.Threading.Thread.CurrentThread; RichBoxArgs rbArgs = new RichBoxArgs("Clearing templates on " + details.Name + "...\r\n"); WriteToRichBox(sender, rbArgs); WebResponse wResp; HttpWebRequest wr; string s = "http://" + _hostName + details.Path + "h2g2/status?clear_templates=1&skin=purexml"; wr = GetWebRequest(s, true); wResp = wr.GetResponse(); wResp.Close(); s = "http://" + _hostName + details.Path + "h2g2/purexml/dnastatus?clear_templates=1"; wr = GetWebRequest(s, true); wResp = wr.GetResponse(); wResp.Close(); rbArgs.stringToWrite = "Cleared\r\n"; WriteToRichBox(sender, rbArgs); }
private void TestUpload(string skinname) { // Given a selected file, download this and all included/imported files string mainleaf; mainleaf = "HTMLOutput.xsl"; object sender = System.Threading.Thread.CurrentThread; string rootfile = this.PathToSkins.Text + @"\" + mainleaf; string rootdir = this.PathToSkins.Text; string tempfilesroot = Application.UserAppDataPath + @"\skins"; string subfilesroot = tempfilesroot + @"\" + skinname; string mainskinpath = tempfilesroot + @"\" + skinname + @"\" + mainleaf; RichBoxArgs a = new RichBoxArgs("Testing " + rootfile + "\r\n", true); this.WriteToRichBox(sender, a); a.clear = false; a.stringToWrite = "dowloading files\r\n"; this.WriteToRichBox(sender, a); DownloadSkinFile(tempfilesroot, subfilesroot, mainleaf, skinname, new SortedList(), false, "default"); /* * Now we've got the skins from live, apply the changes (one by one) and see if it still works * We can rearrange the filenames in the list in order to accomodate the success or otherwise * * Simply put: Go down the list of selected items until one fails, then keep going until one * succeeds, then swap the failure and success, then start again from the next * one. If you run out of files and they've all failed, report the problem * */ int current = 0; int lastfailed = 0; int iFilecount = this.GetCheckedFileCount(); while (current < iFilecount && lastfailed < iFilecount) { // rename existing file in the test directory string curfilename = subfilesroot + @"\" + this.GetCheckedFilename(current); string filetocopy = rootdir + @"\" + this.GetCheckedFilename(current); string renamefile = subfilesroot + @"\" + this.GetCheckedFilename(current) + ".___temp"; a.stringToWrite = "Trying " + this.GetCheckedFilename(current) + "..."; this.WriteToRichBox(sender, a); bool bFileExists = System.IO.File.Exists(curfilename); if (bFileExists) { System.IO.Directory.Move(curfilename, renamefile); } System.IO.File.Copy(filetocopy, curfilename, true); string result; if (TestXSLTFile(mainskinpath, out result)) { a.stringToWrite = "succeeded\r\n"; this.WriteToRichBox(sender, a); // succeeded if (bFileExists) { System.IO.File.Delete(renamefile); } if (current != lastfailed) { a.stringToWrite = "Swapping " + this.GetCheckedFilename(current) + " with " + this.GetCheckedFilename(lastfailed); this.WriteToRichBox(sender, a); SwapFileItemsArgs arg = new SwapFileItemsArgs(current, lastfailed); SwapFileItems(sender, arg); lastfailed = current; } else { current++; lastfailed = current; } } else { a.stringToWrite = "failed (" + result + ")\r\n"; this.WriteToRichBox(sender, a); System.IO.File.Delete(curfilename); if (bFileExists) { System.IO.File.Move(renamefile, curfilename); } current++; } } if (current == lastfailed) { a.stringToWrite = "All files successfully tested\r\n"; this.WriteToRichBox(sender, a); } else { a.stringToWrite = this.directoryStructure.Nodes[lastfailed].Text + " cannot be uploaded\r\n"; this.WriteToRichBox(sender, a); } }
private void DoUpload(int serverCount, int filenameCount, ServerDetails[] servers, int[] serverIndex, string[] filenames, int[] fileIndex, bool[,] uploaded) { object sender = System.Threading.Thread.CurrentThread; RichBoxArgs rbArgs = new RichBoxArgs("", true); rbArgs.stringToWrite = "\r\n--------------------------------------------\r\n"; WriteToRichBox(sender, rbArgs); rbArgs.clear = false; rbArgs.stringToWrite = DateTime.Today.ToLongDateString() + " : "; rbArgs.stringToWrite += DateTime.Now.ToLongTimeString() + "\r\n"; WriteToRichBox(sender, rbArgs); rbArgs.stringToWrite = string.Format("Host: {0}\r\n", _hostName); WriteToRichBox(sender, rbArgs); rbArgs.stringToWrite = string.Format("Starting to Upload to the skins folder from {0}\r\n", PathToSkins.Text); WriteToRichBox(sender, rbArgs); int pass = 1; bool anyFailed = false; do { anyFailed = false; for (int iServerIndex = 0; iServerIndex < serverCount && rbArgs.Cancel == false; iServerIndex++) { ServerDetails details = servers[iServerIndex]; rbArgs.stringToWrite = String.Concat("Uploading to ", details.Name, " (pass ", pass, ")\r\n"); for (int fi = 0; fi < filenameCount; fi++) { try { string webResponse = String.Empty; if (!filenames[fi].EndsWith("\\")) //skip actual directories { webResponse = UploadFile(filenames[fi], details.Path); System.Threading.Thread.Sleep(200); XmlDocument response = new XmlDocument(); response.LoadXml(webResponse); XmlNode savedpath = response.SelectSingleNode("//H2G2/SKINUPLOADSERVER/SKINSSAVED/PATH"); if (savedpath != null) { string path = savedpath.InnerText; XmlNodeList saved = response.SelectNodes("//H2G2/SKINUPLOADSERVER/SKINSSAVED/FILENAME"); foreach (XmlNode node in saved) { rbArgs.stringToWrite = node.InnerText + " uploaded to " + path + " on " + details.Name + "\r\n"; WriteToRichBox(sender, rbArgs); } } else { throw new Exception("Error occured"); } } } catch (Exception Ex) { if (filenames[fi].Contains("configuration.xsl")) { rbArgs.stringToWrite = "WARNING - Trying to overwrite " + filenames[fi] + "\r\n"; WriteToRichBox(sender, rbArgs); } else { string innermsg = String.Empty; if (Ex.InnerException != null && Ex.InnerException.Message != null) { innermsg = Ex.InnerException.Message; } anyFailed = true; rbArgs.stringToWrite = Ex.Message + innermsg + " - When trying to process " + filenames[fi] + "\r\n"; WriteToRichBox(sender, rbArgs); } } } if (_autoClearTemplates) { ClearTemplates(details); } pass++; } } while (pass < 4 && anyFailed && rbArgs.Cancel == false); if (rbArgs.Cancel == false) { rbArgs.Completed = true; rbArgs.stringToWrite = "Finished uploading\r\n"; WriteToRichBox(sender, rbArgs); if (anyFailed) { rbArgs.stringToWrite = "Some files were not uploaded\r\n"; WriteToRichBox(sender, rbArgs); MessageBox.Show("Upload finished. Some files were not uploaded.", "Message from Skin Manager"); } else { MessageBox.Show("Upload finished.", "Message from Skin Manager"); } } else { rbArgs.stringToWrite = "Upload cancelled\r\n"; WriteToRichBox(sender, rbArgs); } }