Ejemplo n.º 1
0
        /// <summary>
        /// Checks whether the DLL defines an Omea plugin, and adds registration for it, if that is the case.
        /// </summary>
        private static void RegisterPlugin(AssemblyXml assemblyxml, File wixFileAssembly, Component wixComponentRegistry)
        {
            Assembly assembly = Assembly.Load(assemblyxml.Include);

            foreach (Type type in assembly.GetTypes())
            {
                if (type.ContainsGenericParameters)
                {
                    continue;                     // Generics cannot be plugins
                }
                if (type.FindInterfaces(delegate(Type m, object filterCriteria) { return((m.Name == "IPlugin") && (m.Assembly.GetName().Name == "OpenAPI")); }, null).Length == 0)
                {
                    continue;                     // Not a single plugin in this DLL
                }
                // Yes, it's a plugin — produce registration in the Registry
                var wixRegValue = new RegistryValue();
                wixComponentRegistry.AddChild(wixRegValue);
                wixRegValue.Id     = string.Format("{0}.Plugin.{1}", RegistryValueIdPrefix, assemblyxml.Include);
                wixRegValue.Action = RegistryValue.ActionType.write;
                wixRegValue.Root   = RegistryRootType.HKMU;
                wixRegValue.Key    = PluginsRegistryKey;
                wixRegValue.Name   = Regex.Replace(assemblyxml.Include, "(.+?)(Plugin)?", "$1");
                wixRegValue.Type   = RegistryValue.TypeType.@string;
                wixRegValue.Value  = string.Format("[#{0}]", wixFileAssembly.Id);
            }
        }
Ejemplo n.º 2
0
        private BaseQueryResolverArgs Build(AssemblyXml xml, string connectionString, IEnumerable <IQueryParameter> parameters, IEnumerable <IQueryTemplateVariable> templateVariables, TimeSpan timeout)
        {
            var file = GetFullPath(xml?.Settings?.BasePath, xml.Path);

            return(new AssemblyQueryResolverArgs(
                       file, xml.Klass, xml.Method,
                       xml.Static, xml.GetMethodParameters()
                       , connectionString, parameters, templateVariables, timeout));
        }
Ejemplo n.º 3
0
        public void Save(AssemblyDto model)
        {
            AssemblyXml assemblyXml = Mapper.Map <AssemblyXml>(model);

            DataContractSerializer dataContractSerializer =
                new DataContractSerializer(typeof(AssemblyXml));

            using (FileStream fileStream = new FileStream(path, FileMode.Create))
            {
                dataContractSerializer.WriteObject(fileStream, assemblyXml);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Harvests the satellite files for an assembly.
        /// </summary>
        /// <param name="sFileLocalName">Local name (without path, but with extension) of the file to seek for.</param>
        /// <param name="errorlevel">How to treat the missing file.</param>
        /// <param name="sSatelliteDisplayName">Display name of the satellite to be included into the error message.</param>
        /// <param name="wixparent">The parent component to mount the new entry into.</param>
        /// <param name="assemblyxml">The assembly for which we're seeking for satellites.</param>
        private void HarvestSatellite(AssemblyXml assemblyxml, string sFileLocalName, IParentElement wixparent, MissingSatelliteErrorLevel errorlevel, string sSatelliteDisplayName, Dictionary <string, string> mapTargetFiles)
        {
            if (sFileLocalName == null)
            {
                throw new ArgumentNullException("sFileLocalName");
            }
            if (sSatelliteDisplayName == null)
            {
                throw new ArgumentNullException("sSatelliteDisplayName");
            }
            if (wixparent == null)
            {
                throw new ArgumentNullException("wixparent");
            }

            // Full path
            var fi = new FileInfo(Path.Combine(Bag.GetString(AttributeName.ProductBinariesDir), sFileLocalName));

            // Missing?
            if (!fi.Exists)
            {
                string sErrorMessage = string.Format("Could not locate the {2} for the “{0}” assembly. The expected full path is “{1}”.", assemblyxml.Include, fi.FullName, sSatelliteDisplayName);
                switch (errorlevel)
                {
                case MissingSatelliteErrorLevel.None:
                    break;                     // Ignore

                case MissingSatelliteErrorLevel.Warning:
                    Log.LogWarning(sErrorMessage);
                    break;

                case MissingSatelliteErrorLevel.Error:
                    throw new InvalidOperationException(sErrorMessage);

                default:
                    throw new ArgumentOutOfRangeException("errorlevel", errorlevel, "Oops.");
                }
                return;
            }

            // Create an entry
            var wixFile = new File();

            wixparent.AddChild(wixFile);
            wixFile.Id       = string.Format("{0}{1}", FileIdPrefix, fi.Name);
            wixFile.Name     = fi.Name;
            wixFile.KeyPath  = YesNoType.no;
            wixFile.Checksum = YesNoType.no;
            wixFile.Vital    = YesNoType.no;

            RegisterTargetFile(wixFile.Name, string.Format("Satellite for the {0} product assembly.", assemblyxml.Include), mapTargetFiles);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Checks for the existing files and choses the assembly extension from the list, eg “exe” or “dll”.
        /// Throws if not found.
        /// </summary>
        public FileInfo FindAssemblyFile(AssemblyXml assemblyxml)
        {
            var sbProbingPaths = new StringBuilder();

            foreach (string sExtension in AssemblyExtensions.Split(';'))
            {
                string sProbingPath = Path.Combine(Bag.GetString(AttributeName.ProductBinariesDir), string.Format("{0}.{1}", assemblyxml.Include, sExtension));
                var    fi           = new FileInfo(sProbingPath);
                if (fi.Exists)
                {
                    return(fi);
                }
                sbProbingPaths.AppendLine();
                sbProbingPaths.Append(sProbingPath);
            }
            throw new InvalidOperationException(string.Format("Could not locate the “{0}” assembly in the “{1}” product binaries directory. The probing paths are listed below.{2}", assemblyxml.Include, Bag.GetString(AttributeName.ProductBinariesDir), sbProbingPaths));
        }
Ejemplo n.º 6
0
        private void HarvestPublisherPolicyAssemblies(AssemblyXml assemblyxml, Directory directory, ComponentGroup componentgroup, ref int nGeneratedComponents, Dictionary <string, string> mapTargetFiles, GuidCacheXml guidcachexml)
        {
            if (!Bag.Get <bool>(AttributeName.IncludePublisherPolicy))
            {
                return;
            }

            int    nWasGeneratedComponents = nGeneratedComponents;
            var    diFolder           = new DirectoryInfo(Bag.GetString(AttributeName.ProductBinariesDir));
            string sSatelliteWildcard = string.Format("Policy.*.{0}.{1}", assemblyxml.Include, "dll");             // Even an EXE assembly has a DLL policy file

            foreach (FileInfo fiPolicyAssembly in diFolder.GetFiles(sSatelliteWildcard))
            {
                // Find the companion policy config file
                var fiPolicyConfig = new FileInfo(Path.ChangeExtension(fiPolicyAssembly.FullName, ".Config"));
                if (!fiPolicyConfig.Exists)
                {
                    throw new InvalidOperationException(string.Format("Could not locate the publisher policy config file for the assembly “{0}”; expected: “{1}”.", fiPolicyAssembly.FullName, fiPolicyConfig.FullName));
                }

                // We have to create a new component for each of the DLLs we'd like to GAC as publisher policy assemblies
                nGeneratedComponents++;

                // Create the component for the assembly (one per assembly)
                var component = new Component();
                directory.AddChild(component);
                component.Id       = string.Format("{0}.{1}", FileComponentIdPrefix, fiPolicyAssembly.Name);
                component.Guid     = guidcachexml[assemblyxml.Include + " PublisherPolicy"].ToString("B").ToUpper();
                component.DiskId   = Bag.Get <int>(AttributeName.DiskId);
                component.Location = Component.LocationType.local;

                // Register component in the group
                var componentref = new ComponentRef();
                componentgroup.AddChild(componentref);
                componentref.Id = component.Id;

                // Add the assembly file (and make it the key path)
                var fileAssembly = new File();
                component.AddChild(fileAssembly);
                fileAssembly.Id       = string.Format("{0}.{1}", FileIdPrefix, fiPolicyAssembly.Name);
                fileAssembly.Name     = fiPolicyAssembly.Name;
                fileAssembly.KeyPath  = YesNoType.yes;
                fileAssembly.Checksum = YesNoType.yes;
                fileAssembly.Vital    = YesNoType.no;
                fileAssembly.Assembly = File.AssemblyType.net;
                fileAssembly.ReadOnly = YesNoType.yes;

                RegisterTargetFile(fileAssembly.Name, string.Format("Publisher policy assembly file for the {0} product assembly.", assemblyxml.Include), mapTargetFiles);

                // Add the policy config file
                var filePolicy = new File();
                component.AddChild(filePolicy);
                filePolicy.Id       = string.Format("{0}.{1}", FileIdPrefix, fiPolicyConfig.Name);
                filePolicy.Name     = fiPolicyConfig.Name;
                filePolicy.KeyPath  = YesNoType.no;
                filePolicy.Checksum = YesNoType.yes;
                filePolicy.Vital    = YesNoType.no;
                filePolicy.ReadOnly = YesNoType.yes;

                RegisterTargetFile(fileAssembly.Name, string.Format("Publisher policy configuration file for the {0} product assembly.", assemblyxml.Include), mapTargetFiles);
            }

            if (nWasGeneratedComponents == nGeneratedComponents)            // None were actually collected
            {
                throw new InvalidOperationException(string.Format("Could not locate the Publisher Policy assemblies for the “{0}” assembly. The expected full path is “{1}\\{2}”.", assemblyxml.Include, diFolder.FullName, sSatelliteWildcard));
            }
        }