Exemplo n.º 1
0
 internal void Add(ITableSnapshot tableSnapshot, ISnapTable snapTable)
 {
     Debug.Assert(tableSnapshot.StoreSnapshot == this);
     Debug.Assert(snapTable.SnapStore == this.SnapStore);
     this.table.Add(snapTable, tableSnapshot);
     this.primaryKeyHolder.Add((IPrimaryKeyHolder)tableSnapshot);
 }
Exemplo n.º 2
0
 public TableDiffByLookup(ITableSnapshot oldTable, ITableSnapshot newTable)
 {
     this.OldSnapshot            = oldTable;
     this.NewSnapshot            = newTable;
     this.OldSnapshotRecordCount = -1;
     this.NewSnapshotRecordCount = -1;
 }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        // Constructor
        public WireSet(CircuitProject store)
        {
            ITableSnapshot table = store.Table("Wire");

            if (table != null)
            {
                Debug.Assert(store.IsFrozen, "The store should be frozen");
                this.Table = (TableSnapshot <WireData>)table;
            }
            else
            {
                Debug.Assert(!store.IsFrozen, "In order to create table, the store should not be frozen");
                this.Table = WireData.CreateTable(store);
            }
            this.InitializeWireSet();
        }
Exemplo n.º 5
0
        // Constructor
        public CollapsedCategorySet(CircuitProject store)
        {
            ITableSnapshot table = store.Table("CollapsedCategory");

            if (table != null)
            {
                Debug.Assert(store.IsFrozen, "The store should be frozen");
                this.Table = (TableSnapshot <CollapsedCategoryData>)table;
            }
            else
            {
                Debug.Assert(!store.IsFrozen, "In order to create table, the store should not be frozen");
                this.Table = CollapsedCategoryData.CreateTable(store);
            }
            this.InitializeCollapsedCategorySet();
        }
Exemplo n.º 6
0
        [InlineData("Dotnet", "core")] //small repo
        //[InlineData("Microsoft", "vscode")]
        public void Issue_Snapshot_from_Web(string owner, string repo)
        {
            ITableSnapshotBuilder builder;

            Assert.True(this.Extractor.MaximumNodesCountPerRequest > 50);
            builder = IssueListSnapshotBuilder.CreateInMemorySnapshotFromRequest(this.Extractor.GetIssueMetadataAsynch(this.Token, owner, repo).Result);
            using (ITableSnapshot snapshot = builder.Build())
            {
                using (var reader = snapshot.GetDataReader())
                {
                    while (reader.Read())
                    {
                        EventFactory.CreateIssueEvent(reader, EventType.Created);
                    }
                }
            }
        }
        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);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates foreign key
        /// </summary>
        /// <typeparam name="TField"></typeparam>
        /// <param name="name"></param>
        /// <param name="parentTable"></param>
        /// <param name="foreignColumn"></param>
        /// <param name="action"></param>
        /// <param name="allowsDefault"></param>
        public void CreateForeignKey <TField>(string name, ITableSnapshot parentTable, IField <TRecord, TField> foreignColumn, ForeignKeyAction action, bool allowsDefault)
        {
            this.StoreSnapshot.SnapStore.CheckNotFrozen();
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (parentTable == null)
            {
                throw new ArgumentNullException(nameof(parentTable));
            }
            IPrimaryKeyHolder parent = (IPrimaryKeyHolder)parentTable;

            if (parent.PrimaryKey <TField>() == null)
            {
                throw new ArgumentException(Properties.Resources.ErrorPrimaryKeyMissing(this.Name), nameof(parentTable));
            }
            this.table.ValidateField(foreignColumn);
            if (!Enum.IsDefined(typeof(ForeignKeyAction), action))
            {
                throw new ArgumentOutOfRangeException(nameof(action));
            }
            if (this.table.ForeignKeys[foreignColumn.Order] != null)
            {
                throw new ArgumentException(Properties.Resources.ErrorForeignKeyExists(this.Name, foreignColumn.Name));
            }
            foreach (IForeignKey fk in this.table.ForeignKeys)
            {
                if (fk != null && fk.Name == name)
                {
                    throw new ArgumentException(Properties.Resources.ErrorForeignKeyNameExists(this.Name, name), nameof(name));
                }
            }

            ForeignKey <TField> foreignKey = new ForeignKey <TField>(name, parent.PrimaryKey <TField>(), this, foreignColumn, action, allowsDefault);

            this.table.ForeignKeys[foreignColumn.Order] = foreignKey;
            parent.Children.Add(foreignKey);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Create foreign keys with disabled defaults
 /// </summary>
 /// <typeparam name="TField"></typeparam>
 /// <param name="name"></param>
 /// <param name="parentTable"></param>
 /// <param name="foreignColumn"></param>
 /// <param name="action"></param>
 public void CreateForeignKey <TField>(string name, ITableSnapshot parentTable, IField <TRecord, TField> foreignColumn, ForeignKeyAction action)
 {
     this.CreateForeignKey <TField>(name, parentTable, foreignColumn, action, false);
 }
Exemplo n.º 10
0
        public static IEvent[] CreateEvents(string key, Func <string, ITableSnapshotBuilder> currentQuerySnapshotBuilderDelegate, Func <string, ITableSnapshotBuilder> lastSnapshotBuilderDelegate, SnapshotRepository snapshotRepository, bool persistAsLastSnapshot, ILogger logger, Func <IDataRecord, EventType, IEvent> factoryCallback)
        {
            Guard.ArgumentNotNullOrEmptyString(key, nameof(key));
            Guard.ArgumentNotNull(currentQuerySnapshotBuilderDelegate, nameof(currentQuerySnapshotBuilderDelegate));
            Guard.ArgumentNotNull(lastSnapshotBuilderDelegate, nameof(lastSnapshotBuilderDelegate));
            Guard.AssertNotNull(logger);
            Guard.AssertNotNull(snapshotRepository);
            List <IEvent> events = new List <IEvent>();

            using (DisposableFile temporarySnapshot = DisposableFile.GetTempFile())
            {
                Task <ITableSnapshot> queryNow = Task.Factory.StartNew <ITableSnapshot>(() =>
                {
                    ITableSnapshotBuilder builder      = currentQuerySnapshotBuilderDelegate(temporarySnapshot.Path);
                    ITableSnapshot snapShotFromRequest = builder.Build();
                    return(snapShotFromRequest);
                });

                Task <ITableSnapshot> lastSnapshot1 = Task.Factory.StartNew <ITableSnapshot>(() =>
                {
                    string localTempFile               = Path.GetTempFileName(); //DELETE The File at the end ??
                    ITableSnapshotBuilder builder      = lastSnapshotBuilderDelegate(localTempFile);
                    ITableSnapshot snapShotFromRequest = builder.Build();
                    return(snapShotFromRequest);
                });


                int msTimeoutLoggingSteps = 1000;
                while (Task.WaitAll(new Task[] { queryNow, lastSnapshot1 }, msTimeoutLoggingSteps) == false)
                {
                    logger.LogTrace("CreateEvents.Wait-Loop.{0}ms for '{1}'", msTimeoutLoggingSteps, key);
                }


                try
                {
                    TableDiffByLookup differ = new TableDiffByLookup(lastSnapshot1.Result, queryNow.Result);
                    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
                        }
                        if (et != EventType.Modified)
                        {
                            //IEvent ev = //EventFactory.CreateRepositoryEvent(template, et);
                            IEvent ev = factoryCallback(template, et);
                            Guard.AssertNotNull(ev);
                            events.Add(ev);
                        }
                        else
                        {
                            // we ignore modifications!
                        }
                    };
                    differ.Execute();
                }
                finally
                {
                    if (queryNow.IsCompletedSuccessfully())
                    {
                        queryNow.Result.Dispose();
                    }
                    if (lastSnapshot1.IsCompletedSuccessfully())
                    {
                        lastSnapshot1.Result.Dispose();
                    }
                }
                if (persistAsLastSnapshot)
                {
                    snapshotRepository.Push(key, temporarySnapshot.Path);
                }
                else
                {
                    logger.LogInformation("Snapshot {0} NOT persited!", key);
                }
            } //using temporary snapshotfile disposable

            return(events.ToArray());
            //throw new NotImplementedException();
        }
 public void Base_Builder()
 {
     ITableSnapshot snapshot = EventListSnapshotBuilder.CreateInMemorySnapshotFromRequest(new string[] { Resources.GetTRVEvents() }).Build();
 }
 public void Base_Builder()
 {
     ITableSnapshot snapshot = IssueListSnapshotBuilder.CreateInMemorySnapshotFromRequest(new string[] { Resources.GetIssuesResponse_FirstDraft() }).Build();
 }