private void cmdUpload_Click(object sender, EventArgs e) { // Make sure a name has been entered. if (string.IsNullOrWhiteSpace(txtName.Text)) { MessageBox.Show(LanguageManager.GetString("Message_OmaeUpload_DataName", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_OmaeUpload_DataName", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // Make sure there is at least some sort of description. if (string.IsNullOrWhiteSpace(txtDescription.Text)) { MessageBox.Show(LanguageManager.GetString("Message_OameUpload_DataDescription", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_OmaeUpload_DataDescription", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // Make sure at least 1 file is selected. int intCount = 0; foreach (TreeNode objNode in treFiles.Nodes) { if (objNode.Checked) { intCount++; } } if (intCount == 0) { MessageBox.Show(LanguageManager.GetString("Message_OmaeUpload_DataSelectFiles", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_OmaeUpload_SelectFile", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } bool blnSuccess = false; string strFilePath = Path.Combine(Utils.GetStartupPath, "data", "books.xml"); XmlDocument objXmlBooks = new XmlDocument(); objXmlBooks.Load(strFilePath); List <string> lstSource = new List <string>(); // Run through all of the selected items. Create a list of the <source> items seen and make sure they're available in the core files or included in the user's selected item. foreach (TreeNode objNode in treFiles.Nodes) { if (objNode.Checked) { XmlDocument objXmlDocument = new XmlDocument(); objXmlDocument.Load(objNode.Tag.ToString()); XmlNodeList objRootList = objXmlDocument.SelectNodes("/chummer"); foreach (XmlNode objXmlGroup in objRootList[0]) { foreach (XmlNode objXmlNode in objXmlGroup.ChildNodes) { if (objXmlNode["source"] != null) { // Look to see if this sourcebook is already in the list. If not, add it. bool blnFound = false; foreach (string strSource in lstSource) { if (strSource == objXmlNode["source"].InnerText) { blnFound = true; break; } } if (!blnFound) { lstSource.Add(objXmlNode["source"].InnerText); } } } } } } // Now that we have the list of used sourcebooks, check the books file for the items. for (int i = 0; i <= lstSource.Count - 1; i++) { string strSource = lstSource[i]; if (!string.IsNullOrEmpty(strSource)) { XmlNode objNode = objXmlBooks.SelectSingleNode("/chummer/books/book[code = \"" + strSource + "\"]"); if (objNode != null) { lstSource[i] = string.Empty; } } } // Check any custom book files the user selected. foreach (TreeNode objNode in treFiles.Nodes) { if (objNode.Checked && objNode.Tag.ToString().EndsWith("books.xml")) { XmlDocument objXmlCustom = new XmlDocument(); objXmlCustom.Load(objNode.Tag.ToString()); for (int i = 0; i <= lstSource.Count - 1; i++) { string strSource = lstSource[i]; if (!string.IsNullOrEmpty(strSource)) { XmlNode objBookNode = objXmlCustom.SelectSingleNode("/chummer/books/book[code = \"" + strSource + "\"]"); if (objBookNode != null) { lstSource[i] = string.Empty; } } } } } // With all of the books checked, run through the list one more time and display an error if there are still any that were not found. string strMessage = string.Empty; foreach (string strSource in lstSource) { if (!string.IsNullOrEmpty(strSource)) { strMessage += Environment.NewLine + '\t' + strSource; } } if (!string.IsNullOrEmpty(strMessage)) { MessageBox.Show("The following sourcebooks could not be found in the core data files or any of the data files you have selected:" + strMessage); return; } // Everything is OK, so zip up the selected files. List <string> lstFiles = new List <string>(); string strFilesIncluded = string.Empty; foreach (TreeNode objNode in treFiles.Nodes) { if (objNode.Checked) { lstFiles.Add(objNode.Tag.ToString()); strFilesIncluded += objNode.Text + ","; } } byte[] bytFile = OmaeHelper.CompressMutiple(lstFiles); // Make sure the file doesn't exceed 250K in size (256,000 bytes). if (bytFile.Length > 256000) { MessageBox.Show(LanguageManager.GetString("Message_OmaeUpload_FileTooLarge", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_OmaeUpload_FileTooLarge", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Upload the file. omaeSoapClient objService = OmaeHelper.GetOmaeService(); try { cmdUpload.Enabled = false; txtDescription.Enabled = false; txtName.Enabled = false; if (objService.UploadDataFile(_strUserName, _intDataID, txtName.Text, txtDescription.Text, strFilesIncluded, bytFile)) { blnSuccess = true; MessageBox.Show(LanguageManager.GetString("Message_OmaeUpload_UploadComplete", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_OmaeUpload_UploadComplete", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(LanguageManager.GetString("Message_OmaeUpload_UploadFailed", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_OmaeUpload_UploadFailed", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (EndpointNotFoundException) { MessageBox.Show(NO_CONNECTION_MESSAGE, NO_CONNECTION_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); } objService.Close(); cmdUpload.Enabled = true; txtDescription.Enabled = true; txtName.Enabled = true; if (blnSuccess) { DialogResult = DialogResult.OK; } //OmaeHelper.DecompressMultiple(bytFile); }
private void cmdUpload_Click(object sender, EventArgs e) { // Make sure a name has been entered. if (txtName.Text == "") { MessageBox.Show(LanguageManager.Instance.GetString("Message_OmaeUpload_SheetName"), LanguageManager.Instance.GetString("MessageTitle_OmaeUpload_SheetName"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // Make sure there is at least some sort of description. if (txtDescription.Text.Trim() == "") { MessageBox.Show(LanguageManager.Instance.GetString("Message_OameUpload_SheetDescription"), LanguageManager.Instance.GetString("MessageTitle_OmaeUpload_SheetDescription"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // Make sure at least 1 file was selected. if (txtFilePath.Text == string.Empty) { MessageBox.Show(LanguageManager.Instance.GetString("Message_OmaeUpload_SheetSelectFiles"), LanguageManager.Instance.GetString("MessageTitle_OmaeUpload_SelectFile"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } bool blnSuccess = false; // Compress the files. byte[] bytFile = _objOmaeHelper.CompressMutiple(_lstFiles); // Make sure the file doesn't exceed 250K in size (256,000 bytes). if (bytFile.Length > 256000) { MessageBox.Show(LanguageManager.Instance.GetString("Message_OmaeUpload_FileTooLarge"), LanguageManager.Instance.GetString("MessageTitle_OmaeUpload_FileTooLarge"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Upload the file. omaeSoapClient objService = _objOmaeHelper.GetOmaeService(); try { cmdUpload.Enabled = false; txtDescription.Enabled = false; txtName.Enabled = false; if (objService.UploadSheet(_strUserName, _intSheetID, txtName.Text, txtDescription.Text, bytFile)) { blnSuccess = true; MessageBox.Show(LanguageManager.Instance.GetString("Message_OmaeUpload_UploadComplete"), LanguageManager.Instance.GetString("MessageTitle_OmaeUpload_UploadComplete"), MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(LanguageManager.Instance.GetString("Message_OmaeUpload_UploadFailed"), LanguageManager.Instance.GetString("MessageTitle_OmaeUpload_UploadFailed"), MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (EndpointNotFoundException) { MessageBox.Show(NO_CONNECTION_MESSAGE, NO_CONNECTION_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); } objService.Close(); cmdUpload.Enabled = true; txtDescription.Enabled = true; txtName.Enabled = true; if (blnSuccess) { this.DialogResult = DialogResult.OK; } }