public IActionResult ImportTests(ImportTestsViewModel viewModel)
        {
            var tests         = ImportExportUtil.CreateTests(viewModel.Separator, viewModel.Text);
            var allCategories = _database.Categories.ToList();

            tests.ForEach(t =>
            {
                var category = _database.Categories.FirstOrDefault(c => c.Name == t.CategoryName);
                if (category == null)
                {
                    category = new CategoryModel
                    {
                        Name = t.CategoryName
                    };

                    _database.Categories.Add(category);
                    _database.SaveChanges();
                }

                t.CategoryID = category.ID;

                _database.CategoryTests.Add(t);
            });

            _database.SaveChanges();

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> ExportAppData()
        {
            var appData = await ImportExportUtil.ExportApplicationData(_database);

            var fileBytes = Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(appData));

            return(File(fileBytes, "application/x-msdownload", ImportExportUtil.EXPORT_FILENAME));
        }
        public async Task <IActionResult> ImportAppData(IFormFile file)
        {
            if (file == null)
            {
                return(RedirectToAction("ImportAppData"));
            }

            var content = "";

            using (var reader = new StreamReader(file.OpenReadStream()))
            {
                content = await reader.ReadToEndAsync();
            }

            var appData = JsonConvert.DeserializeObject <AppDataModel>(content);

            await ImportExportUtil.ImportApplicationData(_database, appData);

            return(RedirectToAction("Index"));
        }
Пример #4
0
        static int Main(string[] args)
        {
            new ObSS();

            string logFile = args.Length > 0 ? args[0] : null;

            //Disable IQ Engine Activity Validation.  The "GetEnglishStrings()" call below invokes the mechanism used
            //to validate IQ Scripts in MOSAIQ.  We can't disable that mechanism from firing, but we can disable the
            //validtion calls what we make within that mechanism, which is what we do below.
            IQSettings.ActivityValidationEnabled = false;

            //Get the list of IQ Export files.
            var iqExportFiles = new List <string>();

            foreach (var iqArchivePath in IQEngine.IQArchivePaths.Where(Directory.Exists))
            {
                iqExportFiles.AddRange(Directory.GetFiles(iqArchivePath, "*.iq", SearchOption.TopDirectoryOnly));
            }

            //Loop through the files and validate them.
            var errors = new StringBuilder();

            foreach (string file in iqExportFiles)
            {
                IQExportFile iqFile     = ImportExportUtil.GetFileContents(file);
                String       fileErrors = iqFile.ValidateContents();
                if (!String.IsNullOrWhiteSpace(fileErrors))
                {
                    errors.AppendLine("=================================================================");
                    errors.AppendLine(file);
                    errors.AppendLine("=================================================================");
                    errors.AppendLine(fileErrors);
                    errors.AppendLine();
                }
            }

            //Convert the string builder to a string.
            string errorString = errors.ToString();

            //if no errors are found, bail out w/ Success Code.
            if (String.IsNullOrWhiteSpace(errorString))
            {
                const string msgSuccess = @"IQ Export Files Verified Succesfully.";
                Console.WriteLine(msgSuccess);
                return((int)ExitCode.Success);
            }

            //Otherwise, write the errors to console in red letters and return failure.
            Console.ForegroundColor = ConsoleColor.Red;
            string msgFail = Environment.NewLine + errorString.TrimEnd();

            Console.WriteLine(msgFail);

            if (!String.IsNullOrWhiteSpace(logFile))
            {
                WriteToOutputFile(args[0], msgFail);
            }
            Console.ResetColor();

            return((int)ExitCode.Failure);
        }
Пример #5
0
 /// <summary>
 /// Method which can be called from clarion which automatically imports all files with the "iq" extension
 /// in the "IQ Scripts" folder in the application directory.
 /// </summary>
 public void ImportIQFilesOnUpgrade()
 {
     ImportExportUtil.ImportAllIQFiles();
     ImportExportUtil.ImportConfiguredAssignments();
 }
Пример #6
0
        private bool ImportConfigurationFiles()
        {
            try
            {
                SystemTrace.Instance.Debug("Checking for import files");

                string[] importFiles = Directory.GetFiles("Import", "*.stbs");

                if (importFiles.Count() > 0)
                {
                    // Import any exported scenario files that were included in the installation
                    using (EnterpriseTestContext context = new EnterpriseTestContext())
                    {
                        UpdateStatus("Importing Scenarios");
                        ContractFactory.OnStatusChanged += ContractFactory_OnStatusChanged;

                        string folderName = $"V{_ticket.CurrentVersion} Imports";

                        ConfigurationTreeFolder folder = context.ConfigurationTreeFolders.FirstOrDefault(x => x.Name.Equals(folderName));
                        if (folder == null)
                        {
                            folder = new ConfigurationTreeFolder(SequentialGuid.NewGuid(), folderName, ConfigurationObjectType.ScenarioFolder.ToString(), null);
                            context.AddToConfigurationTreeFolders(folder);
                            context.SaveChanges();
                        }

                        //Ensure the path exists for import files in the shared folder location
                        StringBuilder importDestination = new StringBuilder(_fileSharePath);
                        importDestination.Append("\\Import\\V");
                        importDestination.Append(_ticket.CurrentVersion);

                        Directory.CreateDirectory(importDestination.ToString());

                        importDestination.Append("\\");
                        int destinationPathIndex = importDestination.Length;

                        foreach (string fileName in importFiles)
                        {
                            SystemTrace.Instance.Debug($"Importing {fileName}");
                            EnterpriseScenario enterpriseScenario = null;

                            try
                            {
                                XElement fileData = XElement.Parse(File.ReadAllText(fileName));

                                // If this is a composite contract file it may contain printer and document
                                // information in addition to the base scenario data.
                                if (fileData.Name.LocalName == "Composite")
                                {
                                    var compositeContract = Serializer.Deserialize <EnterpriseScenarioCompositeContract>(fileData);

                                    if (!ImportExportUtil.ProcessCompositeContractFile(compositeContract))
                                    {
                                        SystemTrace.Instance.Error($"Failed to process composite contract: {fileName}.");
                                    }

                                    enterpriseScenario = ContractFactory.Create(compositeContract.Scenario);
                                }
                                else
                                {
                                    var scenarioContract = Serializer.Deserialize <EnterpriseScenarioContract>(fileData);
                                    enterpriseScenario = ContractFactory.Create(scenarioContract);
                                }

                                enterpriseScenario.FolderId = folder.ConfigurationTreeFolderId;
                                SystemTrace.Instance.Debug($"Adding Scenario '{enterpriseScenario.Name}'");
                                context.AddToEnterpriseScenarios(enterpriseScenario);

                                // Copy the import file to the shared folder location
                                importDestination.Append(Path.GetFileName(fileName));
                                try
                                {
                                    File.Copy(fileName, importDestination.ToString(), true);
                                }
                                catch (Exception ex)
                                {
                                    SystemTrace.Instance.Error($"Failed to copy '{fileName}' to '{importDestination.ToString()}'.", ex);
                                }
                                importDestination.Remove(destinationPathIndex, importDestination.Length - destinationPathIndex);
                            }
                            catch (Exception ex)
                            {
                                // Log an error for the current file, but keep going
                                SystemTrace.Instance.Error($"Failed to import: {fileName}", ex);
                            }
                        }

                        context.SaveChanges();
                        ContractFactory.OnStatusChanged -= ContractFactory_OnStatusChanged;

                        UpdateStatus("Scenario Import Complete");
                    }
                }
            }
            catch (Exception ex)
            {
                SendError(ex);
                return(false);
            }

            return(true);
        }
Пример #7
0
        /// <summary>
        /// Commits this instance.
        /// </summary>
        private void Commit()
        {
            using (new BusyCursor())
            {
                try
                {
                    if (_deletedItems.Count > 0)
                    {
                        foreach (var item in _deletedItems)
                        {
                            _context.TestDocuments.Remove(item);
                        }
                        _context.SaveChanges();
                        _deletedItems.Clear();
                    }

                    foreach (var document in _documents)
                    {
                        if (_context.Entry(document).State == EntityState.Added)
                        {
                            document.SubmitDate = DateTime.Now;
                            _context.TestDocuments.Add(document);

                            if (_addedDocumentPath.ContainsKey(document.TestDocumentId))
                            {
                                var source = _addedDocumentPath[document.TestDocumentId];

                                try
                                {
                                    ImportExportUtil.CopyDocumentToServer(document, GlobalSettings.Items[Setting.DocumentLibraryServer], source);
                                    TraceFactory.Logger.Debug("File copied");
                                    _addedDocumentPath.Remove(document.TestDocumentId);
                                }
                                catch (UnauthorizedAccessException)
                                {
                                    MessageBox.Show
                                    (
                                        "You do not have authorization to save {0} to the STB Document Server. This document will not be added.".FormatWith(source),
                                        "Unauthorized Access",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error
                                    );
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show
                                    (
                                        "A error occurred when trying to save {0} to the STB Document Server. This document will not be added. Error: {1}".FormatWith(source, ex.Message),
                                        "Unauthorized Access",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error
                                    );
                                }
                            }
                            else if (_importedDocumentData.ContainsKey(document.TestDocumentId))
                            {
                                var data = _importedDocumentData[document.TestDocumentId];
                                ImportExportUtil.WriteDocumentToServer(document, GlobalSettings.Items[Setting.DocumentLibraryServer], data);
                                TraceFactory.Logger.Debug("File imported");
                                _importedDocumentData.Remove(document.TestDocumentId);
                            }
                        }
                    }
                    _context.SaveChanges();
                }
                catch (Exception ex)
                {
                    TraceFactory.Logger.Error(ex);
                    MessageBox.Show
                    (
                        "A error occurred when trying to save to the STB Document Server. This document will not be added. Error: {0}".FormatWith(ex.Message),
                        "Unauthorized Access",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error
                    );
                }
            }
        }