示例#1
0
        private void Import_CB_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter      = "Character File|*.dnd4e";
            dlg.Multiselect = true;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                foreach (string filename in dlg.FileNames)
                {
                    string xml  = File.ReadAllText(filename);
                    Hero   hero = AppImport.ImportHero(xml);

                    if (hero != null)
                    {
                        add_hero(hero);
                        update_view();
                    }
                    else
                    {
                        MessageBox.Show("The character file could not be loaded.", "Masterplan", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
        }
示例#2
0
 private void Import_iPlay4e_Party_Click(object sender, EventArgs e)
 {
     try
     {
         HeroIPlay4eForm heroIPlay4eForm = new HeroIPlay4eForm("", false);
         if (heroIPlay4eForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             System.Windows.Forms.Cursor.Current = Cursors.WaitCursor;
             List <Hero> heros = AppImport.ImportParty(heroIPlay4eForm.Key);
             System.Windows.Forms.Cursor.Current = Cursors.Default;
             foreach (Hero hero in heros)
             {
                 this.add_hero(hero);
             }
             this.update_view();
             if (heros.Count == 0)
             {
                 MessageBox.Show("No characters were found (make sure they are public).", "Masterplan", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
             }
         }
     }
     catch (Exception exception)
     {
         LogSystem.Trace(exception);
     }
 }
示例#3
0
        private void Import_CB_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog()
            {
                Filter      = "Character File|*.dnd4e",
                Multiselect = true
            };

            if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string[] fileNames = openFileDialog.FileNames;
                for (int i = 0; i < (int)fileNames.Length; i++)
                {
                    string str  = fileNames[i];
                    Hero   hero = AppImport.ImportHero(File.ReadAllText(str));
                    if (hero == null)
                    {
                        MessageBox.Show("The character file could not be loaded.", "Masterplan", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    }
                    else
                    {
                        this.add_hero(hero);
                        this.update_view();
                    }
                }
            }
        }
示例#4
0
        /// <summary>
        /// Imports tenant ZIP archive to current tenant (see <see
        /// cref="ActionManager.CurrentTenant"/>). The ZIP file will be taken by path in
        /// <see cref="TestConfig.BrowserDownloadFolder"/>.
        /// </summary>
        /// <param name="fileName">Exported tenant archive file name without path (like
        /// tenantCode_[timestamp].zip)</param>
        public static void ImportTenant(string fileName)
        {
            var tenantFilePath = string.Empty;
            var token          = BackgroundTaskApi.GetPackageSas();

            try
            {
                var blob = new CloudAppendBlob(new Uri(token));
                tenantFilePath = Path.Combine(TestConfig.BrowserDownloadFolder, fileName);
                blob.UploadFromFile(tenantFilePath);
                blob.SetProperties();
            }
            catch (Exception e)
            {
                throw new FileLoadException(
                          $"Tenant API: Error uploading file {tenantFilePath} to cloud: {e.Message}");
            }

            var task = BackgroundTaskApi.NewBackgroundTask(TaskActionType.ImportTenant, fileName,
                                                           new FileInfo(tenantFilePath).Length,
                                                           token);

            if (task == null || string.IsNullOrEmpty(task.TaskId))
            {
                throw new Exception(
                          $"Could not start new background task for tenant archive '{fileName}' import");
            }
            var body = new AppImport
            {
                PackageSas = token,
                TaskId     = task.TaskId
            };

            BackgroundTaskApi.ProcessedObjects.AddOrUpdate(task.TaskId,
                                                           (null, null, new ManualResetEvent(false)),
                                                           (k, v) => (null, null, new ManualResetEvent(false)));
            Trace.TraceInformation($"Tenant API: Import task {task.TaskId} started");

            RestController.HttpRequestJson(UriCxm.BackgroundTaskExecution, Method.POST, body);

            if (BackgroundTaskApi.ProcessedObjects.TryGetValue(task.TaskId, out var tenantObj) &&
                tenantObj.Item3.WaitOne(TimeSpan.FromSeconds(TestConfig.TenantImportTimeout)))
            {
                Trace.TraceInformation($"Tenant API: Import task {task.TaskId} complete");
            }
            else
            {
                Trace.TraceError($"Tenant API: {task.TaskId} import timed out!");
                BackgroundTaskApi.DeleteTaskId(task.TaskId);
                throw new TimeoutException(
                          $"Tenant API: Import to tenant {ActionManager.CurrentTenantCode} timed out after " +
                          $"{TestConfig.TenantImportTimeout} s. File {fileName}.");
            }

            BackgroundTaskApi.ProcessedObjects.TryRemove(task.TaskId, out _);
            BackgroundTaskApi.DeleteTaskId(task.TaskId);
        }
示例#5
0
 private void UpdateBtn_Click(object sender, EventArgs e)
 {
     System.Windows.Forms.Cursor.Current = Cursors.WaitCursor;
     foreach (Hero hero in Session.Project.Heroes)
     {
         if (hero.Key == null || hero.Key == "")
         {
             continue;
         }
         AppImport.ImportIPlay4e(hero);
     }
     Session.Modified = true;
     this.update_view();
     System.Windows.Forms.Cursor.Current = Cursors.Default;
 }
示例#6
0
        private void edit_iplay4e()
        {
            List <Hero>     heros           = (Session.Project.Heroes.Contains(this.SelectedHero) ? Session.Project.Heroes : Session.Project.InactiveHeroes);
            int             num             = heros.IndexOf(this.SelectedHero);
            HeroIPlay4eForm heroIPlay4eForm = new HeroIPlay4eForm(this.SelectedHero.Key, true);

            if (heroIPlay4eForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                Hero hero = new Hero()
                {
                    Key = heroIPlay4eForm.Key
                };
                System.Windows.Forms.Cursor.Current = Cursors.WaitCursor;
                bool flag = AppImport.ImportIPlay4e(hero);
                System.Windows.Forms.Cursor.Current = Cursors.Default;
                if (flag)
                {
                    heros[num]       = hero;
                    Session.Modified = true;
                    this.update_view();
                }
            }
        }
示例#7
0
 private void Import_iPlay4e_Click(object sender, EventArgs e)
 {
     try
     {
         HeroIPlay4eForm heroIPlay4eForm = new HeroIPlay4eForm("", true);
         if (heroIPlay4eForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             Hero hero = new Hero()
             {
                 Key = heroIPlay4eForm.Key
             };
             System.Windows.Forms.Cursor.Current = Cursors.WaitCursor;
             bool flag = AppImport.ImportIPlay4e(hero);
             System.Windows.Forms.Cursor.Current = Cursors.Default;
             if (!flag)
             {
                 string str = string.Concat("The character could not be found.", Environment.NewLine);
                 str = string.Concat(str, Environment.NewLine);
                 str = string.Concat(str, "Make sure:");
                 str = string.Concat(str, Environment.NewLine);
                 str = string.Concat(str, "* The key is correct");
                 str = string.Concat(str, Environment.NewLine);
                 str = string.Concat(str, "* The character is public");
                 MessageBox.Show(str, "Masterplan", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
             }
             else
             {
                 this.add_hero(hero);
                 this.update_view();
             }
         }
     }
     catch (Exception exception)
     {
         LogSystem.Trace(exception);
     }
 }
示例#8
0
        /// <summary>
        /// Imports app from file by app version in file name
        /// </summary>
        /// <param name="path">Full path to file</param>
        /// <param name="mask">File name mask (like name*.zip) or file name without path</param>
        /// <param name="version">App version</param>
        /// <returns>(<see cref="AppResponse"/>) App object</returns>
        public static AppResponse ImportApp(string path, string mask, string version)
        {
            var appFilePath = string.Empty;
            var token       = BackgroundTaskApi.GetPackageSas();

            try
            {
                var blob = new CloudAppendBlob(new Uri(token));
                appFilePath = FileManager.GetFileByVersion(path, mask, version);
                blob.UploadFromFile(appFilePath);
                blob.SetProperties();
            }
            catch (Exception e)
            {
                throw new FileLoadException(
                          $"App API: Error uploading file {appFilePath} to cloud: {e.Message}");
            }

            var fileName = Path.GetFileName(appFilePath);
            var task     = BackgroundTaskApi.NewBackgroundTask(TaskActionType.UploadApp, fileName,
                                                               new FileInfo(appFilePath).Length,
                                                               token);

            if (task == null || string.IsNullOrEmpty(task.TaskId))
            {
                throw new Exception($"Could not start new background task for app '{fileName}' import");
            }
            var body = new AppImport
            {
                PackageSas = token,
                TaskId     = task.TaskId
            };

            BackgroundTaskApi.ProcessedObjects.AddOrUpdate(task.TaskId,
                                                           (null, null, new ManualResetEvent(false)),
                                                           (k, v) => (null, null, new ManualResetEvent(false)));
            Trace.TraceInformation($"App API: Import task {task.TaskId} started");

            RestController.HttpRequestJson(UriCxm.BackgroundTaskExecution, Method.POST, body);

            if (BackgroundTaskApi.ProcessedObjects.TryGetValue(task.TaskId, out var appObj) &&
                appObj.Item3.WaitOne(TimeSpan.FromSeconds(TestConfig.AppImportTimeout)))
            {
                Trace.TraceInformation($"App API: Import task {task.TaskId} complete");
            }
            else
            {
                Trace.TraceError($"App API: {task.TaskId} timed out!");
                throw new TimeoutException(
                          $"App API: Import on tenant {ActionManager.CurrentTenantCode} timed out after " +
                          $"{TestConfig.AppImportTimeout} s. File {fileName}.");
            }

            var result = BackgroundTaskApi.ProcessedObjects.TryGetValue(task.TaskId, out appObj) ?
                         appObj.Item1 as AppResponse :
                         null;

            BackgroundTaskApi.ProcessedObjects.TryRemove(task.TaskId, out _);

            return(result);
        }