Esempio n. 1
0
        /// <summary>
        /// Saves documents from the specified composite contract to the Document Library.
        /// </summary>
        /// <param name="composite">The EnterpriseScenarioCompositeContract.</param>
        /// <returns>true if the operation completed successfully.</returns>
        public static bool ProcessCompositeContractFile(EnterpriseScenarioCompositeContract composite)
        {
            using (DocumentLibraryContext context = DbConnect.DocumentLibraryContext())
            {
                bool changesMade = false;

                foreach (DocumentContract documentContract in composite.Documents)
                {
                    if (CanInsertDocument(documentContract, context))
                    {
                        TestDocument documentEntity = ContractFactory.Create(context, documentContract);
                        WriteDocumentToServer(documentEntity, GlobalSettings.Items[Setting.DocumentLibraryServer], documentContract.Data);
                        context.TestDocuments.Add(documentEntity);
                        changesMade = true;
                    }
                }

                if (changesMade)
                {
                    context.SaveChanges();
                }
            }

            return(true);
        }
Esempio n. 2
0
        public void LoadPrinters(AssetContractCollection <PrinterContract> printers)
        {
            _printers = printers;

            bool changesMade = false;

            using (AssetInventoryContext context = DbConnect.AssetInventoryContext())
            {
                foreach (var printer in _printers)
                {
                    if (!context.Assets.Any(x => x.Pool.Name.Equals(printer.PoolName)))
                    {
                        if (context.AssetPools.Count() > 0)
                        {
                            printer.PoolName = context.AssetPools.First().Name;
                            if (!context.Assets.Any(x => x.AssetId.Equals(printer.AssetId)))
                            {
                                context.Assets.Add(ContractFactory.Create(printer, context));
                                changesMade = true;
                            }
                        }
                    }
                }

                if (changesMade)
                {
                    context.SaveChanges();
                }
            }

            resolveDataGridView.DataSource = _printers;

            CheckItemsResolved();
        }
Esempio n. 3
0
        private void ResolveDataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            var printer = resolveDataGridView.Rows[e.RowIndex].DataBoundItem as PrinterContract;

            if (printer != null)
            {
                using (AssetInventoryContext context = DbConnect.AssetInventoryContext())
                {
                    var entity = context.Assets.FirstOrDefault(x => x.AssetId.Equals(printer.AssetId));
                    if (entity == null)
                    {
                        context.Assets.Add(ContractFactory.Create(printer, context));
                    }
                    else
                    {
                        entity.Pool = context.AssetPools.FirstOrDefault(n => n.Name == printer.PoolName);
                    }

                    context.SaveChanges();
                }
            }

            CheckItemsResolved();
            resolveDataGridView.Invalidate();
        }
Esempio n. 4
0
        private void importToolStripButton_Click(object sender, EventArgs e)
        {
            using (var dialog = new ExportOpenFileDialog(_directory, "Open STB Device Export File", ImportExportType.Printer))
            {
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    var file = dialog.Base.FileName;
                    _directory = Path.GetDirectoryName(file);

                    using (AssetInventoryContext context = DbConnect.AssetInventoryContext())
                    {
                        var contracts = LegacySerializer.DeserializeDataContract <AssetContractCollection <PrinterContract> >(File.ReadAllText(file));
                        foreach (var contract in contracts)
                        {
                            var printer = ContractFactory.Create(contract, context);
                            AddPrinter(printer);
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        private void importToolStripButton_Click(object sender, EventArgs e)
        {
            try
            {
                using (var dialog = new ExportOpenFileDialog(_directory, "Open Test Document Export File", ImportExportType.Document))
                {
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        var file = dialog.Base.FileName;
                        _directory = Path.GetDirectoryName(file);

                        var contracts = LegacySerializer.DeserializeDataContract <DocumentContractCollection>(File.ReadAllText(file));

                        foreach (var contract in contracts)
                        {
                            if (!_context.TestDocuments.Any(x => x.FileName.Equals(contract.FileName, StringComparison.OrdinalIgnoreCase)))
                            {
                                var document = ContractFactory.Create(_context, contract);
                                _importedDocumentData.Add(document.TestDocumentId, contract.Data);
                                AddDocument(document);
                            }
                            else
                            {
                                // Log an error for the current file, but keep going
                                TraceFactory.Logger.Debug("Document already exists: {0}".FormatWith(contract.FileName));
                            }
                        }

                        MessageBox.Show("Documents have been imported", "Import Documents", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            catch (Exception ex)
            {
                TraceFactory.Logger.Error(ex);
                MessageBox.Show("Error importing document: {0}. Check log file for more details.".FormatWith(ex.Message));
            }
        }
Esempio n. 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);
        }
        private bool AssetPoolResolutionRequired()
        {
            if (_compositeContract == null)
            {
                return(false);
            }
            else if (_compositeContract.Printers.Count == 0)
            {
                return(false);
            }

            if (_assetPoolFirstPass)
            {
                // Only run through this code the first time.  It will remove existing
                // entries first but then display the remaining entries if the user
                // goes back and forth through the wizard
                using (AssetInventoryContext context = DbConnect.AssetInventoryContext())
                {
                    var values = _compositeContract.Printers.Select(x => x.AssetId).ToList();
                    var source = context.Assets.Select(x => x.AssetId).ToList();
                    foreach (var assetId in values.Where(i => source.Contains(i)))
                    {
                        // Get rid of any printers referenced in the import data that are
                        // already present in the asset inventory system.
                        var printer = _compositeContract.Printers.First(x => x.AssetId.Equals(assetId));
                        _compositeContract.Printers.Remove(printer);
                    }

                    if (_compositeContract.Printers.Count == 0)
                    {
                        // If there are no new printers left to add, return false
                        return(false);
                    }
                    else if (context.AssetPools.Count() == 1)
                    {
                        // If there are new printers to add, and there is only one pool
                        // name to choose from, then add the new printers and return false
                        // There's no reason to show this wizard page.
                        var poolName = context.AssetPools.First().Name;
                        foreach (var printer in _compositeContract.Printers)
                        {
                            printer.PoolName = poolName;
                            context.Assets.Add(ContractFactory.Create(printer, context));
                        }

                        context.SaveChanges();
                        EvaluateUsageAgents();
                        return(false);
                    }
                    else
                    {
                        foreach (var printer in _compositeContract.Printers)
                        {
                            printer.PoolName = string.Empty;
                        }
                    }

                    _assetPoolFirstPass = false;
                }
            }

            // There are printers still to be added, and there is more than one
            // Asset Pool to choose, so show this page.

            _masterCompositeControl.SetPanel(_assetPoolControl);
            assetPoolPanel.Controls.Add(_masterCompositeControl);
            importWizard.SelectedPage = assetPoolWizardPage;
            return(true);
        }
        private void ProcessFinish()
        {
            if (_completionControl.SelectedFolderId == Guid.Parse("00000000-0000-0000-0000-000000000000"))
            {
                MessageBox.Show("Please Select a destination folder", "Import Scenario", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            StringBuilder importMessage = new StringBuilder("The Scenario '");

            importMessage.Append(_scenarioContract.Name);
            importMessage.AppendLine("' was successfully imported.");

            try
            {
                using (new BusyCursor())
                {
                    if (!_masterCompositeControl.Validate())
                    {
                        return;
                    }

                    if (_compositeContract != null)
                    {
                        using (AssetInventoryContext context = DbConnect.AssetInventoryContext())
                        {
                            bool           changesMade = false;
                            HashSet <Guid> pQueues     = new HashSet <Guid>();

                            foreach (var printer in _compositeContract.Printers)
                            {
                                if (!context.Assets.Any(x => x.AssetId.Equals(printer.AssetId)))
                                {
                                    context.Assets.Add(ContractFactory.Create(printer, context));
                                    changesMade = true;
                                }
                            }

                            var items = _compositeContract.Scenario.ActivityPrintQueueUsage;

                            XmlDocument doc = new XmlDocument();
                            foreach (var item in items)
                            {
                                doc.LoadXml(item.XmlSelectionData);
                                XmlNode node = doc.DocumentElement.FirstChild.FirstChild.FirstChild;
                                if (!string.IsNullOrEmpty(node.InnerText) && IsGuid(node.InnerText))
                                {
                                    if (!pQueues.Contains(Guid.Parse(node.InnerText)) && node.FirstChild.FirstChild.Name == "_printQueueId")
                                    {
                                        pQueues.Add(Guid.Parse(node.InnerText));
                                    }
                                }
                            }
                            var containsQueues = context.RemotePrintQueues.Where(x => pQueues.Contains(x.RemotePrintQueueId)).Select(x => x.Name);

                            if (pQueues.Count() != containsQueues.Count() || containsQueues.Count() == 0)
                            {
                                importMessage.AppendLine("Warning: Some Print Queues May Not Have Imported.");
                                importMessage.AppendLine("Please use Bulk Edit Tool to resolve.");
                            }

                            if (changesMade)
                            {
                                context.SaveChanges();
                            }
                        }
                    }

                    using (EnterpriseTestContext context = new EnterpriseTestContext())
                    {
                        var importMaps = new List <ContractFactory.ImportMap>();
                        if (_finalScenarioEntity == null)
                        {
                            _finalScenarioEntity = ContractFactory.Create(_scenarioContract, out importMaps);
                        }

                        var emptyPlatforms =
                            (
                                from r in _finalScenarioEntity.VirtualResources
                                where (string.IsNullOrEmpty(r.Platform) || r.Platform.Equals("LOCAL")) &&
                                !r.ResourceType.Equals("SolutionTester")
                                select r
                            );

                        if (emptyPlatforms != null && emptyPlatforms.Count() > 0)
                        {
                            using (AssignPlatformDialog dialog = new AssignPlatformDialog(emptyPlatforms))
                            {
                                dialog.ShowDialog();
                                return;
                            }
                        }

                        _finalScenarioEntity.Owner = UserManager.CurrentUserName;
                        foreach (var group in _scenarioContract.UserGroups)
                        {
                            var entity = context.UserGroups.FirstOrDefault(x => x.GroupName.Equals(group));
                            if (entity != null)
                            {
                                _finalScenarioEntity.UserGroups.Add(entity);
                            }
                        }

                        _finalScenarioEntity.FolderId = _completionControl.SelectedFolderId;
                        context.AddToEnterpriseScenarios(_finalScenarioEntity);
                        CreateFolders(_scenarioContract, _finalScenarioEntity, context, importMaps);

                        context.SaveChanges();
                        ScenarioImported = true;
                    }

                    if (_importMetadataMessages.Length > 0)
                    {
                        importMessage.AppendLine(_importMetadataMessages.ToString());
                    }

                    MessageBox.Show(importMessage.ToString(), "Import Scenario", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                TraceFactory.Logger.Error(ex);
            }
        }