Exemple #1
0
        public void Base()
        {
            Converts.Repository
            .AddJsonEnumSearchHandler()
            .AddJsonPrimitivesSearchHandler()
            .AddJsonObjectSearchHandler()
            .AddJsonKey()
            .AddJsonTimeSpan();

            CompositeEventFormatter formatter = new CompositeEventFormatter(
                new ReflectionCompositeTypeProvider(new ReflectionCompositeDelegateFactory()),
                Factory.Default <JsonCompositeStorage>()
                );
            MockEventStore eventStore = new MockEventStore();

            // Creation of state.
            Order order = new Order(KeyFactory.Create(typeof(Order)));

            order.AddItem(KeyFactory.Create(typeof(T_EventSourcing_ReadModels_Rebuilder)), 2);
            order.AddItem(KeyFactory.Create(typeof(Rebuilder)), 5);
            eventStore.Save(order.Events.Select(e => new EventModel(order.Key, e.Key, formatter.Serialize(e), e.Version)));

            // Rebuilding model.
            Rebuilder        rebuilder = new Rebuilder(eventStore, formatter);
            ReadModelHandler handler   = new ReadModelHandler();

            rebuilder.AddAll(handler);
            rebuilder.RunAsync().Wait();

            Assert.AreEqual(1, handler.Totals.Count);
            Assert.AreEqual(
                order.Events.OfType <OrderTotalRecalculated>().Last().TotalPrice,
                handler.Totals.FirstOrDefault().Value
                );
        }
Exemple #2
0
        public BackupContents(Rebuilder rebuilder, IUrlGenerator urlGenerator)
        {
            Guard.NotNull(rebuilder, nameof(rebuilder));
            Guard.NotNull(urlGenerator, nameof(urlGenerator));

            this.rebuilder = rebuilder;

            this.urlGenerator = urlGenerator;
        }
Exemple #3
0
 public RebuildRunner(
     IOptions <RebuildOptions> rebuildOptions,
     Rebuilder rebuilder,
     RebuildFiles rebuildFiles)
 {
     this.rebuildFiles   = rebuildFiles;
     this.rebuilder      = rebuilder;
     this.rebuildOptions = rebuildOptions.Value;
 }
Exemple #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting in thread: {0}", Thread.CurrentThread.ManagedThreadId);
            var config = LocalConfig.CreateNew(ConfigurationManager.AppSettings["fileStore"]);

            //where to send commands: this command sender is used by "processes" (things that receive events and
            //publish commands). It makes sense to do it "locally", avoiding any queues.
            //So it would look: got an event -> produced a command -> dispatched/executed it immediately.
            var whereToSendLocalCommands = new ToDispatcherCommandSender(CommandDispatcher);

            //spin up a commands receiver, it will receive commands and dispatch them to the CommandDispatcher
            var commandsReceiver = config.CreateIncomingMessagesDispatcher(IncommingCommandsQueue, DispatchCommand);
            var eventsReceiver = config.CreateIncomingMessagesDispatcher(IncommingEventsQueue, x => DispatchEvent((Envelope)x));

            using (var host = new Host())
            {
                using (var eventStore = config.CreateEventStore("ZigguratES"))
                {
                    var eventsFromEventSourceToQueueDistributor =
                        new EventStoreToQueueDistributor(IncommingEventsQueue, config.QueueFactory, eventStore, config.ProjectionsStore, config.Serializer);

                    var appServices = DomainBoundedContext.BuildApplicationServices(eventStore, config.ProjectionsStore);
                    var processes = DomainBoundedContext.BuildEventProcessors(whereToSendLocalCommands);

                    Func<IDocumentStore, IEnumerable<object>> getProjectionsFunction =
                        factory =>
                        {
                            var domainProjections = DomainBoundedContext.BuildProjections(factory);
                            var clientProjections = ClientBoundedContext.BuildProjections(factory);
                            return domainProjections.Concat(clientProjections);
                        };

                    var projectionRebuilder = new Rebuilder(
                        "definition",
                        eventStore,
                        config.ProjectionsStore,
                        getProjectionsFunction);

                    host.AddStartupTask(c => projectionRebuilder.Run());

                    var projections = getProjectionsFunction(config.ProjectionsStore);

                    foreach (var appService in appServices) CommandDispatcher.Subscribe(appService);
                    foreach (var projection in projections) EventsDispatcher.Subscribe(projection);
                    foreach (var process in processes) EventsDispatcher.Subscribe(process);

                    host.AddTask(c => commandsReceiver.Run(c));
                    host.AddTask(c => eventsFromEventSourceToQueueDistributor.Run(c));
                    host.AddTask(c => eventsReceiver.Run(c));
                    host.Run();

                    Thread.Sleep(400);
                    Console.ReadKey();
                }
            }
        }
Exemple #5
0
        public BackupAssets(Rebuilder rebuilder, IAssetFileStore assetFileStore, ITagService tagService)
        {
            Guard.NotNull(rebuilder, nameof(rebuilder));
            Guard.NotNull(assetFileStore, nameof(assetFileStore));
            Guard.NotNull(tagService, nameof(tagService));

            this.rebuilder      = rebuilder;
            this.assetFileStore = assetFileStore;
            this.tagService     = tagService;
        }
        public RebuildRunner(Rebuilder rebuilder, IOptions <RebuildOptions> rebuildOptions, PopulateGrainIndexes populateGrainIndexes)
        {
            Guard.NotNull(rebuilder, nameof(rebuilder));
            Guard.NotNull(rebuildOptions, nameof(rebuildOptions));
            Guard.NotNull(populateGrainIndexes, nameof(populateGrainIndexes));

            this.rebuilder            = rebuilder;
            this.rebuildOptions       = rebuildOptions.Value;
            this.populateGrainIndexes = populateGrainIndexes;
        }
Exemple #7
0
        public Boolean SyncronizeDatabases(ConnectionData gold, ConnectionData toUpdate, bool continueOnFailure)
        {
            DatabaseDiffer diff = new DatabaseDiffer();


            DatabaseRunHistory toBeRun = diff.GetDatabaseHistoryDifference(gold, toUpdate);

            PushInfo(string.Format("{0} database packages found to run on {1}.{2}", toBeRun.BuildFileHistory.Count, toUpdate.SQLServerName, toUpdate.DatabaseName));

            if (toBeRun.BuildFileHistory.Count == 0) //already in sync
            {
                return(true);
            }

            //Make temp directory for rebuild packages...
            string tempPath = System.IO.Path.GetTempPath() + System.Guid.NewGuid();

            Directory.CreateDirectory(tempPath);
            List <string> rebuiltPackages = new List <string>();

            //Create SBM packages for each
            foreach (var buildFileHistory in toBeRun.BuildFileHistory)
            {
                PushInfo(string.Format("Rebuilding Package {0} (Hash:{1})", buildFileHistory.BuildFileName, buildFileHistory.BuildFileHash));

                var fileName    = tempPath + "\\" + Path.GetFileNameWithoutExtension(buildFileHistory.BuildFileName) + ".sbm"; //Make sure it creates and SBM and not an SBX
                var rebuildData = Rebuilder.RetreiveBuildData(gold, buildFileHistory.BuildFileHash, buildFileHistory.CommitDate);
                rebuildData.ForEach(h => h.ScriptFileName = Path.GetFileName(h.ScriptFileName));                               //trim off the path, we just want the file name

                bool success = Rebuilder.RebuildBuildManagerFile(500, fileName, rebuildData);
                if (!success)
                {
                    PushInfo(string.Format("Error creating package {0} (Hash:{1}) see error log for details.", buildFileHistory.BuildFileName, buildFileHistory.BuildFileHash));
                    ProcessDirectoryCleanup(tempPath);
                    return(false);
                }
                rebuiltPackages.Add(fileName);
            }

            bool syncronized = ProcessSyncronizationPackages(rebuiltPackages, toUpdate, false, continueOnFailure);

            if (syncronized)
            {
                PushInfo(string.Format("Syncronized database {0}.{1} to source {2}.{3}", toUpdate.SQLServerName,
                                       toUpdate.DatabaseName, gold.SQLServerName, gold.DatabaseName));
            }
            else
            {
                PushInfo(string.Format("Syncronize failed to {0}.{1} from source {2}.{3}. See log for details.", toUpdate.SQLServerName,
                                       toUpdate.DatabaseName, gold.SQLServerName, gold.DatabaseName));
            }
            ProcessDirectoryCleanup(tempPath);

            return(syncronized);
        }
Exemple #8
0
 public RebuildRunner(
     IOptions <RebuildOptions> rebuildOptions,
     Rebuilder rebuilder,
     RebuildFiles rebuildFiles,
     PopulateGrainIndexes populateGrainIndexes)
 {
     this.rebuildFiles         = rebuildFiles;
     this.rebuilder            = rebuilder;
     this.rebuildOptions       = rebuildOptions.Value;
     this.populateGrainIndexes = populateGrainIndexes;
 }
Exemple #9
0
 public BackupApps(
     Rebuilder rebuilder,
     IAppImageStore appImageStore,
     IAppsIndex appsIndex,
     IAppUISettings appUISettings)
 {
     this.appsIndex     = appsIndex;
     this.rebuilder     = rebuilder;
     this.appImageStore = appImageStore;
     this.appUISettings = appUISettings;
 }
Exemple #10
0
 public void LoadSave(Rebuilder data)
 {
     try
     {
         Globals.Player = data.BuildPlayer();
     }
     catch (Exception e)
     {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine("Could not load save data.\nError: ");
         Console.ResetColor();
         Console.WriteLine(e.StackTrace);
     }
 }
Exemple #11
0
        private Task RecreateReadModelContext()
        {
            using (var readModels = new ReadModelContext())
            {
                readModels.Database.EnsureDeleted();
                readModels.Database.EnsureCreated();
            }

            // Should match with ReadModels.
            Rebuilder rebuilder = new Rebuilder(eventStore, eventFormatter);

            rebuilder.AddAll(new CategoryBuilder());
            rebuilder.AddAll(new OutcomeBuilder(domainFacade.PriceFactory));
            return(rebuilder.RunAsync());
        }
Exemple #12
0
        public override bool ProcessFeatures(Dictionary <string, Feature> features)
        {
            // If the base fails, just fail out
            if (!base.ProcessFeatures(features))
            {
                return(false);
            }

            // Get feature flags
            bool   copy   = GetBoolean(features, CopyValue);
            string outdat = GetString(features, OutStringValue);

            // Verify the filenames
            Dictionary <string, string> foundDats = GetValidDats(Inputs);

            // Ensure the output directory is set
            if (string.IsNullOrWhiteSpace(outdat))
            {
                outdat = "out";
            }

            // Now that we have the dictionary, we can loop through and output to a new folder for each
            foreach (string key in foundDats.Keys)
            {
                // Get the DAT file associated with the key
                DatFile datFile = Parser.CreateAndParse(Path.Combine(_dats, foundDats[key]));

                // Set the depot values
                datFile.Header.InputDepot  = new DepotInformation(true, 4);
                datFile.Header.OutputDepot = new DepotInformation(true, 4);

                // Create the new output directory if it doesn't exist
                string outputFolder = Path.Combine(outdat, Path.GetFileNameWithoutExtension(foundDats[key]));
                outputFolder.Ensure(create: true);

                // Get all online depots
                List <string> onlineDepots = _depots.Where(d => d.Value.Item2).Select(d => d.Key).ToList();

                // Now scan all of those depots and rebuild
                Rebuilder.RebuildDepot(
                    datFile,
                    onlineDepots,
                    outDir: outputFolder,
                    outputFormat: copy ? OutputFormat.TorrentGzipRomba : OutputFormat.TorrentZip);
            }

            return(true);
        }
Exemple #13
0
        internal async Task RecreateReadModelContextAsync()
        {
            using (var readModels = readModelContextFactory.Create())
            {
                await readModels.Database.EnsureDeletedAsync();

                await readModels.Database.EnsureCreatedAsync();
            }

            // Should match with ReadModels.
            Rebuilder rebuilder = new Rebuilder(eventStore, eventFormatter);
            DefaultQueryDispatcher queryDispatcher = new DefaultQueryDispatcher();

            Models.Builders.BootstrapTask bootstrapTask = new Models.Builders.BootstrapTask(queryDispatcher, rebuilder, readModelContextFactory, priceConverter);
            bootstrapTask.Initialize();

            await rebuilder.RunAsync();
        }
 public static Task RebuildRulesAsync(this Rebuilder rebuilder, CancellationToken ct = default)
 {
     return(rebuilder.RebuildAsync <RuleDomainObject, RuleState>("^rule\\-", ct));
 }
 public static Task RebuildSchemasAsync(this Rebuilder rebuilder, CancellationToken ct = default)
 {
     return(rebuilder.RebuildAsync <SchemaDomainObject, SchemaState>("^schema\\-", ct));
 }
 public static Task RebuildAppsAsync(this Rebuilder rebuilder, CancellationToken ct = default)
 {
     return(rebuilder.RebuildAsync <AppDomainObject, AppState>("^app\\-", ct));
 }
Exemple #17
0
        public BackupContents(Rebuilder rebuilder)
        {
            Guard.NotNull(rebuilder);

            this.rebuilder = rebuilder;
        }
 public RebuildSnapshots(Rebuilder rebuilder)
 {
     this.rebuilder = rebuilder;
 }
 public RebuildContents(Rebuilder rebuilder)
 {
     this.rebuilder = rebuilder;
 }
Exemple #20
0
 public RebuildAssetFolders(Rebuilder rebuilder,
                            IOptions <RebuildOptions> rebuildOptions)
 {
     this.rebuilder      = rebuilder;
     this.rebuildOptions = rebuildOptions.Value;
 }
Exemple #21
0
 public static Task RebuildAssetsAsync(this Rebuilder rebuilder, int batchSize, CancellationToken ct = default)
 {
     return(rebuilder.RebuildAsync <AssetDomainObject, AssetDomainObject.State>("^asset\\-", batchSize, ct));
 }
 public static Task RebuildAssetFoldersAsync(this Rebuilder rebuilder, CancellationToken ct = default)
 {
     return(rebuilder.RebuildAsync <AssetFolderDomainObject, AssetFolderState>("^assetFolder\\-", ct));
 }
 public RebuildAssets(Rebuilder rebuilder)
 {
     this.rebuilder = rebuilder;
 }
Exemple #24
0
 public BackupAssets(Rebuilder rebuilder, IAssetFileStore assetFileStore, ITagService tagService)
 {
     this.rebuilder      = rebuilder;
     this.assetFileStore = assetFileStore;
     this.tagService     = tagService;
 }
Exemple #25
0
        public override bool ProcessFeatures(Dictionary <string, SabreTools.Help.Feature> features)
        {
            // If the base fails, just fail out
            if (!base.ProcessFeatures(features))
            {
                return(false);
            }

            // Get the archive scanning level
            // TODO: Remove usage
            int sevenzip = GetInt32(features, Include7ZipsInt32Value);
            int gz       = GetInt32(features, IncludeGZipsInt32Value);
            int zip      = GetInt32(features, IncludeZipsInt32Value);

            // Get feature flags
            bool noDb       = GetBoolean(features, NoDbValue);
            bool onlyNeeded = GetBoolean(features, OnlyNeededValue);

            // First we want to get just all directories from the inputs
            List <string> onlyDirs = new List <string>();

            foreach (string input in Inputs)
            {
                if (Directory.Exists(input))
                {
                    onlyDirs.Add(Path.GetFullPath(input));
                }
            }

            // Then process all of the input directories into an internal DAT
            DatFile df = DatFile.Create();

            foreach (string dir in onlyDirs)
            {
                DatFromDir.PopulateFromDir(df, dir, asFiles: TreatAsFile.NonArchive, hashes: Hash.Standard);
                DatFromDir.PopulateFromDir(df, dir, asFiles: TreatAsFile.All, hashes: Hash.Standard);
            }

            // Create an empty Dat for files that need to be rebuilt
            DatFile need = DatFile.Create();

            // Open the database connection
            SqliteConnection dbc = new SqliteConnection(_connectionString);

            dbc.Open();

            // Now that we have the Dats, add the files to the database
            string crcquery     = "INSERT OR IGNORE INTO crc (crc) VALUES";
            string md5query     = "INSERT OR IGNORE INTO md5 (md5) VALUES";
            string sha1query    = "INSERT OR IGNORE INTO sha1 (sha1, depot) VALUES";
            string crcsha1query = "INSERT OR IGNORE INTO crcsha1 (crc, sha1) VALUES";
            string md5sha1query = "INSERT OR IGNORE INTO md5sha1 (md5, sha1) VALUES";

            foreach (string key in df.Items.Keys)
            {
                ConcurrentList <DatItem> datItems = df.Items[key];
                foreach (Rom rom in datItems)
                {
                    // If we care about if the file exists, check the databse first
                    if (onlyNeeded && !noDb)
                    {
                        string query = "SELECT * FROM crcsha1 JOIN md5sha1 ON crcsha1.sha1=md5sha1.sha1"
                                       + $" WHERE crcsha1.crc=\"{rom.CRC}\""
                                       + $" OR md5sha1.md5=\"{rom.MD5}\""
                                       + $" OR md5sha1.sha1=\"{rom.SHA1}\"";
                        SqliteCommand    slc  = new SqliteCommand(query, dbc);
                        SqliteDataReader sldr = slc.ExecuteReader();

                        if (sldr.HasRows)
                        {
                            // Add to the queries
                            if (!string.IsNullOrWhiteSpace(rom.CRC))
                            {
                                crcquery += $" (\"{rom.CRC}\"),";
                            }

                            if (!string.IsNullOrWhiteSpace(rom.MD5))
                            {
                                md5query += $" (\"{rom.MD5}\"),";
                            }

                            if (!string.IsNullOrWhiteSpace(rom.SHA1))
                            {
                                sha1query += $" (\"{rom.SHA1}\", \"{_depots.Keys.ToList()[0]}\"),";

                                if (!string.IsNullOrWhiteSpace(rom.CRC))
                                {
                                    crcsha1query += $" (\"{rom.CRC}\", \"{rom.SHA1}\"),";
                                }

                                if (!string.IsNullOrWhiteSpace(rom.MD5))
                                {
                                    md5sha1query += $" (\"{rom.MD5}\", \"{rom.SHA1}\"),";
                                }
                            }

                            // Add to the Dat
                            need.Items.Add(key, rom);
                        }
                    }
                    // Otherwise, just add the file to the list
                    else
                    {
                        // Add to the queries
                        if (!noDb)
                        {
                            if (!string.IsNullOrWhiteSpace(rom.CRC))
                            {
                                crcquery += $" (\"{rom.CRC}\"),";
                            }

                            if (!string.IsNullOrWhiteSpace(rom.MD5))
                            {
                                md5query += $" (\"{rom.MD5}\"),";
                            }

                            if (!string.IsNullOrWhiteSpace(rom.SHA1))
                            {
                                sha1query += $" (\"{rom.SHA1}\", \"{_depots.Keys.ToList()[0]}\"),";

                                if (!string.IsNullOrWhiteSpace(rom.CRC))
                                {
                                    crcsha1query += $" (\"{rom.CRC}\", \"{rom.SHA1}\"),";
                                }

                                if (!string.IsNullOrWhiteSpace(rom.MD5))
                                {
                                    md5sha1query += $" (\"{rom.MD5}\", \"{rom.SHA1}\"),";
                                }
                            }
                        }

                        // Add to the Dat
                        need.Items.Add(key, rom);
                    }
                }
            }

            // Now run the queries, if they're populated
            if (crcquery != "INSERT OR IGNORE INTO crc (crc) VALUES")
            {
                SqliteCommand slc = new SqliteCommand(crcquery.TrimEnd(','), dbc);
                slc.ExecuteNonQuery();
                slc.Dispose();
            }

            if (md5query != "INSERT OR IGNORE INTO md5 (md5) VALUES")
            {
                SqliteCommand slc = new SqliteCommand(md5query.TrimEnd(','), dbc);
                slc.ExecuteNonQuery();
                slc.Dispose();
            }

            if (sha1query != "INSERT OR IGNORE INTO sha1 (sha1, depot) VALUES")
            {
                SqliteCommand slc = new SqliteCommand(sha1query.TrimEnd(','), dbc);
                slc.ExecuteNonQuery();
                slc.Dispose();
            }

            if (crcsha1query != "INSERT OR IGNORE INTO crcsha1 (crc, sha1) VALUES")
            {
                SqliteCommand slc = new SqliteCommand(crcsha1query.TrimEnd(','), dbc);
                slc.ExecuteNonQuery();
                slc.Dispose();
            }

            if (md5sha1query != "INSERT OR IGNORE INTO md5sha1 (md5, sha1) VALUES")
            {
                SqliteCommand slc = new SqliteCommand(md5sha1query.TrimEnd(','), dbc);
                slc.ExecuteNonQuery();
                slc.Dispose();
            }

            // Create the sorting object to use and rebuild the needed files
            Rebuilder.RebuildGeneric(
                need,
                onlyDirs,
                outDir: _depots.Keys.ToList()[0],
                outputFormat: OutputFormat.TorrentGzipRomba,
                asFiles: TreatAsFile.NonArchive);

            return(true);
        }
 public static Task RebuildContentAsync(this Rebuilder rebuilder, CancellationToken ct = default)
 {
     return(rebuilder.RebuildAsync <ContentDomainObject, ContentState>("^content\\-", ct));
 }
Exemple #27
0
 public BackupSchemas(Rebuilder rebuilder)
 {
     this.rebuilder = rebuilder;
 }
Exemple #28
0
 public RebuildContents(Rebuilder rebuilder,
                        IOptions <RebuildOptions> rebuildOptions)
 {
     this.rebuilder      = rebuilder;
     this.rebuildOptions = rebuildOptions.Value;
 }
Exemple #29
0
 public BackupRules(Rebuilder rebuilder)
 {
     this.rebuilder = rebuilder;
 }
Exemple #30
0
        public BackupContents(Rebuilder rebuilder, IUrlGenerator urlGenerator)
        {
            this.rebuilder = rebuilder;

            this.urlGenerator = urlGenerator;
        }
Exemple #31
0
 public RebuildApps(Rebuilder rebuilder)
 {
     this.rebuilder = rebuilder;
 }