Esempio n. 1
0
 public void Start(System.Threading.Tasks.Task task, ILogger log)
 {
     _log = log;
     task.ContinueWith(t => InvokeError(t, t.Exception.InnerException),
                    TaskContinuationOptions.OnlyOnFaulted |
                    TaskContinuationOptions.ExecuteSynchronously);
     task.Start();
 }
Esempio n. 2
0
        public static System.Threading.Tasks.Task OnAfter_SaveGame_Started(System.Threading.Tasks.Task save_task, Game.GnomanEmpire self, bool fallenKingdom)
        {
            // This function is hooked into the game as specified by GetConfig().
            // Be careful to exactly match the required structure (see other doc, sth like [RetVal|void]([retVal][this][arguments]) )
            // Currently there isn't any flexibility, so you have to specifiy all that apply
            return save_task.ContinueWith((task) =>
            {
                try
                {
                    //scaning for the newest dated looks like the easies way to get the latest save, since i havent found any "get current save file"-func
                    var latest_save_file = new System.IO.DirectoryInfo(Game.GnomanEmpire.SaveFolderPath("Worlds\\"))
                        .GetFiles()
                        .Where(file => file.Extension.ToUpper() == ".SAV")
                        .Aggregate((a, b) =>
                        {
                            return a.LastWriteTime > b.LastWriteTime ? a : b;
                        });
                    var backup_folder = System.IO.Path.Combine(latest_save_file.DirectoryName, "Backups");
                    System.IO.Directory.CreateDirectory(backup_folder);
                    System.IO.File.Copy(
                        latest_save_file.FullName,
                        System.IO.Path.Combine(
                            backup_folder,
                            latest_save_file.Name.Remove(latest_save_file.Name.Length - latest_save_file.Extension.Length)
                            + "_" + DateTime.Now.ToString("yyyyMMddHHmmss")
                            + latest_save_file.Extension
                            )
                        );
                    return;
                }
                catch (Exception err)
                {
                    RuntimeModController.Log.Write(err);
                }
            });

            //don't want to return a modified value? In that case you have to return the return_val parameter! (usually first argument)
            //return save_task;
        }
 private static void IgnoreTaskErrors (System.Threading.Tasks.Task task)
 {
     task.ContinueWith (t => {
         var e = t.Exception;
         var log = ServiceContainer.Resolve<ILogger> ();
         log.Info (Tag, e, "Failed to send GCM info to server.");
     }, TaskContinuationOptions.OnlyOnFaulted);
 }