Esempio n. 1
0
        /// <summary>Contructor.</summary>
        /// <param name="path">File path to monitor</param>
        /// <param name="ttl">Cache time-to-live</param>
        /// <param name="items">Items to watch</param>
        public FileSystemCache(string path, double ttl, List <FileSystemEntry> items)
        {
            CheckAndAddPath(path);

            this.ttl     = ttl;
            this.path    = path;
            watchedItems = items;
            try
            {
                watcher = WatcherFactory.CreateWatcher(path, new WatcherDelegates()
                {
                    ChangedHandler = OnFileChange,
                    CreatedHandler = OnFileCreated,
                    DeletedHandler = OnFileDeleted,
                    RenamedHandler = OnFileRenamed
                });
                watcher.EnableRaisingEvents = true;
                CreateTimer();
                timer.Start();
                creationTime = DateTime.UtcNow;
            }
            catch (Exception e)
            {
                lock (_lock)
                {
                    watchedPaths.Remove(path);
                }
                timer.Stop();
                throw e;
            }
        }
Esempio n. 2
0
        /// <summary>Constuctor.</summary>
        /// <param name="path">File path to monitor</param>
        /// <param name="ttl">Cache time-to-live</param>
        public FileSystemCache(string path, double ttl)
        {
            CheckAndAddPath(path);

            Partial      = true;
            this.ttl     = ttl;
            this.path    = path;
            watchedItems = new List <FileSystemEntry>(10);

            try
            {
                watcher = WatcherFactory.CreateWatcher(path, new WatcherDelegates()
                {
                    ChangedHandler = OnFileChange,
                    CreatedHandler = OnFileCreated,
                    DeletedHandler = OnFileDeleted,
                    RenamedHandler = OnFileRenamed
                });
                watcher.EnableRaisingEvents = true;
            }
            catch (Exception e) // catching exception because we are re-throwing it
            {
                lock (_lock)
                {
                    watchedPaths.Remove(path);
                }
                throw e;
            }

            CreateTimer();
            timer.Start();
            creationTime = DateTime.UtcNow;
        }
Esempio n. 3
0
        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="player">The player to track.</param>
        public PlayerTracker(Farmer player)
        {
            // init player data
            this.Player            = player;
            this.PreviousInventory = this.GetInventory();

            // init trackers
            this.LocationWatcher        = WatcherFactory.ForReference(this.GetCurrentLocation);
            this.LocationObjectsWatcher = WatcherFactory.ForNetDictionary(this.GetCurrentLocation().netObjects);
            this.MineLevelWatcher       = WatcherFactory.ForEquatable(() => this.LastValidLocation is MineShaft mine ? mine.mineLevel : 0);
            this.SkillWatchers          = new Dictionary <EventArgsLevelUp.LevelType, IValueWatcher <int> >
            {
                [EventArgsLevelUp.LevelType.Combat]   = WatcherFactory.ForEquatable(() => player.combatLevel),
                [EventArgsLevelUp.LevelType.Farming]  = WatcherFactory.ForEquatable(() => player.farmingLevel),
                [EventArgsLevelUp.LevelType.Fishing]  = WatcherFactory.ForEquatable(() => player.fishingLevel),
                [EventArgsLevelUp.LevelType.Foraging] = WatcherFactory.ForEquatable(() => player.foragingLevel),
                [EventArgsLevelUp.LevelType.Luck]     = WatcherFactory.ForEquatable(() => player.luckLevel),
                [EventArgsLevelUp.LevelType.Mining]   = WatcherFactory.ForEquatable(() => player.miningLevel)
            };

            // track watchers for convenience
            this.Watchers.AddRange(new IWatcher[]
            {
                this.LocationWatcher,
                this.LocationObjectsWatcher,
                this.MineLevelWatcher
            });
            this.Watchers.AddRange(this.SkillWatchers.Values);
        }
Esempio n. 4
0
        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="location">The location to track.</param>
        public LocationTracker(GameLocation location)
        {
            this.Location = location;

            // init watchers
            this.BuildingsWatcher = location is BuildableGameLocation buildableLocation
                ? WatcherFactory.ForNetCollection(buildableLocation.buildings)
                : (ICollectionWatcher <Building>)WatcherFactory.ForObservableCollection(new ObservableCollection <Building>());

            this.DebrisWatcher = WatcherFactory.ForNetCollection(location.debris);
            this.LargeTerrainFeaturesWatcher = WatcherFactory.ForNetCollection(location.largeTerrainFeatures);
            this.NpcsWatcher            = WatcherFactory.ForNetCollection(location.characters);
            this.ObjectsWatcher         = WatcherFactory.ForNetDictionary(location.netObjects);
            this.TerrainFeaturesWatcher = WatcherFactory.ForNetDictionary(location.terrainFeatures);

            this.Watchers.AddRange(new IWatcher[]
            {
                this.BuildingsWatcher,
                this.DebrisWatcher,
                this.LargeTerrainFeaturesWatcher,
                this.NpcsWatcher,
                this.ObjectsWatcher,
                this.TerrainFeaturesWatcher
            });
        }
        private static IWatcherFactory <TModel> CreateWatcherFactory <TModel>()
            where TModel : IModel, new()
        {
            var factory = new WatcherFactory <TModel>();

            return(factory);
        }
Esempio n. 6
0
        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="location">The location to track.</param>
        public LocationTracker(GameLocation location)
        {
            this.Location = location;

            // init watchers
            this.BuildingsWatcher = location is BuildableGameLocation buildableLocation?WatcherFactory.ForNetCollection(buildableLocation.buildings) : WatcherFactory.ForImmutableCollection <Building>();

            this.DebrisWatcher = WatcherFactory.ForNetCollection(location.debris);
            this.LargeTerrainFeaturesWatcher = WatcherFactory.ForNetCollection(location.largeTerrainFeatures);
            this.NpcsWatcher            = WatcherFactory.ForNetCollection(location.characters);
            this.ObjectsWatcher         = WatcherFactory.ForNetDictionary(location.netObjects);
            this.TerrainFeaturesWatcher = WatcherFactory.ForNetDictionary(location.terrainFeatures);
            this.FurnitureWatcher       = WatcherFactory.ForNetCollection(location.furniture);

            this.Watchers.AddRange(new IWatcher[]
            {
                this.BuildingsWatcher,
                this.DebrisWatcher,
                this.LargeTerrainFeaturesWatcher,
                this.NpcsWatcher,
                this.ObjectsWatcher,
                this.TerrainFeaturesWatcher,
                this.FurnitureWatcher
            });

            this.UpdateChestWatcherList(added: location.Objects.Pairs, removed: Array.Empty <KeyValuePair <Vector2, SObject> >());
        }
Esempio n. 7
0
        public IFbWatcher <TModel> CreateWatcher <TModel>()
            where TModel : IModel, new()
        {
            var factory        = new WatcherFactory <TModel>();
            var watcherOptions = new WatcherOptions(TestsContext.MainDbConnectionString,
                                                    TestsContext.TempDbConnectionString);

            return(factory.CreateWatcher(watcherOptions));
        }
Esempio n. 8
0
        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="chest">The chest being tracked.</param>
        public ChestTracker(Chest chest)
        {
            this.Chest            = chest;
            this.InventoryWatcher = WatcherFactory.ForNetList(chest.items);

            this.StackSizes = this.Chest.items
                              .Where(n => n != null)
                              .Distinct()
                              .ToDictionary(n => n, n => n.Stack);
        }
Esempio n. 9
0
        public RepositoryWatcher(SDConnection connection, InitialPayload payload) : base(connection, payload)
        {
            settings = payload.Settings == null || payload.Settings.Count == 0
                ? PluginSettings.CreateDefaultSettings()
                : payload.Settings.ToObject <PluginSettings>();

            watcher         = WatcherFactory.GetWatcher(settings);
            Timer           = new Timer();
            Timer.AutoReset = true;
            Timer.Elapsed  += new ElapsedEventHandler(UpdateKey);
        }
Esempio n. 10
0
        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="location">The location to track.</param>
        public LocationTracker(GameLocation location)
        {
            this.Location = location;

            // init watchers
            this.ObjectsWatcher   = WatcherFactory.ForNetDictionary(location.netObjects);
            this.BuildingsWatcher = location is BuildableGameLocation buildableLocation
                ? WatcherFactory.ForNetCollection(buildableLocation.buildings)
                : (ICollectionWatcher <Building>)WatcherFactory.ForObservableCollection(new ObservableCollection <Building>());

            this.Watchers.AddRange(new IWatcher[]
            {
                this.BuildingsWatcher,
                this.ObjectsWatcher
            });
        }
Esempio n. 11
0
        public override void ReceivedSettings(ReceivedSettingsPayload payload)
        {
            try
            {
                Tools.AutoPopulateSettings(settings, payload.Settings);
                settings.UpdateSettingsEnum();
                watcher           = WatcherFactory.GetWatcher(settings);
                initialDateOffset = initialDateOffset.Subtract(new TimeSpan(settings.InitialOffset, 0, 0, 0));

                UpdateTimer();
                SaveSettings();
            }
            catch (Exception ex)
            {
                Logger.Instance.LogMessage(TracingLevel.ERROR, ex.Message);
                Connection.ShowAlert().Wait();
            }
        }
        public Watchdog(Config config)
        {
            this.Logger = new Logger();
            WatcherFactory factory = new WatcherFactory(this.Logger);

            this.Watchers = new List <BaseWatcher>();
            if (config.Network.EnableWatcher)
            {
                NetworkWatcher watcher = factory.CreateNetworkWatcher(config.Octovisor);
                this.Watchers.Add(watcher);
            }

            foreach ((string procName, MonitorInfo procInfo) in config.Monitoring)
            {
                ProcessWatcher watcher = factory.CreateProcessWatcher(procName, procInfo);
                this.Watchers.Add(watcher);
            }
        }
Esempio n. 13
0
        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="player">The player to track.</param>
        public PlayerTracker(Farmer player)
        {
            // init player data
            this.Player            = player;
            this.PreviousInventory = this.GetInventory();

            // init trackers
            this.LocationWatcher = WatcherFactory.ForReference(this.GetCurrentLocation);
            this.SkillWatchers   = new Dictionary <SkillType, IValueWatcher <int> >
            {
                [SkillType.Combat]   = WatcherFactory.ForNetValue(player.combatLevel),
                [SkillType.Farming]  = WatcherFactory.ForNetValue(player.farmingLevel),
                [SkillType.Fishing]  = WatcherFactory.ForNetValue(player.fishingLevel),
                [SkillType.Foraging] = WatcherFactory.ForNetValue(player.foragingLevel),
                [SkillType.Luck]     = WatcherFactory.ForNetValue(player.luckLevel),
                [SkillType.Mining]   = WatcherFactory.ForNetValue(player.miningLevel)
            };

            // track watchers for convenience
            this.Watchers.Add(this.LocationWatcher);
            this.Watchers.AddRange(this.SkillWatchers.Values);
        }
Esempio n. 14
0
        private TaskInfo CreateTaskInfo(string filter, GatheringPointsInfo gInfo, WatcherType type = WatcherType.NONE)
        {
            try
            {
                var taskInfo = new TaskInfo();

                if (gInfo != null && ConfigInfo != null)
                {
                    taskInfo.Filter = filter;
                    taskInfo.Index  = gInfo.NO;
                }

                taskInfo.Watcher        = WatcherFactory.CreateWatcher(gInfo, ConfigInfo, FtpInfo, SetFilter(filter), type);
                taskInfo.ProcessingTask = new Task(StartProcessing, taskInfo, TaskCreationOptions.LongRunning);

                return(taskInfo);
            }
            catch (Exception ex)
            {
                AppEvents.Instance.OnUpdateScreen("Error : " + ex.Message);
                return(null);
            }
        }
Esempio n. 15
0
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="inputState">Manages input visible to the game.</param>
 /// <param name="gameLocations">The observable list of game locations.</param>
 public WatcherCore(SInputState inputState, ObservableCollection <GameLocation> gameLocations)
 {
     // init watchers
     this.CursorWatcher           = WatcherFactory.ForEquatable(() => inputState.CursorPosition);
     this.MouseWheelScrollWatcher = WatcherFactory.ForEquatable(() => inputState.LastMouse.ScrollWheelValue);
     this.SaveIdWatcher           = WatcherFactory.ForEquatable(() => Game1.hasLoadedGame ? Game1.uniqueIDForThisGame : 0);
     this.WindowSizeWatcher       = WatcherFactory.ForEquatable(() => new Point(Game1.viewport.Width, Game1.viewport.Height));
     this.TimeWatcher             = WatcherFactory.ForEquatable(() => Game1.timeOfDay);
     this.ActiveMenuWatcher       = WatcherFactory.ForReference(() => Game1.activeClickableMenu);
     this.LocationsWatcher        = new WorldLocationsTracker(gameLocations, MineShaft.activeMines);
     this.LocaleWatcher           = WatcherFactory.ForGenericEquality(() => LocalizedContentManager.CurrentLanguageCode);
     this.Watchers.AddRange(new IWatcher[]
     {
         this.CursorWatcher,
         this.MouseWheelScrollWatcher,
         this.SaveIdWatcher,
         this.WindowSizeWatcher,
         this.TimeWatcher,
         this.ActiveMenuWatcher,
         this.LocationsWatcher,
         this.LocaleWatcher
     });
 }
Esempio n. 16
0
        /// <summary>Update the current values if needed.</summary>
        public void Update()
        {
            // update valid location
            this.LastValidLocation = this.GetCurrentLocation();

            // update watchers
            foreach (IWatcher watcher in this.Watchers)
            {
                watcher.Update();
            }

            // replace location objects watcher
            if (this.LocationWatcher.IsChanged)
            {
                this.Watchers.Remove(this.LocationObjectsWatcher);
                this.LocationObjectsWatcher.Dispose();

                this.LocationObjectsWatcher = WatcherFactory.ForNetDictionary(this.GetCurrentLocation().netObjects);
                this.Watchers.Add(this.LocationObjectsWatcher);
            }

            // update inventory
            this.CurrentInventory = this.GetInventory();
        }
 protected override void OnStart(string[] args)
 {
     watcherFactory = new WatcherFactory();
     watcherFactory.Initialize();
 }
Esempio n. 18
0
 public WatcherBL()
 {
     IWatcher = WatcherFactory.CreateWatcher();
 }
Esempio n. 19
0
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="locations">The game's list of locations.</param>
 /// <param name="activeMineLocations">The game's list of active mine locations.</param>
 public WorldLocationsTracker(List <GameLocation> locations, IList <MineShaft> activeMineLocations)
 {
     this.LocationListWatcher     = WatcherFactory.ForReferenceList(locations);
     this.MineLocationListWatcher = WatcherFactory.ForReferenceList(activeMineLocations);
 }
Esempio n. 20
0
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="locations">The game's list of locations.</param>
 /// <param name="activeMineLocations">The game's list of active mine locations.</param>
 /// <param name="activeVolcanoLocations">The game's list of active volcano locations.</param>
 public WorldLocationsTracker(ObservableCollection <GameLocation> locations, IList <MineShaft> activeMineLocations, IList <VolcanoDungeon> activeVolcanoLocations)
 {
     this.LocationListWatcher        = WatcherFactory.ForObservableCollection(locations);
     this.MineLocationListWatcher    = WatcherFactory.ForReferenceList(activeMineLocations);
     this.VolcanoLocationListWatcher = WatcherFactory.ForReferenceList(activeVolcanoLocations);
 }
Esempio n. 21
0
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="locations">The game's list of locations.</param>
 public WorldLocationsTracker(ObservableCollection <GameLocation> locations)
 {
     this.LocationListWatcher = WatcherFactory.ForObservableCollection(locations);
 }