コード例 #1
0
 /// <summary>
 /// Serves as a hash function for a particular type.
 /// </summary>
 /// <returns>
 /// A hash code for the current <see cref="T:System.Object"/>.
 /// </returns>
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = Name?.GetHashCode() ?? 0;
         hashCode = (hashCode * 397) ^ (Path?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (ConfigFilePath?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (FileSystemAssemblyName?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (GACAssemblyName?.GetHashCode() ?? 0);
         return(hashCode);
     }
 }
コード例 #2
0
        public override bool CanSave()
        {
            var canSave = HasChanged;

            if (canSave)
            {
                canSave = (!string.IsNullOrEmpty(FileSystemAssemblyName) && FileSystemAssemblyName.EndsWith(".dll")) ||
                          (!string.IsNullOrEmpty(GACAssemblyName) && GACAssemblyName.StartsWith("GAC:"));
            }

            return(canSave);
        }
コード例 #3
0
#pragma warning disable S1541 // Methods and properties should not be too complex
        public override int GetHashCode()
#pragma warning restore S1541 // Methods and properties should not be too complex
        {
            unchecked
            {
                var hashCode = Name?.GetHashCode() ?? 0;
                hashCode = (hashCode * 397) ^ (Path?.GetHashCode() ?? 0);
                hashCode = (hashCode * 397) ^ (ConfigFilePath?.GetHashCode() ?? 0);
                hashCode = (hashCode * 397) ^ (FileSystemAssemblyName?.GetHashCode() ?? 0);
                hashCode = (hashCode * 397) ^ (GACAssemblyName?.GetHashCode() ?? 0);
                return(hashCode);
            }
        }
コード例 #4
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;
            }
        }