Ejemplo n.º 1
0
        public override int ExecuteAndReturn()
        {
            Guard.AssertNotNull(this.CurrentWork);
            return(HandleWork <RepositoryEvent>(this.Console, this.CurrentWork, this.Logger, (w, i) =>
            {
                string key = w.GetKey(i);

                return CreateEvents(key, (sf) =>
                {
                    return RepositoryListSnapshotBuilder.CreateFileSnapshotFromRequest(sf, ExtractRepositoriesByOwner(w.AccessToken, i));
                }
                                    , (sf2) =>
                {
                    bool exists = w.Repository.TryPull(key, sf2);
                    this.Logger.LogTrace("GetLastSnapshot.SnapshotFilename={0} (Exists={1})", key, exists);
                    if (exists)
                    {
                        ITableSnapshotBuilder builder = RepositoryListSnapshotBuilder.CreateFromFile(sf2);
                        return builder;
                    }
                    else
                    {
                        return RepositoryListSnapshotBuilder.EmptySnapshot();
                    }
                }
                                    , w.Repository, this.PersistLastSnapshot, this.Logger, (dr, et)
                                    => EventFactory.CreateRepositoryEvent(dr, et)
                                    );
            }));
        }
Ejemplo n.º 2
0
        public void Compare_Repos_July_vs_Today(string owner)
        {
            NotificationBuilder         nbuilder        = new NotificationBuilder();
            NotificationChannelsBuilder channelsBuilder = new NotificationChannelsBuilder().UseSmtpPickupDirectory(@"c:\work").UseSmtpPickupDirectory(@"c:\work2\send");

            List <RepositoryEvent> Events = new List <RepositoryEvent>();
            ITableSnapshotBuilder  builder;

            builder = RepositoryListSnapshotBuilder.CreateInMemorySnapshotFromRequest(Resources.GetRepositoryResponse(owner, RepositoryResponseGeneration.July));
            ITableSnapshot microsoftSnapshotJuly = builder.Build();

            builder = RepositoryListSnapshotBuilder.CreateInMemorySnapshotFromRequest(this.Extractor.GetMetadataAsynch(this.Token, owner).Result);
            ITableSnapshot microsoftSnapshotToday = builder.Build();

            TableDiffByLookup differ = new TableDiffByLookup(microsoftSnapshotJuly, microsoftSnapshotToday);


            differ.DifferencesDelegate = (deletedRecord, inserted) =>
            {
                EventType   et       = EventType.Created;
                IDataRecord template = inserted;
                if ((deletedRecord != null) && (inserted != null))
                {
                    et       = EventType.Modified;
                    template = inserted;
                }

                if ((deletedRecord != null) && (inserted == null))
                {
                    et       = EventType.Deleted;
                    template = deletedRecord;
                    //RepositoryTableSnapshot.CreatedAtFieldName
                }

                RepositoryEvent ev = EventFactory.CreateRepositoryEvent(template, et);
                nbuilder.AddEvent(ev);
            };
            differ.Execute();
            //Assert.Equal(1312, differ.OldSnapshotRecordCount);

            //create Notification
            //Deliver Notification

            nbuilder.AddChannels(channelsBuilder);

            List <Notification> toSend = new List <Notification>();

            for (int i = 0; i < 5; i++)
            {
                Notification noti = nbuilder.Build();
                noti.From = new NotificationAddress()
                {
                    Identifier = "*****@*****.**"
                };
                noti.To = new NotificationAddress[] { noti.From };
                toSend.Add(noti);
            }

            Postman.DeliverNotification(toSend);
        }
        public void Repository_Diff()
        {
            ITableSnapshotBuilder builder;

            builder = RepositoryListSnapshotBuilder.CreateInMemorySnapshotFromRequest(Resources.GetRepositoryResponse("Microsoft", RepositoryResponseGeneration.July));
            ITableSnapshot microsoftSnapshotJuly = builder.Build();

            builder = RepositoryListSnapshotBuilder.CreateInMemorySnapshotFromRequest(Resources.GetRepositoryResponse("Xamarin", RepositoryResponseGeneration.July));
            ITableSnapshot xamarinSnapshotJuly = builder.Build();

            TableDiffByLookup differ = new TableDiffByLookup(microsoftSnapshotJuly, xamarinSnapshotJuly);

            differ.DifferencesDelegate = (deletedRecord, inserted) =>
            {
                System.Diagnostics.Debug.WriteLine("");
            };
            differ.Execute();
            Assert.Equal(136, differ.NewSnapshotRecordCount);
            Assert.Equal(1312, differ.OldSnapshotRecordCount);
        }