示例#1
0
        public static void Main()
        {
            // Removes updater temporary dir
            if (Directory.Exists(Path.Combine(Application.StartupPath, "SU_temp")))
            {
                Directory.Delete(Path.Combine(Application.StartupPath, "SU_temp"), true);
            }

            // Cleanup if new version installed before start app
            var cleanNeeded = Directory.GetDirectories(Application.StartupPath)
                              .Where(dir => Path.GetFileName(dir).EndsWith("_new"))
                              .ToList()
                              .AddToEnd(
                Directory.GetFiles(Application.StartupPath)
                .Where(file => Path.GetFileNameWithoutExtension(file).EndsWith("_new")))
                              .Count != 0;

            if (cleanNeeded)
            {
                var cleanOpts = new CleanUpOptions {
                    CleanUpDir  = Application.StartupPath,
                    MergeSuffix = "new"
                };
                Updater.Run(cleanOpts);
            }

            _localLatestVersion = GetLatest();
            if (_localLatestVersion is null)
            {
                Environment.Exit(1);                              // exits if no versions installed.
            }
            // Check update
            var updateThread = new Thread(CheckAndDownload);

            updateThread.Start();

            // Run app
            var exePath =
                Path.Combine(Application.StartupPath, _localLatestVersion.GetVersionString(), "ListenToIt.App.exe");
            var appProc = new Process {
                StartInfo = new ProcessStartInfo {
                    FileName         = exePath,
                    UseShellExecute  = true,
                    WorkingDirectory = exePath.Replace(Path.GetFileName(exePath), string.Empty)
                }
            };

            appProc.Start();
            appProc.WaitForExit();
        }
示例#2
0
        public CleanUpService(ILogger <CleanUpService> logger, IOptions <CleanUpOptions> cleanUpOptions, IServiceScopeFactory serviceScopeFactory)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            if (cleanUpOptions == null)
            {
                throw new ArgumentNullException(nameof(cleanUpOptions));
            }

            if (serviceScopeFactory == null)
            {
                throw new ArgumentNullException(nameof(serviceScopeFactory));
            }

            this.logger              = logger;
            this.cleanUpOptions      = cleanUpOptions.Value;
            this.serviceScopeFactory = serviceScopeFactory;
        }
示例#3
0
        private static void CleanUp(CleanUpOptions options)
        {
            // Kills the existing process
            var procList = Process.GetProcessesByName("ListenToIt.Runner");

            foreach (var proc in procList)
            {
                proc.Kill();
            }

            var cleanupHelper = new CleanUpHelper(options);

            cleanupHelper.Merge();

            // Restart the Runner
            new Process {
                StartInfo = new ProcessStartInfo {
                    FileName        = Path.Combine(Path.GetFullPath("../"), "ListenToIt.Runner.exe"),
                    CreateNoWindow  = false,
                    UseShellExecute = true
                }
            }.Start();
        }
示例#4
0
        public void Start()
        {
            log.Info("---\tInitializing CacheCleanUpService\t---");
            ConfigureScheduledServiceCheck();

            void ConfigureScheduledServiceCheck()
            {
                log.Info("---\tStarting CacheCleanUpService\t---");
                this.StartBase();
                // TODO: Read polling timeout from config
                var cleanUps = GetCleanUps();

                foreach (var cleanUp in cleanUps)
                {
                    Timers.Start("Poller for " + cleanUp.FilePath, (int)TimeSpan.FromSeconds(cleanUp.TimeSpanFromSeconds).TotalMilliseconds, async() =>
                    {
                        try
                        {
                            var guid = Guid.NewGuid();
                            log.Info($"{Environment.NewLine}----------------------- Cache cleanup @ {guid} started -----------------------");

                            CleanUpOptions cleanUpOptions     = new CleanUpOptions(cleanUp.FilePath);
                            cleanUpOptions.RemoveEmptyFolders = cleanUp.CleanUpOptions.RemoveEmptyFolders;
                            ConfigureThreshold();
                            cleanUpOptions.DisplayOnly        = cleanUp.CleanUpOptions.DisplayOnly;
                            cleanUpOptions.RemoveEmptyFolders = cleanUp.CleanUpOptions.RemoveEmptyFolders;
                            cleanUpOptions.UseRecycleBin      = cleanUp.CleanUpOptions.UseRecycleBin;
                            cleanUpOptions.Recursive          = cleanUp.CleanUpOptions.Recursive;

                            Cleaner filesProcessor = new Cleaner(log, cleanUpOptions);
                            filesProcessor.CleanUp();

                            //Activity
                            log.Info($"{Environment.NewLine}----------------------- Cache cleanup @ {guid} finished -----------------------{Environment.NewLine}{Environment.NewLine}{Environment.NewLine}");

                            #region Local Functions
                            void ConfigureThreshold()
                            {
                                if (cleanUp.CleanUpOptions.ThresholdInSeconds != default(int) && cleanUp.CleanUpOptions.ThresholdInDays == default(int))
                                {
                                    cleanUpOptions.Seconds = cleanUp.CleanUpOptions.ThresholdInSeconds;
                                }
                                else if (cleanUp.CleanUpOptions.ThresholdInSeconds == default(int) && cleanUp.CleanUpOptions.ThresholdInDays != default(int))
                                {
                                    cleanUpOptions.Days = cleanUp.CleanUpOptions.ThresholdInDays;
                                }
                                else if (cleanUp.CleanUpOptions.ThresholdInSeconds != default(int) && cleanUp.CleanUpOptions.ThresholdInDays != default(int))
                                {
                                    cleanUpOptions.Days = cleanUp.CleanUpOptions.ThresholdInDays;
                                }
                                else
                                {
                                    cleanUpOptions.Seconds = 300;
                                }
                            }
                            #endregion
                        }
                        catch (Exception ex)
                        {
                            log.Error(ex, $"Exception inside polling action: {ex.ToString()}\n");
                        }
                    },
                                 (e) =>
                    {
                        log.Error(e, "Exception while polling");
                    });
                }
                #region Local Functions

                CleanUps[] GetCleanUps() => (CleanUps[])
                ServicesContainer.WardeinConfigurationManager(Const.WARDEIN_CONFIG_PATH)?.GetConfiguration()?.CleanUps;

                #endregion
            }
        }
示例#5
0
 public CleanUpHelper(CleanUpOptions options)
 {
     _options = options;
 }
示例#6
0
        /// <summary>
        /// The function which returns the manipulated string
        /// </summary>
        /// <param name="input"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public string GetCleanString(string input, CleanUpOptions options)
        {
            if (options == CleanUpOptions.BlankBadText)
            {
                for (int i = 0; i < patterns.Count; i++)
                {
                    //In this instance we want to return an empty string if we find any bad word
                    if (patterns[i].Match(input).Success)
                        return String.Empty;
                }
            }
            else if (options == CleanUpOptions.ReplaceWholeText)
            {
                for (int i = 0; i < patterns.Count; i++)
                {
                    //In this instance we want to return a specified statement if we find any bad word
                    if (patterns[i].Match(input).Success)
                        return Resources.ExpressCMS.TheTextContainsUnsuitableContent;
                }
            }
            else
            {
                for (int i = 0; i < patterns.Count; i++)
                {
                    //In this instance we actually replace each instance of any bad word with a specified string.
                    input = patterns[i].Replace(input, "<span style='color:red;' ><i>**" + Resources.ExpressCMS.UnsuitableWord + "**</i></span>");
                }
            }

            //return the manipulated string
            return input;
        }
示例#7
0
 public static void Run(CleanUpOptions options) => StartCleanup(options.GetCmdArgs());