Beispiel #1
0
        public void Load(string filename)
        {
            if (!File.Exists(filename))
            {
                throw new FileNotFoundException("File not found", filename);
            }

            // Get rid of the existing set of keys
            this._keys = new Dictionary <Guid, MsdnKey>();

            // Load the document
            XDocument doc      = XDocument.Load(filename);
            var       keyNodes = from productKey in doc.Element("YourKey").Elements("Product_Key")
                                 let key = productKey.Element("Key")
                                           where (int)int.Parse((string)key.Attribute("ID"), CultureInfo.InvariantCulture) != -3
                                           select new
            {
                Name    = (string)productKey.Attribute("Name"),
                Id      = int.Parse((string)key.Attribute("ID")),
                KeyText = (string)key.Value,
                Keys    = productKey.Elements("Key")
            };

            foreach (var keyNode in keyNodes)
            {
                // Convert the anonymous object to an MsdnKey object
                MsdnKey key = new MsdnKey();
                key.Name    = keyNode.Name;
                key.Id      = keyNode.Id;
                key.KeyText = keyNode.KeyText;

                // If this is an actual key (versus some CDATA'd HTML), add each key
                if (key.HasKey)
                {
                    foreach (XElement indKey in keyNode.Keys)
                    {
                        MsdnKey.IndividualKey ik = new MsdnKey.IndividualKey();
                        ik.ClaimedDate = MsdnKey.TryParseDateTime((string)indKey.Attribute("ClaimedDate"));
                        ik.KeyType     = (string)indKey.Attribute("Type");
                        ik.Key         = (string)indKey.Value;

                        key.AddKey(ik);
                    }
                }

                this._keys.Add(Guid.NewGuid(), key);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Shows the current record.
        /// </summary>
        private void ShowCurrentRecord()
        {
            if (null != this._dict)
            {
                foreach (ListViewItem item in this.productsListView.SelectedItems)
                {
                    MsdnKey selectedKey = this._dict[(Guid)item.Tag];
                    if (null != selectedKey)
                    {
                        if (selectedKey.HasKey)
                        {
                            this.productNameValueLabel.Text = selectedKey.Name;
                            this.keyIdValueLabel.Text       = selectedKey.Id.ToString(CultureInfo.InvariantCulture);
                            this.keysListView.Items.Clear();

                            foreach (MsdnKey.IndividualKey key in selectedKey.Keys)
                            {
                                ListViewItem keyItem = new ListViewItem(key.KeyType);
                                keyItem.SubItems.Add(null == key.ClaimedDate ? "" : ((DateTime)key.ClaimedDate).ToShortDateString());
                                keyItem.SubItems.Add(key.Key);
                                keyItem.Tag = key;

                                this.keysListView.Items.Add(keyItem);
                            }
                        }
                        else
                        {
                            this.webBrowser.Navigate("about:blank");
                            if (null != webBrowser.Document)
                            {
                                this.webBrowser.Document.Write(string.Empty);
                            }
                            this.webBrowser.DocumentText = "<html>" + selectedKey.CDATA + "</html>";
                        }

                        this.webBrowser.Visible = !selectedKey.HasKey;
                        this.panel.Visible      = selectedKey.HasKey;
                    }
                }
            }
        }
Beispiel #3
0
        private void OpenFile()
        {
            if (DialogResult.OK == this.openFileDialog.ShowDialog())
            {
                Cursor.Current = Cursors.WaitCursor;

                this.productsListView.Items.Clear();
                this.webBrowser.Visible = false;
                this.panel.Visible      = false;

                try
                {
                    KeysCollection collection = new KeysCollection(this.openFileDialog.FileName);
                    this._dict = collection.Keys;

                    foreach (Guid key in _dict.Keys)
                    {
                        // Get the actual data we care about
                        MsdnKey val = _dict[key];

                        // Create a new ListViewItem for this product
                        ListViewItem item = new ListViewItem(val.Name);
                        item.Tag = key;

                        // Add the item to the ListView
                        this.productsListView.Items.Add(item);
                    }
                }
                catch (FileNotFoundException)
                {
                    MessageBox.Show("File " + this.openFileDialog.FileName + " does not exist.", "KeysExport Viewer", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
                }

                Cursor.Current = Cursors.Default;
            }
        }
        public void Load(string filename)
        {
            if (!File.Exists(filename))
            {
                throw new FileNotFoundException("File not found", filename);
            }

            // Get rid of the existing set of keys
            this._keys = new Dictionary<Guid, MsdnKey>();

            // Load the document
            XDocument doc = XDocument.Load(filename);
            var keyNodes = from productKey in doc.Element("YourKey").Elements("Product_Key")
                let key = productKey.Element("Key")
                where (int)int.Parse((string)key.Attribute("ID"), CultureInfo.InvariantCulture) != -3
                select new
                {
                    Name = (string)productKey.Attribute("Name"),
                    Id = int.Parse((string)key.Attribute("ID")),
                    KeyText = (string)key.Value,
                    Keys = productKey.Elements("Key")
                };

            foreach (var keyNode in keyNodes)
            {
                // Convert the anonymous object to an MsdnKey object
                MsdnKey key = new MsdnKey();
                key.Name = keyNode.Name;
                key.Id = keyNode.Id;
                key.KeyText = keyNode.KeyText;

                // If this is an actual key (versus some CDATA'd HTML), add each key
                if (key.HasKey)
                {
                    foreach (XElement indKey in keyNode.Keys)
                    {
                        MsdnKey.IndividualKey ik = new MsdnKey.IndividualKey();
                        ik.ClaimedDate = MsdnKey.TryParseDateTime((string)indKey.Attribute("ClaimedDate"));
                        ik.KeyType = (string)indKey.Attribute("Type");
                        ik.Key = (string)indKey.Value;

                        key.AddKey(ik);
                    }
                }

                this._keys.Add(Guid.NewGuid(), key);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="IndividualKey"/> class.
 /// </summary>
 public IndividualKey()
 {
     this._claimedDate = MsdnKey.TryParseDateTime(null);
     this._keyType     = string.Empty;
     this._key         = string.Empty;
 }