Esempio n. 1
0
        bool Execute()
        {
            SourcePath = STEM.Sys.IO.Path.AdjustPath(SourcePath);
            try
            {
                List <string> files = null;

                if (!ExpandSource && !RecurseSource && !FileFilter.Contains("|") && !FileFilter.Contains("!") && !FileFilter.Contains("<>") && !FileFilter.Contains("?") && !FileFilter.Contains("*"))
                {
                    files = new List <string>();
                    files.Add(Path.Combine(SourcePath, FileFilter));
                }
                else
                {
                    files = STEM.Sys.IO.Directory.STEM_GetFiles(SourcePath, FileFilter, DirectoryFilter, (RecurseSource ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly), ExpandSource);
                }

                foreach (string file in files)
                {
                    try
                    {
                        if (System.IO.File.Exists(file))
                        {
                            STEM.Sys.IO.File.STEM_Delete(file, false, Retry, RetryDelaySeconds);
                            AppendToMessage(file + " deleted");
                        }
                    }
                    catch (Exception ex)
                    {
                        AppendToMessage(ex.ToString());
                        Exceptions.Add(ex);
                    }
                }

                if (DeleteEmptyDirectories)
                {
                    if (RecurseSource)
                    {
                        foreach (string dir in STEM.Sys.IO.Directory.STEM_GetDirectories(SourcePath, DirectoryFilter, SearchOption.AllDirectories, ExpandSource))
                        {
                            try
                            {
                                if (Directory.GetFiles(dir, "*", SearchOption.AllDirectories).Length == 0)
                                {
                                    Directory.Delete(dir, true);
                                    AppendToMessage(dir + " deleted");
                                }
                            }
                            catch (Exception ex)
                            {
                                AppendToMessage(ex.ToString());
                                Exceptions.Add(ex);
                            }
                        }
                    }

                    if (Directory.GetFiles(SourcePath, "*", SearchOption.AllDirectories).Length == 0)
                    {
                        Directory.Delete(SourcePath, true);
                        AppendToMessage(SourcePath + " deleted");
                    }
                }
            }
            catch (Exception ex)
            {
                AppendToMessage(ex.ToString());
                Exceptions.Add(ex);
            }

            return(Exceptions.Count == 0);
        }
Esempio n. 2
0
        bool Execute()
        {
            try
            {
                if (InstructionSet.InstructionSetContainer.ContainsKey(Authentication.ConfigurationName + ".FtpClientAddress"))
                {
                    InstructionSet.InstructionSetContainer[Authentication.ConfigurationName + ".FtpClientAddress"] = Authentication.TargetAddress((string)InstructionSet.InstructionSetContainer[Authentication.ConfigurationName + ".FtpClientAddress"]);
                }
                else
                {
                    InstructionSet.InstructionSetContainer[Authentication.ConfigurationName + ".FtpClientAddress"] = Authentication.TargetAddress(null);
                }

                List <string> files = null;

                if (!ExpandSource && !RecurseSource && !FileFilter.Contains("|") && !FileFilter.Contains("!") && !FileFilter.Contains("<>") && !FileFilter.Contains("?") && !FileFilter.Contains("*"))
                {
                    files = new List <string>();
                    files.Add(Path.Combine(SourcePath, FileFilter));
                }
                else
                {
                    files = Authentication.ListDirectory(SourcePath, Sys.IO.Listing.ListingType.File, RecurseSource, DirectoryFilter, FileFilter).Select(i => Authentication.ToString(i)).ToList();
                }

                foreach (string file in files)
                {
                    try
                    {
                        Authentication.DeleteFile(file);
                        AppendToMessage(file + " deleted");
                    }
                    catch (Exception ex)
                    {
                        AppendToMessage(ex.ToString());
                        Exceptions.Add(ex);
                    }
                }

                if (DeleteEmptyDirectories)
                {
                    if (RecurseSource)
                    {
                        foreach (FtpListItem dir in Authentication.ListDirectory(SourcePath, Sys.IO.Listing.ListingType.Directory, true, DirectoryFilter, "*"))
                        {
                            try
                            {
                                Authentication.DeleteDirectory(Authentication.ToString(dir), true, false);
                            }
                            catch { }
                        }
                    }

                    try
                    {
                        Authentication.DeleteDirectory(SourcePath, true, false);
                    }
                    catch { }
                }
            }
            catch (Exception ex)
            {
                AppendToMessage(ex.ToString());
                Exceptions.Add(ex);
            }

            return(Exceptions.Count == 0);
        }
Esempio n. 3
0
        bool Execute()
        {
            try
            {
                List <string> sources = new List <string>();
                if (ExpandSource)
                {
                    sources = STEM.Sys.IO.Path.ExpandRangedPath(SourcePath);
                }
                else
                {
                    sources.Add(SourcePath);
                }

                List <string> destinations = new List <string>();
                if (ExpandDestination)
                {
                    Random rnd = new Random();

                    if (DestinationActionRule == DestinationRule.FirstSuccess)
                    {
                        destinations = STEM.Sys.IO.Path.OrderPathsWithSubnet(DestinationPath, STEM.Sys.IO.Net.MachineIP());
                    }
                    else
                    {
                        destinations = STEM.Sys.IO.Path.ExpandRangedPath(DestinationPath).OrderBy(i => rnd.Next()).ToList();
                    }
                }
                else
                {
                    destinations.Add(DestinationPath);
                }

                int filesActioned = 0;

                foreach (string src in sources)
                {
                    List <string> files = null;

                    if (!RecurseSource && !FileFilter.Contains("|") && !FileFilter.Contains("!") && !FileFilter.Contains("<>") && !FileFilter.Contains("?") && !FileFilter.Contains("*"))
                    {
                        files = new List <string>();
                        files.Add(Path.Combine(src, FileFilter));
                    }
                    else
                    {
                        files = STEM.Sys.IO.Directory.STEM_GetFiles(src, FileFilter, DirectoryFilter, (RecurseSource ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly), false);
                    }

                    foreach (string s in files)
                    {
                        try
                        {
                            bool success = false;

                            Exception lastEX = null;

                            foreach (string d in destinations)
                            {
                                try
                                {
                                    string dFile = "";
                                    try
                                    {
                                        if (PopulatePostMortemMeta)
                                        {
                                            PostMortemMetaData["SourceIP"]      = STEM.Sys.IO.Path.IPFromPath(s);
                                            PostMortemMetaData["DestinationIP"] = STEM.Sys.IO.Path.IPFromPath(d);
                                            PostMortemMetaData["FileSize"]      = new FileInfo(s).Length.ToString();
                                        }
                                    }
                                    catch { }

                                    string dPath = STEM.Sys.IO.Path.AdjustPath(d);
                                    if (RecurseSource && RecreateTree)
                                    {
                                        dPath = System.IO.Path.Combine(dPath, STEM.Sys.IO.Path.GetDirectoryName(s).Replace(STEM.Sys.IO.Path.AdjustPath(src), "").Trim(System.IO.Path.DirectorySeparatorChar));
                                    }

                                    dPath = System.IO.Path.Combine(dPath, DestinationFilename);

                                    if (dPath.Contains("*.*"))
                                    {
                                        dPath = dPath.Replace("*.*", STEM.Sys.IO.Path.GetFileName(s));
                                    }

                                    if (dPath.Contains("*"))
                                    {
                                        dPath = dPath.Replace("*", STEM.Sys.IO.Path.GetFileNameWithoutExtension(s));
                                    }

                                    STEM.Sys.IO.File.STEM_Copy(s, dPath, ExistsAction, out dFile, Retry, RetryDelaySeconds, UseTempHop);

                                    if (!String.IsNullOrEmpty(dFile))
                                    {
                                        filesActioned++;

                                        _FilesActioned[s] = dFile;

                                        if (Action == ActionType.Move)
                                        {
                                            AppendToMessage(s + " moved to " + dFile);
                                        }
                                        else
                                        {
                                            AppendToMessage(s + " copied to " + dFile);
                                        }
                                    }

                                    success = true;

                                    if (DestinationActionRule == DestinationRule.FirstSuccess)
                                    {
                                        break;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    lastEX = ex;

                                    if (DestinationActionRule == DestinationRule.AllOrNone)
                                    {
                                        throw ex;
                                    }
                                }
                            }

                            if (!success)
                            {
                                throw new Exception("No successful actions taken for " + s, lastEX); // + "\r\n" + ((lastEX == null) ? "No additional information." : lastEX.ToString()));
                            }
                            if (Action == ActionType.Move)
                            {
                                File.Delete(STEM.Sys.IO.Path.AdjustPath(s));
                            }
                        }
                        catch (Exception ex)
                        {
                            AppendToMessage(ex.Message);
                            Exceptions.Add(ex);
                        }
                    }

                    if (PopulatePostMortemMeta)
                    {
                        PostMortemMetaData["FilesActioned"] = filesActioned.ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                AppendToMessage(ex.Message);
                Exceptions.Add(ex);
            }

            if (_FilesActioned.Count == 0)
            {
                switch (ZeroFilesAction)
                {
                case FailureAction.SkipRemaining:
                    SkipRemaining();
                    return(true);

                case FailureAction.SkipNext:
                    SkipNext();
                    return(true);

                case FailureAction.SkipToLabel:
                    SkipForwardToFlowControlLabel(FailureActionLabel);
                    return(true);

                case FailureAction.Rollback:
                    RollbackAllPreceedingAndSkipRemaining();
                    break;

                case FailureAction.Continue:
                    return(true);
                }

                Message = "0 Files Actioned\r\n" + Message;
            }

            return(Exceptions.Count == 0);
        }