/// <summary> /// Set all of the BasicHttpBinding properties and configure the EndPoint. This is done to avoid the need for an app.config file to be shippped with the application. /// </summary> public omaeSoapClient GetOmaeService() { BasicHttpBinding objBinding = new BasicHttpBinding(); objBinding.Name = "omaeSoap"; objBinding.CloseTimeout = TimeSpan.FromMinutes(1); objBinding.OpenTimeout = TimeSpan.FromMinutes(1); objBinding.ReceiveTimeout = TimeSpan.FromMinutes(10); objBinding.SendTimeout = TimeSpan.FromMinutes(1); objBinding.AllowCookies = false; objBinding.BypassProxyOnLocal = false; objBinding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard; objBinding.MaxBufferSize = 5242880; // 5 MB objBinding.MaxReceivedMessageSize = 5242880; // 5 MB objBinding.MaxBufferPoolSize = 524288; objBinding.MessageEncoding = WSMessageEncoding.Text; objBinding.TextEncoding = System.Text.Encoding.UTF8; objBinding.TransferMode = TransferMode.Buffered; objBinding.UseDefaultWebProxy = true; objBinding.ReaderQuotas.MaxDepth = 32; objBinding.ReaderQuotas.MaxStringContentLength = 8388608; objBinding.ReaderQuotas.MaxArrayLength = 5242880; objBinding.ReaderQuotas.MaxBytesPerRead = 4096; objBinding.ReaderQuotas.MaxNameTableCharCount = 32565; objBinding.Security.Mode = BasicHttpSecurityMode.None; objBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None; objBinding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None; objBinding.Security.Transport.Realm = ""; objBinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName; objBinding.Security.Message.AlgorithmSuite = System.ServiceModel.Security.SecurityAlgorithmSuite.Default; const string strEndPoint = "http://www.chummergen.com/dev/chummer/omae/omae.asmx"; EndpointAddress objEndPointAddress = new EndpointAddress(strEndPoint); omaeSoapClient objService = new omaeSoapClient(objBinding, objEndPointAddress); return objService; }
private void cmdSearch_Click(object sender, EventArgs e) { omaeSoapClient objService = _objOmaeHelper.GetOmaeService(); // Clear the current contents of the Omae Panel. Detach the events before clearing it. foreach (OmaeRecord objRecord in panOmae.Controls.OfType <OmaeRecord>()) { objRecord.OmaeDownloadClicked -= objRecord_OmaeDownloadClicked; objRecord.OmaePostUpdateClicked -= objRecord_OmaePostUpdateClicked; objRecord.OmaeDeleteClicked -= objRecord_OmaeDeleteClicked; } panOmae.Controls.Clear(); // Set the current operating mode. switch (cboCharacterTypes.SelectedValue.ToString()) { case "data": _objMode = OmaeMode.Data; break; case "sheets": _objMode = OmaeMode.Sheets; break; default: _objMode = OmaeMode.Character; break; } // Search for characters. if (_objMode == OmaeMode.Character) { try { MemoryStream objStream = new MemoryStream(); XmlTextWriter objWriter = new XmlTextWriter(objStream, Encoding.UTF8); objService.FetchCharacters153(Convert.ToInt32(cboCharacterTypes.SelectedValue), Convert.ToInt32(cboSortOrder.SelectedValue), cboFilterMetatype.Text, cboFilterMetavariant.Text, Convert.ToInt32(cboFilterMode.SelectedValue), txtFilterUser.Text, cboFilterQuality1.Text, cboFilterQuality2.Text, cboFilterQuality3.Text).WriteTo(objWriter); // Flush the output. objWriter.Flush(); objStream.Flush(); XmlDocument objXmlDocument = _objOmaeHelper.XmlDocumentFromStream(objStream); // Close everything now that we're done. objWriter.Close(); objStream.Close(); if (objXmlDocument.SelectNodes("/characters/character").Count == 0) { Label lblResults = new Label(); lblResults.Text = LanguageManager.Instance.GetString("String_Omae_NoCharacters"); lblResults.Width = 200; panOmae.Controls.Add(lblResults); } else { int intCounter = -1; foreach (XmlNode objNode in objXmlDocument.SelectNodes("/characters/character")) { intCounter++; OmaeRecord objRecord = new OmaeRecord(objNode, Convert.ToInt32(cboCharacterTypes.SelectedValue), OmaeMode.Character); objRecord.OmaeDownloadClicked += objRecord_OmaeDownloadClicked; objRecord.OmaePostUpdateClicked += objRecord_OmaePostUpdateClicked; objRecord.OmaeDeleteClicked += objRecord_OmaeDeleteClicked; if ((objRecord.UserName == txtUserName.Text || txtUserName.Text == "Nebular") && _blnLoggedIn) { objRecord.OwnedByUser = true; } objRecord.Top = intCounter * 88; panOmae.Controls.Add(objRecord); } } objService.Close(); } catch (EndpointNotFoundException) { MessageBox.Show(NO_CONNECTION_MESSAGE, NO_CONNECTION_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); } } // Search for data. if (_objMode == OmaeMode.Data) { try { MemoryStream objStream = new MemoryStream(); XmlTextWriter objWriter = new XmlTextWriter(objStream, Encoding.UTF8); objService.FetchDataFiles(Convert.ToInt32(cboSortOrder.SelectedValue), "", txtFilterUser.Text).WriteTo(objWriter); // Flush the output. objWriter.Flush(); objStream.Flush(); XmlDocument objXmlDocument = _objOmaeHelper.XmlDocumentFromStream(objStream); // Close everything now that we're done. objWriter.Close(); objStream.Close(); if (objXmlDocument.SelectNodes("/datas/data").Count == 0) { Label lblResults = new Label(); lblResults.Text = LanguageManager.Instance.GetString("String_Omae_NoData"); lblResults.Width = 200; panOmae.Controls.Add(lblResults); } else { int intCounter = -1; foreach (XmlNode objNode in objXmlDocument.SelectNodes("/datas/data")) { intCounter++; OmaeRecord objRecord = new OmaeRecord(objNode, 0, OmaeMode.Data); objRecord.OmaeDownloadClicked += objRecord_OmaeDownloadClicked; objRecord.OmaePostUpdateClicked += objRecord_OmaePostUpdateClicked; objRecord.OmaeDeleteClicked += objRecord_OmaeDeleteClicked; if ((objRecord.UserName == txtUserName.Text || txtUserName.Text == "Nebular") && _blnLoggedIn) { objRecord.OwnedByUser = true; } objRecord.Top = intCounter * 88; panOmae.Controls.Add(objRecord); } } objService.Close(); } catch (EndpointNotFoundException) { MessageBox.Show(NO_CONNECTION_MESSAGE, NO_CONNECTION_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); } } // Search for character sheets. if (_objMode == OmaeMode.Sheets) { try { MemoryStream objStream = new MemoryStream(); XmlTextWriter objWriter = new XmlTextWriter(objStream, Encoding.UTF8); objService.FetchSheets(Convert.ToInt32(cboSortOrder.SelectedValue), txtFilterUser.Text).WriteTo(objWriter); // Flush the output. objWriter.Flush(); objStream.Flush(); XmlDocument objXmlDocument = _objOmaeHelper.XmlDocumentFromStream(objStream); // Close everything now that we're done. objWriter.Close(); objStream.Close(); if (objXmlDocument.SelectNodes("/sheets/sheet").Count == 0) { Label lblResults = new Label(); lblResults.Text = LanguageManager.Instance.GetString("String_Omae_NoSheets"); lblResults.Width = 200; panOmae.Controls.Add(lblResults); } else { int intCounter = -1; foreach (XmlNode objNode in objXmlDocument.SelectNodes("/sheets/sheet")) { intCounter++; OmaeRecord objRecord = new OmaeRecord(objNode, 0, OmaeMode.Sheets); objRecord.OmaeDownloadClicked += objRecord_OmaeDownloadClicked; objRecord.OmaePostUpdateClicked += objRecord_OmaePostUpdateClicked; objRecord.OmaeDeleteClicked += objRecord_OmaeDeleteClicked; if ((objRecord.UserName == txtUserName.Text || txtUserName.Text == "Nebular") && _blnLoggedIn) { objRecord.OwnedByUser = true; } objRecord.Top = intCounter * 88; panOmae.Controls.Add(objRecord); } } objService.Close(); } catch (EndpointNotFoundException) { MessageBox.Show(NO_CONNECTION_MESSAGE, NO_CONNECTION_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void objRecord_OmaeDeleteClicked(Object sender) { if (_objMode == OmaeMode.Character) { // Make sure the user wants to delete the character. if (MessageBox.Show(LanguageManager.Instance.GetString("Message_Omae_ConfirmDelete"), LanguageManager.Instance.GetString("MessageTitle_Omae_DeleteCharacter"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } // Delete the character. OmaeRecord objRecord = (OmaeRecord)sender; omaeSoapClient objService = _objOmaeHelper.GetOmaeService(); if (objService.DeleteCharacter(objRecord.CharacterID)) { MessageBox.Show(LanguageManager.Instance.GetString("Message_Omae_CharacterDeleted"), LanguageManager.Instance.GetString("MessageTitle_Omae_DeleteCharacter"), MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(LanguageManager.Instance.GetString("Message_Omae_CharacterDeleteError"), LanguageManager.Instance.GetString("MessageTitle_Omae_DeleteCharacter"), MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (_objMode == OmaeMode.Data) { // Make sure the user wants to delete the data. if (MessageBox.Show(LanguageManager.Instance.GetString("Message_Omae_ConfirmData"), LanguageManager.Instance.GetString("MessageTitle_Omae_DeleteData"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } // Delete the data. OmaeRecord objRecord = (OmaeRecord)sender; omaeSoapClient objService = _objOmaeHelper.GetOmaeService(); if (objService.DeleteDataFile(objRecord.CharacterID)) { MessageBox.Show(LanguageManager.Instance.GetString("Message_Omae_DataDeleted"), LanguageManager.Instance.GetString("MessageTitle_Omae_DeleteData"), MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(LanguageManager.Instance.GetString("Message_Omae_DataDeleteError"), LanguageManager.Instance.GetString("MessageTitle_Omae_DeleteData"), MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (_objMode == OmaeMode.Sheets) { // Make sure the user wants to delete the character sheet. if (MessageBox.Show(LanguageManager.Instance.GetString("Message_Omae_ConfirmSheet"), LanguageManager.Instance.GetString("MessageTitle_Omae_DeleteData"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } // Delete the data. OmaeRecord objRecord = (OmaeRecord)sender; omaeSoapClient objService = _objOmaeHelper.GetOmaeService(); if (objService.DeleteSheet(objRecord.CharacterID)) { MessageBox.Show(LanguageManager.Instance.GetString("Message_Omae_SheetDeleted"), LanguageManager.Instance.GetString("MessageTitle_Omae_DeleteData"), MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(LanguageManager.Instance.GetString("Message_Omae_SheetDeleteError"), LanguageManager.Instance.GetString("MessageTitle_Omae_DeleteData"), MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void objRecord_OmaeDownloadClicked(Object sender) { // Setup the web service. OmaeRecord objRecord = (OmaeRecord)sender; omaeSoapClient objService = _objOmaeHelper.GetOmaeService(); if (_objMode == OmaeMode.Character) { if (objRecord.CharacterType != 4) { // Download the selected character. string strFileName = objRecord.CharacterName + ".chum5"; strFileName = FileSafe(strFileName); // If the Omae save directory does not yet exist, create it. string strSavePath = Path.Combine(Application.StartupPath, "saves"); if (!Directory.Exists(strSavePath)) { Directory.CreateDirectory(strSavePath); } if (!Directory.Exists(Path.Combine(strSavePath, "omae"))) { Directory.CreateDirectory(Path.Combine(strSavePath, "omae")); } // See if there is already a file with the character's name in the Downloads directory. string strFullPath = Path.Combine(strSavePath, "omae"); strFullPath = Path.Combine(strFullPath, strFileName); if (File.Exists(strFullPath)) { if (MessageBox.Show(LanguageManager.Instance.GetString("Message_Omae_FileExists").Replace("{0}", strFileName), LanguageManager.Instance.GetString("MessageTitle_Omae_FileExists"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } } try { // Download the compressed file. byte[] bytFile = objService.DownloadCharacter(objRecord.CharacterID); if (bytFile.Length == 0) { MessageBox.Show(LanguageManager.Instance.GetString("Message_Omae_CannotFindCharacter"), LanguageManager.Instance.GetString("MessageTitle_Omae_CannotFindCharacter"), MessageBoxButtons.OK, MessageBoxIcon.Error); objService.Close(); return; } // Decompress the byte array and write it to a file. bytFile = _objOmaeHelper.Decompress(bytFile); string strWritePath = Path.Combine(strSavePath, "omae"); strWritePath = Path.Combine(strWritePath, strFileName); File.WriteAllBytes(strWritePath, bytFile); if (MessageBox.Show(LanguageManager.Instance.GetString("Message_Omae_CharacterDownloaded"), LanguageManager.Instance.GetString("MessageTitle_Omae_CharacterDownloaded"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { _frmMain.LoadCharacter(strWritePath); } } catch (EndpointNotFoundException) { MessageBox.Show(NO_CONNECTION_MESSAGE, NO_CONNECTION_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { // Download the selected NPC pack. string strFileName = objRecord.CharacterName + ".chum5"; strFileName = FileSafe(strFileName); // If the Omae save directory does not yet exist, create it. string strSavePath = Path.Combine(Application.StartupPath, "saves"); if (!Directory.Exists(strSavePath)) { Directory.CreateDirectory(strSavePath); } try { // Download the compressed file. byte[] bytFile = objService.DownloadCharacter(objRecord.CharacterID); if (bytFile.Length == 0) { MessageBox.Show(LanguageManager.Instance.GetString("Message_Omae_CannotFindCharacter"), LanguageManager.Instance.GetString("MessageTitle_Omae_CannotFindCharacter"), MessageBoxButtons.OK, MessageBoxIcon.Error); objService.Close(); return; } // Decompress the byte array and write it to a file. _objOmaeHelper.DecompressNPCs(bytFile); MessageBox.Show(LanguageManager.Instance.GetString("Message_Omae_NPCPackDownloaded"), LanguageManager.Instance.GetString("MessageTitle_Omae_CharacterDownloaded"), MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (EndpointNotFoundException) { MessageBox.Show(NO_CONNECTION_MESSAGE, NO_CONNECTION_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else if (_objMode == OmaeMode.Data) { try { // Download the compressed file. byte[] bytFile = objService.DownloadDataFile(objRecord.CharacterID); if (bytFile.Length == 0) { MessageBox.Show(LanguageManager.Instance.GetString("Message_Omae_CannotFindData"), LanguageManager.Instance.GetString("MessageTitle_Omae_CannotFindData"), MessageBoxButtons.OK, MessageBoxIcon.Error); objService.Close(); return; } // Decompress the byte array and write it to a file. _objOmaeHelper.DecompressDataFile(bytFile, objRecord.CharacterID.ToString()); // Show a message saying everything is done. MessageBox.Show(LanguageManager.Instance.GetString("Message_Omae_DataDownloaded"), LanguageManager.Instance.GetString("MessageTitle_Omae_DataDownloaded"), MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (EndpointNotFoundException) { MessageBox.Show(NO_CONNECTION_MESSAGE, NO_CONNECTION_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (_objMode == OmaeMode.Sheets) { // If the Omae sheets directory does not yet exist, create it. string strSheetsPath = Path.Combine(Application.StartupPath, "sheets"); if (!Directory.Exists(Path.Combine(strSheetsPath, "omae"))) { Directory.CreateDirectory(Path.Combine(strSheetsPath, "omae")); } try { // Download the compressed file. byte[] bytFile = objService.DownloadSheet(objRecord.CharacterID); if (bytFile.Length == 0) { MessageBox.Show(LanguageManager.Instance.GetString("Message_Omae_CannotFindSheet"), LanguageManager.Instance.GetString("MessageTitle_Omae_CannotFindSheet"), MessageBoxButtons.OK, MessageBoxIcon.Error); objService.Close(); return; } // Decompress the byte array and write it to a file. _objOmaeHelper.DecompressCharacterSheet(bytFile); // Show a message saying everything is done. MessageBox.Show(LanguageManager.Instance.GetString("Message_Omae_SheetDownloaded"), LanguageManager.Instance.GetString("MessageTitle_Omae_SheetDownloaded"), MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (EndpointNotFoundException) { MessageBox.Show(NO_CONNECTION_MESSAGE, NO_CONNECTION_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); } } // Close the service now that we're done with it. objService.Close(); }
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_SheetName", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_OmaeUpload_SheetName", 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_SheetDescription", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_OmaeUpload_SheetDescription", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // Make sure at least 1 file was selected. if (string.IsNullOrEmpty(txtFilePath.Text)) { MessageBox.Show(LanguageManager.GetString("Message_OmaeUpload_SheetSelectFiles", GlobalOptions.Language), LanguageManager.GetString("MessageTitle_OmaeUpload_SelectFile", GlobalOptions.Language), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } bool blnSuccess = false; // Compress the files. 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.UploadSheet(_strUserName, _intSheetID, txtName.Text, txtDescription.Text, 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; } }
private void cmdUpload_Click(object sender, EventArgs e) { bool blnSuccess = false; // Make sure a file has been selected. if (txtFilePath.Text == "") { MessageBox.Show(LanguageManager.Instance.GetString("Message_OmaeUpload_SelectFile"), LanguageManager.Instance.GetString("MessageTitle_OmaeUpload_SelectFile"), 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_OmaeUpload_CharacterDescription"), LanguageManager.Instance.GetString("MessageTitle_OmaeUpload_CharacterDescription"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // Read the contents of the file into a byte array, the compress it. byte[] bytFile = _objOmaeHelper.Compress(File.ReadAllBytes(txtFilePath.Text)); // Make sure the file doesn't exceed 500K in size (512,000 bytes). if (bytFile.Length > 512000) { MessageBox.Show(LanguageManager.Instance.GetString("Message_OmaeUpload_FileTooLarge"), LanguageManager.Instance.GetString("MessageTitle_OmaeUpload_FileTooLarge"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } omaeSoapClient objService = _objOmaeHelper.GetOmaeService(); try { cmdUpload.Enabled = false; txtDescription.Enabled = false; string strCharacterName = cboCharacterName.Text; if (strCharacterName.Length > 100) { strCharacterName = strCharacterName.Substring(0, 100); } if (objService.UploadCharacter153(_strUserName, _intCharacterID, strCharacterName, txtDescription.Text, _strMetatype, _strMetavariant, _strQualities, Convert.ToInt32(cboCharacterTypes.SelectedValue), _intCreated, 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; if (blnSuccess) { this.DialogResult = DialogResult.OK; } }
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_DataName"), LanguageManager.Instance.GetString("MessageTitle_OmaeUpload_DataName"), 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_DataDescription"), LanguageManager.Instance.GetString("MessageTitle_OmaeUpload_DataDescription"), 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.Instance.GetString("Message_OmaeUpload_DataSelectFiles"), LanguageManager.Instance.GetString("MessageTitle_OmaeUpload_SelectFile"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } bool blnSuccess = false; string strFilePath = Path.Combine(Environment.CurrentDirectory, "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 (strSource != "") { XmlNode objNode = objXmlBooks.SelectSingleNode("/chummer/books/book[code = \"" + strSource + "\"]"); if (objNode != null) { lstSource[i] = ""; } } } // 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 (strSource != "") { XmlNode objBookNode = objXmlCustom.SelectSingleNode("/chummer/books/book[code = \"" + strSource + "\"]"); if (objBookNode != null) { lstSource[i] = ""; } } } } } // 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 = ""; foreach (string strSource in lstSource) { if (strSource != "") { strMessage += "\n\t" + strSource; } } if (strMessage != string.Empty) { 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 = ""; foreach (TreeNode objNode in treFiles.Nodes) { if (objNode.Checked) { lstFiles.Add(objNode.Tag.ToString()); strFilesIncluded += objNode.Text + ","; } } 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.UploadDataFile(_strUserName, _intDataID, txtName.Text, txtDescription.Text, strFilesIncluded, 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; } //_objOmaeHelper.DecompressMultiple(bytFile); }
private void frmOmaeAccount_Load(object sender, EventArgs e) { omaeSoapClient objService = _objOmaeHelper.GetOmaeService(); txtEmail.Text = objService.GetEmailAddress(_strUserName); }