public override IList <IActivityIOPath> ExecuteOperation() { try { if (_impersonatedUser != null) { return(ExecuteOperationWithAuth()); } if (!Dev2ActivityIOPathUtils.IsStarWildCard(_newPath)) { if (_dirWrapper.Exists(_newPath)) { return(AddDirsToResults(GetDirectoriesForType(_newPath, string.Empty, _type, _dirWrapper), _path)); } throw new Exception(string.Format(ErrorResource.DirectoryDoesNotExist, _newPath)); } var baseDir = Dev2ActivityIOPathUtils.ExtractFullDirectoryPath(_newPath); var pattern = Dev2ActivityIOPathUtils.ExtractFileName(_newPath); return(AddDirsToResults(GetDirectoriesForType(baseDir, pattern, _type, _dirWrapper), _path)); } catch (Exception exception) { Dev2Logger.Error(exception, GlobalConstants.WarewolfError); throw new Exception(string.Format(ErrorResource.DirectoryNotFound, _path.Path)); } }
public void ExtractFullDirectoryPath_Given_Directory() { const string resourcesPath = @"C:\ProgramData\Warewolf\Resources"; var fullDir = Dev2ActivityIOPathUtils.ExtractFullDirectoryPath(resourcesPath); Assert.AreEqual(resourcesPath, fullDir); }
public void ExtractFullDirectoryPath_Given_FilePath() { const string serverLogFile = @"C:\ProgramData\Warewolf\Server Log\wareWolf-Server.log"; const string containingFolder = @"C:\ProgramData\Warewolf\Server Log\"; var results = Dev2ActivityIOPathUtils.ExtractFullDirectoryPath(serverLogFile); Assert.AreEqual(containingFolder, results); }
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; } }