コード例 #1
0
        /// <param name="cfg">IModeCSharp configuration</param>
        /// <param name="msbuild">Flag of supporting MSBuild properties.</param>
        /// <returns>Prepared list of references</returns>
        protected string[] constructReferences(IModeCSharp cfg, bool msbuild)
        {
            if (cfg.References == null)
            {
                return(new string[] { });
            }

            if (!cfg.SmartReferences)
            {
                return(cfg.References
                       .Where(r => !String.IsNullOrEmpty(r))
                       .Select(r => (msbuild)? cmd.MSBuild.parse(r) : r)
                       .ToArray());
            }

            GAC gac = new GAC();

            return(cfg.References
                   .Where(r => !String.IsNullOrEmpty(r))
                   .Select(r =>
                           gac.getPathToAssembly(
                               (msbuild)? cmd.MSBuild.parse(r) : r,
                               true
                               )
                           )
                   .ToArray());
        }
コード例 #2
0
ファイル: AssemblyManager.cs プロジェクト: AlexKub/Cube
        /// <summary>
        /// Регистрация сборки через RegAsm
        /// </summary>
        /// <param name="asm">Ссылка на файл сборки</param>
        /// <param name="force">Флаг принудительной операции</param>
        /// <returns>Возвращает результат операции</returns>
        public static RegistrationResult UnInstall_GAC(FileInfo asm)
        {
            return(GAC.UnInstallAssembly(asm));

            //string command = $"/u"
            //    + (force ? "f" : "")
            //    + " "
            //    + Path.GetFileNameWithoutExtension(asm.FullName);
            ////string command = "/i " + asm.FullName + (force ? " /f" : "");
            //return RunHiddenProcess(RegAsmPath, command);
        }
コード例 #3
0
        protected override Assembly Load(AssemblyName assemblyName)
        {
            var useAssembly = ReferencedAssemblies.FirstOrDefault(x => x.Name == assemblyName.Name);

            string dll;

            if (useAssembly != null)
            {
                dll = GAC.GetAssemblyFile(useAssembly.Name, useAssembly.Version, Framework, GACFolders.All, new[] { LocationDirectory });
            }
            else
            {
                dll = GAC.GetAssemblyFile(assemblyName.Name, assemblyName.Version, Framework, GACFolders.All, new[] { LocationDirectory });
            }

            return(LoadFromAssemblyPath(dll));
        }
コード例 #4
0
        public StringBuilder Execute(Dictionary <string, StringBuilder> values, IWorkspace theWorkspace)
        {
            SortedSet <string> gacList = new SortedSet <string>();

            StringBuilder result = new StringBuilder();

            Dev2Logger.Log.Info("Registered Assembly");
            try
            {
                IAssemblyName assemblyName;
                IAssemblyEnum assemblyEnum = GAC.CreateGACEnum();
                string        json         = "[";
                while (GAC.GetNextAssembly(assemblyEnum, out assemblyName) == 0)
                {
                    try
                    {
                        gacList.Add(GAC.GetDisplayName(assemblyName, ASM_DISPLAY_FLAGS.VERSION | ASM_DISPLAY_FLAGS.CULTURE | ASM_DISPLAY_FLAGS.PUBLIC_KEY_TOKEN));
                    }
                    catch (Exception e)
                    {
                        Dev2Logger.Log.Error(e.Message);
                    }
                }

                // now process each sorted entry
                foreach (string entry in gacList)
                {
                    json += @"{""AssemblyName"":""" + entry + @"""}";
                    json += ",";
                }

                json += "]";
                json  = json.Replace(",]", "]"); //remove the last comma in the string in order to have valid json
                result.Append("<JSON>");
                result.Append(json);
                result.Append("</JSON>");
            }
            catch (Exception ex)
            {
                Dev2Logger.Log.Error(ex);
                result.Append(ex.Message);
            }

            return(result);
        }
コード例 #5
0
ファイル: AssemblyManager.cs プロジェクト: AlexKub/Cube
 string DebugDisplay()
 {
     return("GAC: " + GAC.ToString() + " | RegAsm: " + RegAsm.ToString() + " | RegSvr: " + RegSvr32.ToString());
 }
コード例 #6
0
ファイル: AssemblyManager.cs プロジェクト: AlexKub/Cube
 /// <summary>
 /// Регистрация сборки через RegAsm
 /// </summary>
 /// <param name="asm">Ссылка на файл сборки</param>
 /// <param name="force">Флаг принудительной установки</param>
 /// <returns>Возвращает результат операции</returns>
 public static RegistrationResult Install_GAC(FileInfo asm)
 {
     return(GAC.ReInstallAssembly(asm));
     //string command = "/i " + asm.FullName + (force ? " /f" : "");
     //return RunHiddenProcess(RegAsmPath, command);
 }
コード例 #7
0
        /// <param name="cfg">IModeCSharp configuration</param>
        /// <param name="msbuild">Flag of supporting MSBuild properties.</param>
        /// <returns>Prepared list of references</returns>
        protected string[] constructReferences(IModeCSharp cfg, bool msbuild)
        {
            if(cfg.References == null) {
                return new string[] { };
            }

            if(!cfg.SmartReferences)
            {
                return cfg.References
                            .Where(r => !String.IsNullOrEmpty(r))
                            .Select(r => (msbuild)? cmd.MSBuild.parse(r) : r)
                            .ToArray();
            }

            GAC gac = new GAC();
            return cfg.References
                        .Where(r => !String.IsNullOrEmpty(r))
                        .Select(r =>
                                    gac.getPathToAssembly(
                                            (msbuild)? cmd.MSBuild.parse(r) : r,
                                            true
                                    )
                                )
                        .ToArray();
        }
コード例 #8
0
        public string Execute(IDictionary <string, string> values, IWorkspace theWorkspace)
        {
            try
            {
                string asmLoc;
                string protectionLevel;
                string nameSpace;
                string methodName;

                values.TryGetValue("AssemblyLocation", out asmLoc);
                values.TryGetValue("ProtectionLevel", out protectionLevel);
                values.TryGetValue("NameSpace", out nameSpace);
                values.TryGetValue("MethodName", out methodName);


                if (string.IsNullOrEmpty(asmLoc) || string.IsNullOrEmpty(nameSpace) || string.IsNullOrEmpty(methodName))
                {
                    throw new InvalidDataContractException("AssemblyLoation or NameSpace or MethodName is missing");
                }

                var pluginData = new StringBuilder();

                asmLoc = asmLoc.Replace(@"//", "/");

                // new app domain to avoid security concerns resulting from blinding loading code into Server's space
                AppDomainSetup       setup   = AppDomain.CurrentDomain.SetupInformation;
                IEnumerable <string> plugins = null;

                AppDomain pluginDomain = AppDomain.CreateDomain("PluginMetaDataDiscoveryDomain", null, setup);

                string baseLocation;
                string gacQualifiedName = String.Empty;

                if (asmLoc == string.Empty || asmLoc.StartsWith("Plugins"))
                {
                    setup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory + @"Plugins\";

                    baseLocation = @"Plugins\";

                    plugins = asmLoc == string.Empty ? Directory.EnumerateFiles(pluginDomain.BaseDirectory) : new[] { pluginDomain.BaseDirectory + asmLoc.Replace("/", @"\") };
                }
                else
                {
                    if (asmLoc.StartsWith(GlobalConstants.GACPrefix))
                    {
                        baseLocation = GlobalConstants.GACPrefix;
                        // we have a plugin loaded into the global assembly cache
                        gacQualifiedName = asmLoc.Substring(4);
                    }
                    else
                    {
                        baseLocation = Dev2ActivityIOPathUtils.ExtractFullDirectoryPath(asmLoc);
                        // we have a plugin relative to the file system
                        plugins = new[] { asmLoc };
                    }
                }

                const bool IncludePublic  = true;
                bool       includePrivate = true;

                // default to all if no params
                if (protectionLevel != string.Empty)
                {
                    // only include public methods
                    if (protectionLevel != null && protectionLevel.ToLower() == "public")
                    {
                        includePrivate = false;
                    }
                }

                if (plugins != null)
                {
                    plugins
                    .ToList()
                    .ForEach(plugin =>
                    {
                        int pos          = plugin.LastIndexOf(@"\", StringComparison.Ordinal);
                        pos             += 1;
                        string shortName = plugin.Substring(pos, (plugin.Length - pos));

                        // only attempt to load assemblies
                        if (shortName.EndsWith(".dll"))
                        {
                            try
                            {
                                Assembly asm = Assembly.LoadFrom(plugin);

                                // only include matching references
                                InterogatePluginAssembly(pluginData, asm, shortName, baseLocation + shortName,
                                                         IncludePublic, includePrivate, methodName, nameSpace);

                                // remove the plugin
                                try
                                {
                                    Assembly.UnsafeLoadFrom(plugin);
                                }
                                catch (Exception ex)
                                {
                                    Dev2Logger.Log.Error(ex);
                                }
                            }
                            catch (Exception ex)
                            {
                                Dev2Logger.Log.Error(ex);
                                pluginData.Append("<Dev2Plugin><Dev2PluginName>" + shortName + "</Dev2PluginName>");
                                pluginData.Append(
                                    "<Dev2PluginStatus>Error</Dev2PluginStatus><Dev2PluginStatusMessage>");
                                pluginData.Append(ex.Message + "</Dev2PluginStatusMessage>");
                                pluginData.Append("<Dev2PluginSourceNameSpace></Dev2PluginSourceNameSpace>");
                                pluginData.Append("<Dev2PluginSourceLocation>" + baseLocation + shortName +
                                                  "</Dev2PluginSourceLocation>");
                                pluginData.Append("<Dev2PluginExposedMethod></Dev2PluginExposedMethod>");
                                pluginData.Append("</Dev2Plugin>");
                            }
                        }
                    });
                }
                else if (!String.IsNullOrEmpty(gacQualifiedName))
                {
                    GACAssemblyName gacName = GAC.TryResolveGACAssembly(gacQualifiedName);

                    if (gacName == null)
                    {
                        if (GAC.RebuildGACAssemblyCache(true))
                        {
                            gacName = GAC.TryResolveGACAssembly(gacQualifiedName);
                        }
                    }

                    if (gacName != null)
                    {
                        try
                        {
                            Assembly asm = Assembly.Load(gacName.ToString());
                            InterogatePluginAssembly(pluginData, asm, gacName.Name, baseLocation + gacName, IncludePublic,
                                                     includePrivate, methodName, nameSpace);
                        }
                        catch (Exception ex)
                        {
                            Dev2Logger.Log.Error(ex);
                            pluginData.Append("<Dev2Plugin><Dev2PluginName>" + gacName.Name + "</Dev2PluginName>");
                            pluginData.Append("<Dev2PluginStatus>Error</Dev2PluginStatus><Dev2PluginStatusMessage>");
                            pluginData.Append(ex.Message + "</Dev2PluginStatusMessage>");
                            pluginData.Append("<Dev2PluginSourceNameSpace></Dev2PluginSourceNameSpace>");
                            pluginData.Append("<Dev2PluginSourceLocation>" + baseLocation + gacName +
                                              "</Dev2PluginSourceLocation>");
                            pluginData.Append("<Dev2PluginExposedMethod></Dev2PluginExposedMethod>");
                            pluginData.Append("</Dev2Plugin>");
                        }
                    }
                }

                AppDomain.Unload(pluginDomain);

                string theResult = "<Dev2PluginRegistration>" + pluginData + "</Dev2PluginRegistration>";

                return(theResult);
            }
            catch (Exception e)
            {
                Dev2Logger.Log.Error(e);
                throw;
            }
        }