public void TestMonitorUpdateFile()
        {
            using (var storage = new TemporaryNativeStorage(Guid.NewGuid().ToString()))
                using (var monitor = new MonitoredStorage(storage))
                {
                    int updates = 0;
                    monitor.FileUpdated += _ => updates++;

                    string name = Guid.NewGuid().ToString();
                    storage.GetStream(name, FileAccess.ReadWrite).Dispose();

                    Thread.Sleep(10);

                    using (var stream = storage.GetStream(name, FileAccess.Write, FileMode.Open))
                        using (var writer = new StreamWriter(stream))
                        {
                            writer.Write("Hello");
                            writer.Flush();
                        }

                    Thread.Sleep(10);

                    Assert.IsTrue(updates == 1);
                }
        }
Exemplo n.º 2
0
 private void OnTaskCardRemoved(MonitoredStorage storage, ICard card)
 {
     if (storage.Timers.ContainsKey(card))
     {
         DayTimer dt = storage.Timers[card];
         dt.Deactivate();
         storage.Timers.Remove(card);
     }
 }
        public void TestMonitorAddFile()
        {
            using (var storage = new TemporaryNativeStorage(Guid.NewGuid().ToString()))
                using (var monitor = new MonitoredStorage(storage))
                {
                    int creates = 0;
                    monitor.FileCreated += _ => creates++;

                    string name = Guid.NewGuid().ToString();
                    storage.GetStream(name, FileAccess.ReadWrite).Dispose();

                    Thread.Sleep(10);

                    Assert.IsTrue(monitor.Files.Contains(name));
                    Assert.IsTrue(creates == 1);
                }
        }
Exemplo n.º 4
0
    private void OnTaskCardAdded(MonitoredStorage storage, GameObject card, ICard cardData)
    {
        ITaskCard         taskCard = cardData as ITaskCard;
        TaskCardFormatter cf       = card.GetComponent <TaskCardFormatter>();

        if (cf == null || taskCard == null)
        {
            return;
        }
        int time = storage.Days;

        cf.ActivateCardRemainTime(time);
        DayTimer dt = DayTimeSystem.CreateDayTimer(time);

        dt.AddNewDayListener(cf.UpdateCardRemainTime);
        dt.AddTimerFinishedListener(cf.DeactivateCardRemainTime);
        dt.AddTimerFinishedListener(() => storage.Storage.RemoveCard(cardData));
        dt.AddTimerFinishedListener(() => storage.OnExpired.Invoke(taskCard));
        storage.Timers[cardData] = dt;
        dt.StartTimer();
    }
        public void TestMonitorRenameFile()
        {
            using (var storage = new TemporaryNativeStorage(Guid.NewGuid().ToString()))
                using (var monitor = new MonitoredStorage(storage))
                {
                    int renames = 0;
                    monitor.FileRenamed += (_, __) => renames++;

                    string name = Guid.NewGuid().ToString();
                    storage.GetStream(name, FileAccess.ReadWrite).Dispose();

                    Thread.Sleep(10);

                    string nameReplace = Guid.NewGuid().ToString();
                    var    fi          = new FileInfo(storage.GetFullPath(name));
                    fi.MoveTo(Path.Combine(storage.GetFullPath(string.Empty), nameReplace));

                    Thread.Sleep(10);

                    Assert.IsTrue(monitor.Files.Contains(nameReplace));
                    Assert.IsTrue(renames == 1);
                }
        }