Beispiel #1
0
        static void Main(string[] args)
        {
            System.Console.WriteLine("START");
            var backup = new BackupWorker();

            DoJob(backup);
            System.Console.WriteLine("DONE");
            System.Console.ReadLine();
        }
 // Replace the map with a new map from files
 public static void Reset()
 {
     lock (_deserializationLock) {
         lock (_updateLock) {
             logger.Info("Backing up existing inventory data");
             string inventoryToSave = JsonConvert.SerializeObject(Holder.factionInventories);
             BackupWorker.WriteBoth(FactionInventoryStateManager.ShopFileDirectory, inventoryToSave);
             Holder.factionInventories = new Dictionary <Faction, List <ShopDefItem> >();
         }
     }
 }
 // Replace the map with a new map from files
 public static void Reset()
 {
     lock (_deserializationLock) {
         lock (_updateLock) {
             logger.Info("Backing up existing player history");
             string objectToSave = JsonConvert.SerializeObject(Holder.playerHistory);
             BackupWorker.WriteBoth(PlayerStateManager.StoragePath, objectToSave);
             Holder.playerHistory = null;
             Holder.playerHistory = new HashSet <PlayerHistory>();
         }
     }
 }
Beispiel #4
0
 // Replace the map with a new map from files
 public static void Reset()
 {
     lock (_deserializationLock) {
         lock (_updateLock) {
             logger.Info("Backing up existing starmap");
             string mapToSave = JsonConvert.SerializeObject(Holder.currentMap);
             BackupWorker.WriteBoth(StarMapStateManager.MapFileDirectory, mapToSave);
             Holder.currentMap = null;
             Holder.currentMap = InitializeNewMap();
         }
     }
 }
Beispiel #5
0
        private static async void DoJob(BackupWorker backup)
        {
            await Task.Yield();

            var start = DateTime.Now.ToLongTimeString();
            await backup.DoBackup();

            var end = DateTime.Now.ToLongTimeString();

            System.Console.WriteLine($"CheckDifferentFiles: {start}");
            System.Console.WriteLine($"End: {end}");
        }
Beispiel #6
0
        /*
         * Application that uses Windows Communications Foundation (WCF) to provide a RESTful API that allows persistence of Morphyum's WarTech.
         * If you're unfamiliar with WCF, checkout the following:
         *
         * http://dotnetmentors.com/wcf/overview-on-wcf-service-architecture.aspx
         * https://docs.microsoft.com/en-us/dotnet/framework/wcf/extending/extending-dispatchers
         *
         * The client is the PersistentMapClient, in this repository.
         * This PersistentMapServer is the server.
         *
         * Note that WCF is no longer the preferred solution for REST endpoints, which has become ASP.NET5 w/ MVC6.
         *  See https://blog.tonysneed.com/2016/01/06/wcf-is-dead-long-live-mvc-6/.
         */
        static void Main(string[] args)
        {
            try {
                // Start a heart-beat monitor to check the server status
                BackgroundWorker heartbeatWorker = new BackgroundWorker {
                    WorkerSupportsCancellation = true
                };
                heartbeatWorker.DoWork             += new DoWorkEventHandler(HeartBeatMonitor.DoWork);
                heartbeatWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(HeartBeatMonitor.RunWorkerCompleted);
                heartbeatWorker.RunWorkerAsync();

                SettingsFileMonitor monitor = new SettingsFileMonitor();
                monitor.enable();

                BackgroundWorker playerHistoryPruner = new BackgroundWorker {
                    WorkerSupportsCancellation = true
                };
                playerHistoryPruner.DoWork             += new DoWorkEventHandler(PlayerHistoryPruner.DoWork);
                playerHistoryPruner.RunWorkerCompleted += new RunWorkerCompletedEventHandler(PlayerHistoryPruner.RunWorkerCompleted);
                playerHistoryPruner.RunWorkerAsync();

                BackgroundWorker backupWorker = new BackgroundWorker {
                    WorkerSupportsCancellation = true
                };

                backupWorker.DoWork             += new DoWorkEventHandler(BackupWorker.DoWork);
                backupWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(BackupWorker.RunWorkerCompleted);
                backupWorker.RunWorkerAsync();

                // Preload the data to allow any necessary initialization to happen
                StarMapStateManager.Build();
                FactionInventoryStateManager.Build();
                PlayerStateManager.Build();

                WarServices warServices = new WarServices();
                // Create an AOP proxy object that we can hang Castle.DynamicProxies upon. These are useful for operations across the whole
                //   of the service, or for when we need to fail a message in a reasonable way.
                var proxy = new Castle.DynamicProxy.ProxyGenerator()
                            .CreateClassProxyWithTarget <WarServices>(warServices, new Castle.DynamicProxy.IInterceptor[] {
                    new UserQuotaInterceptor(), new AdminKeyRequiredInterceptor()
                });

                // Create a RESTful service host. The service instance is automatically, through
                //   the WarServiceInstanceProviderBehaviorAttribute. We create the singleton this way to give
                //   us the chance to customize the binding
                WebServiceHost _serviceHost = new WebServiceHost(typeof(WarServices), new Uri(ServiceUrl));
                AddServiceBehaviors(_serviceHost);

                // Create a binding that wraps the default WebMessageEncodingBindingElement with a BindingElement
                //   that can GZip compress responses when a client requests it.
                WebMessageEncodingBindingElement innerEncoding = new WebMessageEncodingBindingElement {
                    ContentTypeMapper = new ForceJsonWebContentMapper()
                };
                GZipMessageEncodingBindingElement encodingWrapper = new GZipMessageEncodingBindingElement(innerEncoding);

                var transport = new HttpTransportBindingElement {
                    ManualAddressing = true,
                    KeepAliveEnabled = false,
                    AllowCookies     = false
                };

                var customBinding = new CustomBinding(encodingWrapper, transport);

                // Create a default endpoint with the JSON/XML behaviors and the behavior to check the incoming headers for GZIP requests
                var endpoint = _serviceHost.AddServiceEndpoint(typeof(IWarServices), customBinding, "");
                endpoint.Behaviors.Add(new WebHttpBehavior());
                endpoint.Behaviors.Add(new GZipBehavior());

                _serviceHost.Open();

                Console.WriteLine("Open Press Key to close");
                Console.ReadKey();

                _serviceHost.Close();
                Console.WriteLine("Connection Closed");

                // Cleanup any outstanding processes
                monitor.disable();

                heartbeatWorker.CancelAsync();

                playerHistoryPruner.CancelAsync();
                PlayerHistoryPruner.PruneOnExit();

                backupWorker.CancelAsync();
                BackupWorker.BackupOnExit();
            } catch (Exception e) {
                Console.WriteLine(e);
                Console.ReadKey();
            }
        }