Beispiel #1
0
 static void SetReferencedSyncModelPath(SyncObjectInstance instance, SyncManifest manifest)
 {
     instance.ObjectId = new SyncId(GetSyncModelLocalPath <SyncObject>(instance.ObjectId.Value, manifest));
 }
Beispiel #2
0
        internal static SyncPrefab GenerateSyncPrefabFromManifest(string name, string rootFolder, SyncManifest manifest)
        {
            var prefab = new SyncPrefab { Name = name };

            var content = manifest.Content;
            foreach (var pair in content)
            {
                if (pair.Key.IsKeyFor<SyncObjectInstance>())
                {
                    // Load SynObjectInstance from disk
                    var instancePath = Path.Combine(rootFolder, pair.Value.ModelPath);
                    var objectInstance = PlayerFile.Load<SyncObjectInstance>(instancePath);
                    objectInstance.Name = Path.GetFileNameWithoutExtension(objectInstance.Name);
                    prefab.Instances.Add(objectInstance);
                }
            }

            return prefab;
        }
Beispiel #3
0
        internal static async Task DownloadAndStore(IPlayerClient client, string sourceId, ManifestEntry entry, SyncManifest newManifest,
                                                    string downloadFolder, DownloadProgress progress)
        {
            Exception exception = null;

            try
            {
                var syncModel = await client.GetSyncModelAsync(sourceId, entry.ModelPath, entry.Hash);

                if (syncModel != null)
                {
                    // Replace model name with local model paths
                    syncModel.Name = entry.ModelPath;
                    SetReferencedSyncModelPath(syncModel, newManifest);

                    var fullPath  = Path.Combine(downloadFolder, entry.ModelPath);
                    var directory = Path.GetDirectoryName(fullPath);

                    await RunFileIOOperation(async() =>
                    {
                        Directory.CreateDirectory(directory);
                        await PlayerFile.SaveAsync(syncModel, fullPath);
                    });
                }
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            if (exception != null)
            {
                progress.errors.Enqueue(new DownloadError(exception, entry));
            }

            progress.ReportCompleted();
        }
Beispiel #4
0
        private static async Task StartHostAsync()
        {
            var hostBuilder = new HostBuilder()
                              .UseContentRoot(Directory.GetCurrentDirectory())
#if DEBUG
                              .UseEnvironment("Development")
#endif
                              .ConfigureAppConfiguration((hostingContext, config) =>
            {
                var env = hostingContext.HostingEnvironment;
                config.SetBasePath(env.ContentRootPath)
                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json",
                             optional: true, reloadOnChange: true)
                .AddEnvironmentVariables();
            })
                              .ConfigureLogging((hostContext, configLogging) => { configLogging.ClearProviders(); })
                              .ConfigureServices((hostContext, services) =>
            {
                //hide console messages
                services.Configure <ConsoleLifetimeOptions>(
                    options => options.SuppressStatusMessages = true);

                //setup the configraution manager
                var configManager = new ConfigManager(hostContext.Configuration);
                services.AddSingleton <IConfigManager>(configManager);

                //use json format for reading / writing the manifest
                var builder  = new JsonManifestBuilder();
                var manifest = new SyncManifest(configManager, builder);

                //load manifest from file
                manifest.ReloadAsync().Wait();
                services.AddSingleton(manifest);

                //fetch the path to monitor
                var path = configManager.SyncDirectory;
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                //show welcome info
                ConsolePrinter.PrintWelcome(path);

                //read config for aws credentials
                var cred = new AWSCredentials();
                hostContext.Configuration.Bind("AWSCredentials", cred);

                //create and register aws glacier client
                var client = new AWSGlacierClient(cred);
                services.AddSingleton <IStorageClient>(client);

                //add the sync daemon
                services.AddHostedService <SyncHoleService>();

                //register worker factory
                services.AddSingleton <IWorkerFactory, WorkerFactory>();
            });

            await hostBuilder.RunConsoleAsync();
        }