Exemple #1
0
 public MainViewModel()
 {
     CreateRule = new RelayCommand <Project>(param =>
     {
         Questions.Clear();
         PublicEventConnection.Dispose();
         Rules.Add(new Rule()
         {
             What       = param.Work.What,
             Enabled    = true,
             Comparison = RuleType.Equals,
             From       = new TimeSpan(0, 0, 0),
             To         = new TimeSpan(23, 59, 59),
             Do         = Rule.Ignore
         });
         PublicEventConnection = PublicEvents.Connect();
     });
 }
Exemple #2
0
        internal void Load()
        {
            Questions = new ObservableDictionary <Work, Project>();
            var awtWatch     = AutoHotKeyObservable.WatchAwt(TimeSpan.FromMilliseconds(2000));
            var windows      = awtWatch.OfType <ProcessInfo>().Select(p => p.ToString()).DistinctUntilChanged();
            var personActive = awtWatch.MouseMoving().PersonActive();

            PublicEvents = windows.CombineLatest(personActive,
                                                 (w, a) => a == PersonInfo.ActiveStatus.Active ? w : a.ToString()).
                           CombineLatest(SessionObservable.SessionSwitched(),
                                         (w, s) => s == SessionSwitchReason.SessionUnlock ? w : s.ToString()).
                           TimeInterval().HowLongHas("Active").Timestamp().Select(i =>
            {
                return(new Timestamped <TimeInterval <string> >(i.Value, i.Timestamp.RoundDown()));
            }).Publish();


            WhatWereYouDoing = PublicEvents.Where(evt =>
            {
                return(!Rules.
                       Where(r => r.Enabled).
                       Where(r => evt.Timestamp.TimeOfDay >= r.From).
                       Where(r => evt.Timestamp.TimeOfDay <= r.To).
                       Where(r => r.Comparison == RuleType.Equals).
                       Where(r => r.What == evt.Value.Value).Any());
            }).ObserveOnDispatcher().Subscribe((i) =>
            {
                Work w = new Work()
                {
                    What = i.Value.Value, When = i.Timestamp.ToLocalTime()
                };
                if (Questions.ContainsKey(w))
                {
                    Questions[w].Interval += i.Value.Interval;
                }
                else
                {
                    Questions.Add(w, new Project(i.Value.Interval, w));
                }
            });
            PublicEventConnection = PublicEvents.Connect();
        }