// find out submission processing result private void Button_Click_1(object sender, RoutedEventArgs e) { XmlDocument doc; // invoke a login dialog if login/pass not entered in wizard already if (username.Text == null || password.Password == null || username.Text == "" || password.Password == "") { LoginPassWindow lpw = new LoginPassWindow(); bool? res = lpw.ShowDialog(); if (lpw.username.Text == null || lpw.username.Text=="" || lpw.password.Password == null || lpw.password.Password == "") return; username.Text = lpw.username.Text; password.Password = lpw.password.Password; } SetProgressStateForCheck("Initialize ...", 0); tmpUsername = username.Text; tmpPassword = password.Password; tmpFilename = resultFilename.Text; resultPage.CancelButtonEnabled = false; resultPage.BackButtonEnabled = false; resultPage.NextButtonEnabled = false; resultDetail.Text = ""; GeneralDataSource.GeneralDataSourceSingleton.ResultHighlights = null; // Initialize the background worker if (checkBackgroundWorker == null) { checkBackgroundWorker = new BackgroundWorker(); checkBackgroundWorker.WorkerReportsProgress = true; checkBackgroundWorker.DoWork += delegate(object sndr, DoWorkEventArgs eventArgs) { SetProgressStateForCheck("Loading XML file...", 1, false, true); // take the already loaded file if it's the one chosen or load another if (tmpFilename == fileName) doc = GeneralDataSource.GeneralDataSourceSingleton.CnbData.Xml; else { doc = new XmlDocument(); // doc.XmlResolver = new EmbeddedResourceResolver(); Stream stream = File.OpenRead(tmpFilename); doc.Load(stream); stream.Close(); } SetProgressStateForCheck("Connecting to CNB...", 50); // call the ws manually string resS = CnbConnection.GetProcessingResult(doc, this.GetType(), tmpUsername, tmpPassword); SetProgressStateForCheck("Processing result...", 75); Application.Current.Dispatcher.Invoke( System.Windows.Threading.DispatcherPriority.Normal, new Action( delegate() { resultDetail.Text = (resS == null) ? "" : resS; } )); // resultDetail.Text = (resS == null) ? "" : resS; GeneralDataSource.GeneralDataSourceSingleton.ResultHighlights = null; if (resS == null) return; // response wasn't base64 encoded (only show detail info) if (resS.StartsWith("RAW RESPONSE:")) return; // and parse the results XmlDocument resDoc; try { resDoc = new XmlDocument(); // resDoc.XmlResolver = new EmbeddedResourceResolver(); resDoc.LoadXml(resS); } catch (Exception ee) { return; } XmlNode node; List<KeyValuePair<string, string>> hili = new List<KeyValuePair<string, string>>(); XmlNamespaceManager nsMan = new XmlNamespaceManager(resDoc.NameTable); nsMan.AddNamespace("a", "www.ewi.ws"); node = resDoc.SelectSingleNode("/a:EwiWSResult/a:ErrorLog/a:Status", nsMan); if (node != null) hili.Add(new KeyValuePair<string, string>("Status", node.InnerText)); node = resDoc.SelectSingleNode("/a:EwiWSResult/a:ErrorLog/a:ErrorCode", nsMan); if (node != null) hili.Add(new KeyValuePair<string, string>("Error Code", node.InnerText)); node = resDoc.SelectSingleNode("/a:EwiWSResult/a:ErrorLog/a:ErrorText", nsMan); if (node != null) hili.Add(new KeyValuePair<string, string>("Error Text", node.InnerText)); node = resDoc.SelectSingleNode("/a:EwiWSResult/a:VydaniSeznam/a:Vyskyt/a:StavKod", nsMan); if (node != null) { int t; if (int.TryParse(node.InnerText, out t)) { string s; if (CnbConnection.VyskytStavKod.ContainsKey(t)) s = CnbConnection.VyskytStavKod[t]; else s = t.ToString(); hili.Add(new KeyValuePair<string, string>("Vyskyt StavKod", s)); } } node = resDoc.SelectSingleNode("/a:EwiWSResult/a:VydaniSeznam/a:Vyskyt/a:Stav", nsMan); if (node != null) hili.Add(new KeyValuePair<string, string>("Vyskyt Status", node.InnerText)); node = resDoc.SelectSingleNode("/a:EwiWSResult/a:VydaniSeznam/a:Vydani/a:StavKod", nsMan); if (node != null) { int t; if (int.TryParse(node.InnerText, out t)) { string s; if (CnbConnection.VydaniStavKod.ContainsKey(t)) s = CnbConnection.VydaniStavKod[t]; else s = t.ToString(); hili.Add(new KeyValuePair<string, string>("Vydani StavKod", s)); } } node = resDoc.SelectSingleNode("/a:EwiWSResult/a:VydaniSeznam/a:Vydani/a:Stav", nsMan); if (node != null) hili.Add(new KeyValuePair<string, string>("Vydani Status", node.InnerText)); node = resDoc.SelectSingleNode("/a:EwiWSResult/a:VydaniSeznam/a:Vydani/a:StavOd", nsMan); if (node != null) hili.Add(new KeyValuePair<string, string>("Stav Od", node.InnerText)); node = resDoc.SelectSingleNode("/a:EwiWSResult/a:VydaniSeznam/a:Vydani/a:DatumPrijmu", nsMan); if (node != null) hili.Add(new KeyValuePair<string, string>("Datum Prijmu", node.InnerText)); node = resDoc.SelectSingleNode("/a:EwiWSResult/a:VydaniSeznam/a:Vydani/a:Druh", nsMan); if (node != null) hili.Add(new KeyValuePair<string, string>("Druh", node.InnerText)); node = resDoc.SelectSingleNode("/a:EwiWSResult/a:VydaniSeznam/a:Vydani/a:ChybaZpracovani", nsMan); if (node != null) hili.Add(new KeyValuePair<string, string>("Chyba Zpracovani", node.InnerText)); node = resDoc.SelectSingleNode("/a:EwiWSResult/a:VydaniSeznam/a:Vydani/a:ChybnyKrokKontroly", nsMan); if (node != null) hili.Add(new KeyValuePair<string, string>("ChybnyKrokKontroly", node.InnerText)); if (hili.Count > 0) GeneralDataSource.GeneralDataSourceSingleton.ResultHighlights = hili.ToArray(); }; checkBackgroundWorker.ProgressChanged += delegate(object sndr, ProgressChangedEventArgs eventArgs) { // SetProgressStateForCheck("Processing...", eventArgs.ProgressPercentage); }; checkBackgroundWorker.RunWorkerCompleted += delegate(object sndr, RunWorkerCompletedEventArgs eventArgs) { SetProgressStateForCheck("", 0, false, false); checkBackgroundWorker = null; resultPage.CancelButtonEnabled = null; resultPage.BackButtonEnabled = null; resultPage.NextButtonEnabled = null; }; } // Start the background work checkBackgroundWorker.RunWorkerAsync(); }
// load xml to return its processing status button private void Button_Click_2(object sender, RoutedEventArgs e) { // request a file name System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog(); ofd.Multiselect = false; ofd.Filter = "Data Files (*.xml)|*.xml|All Files|*.*"; startProcessingButton.IsEnabled = true; string fName; if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) fName = ofd.FileName; else return; if (!fName.EndsWith(".xml")) fName = @"C:\projekty\XtbCnb\XtbCnb\MOKAS42_31052010_377521.xml"; resultFilename.Text = fName; UpdateResultButtonState(); LoginPassWindow lpw = new LoginPassWindow(); }