示例#1
0
        private void XmlDrop(object sender, DragEventArgs e)
        {
            var dropped = ((string[])e.Data.GetData(DataFormats.FileDrop));
            var files   = dropped.ToList();

            if (!files.Any())
            {
                return;
            }

            if (files.Count > 1)
            {
                TopMessageBox.Show("Drop only 1 file!", "Warning");
                return;
            }

            FileAttributes attr = File.GetAttributes(files[0]);

            if (attr.HasFlag(FileAttributes.Directory) || Path.GetExtension(files[0]).ToLower() != ".xml")
            {
                TopMessageBox.Show("This application accepts only XML files", "Warning");
                return;
            }

            ValidaXml(files[0]);
        }
示例#2
0
        private void ValidaXml(string arquivo)
        {
            try {
                XmlDocument x = new XmlDocument();
                x.Load(arquivo);

                bool valid = SignVerify(x);

                if (valid)
                {
                    Result.Text      = "Valid";
                    Result.ForeColor = Color.Green;
                }
                else
                {
                    Result.Text      = "Invalid";
                    Result.ForeColor = Color.Red;
                }
            } catch (Exception e) {
                if (e is XmlException)
                {
                    TopMessageBox.Show("Error parsing file as an XML.\n\nIs this a valid XML file?", "Error!");
                }
                else
                {
                    TopMessageBox.Show(e.GetBaseException().Message, "Error!");
                }
            }
        }