public static void MarkLocalAssetBlessed(MOG_Filename assetFilename, string blessedTimestamp) { // Walk through all of our workspaces foreach (MOG_ControllerSyncData workspace in mWorkspaces.Values) { // Check if this is the current workspace? or // Check if this workspace is active? if (workspace == MOG_ControllerProject.GetCurrentSyncDataController() || workspace.IsAlwaysActive()) { // Build the expected path to this asset in our local workspace MOG_Filename workspaceAsset = MOG_Filename.GetLocalUpdatedTrayFilename(workspace.GetSyncDirectory(), assetFilename); // Open the local asset MOG_ControllerAsset localAsset = MOG_ControllerAsset.OpenAsset(workspaceAsset); if (localAsset != null) { // Stamp this locally update asset with the newly blessed revision timestamp localAsset.GetProperties().BlessedTime = blessedTimestamp; // Change the state of this asset to blessed MOG_ControllerInbox.UpdateInboxView(localAsset, MOG_AssetStatusType.Blessed); localAsset.Close(); } } } }
private void PackageManagementForm_Closing(object sender, System.ComponentModel.CancelEventArgs e) { guiUserPrefs.SaveDynamic_LayoutPrefs(guiUserPrefs.PackageManagementForm_Text, this); // Check if we were modyifying assets? if (ModifyingAssets) { // Itterate through all the assets and mark them as being modified foreach (ListViewItem item in AssetList.Items) { MOG_Filename assetFilename = item.Tag as MOG_Filename; if (assetFilename != null) { // Open up this asset so we can remove the package relationships MOG_ControllerAsset asset = MOG_ControllerAsset.OpenAsset(assetFilename); if (asset != null) { if (asset.GetProperties().NativeDataType) { MOG_ControllerInbox.UpdateInboxView(asset, MOG_AssetStatusType.Processed); } else { MOG_ControllerInbox.UpdateInboxView(asset, MOG_AssetStatusType.Modified); } asset.Close(); } } } } }
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 void FillInAssets(TreeNode node) { // Store assets under this classifcation ArrayList assets = MOG_ControllerAsset.GetAssetsByClassification(node.FullPath); assets.Sort(); bool assetsValid = (assets != null && assets.Count > 0); // If we actually have assets to list, and our archivedAssets do not differ from our branch-related assets... if (assetsValid) { // Foreach asset in this classification... foreach (MOG_Filename asset in assets) { TreeNode assetNode = CreateAssetNode(asset, node.ForeColor); node.Nodes.Add(assetNode); } } // Also, get our archived assets, if we are in archive view ArrayList archivedAssets = MOG_ControllerAsset.GetArchivedAssetsByClassification(node.FullPath); archivedAssets.Sort(); // If we have valid archivedAssets, AND // (we EITHER have more archivedAssets than assets // OR we have no valid assets) if (archivedAssets != null && archivedAssets.Count > 0 && ((assetsValid && assets.Count < archivedAssets.Count) || !assetsValid)) { //TODO: Possibly add a "Removed Assets" node here... // If we do have branch-related assets, check for them by name... List <string> branchAssetsList = new List <string>(); if (assets != null && assets.Count > 0) { // Create a list of our Current assets foreach (MOG_Filename asset in assets) { branchAssetsList.Add(asset.GetAssetFullName().ToLower()); } } // Fill in any Assets that are not current foreach (MOG_Filename archiveAsset in archivedAssets) { TreeNode assetNode = null; // If there is nothing in our branchAssetsList OR // branchAssetsList does not contain the current asset we're looking at... if (branchAssetsList.Count == 0 || !branchAssetsList.Contains(archiveAsset.GetAssetFullName().ToLower())) { assetNode = CreateAssetNode(archiveAsset, Archive_Color); node.Nodes.Add(assetNode); //Add this bad boy to the list so we don't add it more than once branchAssetsList.Add(archiveAsset.GetAssetFullName().ToLower()); } } } }
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); }
/// <summary> /// Remove packages from Assets currently selected. Use CheckForBlessedAssetMessage() before calling. /// </summary> /// <param name="packagesToRemove">ArrayList of MOG_Property objects for packages to be removed</param> private void RemovePackageLinkFromAssets(ArrayList packagesToRemove) { foreach (ListViewItem item in AssetList.Items) { MOG_Filename assetFilename = item.Tag as MOG_Filename; if (assetFilename != null) { // If this asset is not a blessed Asset, and it's not a classification... if (!assetFilename.IsBlessed() && assetFilename.GetFilenameType() != MOG_FILENAME_TYPE.MOG_FILENAME_Unknown) { // Open up this asset so we can remove the package relationships MOG_ControllerAsset asset = MOG_ControllerAsset.OpenAsset(assetFilename); if (asset != null) { // Remove the packages asset.GetProperties().RemovePackages(packagesToRemove); // Depending on how the user clicked, it is possible that an inherited package assignment can be left behind as a non-inherited property // The following code ensures all non-inherited package assignments are flushed by restamping any non-inherited assignemnts. asset.GetProperties().SetProperties(asset.GetProperties().GetNonInheritedPackages()); // Make sure we keep the group in sync with our new assignment MOG_ControllerAsset.SetDefaultGroup(asset); // Change the state of the asset to indicate it has been modified MOG_ControllerInbox.UpdateInboxView(asset, MOG_AssetStatusType.Modifying); ModifyingAssets = true; asset.Close(); } } else { // We should be looking at a classification, so treat it as such... MOG_Properties properties = MOG_Properties.OpenClassificationProperties(assetFilename.GetOriginalFilename()); if (properties != null) { properties.RemovePackages(packagesToRemove); properties.Close(); } } } } }
public ArrayList LocateAssetBinary(MOG_Filename filename, AssetDirectories AssetDirectoryType) { string targetDir = ""; ArrayList binaryFiles = new ArrayList(); MOG_Properties assetProperties = new MOG_Properties(filename); switch (AssetDirectoryType) { case AssetDirectories.IMPORTED: targetDir = MOG_ControllerAsset.GetAssetImportedDirectory(assetProperties); break; case AssetDirectories.PROCESSED: string platformName = ""; // If we have a valid gameDataController? if (MOG_ControllerProject.GetCurrentSyncDataController() != null) { platformName = MOG_ControllerProject.GetCurrentSyncDataController().GetPlatformName(); } targetDir = MOG_ControllerAsset.GetAssetProcessedDirectory(assetProperties, platformName); break; } if (targetDir.Length != 0 && DosUtils.Exist(targetDir)) { FileInfo [] files = DosUtils.FileGetList(targetDir, "*.*"); foreach (FileInfo file in files) { binaryFiles.Add(file.FullName); } } else { MOG_Prompt.PromptMessage("Asset View", "Asset (" + targetDir + ") does not exist or is a zero length file! Cannot View.", Environment.StackTrace); } return(binaryFiles); }
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; } } }
MOG_Tokens(MOG_ControllerAsset asset) { mAsset = asset; mAssetFilename = asset.GetAssetFilename(); mProperties = asset.GetProperties(); }
public void MogControl_LibraryTreeView_DragDrop(object sender, DragEventArgs args) { if (this.dragOverNode != null) { // Restore node's original colors this.dragOverNode.BackColor = SystemColors.Window; this.dragOverNode.ForeColor = SystemColors.ControlText; } // Get node we want to drop at TreeNode targetNode = this.GetNodeAt(this.PointToClient(new Point(args.X, args.Y))); // and select it so it'll show up in the ListView this.SelectedNode = targetNode; if (args.Data.GetDataPresent("FileDrop")) { // Extract the filenames and import string[] filenames = (string[])args.Data.GetData("FileDrop", false); if (filenames != null && filenames.Length > 0) { bool bCopyFiles = true; bool bAutoAddFiles = false; bool bPromptUser = false; bool bCancel = false; // Check if thes files are coming from the same spot? string classification = targetNode.FullPath; string classificationPath = MOG_ControllerLibrary.ConstructPathFromLibraryClassification(classification); // Get the common directory scope of the items ArrayList items = new ArrayList(filenames); string rootPath = MOG_ControllerAsset.GetCommonDirectoryPath("", items); if (rootPath.StartsWith(classificationPath)) { bCopyFiles = false; } // Check if auto import is checked? if (this.LibraryExplorer.IsAutoImportChecked()) { // Automatically add the file on the server bAutoAddFiles = true; bPromptUser = true; // Check if these files are already within the library? if (MOG_ControllerLibrary.IsPathWithinLibrary(rootPath)) { // Ignore what the user specified and rely on the classification generated from the filenames classification = ""; bPromptUser = false; bCopyFiles = false; } } // Promt the user for confirmation before we import these files if (bPromptUser) { // Prompt the user and allow them to cancel if (LibraryFileImporter.PromptUserForConfirmation(filenames, classification) == false) { bCancel = true; } } // Make sure we haven't canceled if (!bCancel) { if (bCopyFiles) { // Import the files List <object> arguments = new List <object>(); arguments.Add(filenames); arguments.Add(classification); ProgressDialog progress = new ProgressDialog("Copying Files", "Please wait while the files are copied", LibraryFileImporter.CopyFiles, arguments, true); progress.ShowDialog(); } } // Make sure we haven't canceled if (!bCancel) { if (bAutoAddFiles) { // Import the files List <object> arguments = new List <object>(); arguments.Add(filenames); arguments.Add(classification); ProgressDialog progress = new ProgressDialog("Copying Files", "Please wait while the files are copied", LibraryFileImporter.ImportFiles, arguments, true); progress.ShowDialog(); } } // Refresh view DeInitialize(); Initialize(); } } else if (args.Data.GetDataPresent("LibraryListItems")) { ArrayList items = args.Data.GetData("LibraryListItems") as ArrayList; foreach (string item in items) { // Move library asset here MOG_Filename assetName = new MOG_Filename(item); // Check if this was an asset? if (assetName.GetFilenameType() == MOG_FILENAME_TYPE.MOG_FILENAME_Asset) { bool success = MOG_ControllerProject.GetProject().AssetRename(assetName.GetAssetFullName(), SelectedNode.FullPath + assetName.GetAssetName()); // Make sure we unsync this asset just in case it had already been synced MOG_ControllerLibrary.Unsync(assetName); } // Check if this was a file? else if (DosUtils.FileExistFast(item)) { string dstPath = MOG_ControllerLibrary.ConstructPathFromLibraryClassification(SelectedNode.FullPath); string dstTarget = Path.Combine(dstPath, Path.GetFileName(item)); DosUtils.FileMoveFast(item, dstTarget, true); } } } else if (args.Data.GetDataPresent("LibraryTreeNode")) { string classification = args.Data.GetData("LibraryTreeNode") as string; if (classification != null && classification.Length > 0) { //Move classification here string[] parts = classification.Split("~".ToCharArray()); if (parts.Length > 0) { string lastPart = parts[parts.Length - 1]; bool success = MOG_ControllerProject.GetProject().ClassificationRename(classification, SelectedNode.FullPath + "~" + lastPart); } else { MOG_Prompt.PromptResponse("Cannot move classification", "MOG was unable to move the classification", Environment.StackTrace, MOGPromptButtons.OK); } } } }
public void MogControl_LibraryListView_DragDrop(object sender, DragEventArgs args) { // Extract the filenames string[] filenames = (string[])args.Data.GetData("FileDrop", false); if (filenames != null && filenames.Length > 0) { bool bCopyFiles = true; bool bAutoAddFiles = false; bool bPromptUser = false; bool bCancel = false; // Check if thes files are coming from the same spot? string classification = this.CurrentClassification; string classificationPath = MOG_ControllerLibrary.ConstructPathFromLibraryClassification(classification); // Get the common directory scope of the items ArrayList items = new ArrayList(filenames); string rootPath = MOG_ControllerAsset.GetCommonDirectoryPath("", items); if (rootPath.StartsWith(classificationPath)) { bCopyFiles = false; } // Check if auto import is checked? if (this.LibraryExplorer.IsAutoImportChecked()) { // Automatically add the file on the server bAutoAddFiles = true; bPromptUser = true; // Check if these files are already within the library? if (MOG_ControllerLibrary.IsPathWithinLibrary(rootPath)) { // Ignore what the user specified and rely on the classification generated from the filenames classification = ""; bPromptUser = false; bCopyFiles = false; } } // Promt the user for confirmation before we import these files if (bPromptUser) { // Prompt the user and allow them to cancel if (LibraryFileImporter.PromptUserForConfirmation(filenames, classification) == false) { bCancel = true; } } // Make sure we haven't canceled if (!bCancel) { if (bCopyFiles) { // Import the files List <object> arguments = new List <object>(); arguments.Add(filenames); arguments.Add(classification); ProgressDialog progress = new ProgressDialog("Copying Files", "Please wait while the files are copied", LibraryFileImporter.CopyFiles, arguments, true); progress.ShowDialog(); } } // Make sure we haven't canceled if (!bCancel) { if (bAutoAddFiles) { // Import the files List <object> arguments = new List <object>(); arguments.Add(filenames); arguments.Add(classification); ProgressDialog progress = new ProgressDialog("Copying Files", "Please wait while the files are copied", LibraryFileImporter.ImportFiles, arguments, true); progress.ShowDialog(); } } // Refresh view this.LibraryExplorer.Refresh(); } }
public void Populate(string classification) { CurrentClassification = classification; mCurrentClassificationProperties = new MOG_Properties(CurrentClassification); // For speed purposes, create 3 HybridDictionary lists // Populate the files that exist on the local hardrive string drivePath = Path.Combine(MOG_ControllerLibrary.GetWorkingDirectory(), MOG_Filename.GetClassificationPath(classification)); string[] files = new string[] { }; if (DosUtils.DirectoryExistFast(drivePath)) { files = Directory.GetFiles(drivePath); } HybridDictionary filesOnDisk = new HybridDictionary(); foreach (string file in files) { filesOnDisk[Path.GetFileName(file)] = file; } // Populate the assets that exist in MOG ArrayList assets = MOG_ControllerAsset.GetAssetsByClassification(classification); HybridDictionary assetsInMOG = new HybridDictionary(); foreach (MOG_Filename asset in assets) { assetsInMOG[asset.GetAssetLabel()] = asset; } // Create a master list HybridDictionary masterList = new HybridDictionary(); foreach (string file in filesOnDisk.Values) { masterList[Path.GetFileName(file)] = Path.GetFileName(file); } foreach (MOG_Filename asset in assetsInMOG.Values) { masterList[asset.GetAssetLabel()] = asset.GetAssetLabel(); } // Rebuild our LibraryListView LibraryListView.BeginUpdate(); mLibrarySortManager.SortEnabled = false; LibraryListView.Items.Clear(); foreach (string file in masterList.Keys) { // Check if this file is in MOG? if (assetsInMOG.Contains(file)) { MOG_Filename asset = assetsInMOG[file] as MOG_Filename; // Create the ListView item for this asset ListViewItem item = CreateListViewItemForAsset(asset); LibraryListView.Items.Add(item); } else { string fullFilename = filesOnDisk[file] as string; bool bIsValid = true; // Check the classification's inclusion filter. if (mCurrentClassificationProperties.FilterInclusions.Length > 0) { MOG.FilePattern inclusions = new MOG.FilePattern(mCurrentClassificationProperties.FilterInclusions); if (inclusions.IsFilePatternMatch(Path.GetFileName(fullFilename)) == false) { bIsValid = false; } } // Check the classification's exclusion filter. if (mCurrentClassificationProperties.FilterExclusions.Length > 0) { MOG.FilePattern exclusions = new MOG.FilePattern(mCurrentClassificationProperties.FilterExclusions); if (exclusions.IsFilePatternMatch(Path.GetFileName(fullFilename)) == true) { bIsValid = false; } } // Check if we determined this to be a valid file to show? if (bIsValid) { ListViewItem item = CreateListViewItemForFile(fullFilename); UpdateListViewItemColors(item, "Unknown"); LibraryListView.Items.Add(item); } } } mLibrarySortManager.SortEnabled = true; LibraryListView.EndUpdate(); // Check if we have a mLastTopItem specified? if (mLastTopItem.Length > 0) { LibraryListView.TopItem = LibraryListView.FindItemWithText(mLastTopItem); mLastTopItem = ""; } }
static public bool AddAssetToWorkspaces(MOG_Filename assetFilename, bool userInitiated, BackgroundWorker worker) { bool bFailed = false; // Open the asset now to save time later so it doesn't need to be opened for each workspace MOG_ControllerAsset asset = MOG_ControllerAsset.OpenAsset(assetFilename); if (asset != null) { try { // Walk through all of our workspaces foreach (MOG_ControllerSyncData workspace in mWorkspaces.Values) { bool bAddAsset = false; // Check if this workspace is active? if (workspace.IsAlwaysActive()) { bAddAsset = true; } // Imported asset has special logic else if (asset.GetProperties().Status == MOG_AssetStatus.GetText(MOG_AssetStatusType.Imported)) { // Check if this asset originated from within this workspace? (special case added for SmartBomb so editor will always update the workspace of an object sent from the editor) if (DosUtils.PathIsWithinPath(workspace.GetSyncDirectory(), asset.GetProperties().SourcePath)) { bAddAsset = true; } // Check if the user actually initiated this event? else if (userInitiated && workspace == MOG_ControllerProject.GetCurrentSyncDataController()) { bAddAsset = true; } } // All other assets should simply go into the current else if (workspace == MOG_ControllerProject.GetCurrentSyncDataController()) { bAddAsset = true; } // Should this asset be added? if (bAddAsset) { // Decide if the user wants to be notified about the asset's update bool bInformUser = userInitiated; // Check if no worker was specified? or // Check if this isn't the active workspace? if (worker == null || workspace != MOG_ControllerProject.GetCurrentSyncDataController()) { // Don't bother the user about any problems bInformUser = false; } // Check if we can add this asset to the local workspace? if (workspace.CanAddAssetToLocalWorkspace(asset, bInformUser)) { // Check if this asset comming from an inbox? and // Check if this asset comming from our inbox? and // Check if this asset's current state is 'Imported' and // Check if this asset originated from this workspace? // Finally, Make sure this wasn't user initiated? if (assetFilename.IsWithinInboxes() && string.Compare(assetFilename.GetUserName(), MOG_ControllerProject.GetUserName(), true) == 0 && string.Compare(asset.GetProperties().Status, MOG_AssetStatus.GetText(MOG_AssetStatusType.Imported), true) == 0 && MOG_Filename.IsWithinPath(workspace.GetSyncDirectory(), asset.GetProperties().SourcePath) && !userInitiated) { // Looks like we can proceed to import if (!workspace.AddAssetToLocalUpdatedTray(asset, worker)) { bFailed = true; } // Continue on to the next asset continue; } // Proceed to add the asset to this workspace if (!workspace.AddAssetToLocalWorkspace(asset, worker)) { bFailed = true; } } } } } finally { asset.Close(); } } else { bFailed = true; } if (!bFailed) { return(true); } return(false); }
private bool EncodeAll(TreeNodeCollection nodes, BackgroundWorker worker) { foreach (classTreeNode ctn in nodes) { if (worker != null) { // Check for user initiated cancel if (worker.CancellationPending) { return(false); } // Report progress to the user worker.ReportProgress(0, ctn.FullPath); } if (!ctn.FilledIn) { if (ctn.assetTreeNode != null) { // kill dummy node ctn.Nodes.Clear(); // populate properties if (ctn.props == null) { // Get the classification's properties that we can edit ctn.props = MOG_Properties.OpenClassificationProperties(ctn.FullPath.Replace("\\", "~")); ctn.props.SetImmeadiateMode(true); } // add converted children foreach (AssetTreeNode atn in ctn.assetTreeNode.Nodes) { ctn.Nodes.Add(EncodeNode(atn, ctn.props)); } // Setup SyncTargetPath Property of this classification // First, we need to build a complete list of all the files being imported in this classification ArrayList allImportFiles = new ArrayList(); foreach (classTreeNode ttn in ctn.Nodes) { allImportFiles.AddRange(ttn.importFiles); } // Check if we have any contained items? if (allImportFiles.Count > 0) { // Scan for the highest common path amoung these files string assetDirectoryPath = MOG_ControllerAsset.GetCommonDirectoryPath(this.projectRootPath, allImportFiles); // Check if this command path is longer than the projectRootPath? if (assetDirectoryPath.Length > this.projectRootPath.Length) { // Trim off the projectRootPath to obtain our desiredSyncTargetPath string desiredSyncTargetPath = assetDirectoryPath.Substring(this.projectRootPath.Length + 1); // Add the detected SyncTargetPath to this classification ctn.props.SyncTargetPath = desiredSyncTargetPath; } } else { // build synctargetpath if (ctn.assetTreeNode.FileFullPath != "" && // "" indicates don't set sync data path ctn.assetTreeNode.FileFullPath != "<empty>") // "<empty>" indicates don't set sync data path { string syncDataPath = ctn.assetTreeNode.FileFullPath; if (syncDataPath.ToLower().StartsWith(this.projectRootPath.ToLower())) { syncDataPath = syncDataPath.Substring(this.projectRootPath.Length).Trim("\\".ToCharArray()); } // Check if the syncTargetPath was resolved to nothing? if (syncDataPath == "") { // Force the syncTargetPath to 'Nothing' so it will resemble the resolved syncDataPath and not simply inherit syncDataPath = "Nothing"; } ctn.props.SyncTargetPath = syncDataPath; } } // mark this node as filled-in ctn.FilledIn = true; ctn.assetTreeNode = null; } } // recurse if (!EncodeAll(ctn.Nodes, worker)) { return(false); } } return(true); }
private bool AddPackageLinkToAssets(string packageName, Color color, bool markAsInherited, bool setPackageProperties) { bool success = true; ListViewItem item = FindAssignmentListItem(packageName); if (item == null) { item = new ListViewItem(packageName); item.ForeColor = color; AssignmentList.Items.Add(item); if (setPackageProperties) { success = false; ArrayList PackageAssignmentProps = new ArrayList(); PackageAssignmentProps.Add(CreatePackageAssignmentProperty(packageName)); // Go through our listview items again to Add or Remove assets we found in the previous foreach loop foreach (ListViewItem assetItem in AssetList.Items) { MOG_Filename assetFilename = assetItem.Tag as MOG_Filename; if (assetFilename != null && assetFilename.GetFilenameType() == MOG_FILENAME_TYPE.MOG_FILENAME_Asset) { // If this asset is not a blessed Asset, and it's not a classification... if (!assetFilename.IsBlessed()) { MOG_ControllerAsset asset = MOG_ControllerAsset.OpenAsset(assetFilename); if (asset != null) { if (asset.GetProperties().AddPackages(PackageAssignmentProps)) { success = true; // Make sure we keep the group in sync with our new assignment MOG_ControllerAsset.SetDefaultGroup(asset); // Change the state of the asset to indicate it has been modified MOG_ControllerInbox.UpdateInboxView(asset, MOG_AssetStatusType.Modifying); ModifyingAssets = true; } asset.Close(); } } else { MOG_Prompt.PromptMessage("Cannot add PackageAssignments to Blessed Assets", "Please copy the Asset to your Inbox and change its package assignments from there so it can be properly processed and re-Blessed.", "", MOG.PROMPT.MOG_ALERT_LEVEL.ALERT); } } else if (assetFilename.GetFilenameType() == MOG_FILENAME_TYPE.MOG_FILENAME_Unknown) { // We should be looking at a classification, so treat it as such... MOG_Properties properties = MOG_Properties.OpenClassificationProperties(assetFilename.GetOriginalFilename()); if (properties != null) { if (properties.AddPackages(PackageAssignmentProps)) { success = true; } properties.Close(); } } } } } if (item != null && markAsInherited) { item.Font = new Font(AssignmentList.Font, FontStyle.Italic); } if (!success) { MOG_Report.ReportMessage("Error Adding Package Assignment", "Failed to add package assignment!", Environment.StackTrace, MOG_ALERT_LEVEL.ERROR); } return(success); }
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 void InitializeAssetNames(ArrayList sourceFiles) { RenameListView.Items.Clear(); InitializePlatformComboBox(); string listOfBlessedAssets = ""; // Check for presence of wildcards foreach (string fullFilename in sourceFiles) { MOG_Filename asset = new MOG_Filename(fullFilename); // If this Asset has been previously blessed... if (CheckIfAssetHasBeenBlessed(asset)) { listOfBlessedAssets += asset.GetAssetFullName() + "\r\n"; } // Get the imported filenames ArrayList importFiles = DosUtils.FileGetRecursiveList(MOG_ControllerAsset.GetAssetImportedDirectory(MOG_Properties.OpenFileProperties(fullFilename + "\\Properties.info")), "*.*"); if (importFiles.Count > 1) { // If there are more that one, then we cannot rename the files of this asset RenameFiles.Checked = false; RenameFiles.Enabled = false; importFilename = "*Complex asset*"; } else { String importFile = importFiles[0] as string; // Does this asset label match the imported filename? if (string.Compare(DosUtils.PathGetFileNameWithoutExtension(importFile), DosUtils.PathGetFileNameWithoutExtension(asset.GetAssetLabel()), true) == 0) { // All is good then importFilename = DosUtils.PathGetFileName(importFile); } else { // We cannot rename the files of this asset because the label and the imported filename do not match RenameFiles.Checked = false; RenameFiles.Enabled = false; importFilename = string.Format("Asset label({0}) and imported filename({1}) do not match!", DosUtils.PathGetFileNameWithoutExtension(asset.GetAssetLabel()), DosUtils.PathGetFileNameWithoutExtension(importFile)); } } mFullFilename = fullFilename; ListViewItem item = RenameListView.Items.Add(asset.GetAssetFullName()); item.SubItems.Add(asset.GetAssetFullName()); item.SubItems.Add(asset.GetAssetEncodedPath()); item.SubItems.Add(importFilename); item.Selected = true; CheckStringForMatch(ref mCommonClass, asset.GetAssetClassification()); CheckStringForMatch(ref mCommonPlatform, asset.GetAssetPlatform()); CheckStringForMatch(ref mCommonLabel, asset.GetAssetLabel()); } // If we have any Blessed Assets and we don't have privilege to rename them, warn the user if (listOfBlessedAssets.Length > 0 && !CheckPrivilegeToRename()) { MOG_Prompt.PromptMessage("Insufficient privileges to rename already blessed assets", "You do not have permission to rename these previously blessed assets:\r\n" + listOfBlessedAssets); } // Else, If we have any Blessed Assets, warn user about the rename else if (listOfBlessedAssets.Length > 0) { MOG_Prompt.PromptMessage("Inbox renames don't rename previously blessed assets", "The following blessed assets will still exist when renamed assets are blessed:\r\n" + listOfBlessedAssets); } RenameListView.Select(); InitializeTextBoxes(mCommonClass, mCommonPlatform, mCommonLabel); // Make it so that our user will hopefully type over the "*" when assigning a classification... if (mCommonClass == "*") { this.RenameNewClassNameTextBox.SelectAll(); } bInitialized = true; } // end ()
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); }
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); }