コード例 #1
0
        public void InitializeLogger(ISaveRepository repo)
        {
            /////////////////////////////////////////
            /// Mirror LogEntries to repo
            /////////////////////////////////////////

            LogEntries
            .Connect()
            .WhereReasonsAre(ListChangeReason.Add)
            .Subscribe(ch =>
            {
                foreach (Change <LogEntryViewModel> c in ch)
                {
                    LogEntryViewModel Entry = c.Item.Current;
                    if (Entry != null)
                    {
                        Repo_CreateOrUpdateLogEntry(repo, Entry);
                        Entry.PropertyChanged += Entry_PropertyChanged;
                    }
                    if (c.Range != null)
                    {
                        foreach (LogEntryViewModel REntry in c.Range.ToList())
                        {
                            Repo_CreateOrUpdateLogEntry(repo, REntry);
                            REntry.PropertyChanged += Entry_PropertyChanged;
                        }
                    }
                }
            });

            LogEntries
            .Connect()
            .WhereReasonsAre(ListChangeReason.AddRange)
            .Subscribe(ch =>
            {
                foreach (Change <LogEntryViewModel> c in ch)
                {
                    LogEntryViewModel Entry = c.Item.Current;
                    if (Entry != null)
                    {
                        Entry.PropertyChanged += Entry_PropertyChanged;
                    }
                    if (c.Range != null)
                    {
                        foreach (LogEntryViewModel REntry in c.Range.ToList())
                        {
                            REntry.PropertyChanged += Entry_PropertyChanged;
                        }
                    }
                }
            });


            LogEntries
            .Connect()
            .WhereReasonsAre(ListChangeReason.Remove)
            .Subscribe(ch =>
            {
                foreach (Change <LogEntryViewModel> c in ch)
                {
                    LogEntryViewModel Entry = c.Item.Current;
                    if (Entry != null)
                    {
                        Repo_CreateOrUpdateLogEntry(repo, Entry);
                        repo.RemoveLogEntry(Entry.Id);
                    }
                    if (c.Range != null)
                    {
                        foreach (LogEntryViewModel REntry in c.Range.ToList())
                        {
                            repo.RemoveLogEntry(REntry.Id);
                        }
                    }
                }
            });

            /////////////////////////////////////////
            /// Log Cards
            /////////////////////////////////////////

            var CardChanges = Cards.Connect();

            CardChanges.WhereReasonsAre(ListChangeReason.Add)
            .Subscribe(c =>
            {
                foreach (Change <CardViewModel> ccvm in c)
                {
                    LogCardChanges(ccvm.Item.Current, repo);

                    LogEntryViewModel Entry = new LogEntryViewModel()
                    {
                        Time     = DateTime.Now,
                        ColumnId = ccvm.Item.Current.ColumnDeterminant,

                        RowId   = ccvm.Item.Current.RowDeterminant,
                        CardId  = ccvm.Item.Current.Id,
                        BoardId = ccvm.Item.Current.BoardId,

                        Topic = ccvm.Reason.ToString(),
                        Note  = ccvm.Item.Current.Header
                    };

                    Entry.Note = "Add Card #" + ccvm.Item.Current.Id.ToString() + ": " + ccvm.Item.Current.Header + "\r\n";

                    Entry.Column = Columns.Items.Where(x => { return(x.Id == Entry.ColumnId); }).First().Name;
                    Entry.Row    = Rows.Items.Where(x => { return(x.Id == Entry.RowId); }).First().Name;
                    Entry.Board  = Boards.Items.Where(x => { return(x.Id == Entry.BoardId); }).First().Name;

                    LogEntries.Add(Entry);
                }
                ;
            });

            CardChanges.WhereReasonsAre(ListChangeReason.AddRange)
            .Subscribe(c =>
            {
                foreach (Change <CardViewModel> ccvm in c)
                {
                    foreach (CardViewModel cvm in ccvm.Range.ToList())
                    {
                        LogCardChanges(cvm, repo);     // Add Observer

                        // Don't generate Log Entry, since AddRange is issued only at loading of Box.
                    }
                }
            });


            CardChanges.WhereReasonsAre(ListChangeReason.Remove)
            .Subscribe(c =>
            {
                foreach (Change <CardViewModel> ccvm in c)
                {
                    LogEntryViewModel Entry = new LogEntryViewModel()
                    {
                        Time     = DateTime.Now,
                        ColumnId = ccvm.Item.Current.ColumnDeterminant,
                        RowId    = ccvm.Item.Current.RowDeterminant,
                        BoardId  = ccvm.Item.Current.BoardId,
                        Topic    = ccvm.Reason.ToString(),
                        Note     = ccvm.Item.Current.Header
                    };

                    Entry.Note = "Remove Card #" + ccvm.Item.Current.Id.ToString() + ": " + ccvm.Item.Current.Header + "\r\n";

                    Entry.Column = Columns.Items.Where(x => { return(x.Id == Entry.ColumnId); }).First().Name;
                    Entry.Row    = Rows.Items.Where(x => { return(x.Id == Entry.RowId); }).First().Name;
                    Entry.Board  = Boards.Items.Where(x => { return(x.Id == Entry.BoardId); }).First().Name;

                    LogEntries.Add(Entry);
                }
            });

            CardChanges.WhereReasonsAre(ListChangeReason.RemoveRange)
            .Subscribe(c =>
            {
                foreach (Change <CardViewModel> ccvm in c)
                {
                    foreach (CardViewModel cvm in ccvm.Range.ToList())
                    {
                        LogEntryViewModel Entry = new LogEntryViewModel()
                        {
                            Time     = DateTime.Now,
                            ColumnId = cvm.ColumnDeterminant,
                            RowId    = cvm.RowDeterminant,
                            BoardId  = cvm.BoardId,
                            Topic    = ccvm.Reason.ToString()
                        };

                        Entry.Note = "Remove Card #" + ccvm.Item.Current.Id.ToString() + ": " + ccvm.Item.Current.Header + "\r\n";

                        Entry.Column = Columns.Items.Where(x => { return(x.Id == Entry.ColumnId); }).First().Name;
                        Entry.Row    = Rows.Items.Where(x => { return(x.Id == Entry.RowId); }).First().Name;
                        Entry.Board  = Boards.Items.Where(x => { return(x.Id == Entry.BoardId); }).First().Name;

                        LogEntries.Add(Entry);
                    }
                }
            });
        }