private static void ImportAsset_Worker(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; // Loop through each filename to be imported, and import them for (int i = 0; i < mInvalidAssetNames.Count && !worker.CancellationPending; i++) { // A new name that is null is a canceled import string newAssetName = mNewAssetNames[i]; string message = "Importing:\n" + " " + newAssetName; worker.ReportProgress(i * 100 / mInvalidAssetNames.Count, message); if (!String.IsNullOrEmpty(newAssetName)) { // Create pure import source files array ArrayList importList = new ArrayList(); importList.Add(mInvalidAssetNames[i].mImportFilename); Debug.Write(newAssetName, "\nImport"); // Import this asset with its properties MOG_ControllerAsset.CreateAsset(newAssetName, "", importList, null, mNewAssetProperties[i], false, false); } } }
private static void CreateSingleAsset_Worker(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; List <object> args = e.Argument as List <object>; string theOneName = args[0] as string; string[] sourceFilenames = args[1] as string[]; ArrayList propertiesList = args[2] as ArrayList; //use the name of the asset we found, and import all of the assets as that ArrayList importFiles = new ArrayList(sourceFilenames); MOG_ControllerAsset.CreateAsset(theOneName, "", importFiles, null, propertiesList, false, false); }
private static void ImportRemainingItems_Worker(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; List <Object> args = e.Argument as List <Object>; List <ImportFile> remainingItems = args[0] as List <ImportFile>; bool useExtension = (bool)args[1]; string classification = args[2] as string; string platform = args[3] as string; ArrayList propertyArray = args[4] as ArrayList; int itemCount = 0; foreach (ImportFile remainingItem in remainingItems) { // Create the MOG asset name string assetLabel = useExtension ? DosUtils.PathGetFileName(remainingItem.mImportFilename) : DosUtils.PathGetFileNameWithoutExtension(remainingItem.mImportFilename); MOG_Filename multiFile = MOG_Filename.CreateAssetName(classification, platform, assetLabel); // Create our import file list ArrayList multiInFiles = new ArrayList(); multiInFiles.Add(remainingItem.mImportFilename); string message = "Importing:\n" + " " + classification + "\n" + " " + Path.GetFileName(remainingItem.mImportFilename); worker.ReportProgress(itemCount++ *100 / remainingItems.Count, message); // Import the asset MOG_ControllerAsset.CreateAsset(multiFile, "", multiInFiles, null, propertyArray, false, false); // Check if the user canceled things? if (worker.CancellationPending) { break; } } }
private static void ImportPrevious_Worker(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; List <object> args = e.Argument as List <object>; bool looseMatching = (bool)args[0]; string[] sourceFullNames = (args[1]) as string[]; //string[] sourceFullNames = e.Argument as string[]; mInvalidAssetNames.Clear(); mNewAssetNames.Clear(); mNewAssetProperties.Clear(); // Check if asset has been previously imported into the system for (int i = 0; i < sourceFullNames.Length && !worker.CancellationPending; i++) { string sourceFullName = sourceFullNames[i]; ArrayList previousSourceFiles = new ArrayList(); string message = "Importing:\n" + " " + Path.GetDirectoryName(sourceFullName) + "\n" + " " + Path.GetFileName(sourceFullName); worker.ReportProgress(i * 100 / sourceFullNames.Length, message); // Check if this is a directory? if (DosUtils.DirectoryExistFast(sourceFullName)) { // Obtain the list of contained files ArrayList containedFiles = DosUtils.FileGetRecursiveList(sourceFullName, "*.*"); if (containedFiles != null) { // Map these filenames to all the possible assetnames previousSourceFiles = MOG_ControllerProject.MapFilenamesToAssetNames(containedFiles, MOG_ControllerProject.GetPlatformName(), null); } } else { // Map this filename to all possible assetnames previousSourceFiles = MOG_ControllerProject.MapFilenameToAssetName(sourceFullName, MOG_ControllerProject.GetPlatformName(), MOG_ControllerProject.GetWorkspaceDirectory()); } // Are we loose matching? if (looseMatching) { // Did we get back only 2 files if (previousSourceFiles.Count == 2) { // Is the second one a blank? MOG_Filename file = previousSourceFiles[1] as MOG_Filename; if (file.GetFullFilename().Length == 0) { // Then remove it! previousSourceFiles.RemoveAt(1); } } } if (previousSourceFiles.Count == 1) { MOG_Filename previousFile = previousSourceFiles[0] as MOG_Filename; if (MogMainForm.MainApp.AssetManagerAutoImportCheckBox.Checked) { // Create the correct controller MOG_ControllerAsset.CreateAsset(sourceFullName, previousFile.GetEncodedFilename(), false); } else { // Create a new invalid name ImportFile invalidName = new ImportFile(sourceFullName); // Add all possible matches to this name foreach (MOG_Filename potentialMatch in previousSourceFiles) { // Make sure we have a valid match? if (potentialMatch != null && potentialMatch.GetOriginalFilename().Length > 0) { invalidName.mPotentialFileMatches.Add(potentialMatch); } } // Add to our invalidNames array mInvalidAssetNames.Add(invalidName); } } else { // Create a new invalid name ImportFile invalidName = new ImportFile(sourceFullName); // Add all possible matches to this name foreach (MOG_Filename potentialMatch in previousSourceFiles) { // Make sure we have a valid match? if (potentialMatch != null && potentialMatch.GetOriginalFilename().Length > 0) { invalidName.mPotentialFileMatches.Add(potentialMatch); } } // Add to our invalidNames array mInvalidAssetNames.Add(invalidName); } } }
private static bool ImportWithWizard(string[] sourceFullNames, out DialogResult result) { ImportAssetWizard wizard; List <ImportFile> remove = new List <ImportFile>(); try { // Loop through each filename to be imported, and import them for (int f = 0; f < mInvalidAssetNames.Count; f++) { // Launch the wizard wizard = new ImportAssetWizard(); // Set the wizard startup variables wizard.ImportSourceFilename = mInvalidAssetNames[f].mImportFilename; wizard.ImportPotentialMatches = mInvalidAssetNames[f].mPotentialFileMatches; wizard.ImportHasMultiples = mInvalidAssetNames.Count > 1; // Show the form wizard.ShowDialog(MogMainForm.MainApp); result = wizard.DialogResult; // Did the user complete the wizard if (result == DialogResult.OK) { // Create pur import source files array ArrayList importList = new ArrayList(); importList.Add(wizard.ImportEndSourceTextBox.Text); // Import it according to the wizard settings try { // Import this asset with its properties if (MOG_ControllerAsset.CreateAsset(wizard.ImportEndMogTextBox.Text, "", importList, null, wizard.ImportPropertyArray, false, false) != null) { remove.Add(mInvalidAssetNames[f]); } // Has the user elected to import all the remaining files with the same settings? if (wizard.ImportHasMultiples && wizard.ImportMultipleApplyToAll) { List <ImportFile> remainingItems = new List <ImportFile>(mInvalidAssetNames); remainingItems.RemoveRange(0, f); List <Object> args = new List <object>(); args.Add(remainingItems); args.Add(wizard.ImportShowExtension); args.Add(wizard.ImportFinalMOGFilename.GetAssetClassification()); args.Add(wizard.ImportFinalMOGFilename.GetAssetPlatform()); args.Add(wizard.ImportPropertyArray); ProgressDialog creationProgress = new ProgressDialog("Importing Asset", "Please wait while the remaining items are imported.", ImportRemainingItems_Worker, args, true); creationProgress.ShowDialog(MogMainForm.MainApp); // Now break out of this entire loop as we have now just imported all the remaining files to be imported break; } } catch (Exception e) { MOG_Report.ReportMessage("Import", "Could not import the file:\n" + wizard.ImportEndMogTextBox.Text + "\n\nError Message:\n" + e.Message, e.StackTrace, MOG.PROMPT.MOG_ALERT_LEVEL.ERROR); return(false); } } else if (result == DialogResult.Cancel) { result = DialogResult.Cancel; return(true); } else if (result == DialogResult.Ignore) { return(true); } } } finally { foreach (ImportFile rem in remove) { mInvalidAssetNames.Remove(rem); } } result = DialogResult.OK; return(true); }
private void CreateAssetConfigs_Worker(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; MOG_ControllerProject.LoginUser("Admin"); // Construct a new common timestamp for all of these assets string timestamp = MOG_Time.GetVersionTimestamp(); // Activate the properties cache to help save time during the importation process MOG_Properties.ActivatePropertiesCache(true); for (int nodeIndex = 0; nodeIndex < assetFilenameNodes.Count; nodeIndex++) { classTreeNode tn = assetFilenameNodes[nodeIndex] as classTreeNode; string fullAssetName = tn.FullPath; //tn.Parent.FullPath + tn.Text; string fileList = Utils.ArrayListToString(tn.importFiles, ""); // Check if this is a library asset? bool bIsInLibrary = false; if (tn.TreeView != null) { string fullPath = tn.FullPath + tn.TreeView.PathSeparator; string testPath = tn.TreeView.PathSeparator + "Library" + tn.TreeView.PathSeparator; if (fullPath.IndexOf(testPath, 0, StringComparison.CurrentCultureIgnoreCase) != -1) { bIsInLibrary = true; } } MOG_Filename repositoryName = null; if (bIsInLibrary && tn.importFiles.Count > 0) { // Use the timestamp of the file (Needed for out-of-date checks with library assets) String libraryTimestamp = ""; FileInfo file = new FileInfo(tn.importFiles[0] as string); if (file != null && file.Exists) { libraryTimestamp = MOG_Time.GetVersionTimestamp(file.LastWriteTime); } repositoryName = MOG_ControllerRepository.GetAssetBlessedVersionPath(new MOG_Filename(fullAssetName), libraryTimestamp); } else { // Use the common timestamp for all the assets repositoryName = MOG_ControllerRepository.GetAssetBlessedVersionPath(new MOG_Filename(fullAssetName), timestamp); } MOG_Filename createdAssetFilename = null; string message = "Importing:\n" + " " + repositoryName.GetAssetClassification() + "\n" + " " + repositoryName.GetAssetName(); worker.ReportProgress(nodeIndex * 100 / assetFilenameNodes.Count, message); if (worker.CancellationPending) { if (Utils.ShowMessageBoxConfirmation("Are you sure you want to cancel asset importation?", "Cancel Asset Importation?") == MOGPromptResult.Yes) { return; } } try { string dirScope = MOG_ControllerAsset.GetCommonDirectoryPath(this.projectRootPath, tn.importFiles); // Construct our list non-inherited asset assuming none ArrayList props = null; if (tn.props != null) { // Ask the tn.props for the list of non-inherited properties props = tn.props.GetNonInheritedProperties(); } else { props = new ArrayList(); // Setup SyncTargetPath Property string assetDirectoryScope = MOG_ControllerAsset.GetCommonDirectoryPath(this.projectRootPath, tn.importFiles); if (assetDirectoryScope.Length > this.projectRootPath.Length) { string syncTargetPath = assetDirectoryScope.Substring(this.projectRootPath.Length + 1); props.Add(MOG.MOG_PropertyFactory.MOG_Sync_OptionsProperties.New_SyncTargetPath(syncTargetPath)); } } // Proceed to import the asset createdAssetFilename = MOG_ControllerAsset.CreateAsset(repositoryName, dirScope, tn.importFiles, null, props, false, false); if (createdAssetFilename == null) { // it's probably a network problem (TODO: Check for sure) // build a list of files for error message string files = "\n\nFiles contained in " + tn.Text + "\n"; foreach (string fname in tn.importFiles) { files += "\t" + fname + "\n"; } MOGPromptResult r = MOG_Prompt.PromptResponse("Import Error", "Importation of " + tn.FullPath + " failed. Please ensure that the file is accessible and click Retry." + files, MOGPromptButtons.AbortRetryIgnore); if (r == MOGPromptResult.Retry) { --nodeIndex; // stay on the same node (continue auto-increments) continue; } else if (r == MOGPromptResult.Abort) { RaiseAssetImport_Finish(); MOG_Prompt.PromptResponse("Cancelled", "Importation Cancelled", Environment.StackTrace, MOGPromptButtons.OK, MOG_ALERT_LEVEL.MESSAGE); return; } else if (r == MOGPromptResult.Ignore) { continue; } } // Schedule this asset for posting under this project name MOG_ControllerProject.AddAssetForPosting(createdAssetFilename, MOG_ControllerProject.GetProjectName()); } catch (Exception ex) { MOG_Report.ReportMessage("Create Asset", "Could not correctly create asset.\nMessage=" + ex.Message, ex.StackTrace, MOG_ALERT_LEVEL.CRITICAL); continue; } } // Shut off the properties cache MOG_Properties.ActivatePropertiesCache(false); }