コード例 #1
0
        public TreeWalker()
        {
            Mq = BlockingMq.GetMq();

            FileTaskScheduler = SnaffCon.GetFileTaskScheduler();
            TreeTaskScheduler = SnaffCon.GetTreeTaskScheduler();
            FileScanner       = SnaffCon.GetFileScanner();
        }
コード例 #2
0
ファイル: ShareFinder.cs プロジェクト: ashr/Snaffler
        internal void GetComputerShares(string computer)
        {
            // find the shares
            HostShareInfo[]             hostShareInfos    = GetHostShareInfo(computer);
            BlockingStaticTaskScheduler treeTaskScheduler = SnaffCon.GetTreeTaskScheduler();

            foreach (HostShareInfo hostShareInfo in hostShareInfos)
            {
                string shareName = GetShareName(hostShareInfo, computer);
                if (!String.IsNullOrWhiteSpace(shareName))
                {
                    bool matched = false;

                    // classify them
                    foreach (ClassifierRule classifier in MyOptions.ShareClassifiers)
                    {
                        ShareClassifier shareClassifier = new ShareClassifier(classifier);
                        if (shareClassifier.ClassifyShare(shareName))
                        {
                            matched = true;
                            break;
                        }
                    }
                    // by default all shares should go on to TreeWalker unless the classifier pulls them out.
                    // send them to TreeWalker
                    if (!matched)
                    {
                        if (IsShareReadable(shareName))
                        {
                            ShareResult shareResult = new ShareResult()
                            {
                                Listable  = true,
                                SharePath = shareName
                            };
                            Mq.ShareResult(shareResult);

                            Mq.Info("Creating a TreeWalker task for " + shareResult.SharePath);
                            treeTaskScheduler.New(() =>
                            {
                                try
                                {
                                    new TreeWalker(shareResult.SharePath);
                                }
                                catch (Exception e)
                                {
                                    Mq.Trace(e.ToString());
                                }
                            });
                        }
                    }
                }
            }
        }
コード例 #3
0
ファイル: TreeWalker.cs プロジェクト: ashr/Snaffler
        public TreeWalker(string shareRoot)
        {
            Mq = BlockingMq.GetMq();

            FileTaskScheduler = SnaffCon.GetFileTaskScheduler();

            if (shareRoot == null)
            {
                Mq.Trace("A null made it into TreeWalker. Wtf.");
                return;
            }

            Mq.Trace("About to start a TreeWalker on share " + shareRoot);
            WalkTree(shareRoot);
            Mq.Trace("Finished TreeWalking share " + shareRoot);
        }
コード例 #4
0
 public ArchiveClassifier(FileInfo fileInfo)
 {
     Mq          = BlockingMq.GetMq();
     FileScanner = SnaffCon.GetFileScanner();
 }
コード例 #5
0
ファイル: ShareFinder.cs プロジェクト: zhouzu/Snaffler
 public ShareFinder()
 {
     Mq = BlockingMq.GetMq();
     TreeTaskScheduler = SnaffCon.GetTreeTaskScheduler();
     TreeWalker        = SnaffCon.GetTreeWalker();
 }
コード例 #6
0
        public void Run(string[] args)
        {
            // prime the hoststring lazy instantiator
            hostString();
            // print the thing
            PrintBanner();
            // set up the message queue for operation
            BlockingMq.MakeMq();
            // get a handle to the message queue singleton
            Mq = BlockingMq.GetMq();
            // prime the UI handler
            SnaffCon controller = null;

            try
            {
                // parse cli opts in
                Options = Config.Parse(args);

                // set up the  TSV output if the flag is set
                if (Options.LogTSV)
                {
                    // treat all as strings except LastWriteTime {6}
                    fileResultTemplate  = Options.Separator + "{0}" + Options.Separator + "{1}" + Options.Separator + "{2}" + Options.Separator + "{3}" + Options.Separator + "{4}" + Options.Separator + "{5}" + Options.Separator + "{6:u}" + Options.Separator + "{7}" + Options.Separator + "{8}";
                    shareResultTemplate = Options.Separator + "{0}" + Options.Separator + "{1}";
                    dirResultTemplate   = Options.Separator + "{0}" + Options.Separator + "{1}";
                }
                // otherwise just do the normal thing
                else
                {
                    // treat all as strings except LastWriteTime {6}
                    fileResultTemplate  = "{{{0}}}<{1}|{2}{3}|{4}|{5}|{6:u}>({7}) {8}";
                    shareResultTemplate = "{{{0}}}({1})";
                    dirResultTemplate   = "{{{0}}}({1})";
                }
                //------------------------------------------
                // set up new fangled logging
                //------------------------------------------
                LoggingConfiguration nlogConfig = new LoggingConfiguration();

                ColoredConsoleTarget logconsole = null;
                FileTarget           logfile    = null;

                ParseLogLevelString(Options.LogLevelString);

                // Targets where to log to: File and Console
                if (Options.LogToConsole)
                {
                    logconsole = new ColoredConsoleTarget("logconsole")
                    {
                        DetectOutputRedirected         = true,
                        UseDefaultRowHighlightingRules = false,
                        WordHighlightingRules          =
                        {
                            new ConsoleWordHighlightingRule("{Green}",                 ConsoleOutputColor.DarkGreen,
                                                            ConsoleOutputColor.White),
                            new ConsoleWordHighlightingRule("{Yellow}",                ConsoleOutputColor.DarkYellow,
                                                            ConsoleOutputColor.White),
                            new ConsoleWordHighlightingRule("{Red}",                   ConsoleOutputColor.DarkRed,
                                                            ConsoleOutputColor.White),
                            new ConsoleWordHighlightingRule("{Black}",                 ConsoleOutputColor.Black,
                                                            ConsoleOutputColor.White),

                            new ConsoleWordHighlightingRule("[Trace]",                 ConsoleOutputColor.DarkGray,
                                                            ConsoleOutputColor.Black),
                            new ConsoleWordHighlightingRule("[Degub]",                 ConsoleOutputColor.Gray,
                                                            ConsoleOutputColor.Black),
                            new ConsoleWordHighlightingRule("[Info]",                  ConsoleOutputColor.White,
                                                            ConsoleOutputColor.Black),
                            new ConsoleWordHighlightingRule("[Error]",                 ConsoleOutputColor.Magenta,
                                                            ConsoleOutputColor.Black),
                            new ConsoleWordHighlightingRule("[Fatal]",                 ConsoleOutputColor.Red,
                                                            ConsoleOutputColor.Black),
                            new ConsoleWordHighlightingRule("[File]",                  ConsoleOutputColor.Green,
                                                            ConsoleOutputColor.Black),
                            new ConsoleWordHighlightingRule("[Share]",                 ConsoleOutputColor.Yellow,
                                                            ConsoleOutputColor.Black),
                            new ConsoleWordHighlightingRule
                            {
                                CompileRegex    = true,
                                Regex           = @"<.*\|.*\|.*\|.*?>",
                                ForegroundColor = ConsoleOutputColor.Cyan,
                                BackgroundColor = ConsoleOutputColor.Black
                            },
                            new ConsoleWordHighlightingRule
                            {
                                CompileRegex    = true,
                                Regex           = @"^\d\d\d\d-\d\d\-\d\d \d\d:\d\d:\d\d [\+-]\d\d:\d\d ",
                                ForegroundColor = ConsoleOutputColor.DarkGray,
                                BackgroundColor = ConsoleOutputColor.Black
                            },
                            new ConsoleWordHighlightingRule
                            {
                                CompileRegex    = true,
                                Regex           = @"\((?:[^\)]*\)){1}",
                                ForegroundColor = ConsoleOutputColor.DarkMagenta,
                                BackgroundColor = ConsoleOutputColor.Black
                            }
                        }
                    };
                    nlogConfig.AddRule(LogLevel, LogLevel.Fatal, logconsole);
                    logconsole.Layout = "${message}";
                }

                if (Options.LogToFile)
                {
                    logfile = new FileTarget("logfile")
                    {
                        FileName = Options.LogFilePath
                    };
                    nlogConfig.AddRule(LogLevel, LogLevel.Fatal, logfile);
                    logfile.Layout = "${message}";
                }

                // Apply config
                LogManager.Configuration = nlogConfig;

                //-------------------------------------------

                if (Options.Snaffle && (Options.SnafflePath.Length > 4))
                {
                    Directory.CreateDirectory(Options.SnafflePath);
                }

                controller = new SnaffCon(Options);
                Task thing = Task.Factory.StartNew(() => { controller.Execute(); });

                while (true)
                {
                    HandleOutput();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                DumpQueue();
            }
        }
コード例 #7
0
        public void Run(string[] args)
        {
            PrintBanner();
            MqHandle = new BlockingMq();
            SnaffCon controller = null;

            try
            {
                Config     = new Config(args, MqHandle);
                controller = new SnaffCon(Config);
                //------------------------------------------
                // set up new fangled logging
                //------------------------------------------
                var nlogConfig = new LoggingConfiguration();

                ColoredConsoleTarget logconsole = null;
                FileTarget           logfile    = null;

                // Targets where to log to: File and Console
                if (Config.LogToConsole)
                {
                    logconsole = new ColoredConsoleTarget("logconsole")
                    {
                        DetectOutputRedirected         = true,
                        UseDefaultRowHighlightingRules = false,
                        WordHighlightingRules          =
                        {
                            new ConsoleWordHighlightingRule("[Trace]",                 ConsoleOutputColor.DarkGray,
                                                            ConsoleOutputColor.Black),
                            new ConsoleWordHighlightingRule("[Degub]",                 ConsoleOutputColor.Gray,
                                                            ConsoleOutputColor.Black),
                            new ConsoleWordHighlightingRule("[Info]",                  ConsoleOutputColor.White,
                                                            ConsoleOutputColor.Black),
                            new ConsoleWordHighlightingRule("[Error]",                 ConsoleOutputColor.Magenta,
                                                            ConsoleOutputColor.Black),
                            new ConsoleWordHighlightingRule("[Fatal]",                 ConsoleOutputColor.Red,
                                                            ConsoleOutputColor.Black),
                            new ConsoleWordHighlightingRule("[File]",                  ConsoleOutputColor.Green,
                                                            ConsoleOutputColor.Black),
                            new ConsoleWordHighlightingRule("[Share]",                 ConsoleOutputColor.Yellow,
                                                            ConsoleOutputColor.Black),
                            new ConsoleWordHighlightingRule
                            {
                                CompileRegex    = true,
                                Regex           = @"<.*\|.*\|.*\|.*?>",
                                ForegroundColor = ConsoleOutputColor.Cyan
                            },
                            new ConsoleWordHighlightingRule
                            {
                                CompileRegex    = true,
                                Regex           = @"^\d\d\d\d-\d\d\-\d\d \d\d:\d\d:\d\d [\+-]\d\d:\d\d ",
                                ForegroundColor = ConsoleOutputColor.DarkGray
                            },
                            new ConsoleWordHighlightingRule
                            {
                                CompileRegex    = true,
                                Regex           = @"\((?:[^\)]*\)){1}",
                                ForegroundColor = ConsoleOutputColor.DarkMagenta
                            }
                        }
                    };
                    nlogConfig.AddRule(Config.LogLevel, LogLevel.Fatal, logconsole);
                    logconsole.Layout = "${message}";
                }

                if (Config.LogToFile)
                {
                    logfile = new FileTarget("logfile")
                    {
                        FileName = Config.LogFilePath
                    };
                    nlogConfig.AddRule(Config.LogLevel, LogLevel.Fatal, logfile);
                    logfile.Layout = "${message}";
                }

                // Apply config
                LogManager.Configuration = nlogConfig;

                //-------------------------------------------

                if (Config.EnableMirror && (Config.MirrorPath.Length > 4))
                {
                    Directory.CreateDirectory(Config.MirrorPath);
                }

                var thing = Task.Factory.StartNew(() => { controller.Execute(); });

                while (true)
                {
                    HandleOutput();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                DumpQueue();
            }
        }