Ejemplo n.º 1
0
        public void ThatShit()
        {
            //string input = Input.Text.Trim().Replace("&", "&");
            string        input          = Input.Text.Trim();
            List <string> activationList = new List <string>();

            while (true)
            {
                int startIndex = input.IndexOf("<ACTIVATION_CODE>");
                if (startIndex < 0)
                {
                    break;
                }
                int endIndex = input.IndexOf("</ACTIVATION_CODE>");
                int length   = endIndex - (startIndex + 17);
                activationList.Add(input.Substring(startIndex + 17, length));
                input = input.Remove(startIndex, length + 35);
            }

            try
            {
                XElement str = XElement.Parse(input);
                // find specific tag
                foreach (XElement XE in str.Elements("ITEM_DETAILS"))
                {
                    string number = XE.Descendants("ITEM_NUMBER").FirstOrDefault()?.Value;
                    string xmltag = XE.Descendants("XML_TAG").FirstOrDefault()?.Value;
                    itemNumbers.Add(number);
                }
                Output.Text += "Item Numbers found:" + Environment.NewLine;
                foreach (string item in itemNumbers)
                {
                    Output.Text += item + Environment.NewLine;
                }
                Output.Text += "End of item numbers found." + Environment.NewLine + Environment.NewLine;
                Output.Text += "Start of activation code list." + Environment.NewLine;
                foreach (string act in activationList)
                {
                    Output.Text += act + Environment.NewLine;
                }
                Output.Text += "End of activation code list." + Environment.NewLine;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception thrown when parsing. Message: " + ex.Message.ToString());
            }
        }
Ejemplo n.º 2
0
        private void Deserialize_Click(object sender, EventArgs e)
        {
            try
            {
                if (rslt2 == null || rslt2.Reports == null || rslt2.Reports.Report == null || rslt2.Reports.Report[0].FileContent == null)
                {
                    // Error OAC response or member is null
                    LogBox.Text += "Error: OAC response or member is null.." + Environment.NewLine;
                    return;
                }

                // File content contains base 64 encoded xml to retrieve info
                string encoded = rslt2.Reports.Report[0].FileContent;

                LogBox.Text += "File Content: " + Environment.NewLine;
                LogBox.Text += encoded + Environment.NewLine + Environment.NewLine;

                // Decode the message into byte array
                var decoded = Convert.FromBase64String(encoded);

                // Convert byte array to string
                string xmlMessage = Encoding.Default.GetString(decoded);
                if (xmlMessage.Trim() == "")
                {
                    LogBox.Text += "**** xml message is empty ****" + Environment.NewLine;
                }
                LogBox.Text += "xml message decoded is: " + Environment.NewLine;
                LogBox.Text += xmlMessage + Environment.NewLine + Environment.NewLine;

                while (true)
                {
                    int startIndex = xmlMessage.IndexOf("<ACTIVATION_CODE>");
                    if (startIndex < 0)
                    {
                        break;
                    }
                    int endIndex = xmlMessage.IndexOf("</ACTIVATION_CODE>");
                    int length   = endIndex - (startIndex + 17);
                    xmlMessage = xmlMessage.Remove(startIndex, length + 35);
                }
                itemNumbers.Clear();
                // Parse the message (in XML) MAKE SURE xmlMessage is NOT NULL
                try
                {
                    XElement str = XElement.Parse(xmlMessage);
                    LogBox.Text += "xml parsed." + Environment.NewLine;
                    //itemNumbers.Clear();
                    // find specific tag
                    foreach (XElement XE in str.Elements("ITEM_DETAILS"))
                    {
                        string number = XE.Descendants("OPTION_CODE").FirstOrDefault()?.Value;
                        string xmltag = XE.Descendants("XML_TAG").FirstOrDefault()?.Value;
                        if (xmltag != "SWOPT")
                        {
                            if (!itemNumbers.Contains(number))
                            {
                                itemNumbers.Add(number);
                            }
                        }
                        else
                        {
                            string opt = XE.Descendants("OPTION_NAME").FirstOrDefault()?.Value;
                            if (opt.Contains("Vivid"))
                            {
                                string[] pns = number.Split(',');
                                foreach (string pn in pns)
                                {
                                    if (!itemNumbers.Contains(pn))
                                    {
                                        itemNumbers.Add(pn);
                                    }
                                }
                            }
                        }
                    }

                    txtResponse.Text += "Item numbers found: " + (itemNumbers.Count == 0 ? "None" : "") + Environment.NewLine;
                    foreach (string item in itemNumbers)
                    {
                        txtResponse.Text += item + Environment.NewLine;
                    }
                }
                catch (Exception ex)
                {
                    LogBox.Text += Environment.NewLine + "Exception thrown when parsing. Message: " + ex.Message.ToString() + Environment.NewLine;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception when deserializing. Message: " + ex.Message.ToString());
            }
        }