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 IsDirectory_Given_Drive_Returns_True()
        {
            const string resourcesPath = @"C:\\";
            var          results       = Dev2ActivityIOPathUtils.IsDirectory(resourcesPath);

            Assert.IsTrue(results);
        }
        public void IsStarWildCard_Given_Star_In_Path_Returns_True()
        {
            const string resourcesPath = @"C:\ProgramData\Warewolf\*.*";
            var          results       = Dev2ActivityIOPathUtils.IsStarWildCard(resourcesPath);

            Assert.IsTrue(results);
        }
        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);
        }
示例#6
0
            public enPathType PathIs(IActivityIOPath path)
            {
                var result = enPathType.File;

                if (Dev2ActivityIOPathUtils.IsDirectory(path.Path))
                {
                    result = enPathType.Directory;
                }
                return(result);
            }
示例#7
0
        public enPathType PathIs(IActivityIOPath path)
        {
            enPathType result = enPathType.File;

            // WARN : here for now because FTP has no way of knowing of the user wants a directory or file?!?!
            if (Dev2ActivityIOPathUtils.IsDirectory(path.Path))
            {
                result = enPathType.Directory;
            }
            return(result);
        }
示例#8
0
        public static void DeleteAuthedUNCPath(string path, bool inDomain = false)
        {
            const int LOGON32_PROVIDER_DEFAULT = 0;
            //This parameter causes LogonUser to create a primary token.
            const int LOGON32_LOGON_INTERACTIVE = 2;

            // handle UNC path
            SafeTokenHandle safeTokenHandle;

            try
            {
                bool loginOk = LogonUser(ParserStrings.PathOperations_Correct_Username, inDomain ? "DEV2" : string.Empty, ParserStrings.PathOperations_Correct_Password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, out safeTokenHandle);

                if (loginOk)
                {
                    using (safeTokenHandle)
                    {
                        WindowsIdentity newID = new WindowsIdentity(safeTokenHandle.DangerousGetHandle());
                        using (WindowsImpersonationContext impersonatedUser = newID.Impersonate())
                        {
                            // Do the operation here
                            if (Dev2ActivityIOPathUtils.IsDirectory(path))
                            {
                                Directory.Delete(path, true);
                            }
                            else
                            {
                                File.Delete(path);
                            }

                            // remove impersonation now
                            impersonatedUser.Undo();
                        }
                    }
                }
                else
                {
                    // login failed
                    throw new Exception("Failed to authenticate for resource [ " + path + " ] ");
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public static enPathType PathIs(IActivityIOPath path, IFile fileWrapper, IDirectory dirWrapper)
        {
            if (Dev2ActivityIOPathUtils.IsDirectory(path.Path))
            {
                return(enPathType.Directory);
            }

            if ((FileExist(path, fileWrapper) || DirectoryExist(path, dirWrapper)) &&
                !Dev2ActivityIOPathUtils.IsStarWildCard(path.Path))
            {
                var fa = fileWrapper.GetAttributes(path.Path);
                if ((fa & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    return(enPathType.Directory);
                }
            }
            return(enPathType.File);
        }
示例#10
0
 static bool IsDirectory(string part) => Dev2ActivityIOPathUtils.IsDirectory(part) || part.ToLower(CultureInfo.InvariantCulture).Contains(@"<dir>");
示例#11
0
 static bool IsDirectory(string part)
 {
     return(Dev2ActivityIOPathUtils.IsDirectory(part) || part.ToLower().Contains(@"<dir>"));
 }
示例#12
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;
            }
        }