Esempio n. 1
0
        private bool ReadConfiguration(out string error)
        {
            XmlNamespaceManager    ns_mgr;
            XmlDocument            doc;
            XmlNodeList            nodes;
            XmlNode                node;
            SigningKey             key;
            DllReference           reference;
            DllToSign              sign;
            ResignAssemblyResolver resolver;

            error    = string.Empty;
            resolver = new ResignAssemblyResolver(this);
            try {
                doc = new XmlDocument();
                doc.Load(configuration_file);
                ns_mgr = new XmlNamespaceManager(doc.NameTable);

                node = doc.SelectSingleNode("/resign/sign");
                if (node != null)
                {
                    reference_dir = GetAttribute(node, "referencedir", string.Empty);
                }

                nodes = doc.SelectNodes("/resign/signingkey");
                foreach (XmlNode key_node in nodes)
                {
                    key           = new SigningKey();
                    key.Name      = GetAttribute(key_node, "name", string.Empty);
                    key.Filename  = GetAttribute(key_node, "file", string.Empty);
                    key.Container = GetAttribute(key_node, "container", string.Empty);
                    if (!string.IsNullOrEmpty(key.Filename) && !File.Exists(key.Filename))
                    {
                        error = "signingkey tag '" + key.Name + "' references non-existing file '" + key.Filename + "'";
                        return(false);
                    }

                    keys.Add(key.Name, key);
                }

                nodes = doc.SelectNodes("/resign/references/dll");
                foreach (XmlNode ref_node in nodes)
                {
                    reference          = new DllReference();
                    reference.Name     = GetAttribute(ref_node, "name", string.Empty);
                    reference.Filename = GetAttribute(ref_node, "path", string.Empty);
                    if (!File.Exists(reference.Filename))
                    {
                        error = "references/dll tag '" + reference.Name + "' references non-existing file '" + reference.Filename + "'";
                        return(false);
                    }
                    references.Add(Path.GetFileNameWithoutExtension(reference.Name), reference);
                }

                nodes = doc.SelectNodes("/resign/sign/dll");
                foreach (XmlNode dll_node in nodes)
                {
                    sign          = new DllToSign(resolver);
                    sign.Filename = GetAttribute(dll_node, "path", string.Empty);
                    if (!File.Exists(sign.Filename))
                    {
                        error = "dll tag references non-existing path '" + sign.Filename + "'";
                        return(false);
                    }

                    sign.Key = GetAttribute(dll_node, "key", string.Empty);
                    if (!keys.Keys.Contains(sign.Key))
                    {
                        error = "dll tag '" + sign.Filename + "' references undefined key '" + sign.Key;
                        return(false);
                    }
                    signdlls.Add(sign);
                }

                node               = doc.SelectSingleNode("/resign/sign");
                output_dir         = GetAttribute(node, "outputdir", string.Empty);
                only_sign_on_match = GetAttribute(node, "changedonly", true);

                return(true);
            } catch (Exception ex) {
                error = ex.ToString();
                return(false);
            }
        }
Esempio n. 2
0
 public DllToSign(ResignAssemblyResolver resolver)
 {
     this.resolver = resolver;
 }