/// <summary> /// Shows Assets based on MOG_Property(s) assigned to PropertyList /// </summary> private void ExpandPropertyTreeDown(TreeNode node) { BeginUpdate(); List <string> classificationsToAdd = GetSubClassifications(node); List <string> assetsToAdd = GetAssets(node); // Sort our classifications alphabetically classificationsToAdd.Sort(); // Foreach classification, add it foreach (string classification in classificationsToAdd) { TreeNode classificationNode = new TreeNode(classification); // Assign the default node checked state classificationNode.Checked = node.Checked; classificationNode.Tag = new Mog_BaseTag(classificationNode, classification, RepositoryFocusLevel.Classification, false); ((Mog_BaseTag)classificationNode.Tag).PackageNodeType = PackageNodeTypes.Class; node.Nodes.Add(classificationNode); classificationNode.Name = classificationNode.FullPath; SetImageIndices(classificationNode, GetClassificationImageIndex(classificationNode.FullPath)); classificationNode.Nodes.Add(new TreeNode(Blank_Node_Text)); } // Use the System.IComparable interface for `string` to sort our list assetsToAdd.Sort(); // Foreach Asset, add it foreach (string assetFilename in assetsToAdd) { MOG_Filename assetFile = new MOG_Filename(assetFilename); assetFile = MOG_ControllerProject.GetAssetCurrentBlessedPath(assetFile); TreeNode assetNode; // If we are expandingAssets or expandingPackageGroups, we need to be able to expand down if (ExpandAssets || ExpandPackageGroups) { assetNode = new TreeNode(assetFile.GetAssetName(), new TreeNode[] { new TreeNode(Blank_Node_Text) }); } // Else, do not expand down. Showing the Asset is all we need to do else { assetNode = new TreeNode(assetFile.GetAssetName()); } assetNode.Tag = new Mog_BaseTag(assetNode, assetFile.GetEncodedFilename(), FocusForAssetNodes, true); ((Mog_BaseTag)assetNode.Tag).PackageNodeType = PackageNodeTypes.Asset; ((Mog_BaseTag)assetNode.Tag).PackageFullName = assetFile.GetAssetFullName(); node.Nodes.Add(assetNode); assetNode.Name = assetFile.GetAssetFullName(); SetImageIndices(assetNode, GetAssetFileImageIndex(assetFile.GetEncodedFilename())); } EndUpdate(); }
/// <summary> /// Utility method for the Package portion of AfterLabelEdit() (above) /// </summary> private ArrayList GetValidTargetSyncPath(NodeLabelEditEventArgs e, MOG_Filename packageName) { // Get the gameDataPath for this new package GameDataPathForm getPath = new GameDataPathForm(packageName.GetAssetPlatform(), packageName.GetAssetName()); ArrayList targetSyncPath = null; // This dialog should be pushed to topmost when it doesn't have a parent or else it can ger lost behind other apps. // You would think this is simple but for some reason MOG has really struggled with these dialogs being kept on top... // We have tried it all and finally ended up with this...toggling the TopMost mode seems to be working 100% of the time. getPath.TopMost = true; getPath.TopMost = false; getPath.TopMost = true; // Show the dialog if (DialogResult.Cancel != getPath.ShowDialog()) { targetSyncPath = getPath.MOGPropertyArray; // Get a value for our relative gamedata path string relativePath = null; if (targetSyncPath.Count > 0) { relativePath = ((MOG_Property)targetSyncPath[0]).mPropertyValue; } // If we found our relativePath... if (relativePath != null) { // Go ahead and add an initial backslash, if necessary... if (relativePath.Length > 0 && relativePath[0] != '\\') { relativePath = "\\" + relativePath; } // Find all our assets with this gamedata path ArrayList assets = MOG_DBAssetAPI.GetAllAssetsBySyncLocation(relativePath, packageName.GetAssetPlatform()); // If we found assets... if (assets != null && assets.Count > 0) { // Check and see if any of the assets we found match the package we want to add... foreach (MOG_Filename asset in assets) { // If we already have the package name we want to add, warn user and quit... if (asset.GetAssetName().ToLower() == packageName.GetAssetName().ToLower()) { MessageBox.Show(this, "Package name, " + packageName.GetAssetName() + ", already exists in location, '" + relativePath.Substring(1) + "'!", "Package Already Exists!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); e.Node.EndEdit(true); e.Node.Remove(); return null; } } } } } // Finished our method, so return true return targetSyncPath; }
private void CheckPackages(HybridDictionary packages, bool markAsInherited) { // Add our packages to our mogPackagesSet and expand the tree to that node foreach (DictionaryEntry entry in packages) { string package = entry.Key as string; int count = (int)entry.Value; // Generate a MOG_Filename and concat our path from it MOG_Filename packageFile = new MOG_Filename(package); string assetName = packageFile.GetAssetName(); string assetFullName = packageFile.GetAssetClassification() + assetName; // Make sure we have this Package selected (if possible) TreeNode node = FindPackageNode(assetFullName); if (node == null) { node = AddPackageNode(assetFullName); } if (node != null) { if (count < AssetList.Items.Count) { node.ForeColor = Color.Gray; } if (markAsInherited) { node.NodeFont = new Font(node.TreeView.Font, FontStyle.Italic); } node.Checked = true; } } }
/// <summary> /// Used to get an Asset node with a good node.Tag for this TreeView or any inheriting classes. /// </summary> private TreeNode CreateAssetNode(MOG_Filename asset, System.Drawing.Color foreColor, bool useFullFilename) { string assetName = asset.GetAssetFullName(); MOG_Filename assetFullFilename; // If we found revisions, go ahead and select the first one as the full filename for our tag... assetFullFilename = MOG_ControllerRepository.GetAssetBlessedPath(asset); TreeNode assetNode = new TreeNode(asset.GetAssetName()); if (useFullFilename) { assetNode.Text = asset.GetAssetFullName(); } assetNode.Tag = new Mog_BaseTag(assetNode, assetFullFilename.GetEncodedFilename(), RepositoryFocusLevel.Repository, true); // If we are Archive_Color, remain displayed as such if (foreColor == Archive_Color) { assetNode.ForeColor = Archive_Color; } assetNode.Nodes.Add(new TreeNode(Blank_Node_Text)); assetNode.Name = asset.GetAssetFullName(); SetImageIndices(assetNode, GetAssetImageIndex(((Mog_BaseTag)assetNode.Tag).FullFilename)); return(assetNode); }
/// <summary> /// Utility method to make sure we are not duplicating an existing node /// </summary> private bool ValidateNewNodeName(NodeLabelEditEventArgs e, MOG_Filename packageName) { // Foreach node in our Parent's nodes, see if we already have the AssetName we propose to add foreach (TreeNode node in e.Node.Parent.Nodes) { // If we find the AssetName we propose to add, warn the user and quit... if (node.Text.ToLower() == packageName.GetAssetName().ToLower()) { MessageBox.Show(this, "Package name, " + packageName.GetAssetName() + ", already exists!", "Package Already Exists!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); e.Node.EndEdit(true); e.Node.Remove(); return false; } } return true; }
private void RenameNode(NodeLabelEditEventArgs e, MOG_Filename repositoryName) { TreeNode parent = e.Node.Parent; e.Node.Text = repositoryName.GetAssetName(); e.Node.Tag = new Mog_BaseTag(e.Node, repositoryName.GetEncodedFilename(), RepositoryFocusLevel.Repository, true); ((Mog_BaseTag)e.Node.Tag).PackageNodeType = PackageNodeTypes.Asset; ((Mog_BaseTag)e.Node.Tag).PackageFullName = repositoryName.GetAssetFullName(); e.CancelEdit = true; }
/// <summary> /// Used to get an Asset node with a good node.Tag for this TreeView or any inheriting classes. /// Does not use full filename. /// </summary> protected virtual TreeNode CreateAssetNode(MOG_Filename asset) { // Create a basic tree node TreeNode assetNode = new TreeNode(asset.GetAssetName()); MOG_Filename assetFile = MOG_ControllerProject.GetAssetCurrentBlessedPath(asset); assetNode.Tag = new Mog_BaseTag(assetNode, "", RepositoryFocusLevel.Repository, true); assetNode.Name = asset.GetAssetFullName(); // Initialize the treenode's image SetImageIndices(assetNode, GetAssetImageIndex(asset.GetAssetFullName())); return(assetNode); }
public static bool RemoveBlessedGroup(MOG_Filename asset, string groups, bool ShowConfirmation) { if (MOG_ControllerPackage.RemoveGroup(asset, groups)) { if (ShowConfirmation) { string groupString = (groups.Length > 0) ? (" GROUP: " + groups) : ""; // Display our message MOG_Prompt.PromptResponse("Asset Remove", asset.GetAssetName() + groupString + " has been successfully removed from the current version info file. To be completely removed from the game you must rebuild its package.", MOGPromptButtons.OK); } return(true); } else { return(false); } }
public List <string> DrillToAsset_BuildDrillPathParts(MOG_Filename assetFilename, bool includeRevisions) { List <string> parts = new List <string>(); if (Nodes != null) { if (Nodes.Count > 0) { if (!String.IsNullOrEmpty(assetFilename.GetOriginalFilename())) { // Add classification elements string classification = assetFilename.GetAssetClassification(); if (!String.IsNullOrEmpty(classification)) { string[] classificationParts = MOG_Filename.SplitClassificationString(classification); parts.AddRange(classificationParts); // Add asset name elements string assetName = assetFilename.GetAssetName(); if (!String.IsNullOrEmpty(assetName)) { parts.Add(assetName); // Check if we have a version? if (!String.IsNullOrEmpty(assetFilename.GetVersionTimeStamp()) && includeRevisions) { // Date format string string dateFormat = MOG_Tokens.GetMonth_1() + "/" + MOG_Tokens.GetDay_1() + "/" + MOG_Tokens.GetYear_4() + " " + MOG_Tokens.GetHour_1() + ":" + MOG_Tokens.GetMinute_2() + " " + MOG_Tokens.GetAMPM(); parts.Add(Revisions_Text); parts.Add("<" + assetFilename.GetVersionTimeStampString(dateFormat) + ">"); } } } } } } return(parts); }
private void ClearInheritedPackageAssignments() { foreach (ListViewItem item in AssignmentList.Items) { // Generate a MOG_Filename and concat our path from it MOG_Filename packageFile = new MOG_Filename(item.Text); string assetName = packageFile.GetAssetName(); string assetFullName = packageFile.GetAssetClassification() + assetName; // Find this package's node TreeNode node = FindPackageNode(assetFullName); if (node != null) { // Check if this was inherited? if (node.NodeFont != null && node.NodeFont.Italic) { // Clear the check and reset its font node.Checked = false; node.NodeFont = new Font(AssignmentList.Font, FontStyle.Regular); } } } }
/// <summary> /// Returns the parent node of this asset type. We search the key then package and group to find the parent node. /// </summary> /// <param name="tree"></param> /// <param name="assetName"></param> /// <returns></returns> static protected TreeNode FindAssetNodeInTree(TreeView tree, MOG_Filename assetName) { // TreeNode keyNode, packageNode, groupNode, assetNode; int imageIndex = MogUtil_AssetIcons.GetClassIconIndex(assetName.GetAssetName()); return(new TreeNode()); // TODO - Rebuild this code!! // // First find the key // foreach (TreeNode keyNodes in tree.Nodes) // { // if (string.Compare(keyNodes.Text, assetName.GetAssetClassification(), true) == 0) // { // // Find the package // packageNode = FindNode(keyNodes, assetName.GetAssetClassification()); // if (packageNode != null) // { // // Find the group // groupNode = FindNode(packageNode, assetName.GetAssetSubClass()); // if (groupNode != null) // { // // Find the asset // assetNode = FindNode(groupNode, assetName.GetAssetName()); // if (assetNode != null) // { // assetNode.Remove(); // return groupNode; // } // else // { // // This is the group of the new child asset // return groupNode; // } // } // else // { // // Create the group // groupNode = new TreeNode(assetName.GetAssetSubClass()); // groupNode.ImageIndex = imageIndex; // groupNode.Tag = new guiAssetTreeTag("", guiAssetTreeTag.TREE_FOCUS.SUBCLASS); // // try // { // // Add this branch to the tree // packageNode.Nodes.Add(groupNode); // // // This is the group of the new child asset // return groupNode; // } // catch(Exception e) // { // e.ToString(); // return null; // } // } // } // else // { // // Create the package and the group // packageNode = new TreeNode(assetName.GetAssetClassification()); // packageNode.ImageIndex = imageIndex; // packageNode.Tag = new guiAssetTreeTag("", guiAssetTreeTag.TREE_FOCUS.CLASS); // // groupNode = new TreeNode(assetName.GetAssetSubClass()); // groupNode.ImageIndex = imageIndex; // groupNode.Tag = new guiAssetTreeTag("", guiAssetTreeTag.TREE_FOCUS.SUBCLASS); // // try // { // packageNode.Nodes.Add(groupNode); // // // Add this branch to the tree // keyNodes.Nodes.Add(packageNode); // // // This is the group of the new child asset // return groupNode; // } // catch(Exception e) // { // e.ToString(); // return null; // } // } // } // } // // Create the key, package and the group // keyNode = new TreeNode(assetName.GetAssetKey(), imageIndex, 0); // keyNode.Tag = new guiAssetTreeTag("", guiAssetTreeTag.TREE_FOCUS.KEY); // // packageNode = new TreeNode(assetName.GetAssetClassification()); // packageNode.ImageIndex = imageIndex; // packageNode.Tag = new guiAssetTreeTag("", guiAssetTreeTag.TREE_FOCUS.CLASS); // keyNode.Nodes.Add(packageNode); // // groupNode = new TreeNode(assetName.GetAssetSubClass()); // groupNode.ImageIndex = imageIndex; // groupNode.Tag = new guiAssetTreeTag("", guiAssetTreeTag.TREE_FOCUS.SUBCLASS); // packageNode.Nodes.Add(groupNode); // // try // { // // Add this branch to the tree // tree.Nodes.Add(keyNode); // // // This is the group of the new child asset // return groupNode; // } // catch(Exception e) // { // e.ToString(); // return null; // } }
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); } } } }
string ResolveToken(string token) { string value = ""; // Make sure this token starts with the '{'? if (token.StartsWith("{")) { // Get the name of this token string[] parts = token.Split("{}.".ToCharArray(), 3); // Make sure this resembled a real token? if (parts.Length == 3) { // Check for any contained commands? string testToken = "{" + parts[1] + "}"; // Determine which token we have? switch (testToken) { // Repository Tokens case TOKEN_Repository_Path: value = MOG_ControllerSystem.GetSystemRepositoryPath(); break; case TOKEN_Repository_ProjectsPath: value = MOG_ControllerSystem.GetSystemProjectsPath(); break; case TOKEN_Repository_ToolsPath: value = MOG_ControllerSystem.GetSystemRepositoryPath() + "\\Tools"; break; case TOKEN_Repository_Project_Path: value = MOG_ControllerProject.GetProjectPath(); break; case TOKEN_Repository_Project_ToolsPath: value = MOG_ControllerProject.GetProjectPath() + "\\Tools"; break; case TOKEN_Repository_Project_AssetsPath: value = MOG_ControllerRepository.GetRepositoryPath(); break; case TOKEN_Repository_Project_ArchivePath: value = MOG_ControllerRepository.GetArchivePath(); break; case TOKEN_Repository_Project_UsersPath: value = MOG_ControllerProject.GetProjectPath() + "\\Users"; break; // Project Tokens case TOKEN_Project_Name: value = MOG_ControllerProject.GetProjectName(); break; case TOKEN_Project_BranchName: value = MOG_ControllerProject.GetBranchName(); break; case TOKEN_Project_UserName: value = MOG_ControllerProject.GetUserName_DefaultAdmin(); break; case TOKEN_Project_PlatformName: value = MOG_ControllerProject.GetPlatformName(); break; case TOKEN_Project_WorkspaceDirectory: value = MOG_ControllerProject.GetWorkspaceDirectory(); break; // Ripper Tokens case TOKEN_Ripper_SourcePath: value = mRipperSourcePath; break; case TOKEN_Ripper_SourceFilePattern: value = mRipperSourceFilePattern; break; case TOKEN_Ripper_DestinationPath: value = mRipperDestinationPath; break; // Package Tokens case TOKEN_Package_WorkspaceDirectory: if (mPackageFileInfo != null) { value = mPackageFileInfo.mPackageWorkspaceDirectory; } break; case TOKEN_Package_DataDirectory: if (mPackageFileInfo != null) { value = mPackageFileInfo.mPackageDataDirectory; } break; case TOKEN_Package_PackageFile_Filename: if (mPackageFileInfo != null) { value = mPackageFileInfo.mPackageFile; } break; case TOKEN_Package_PackageFile_FullName: { MOG_Filename packageFilename = (mPackageFileInfo != null) ? mPackageFileInfo.mPackageAssetFilename : new MOG_Filename(MOG_ControllerPackage.GetPackageName(mPackageAssignment)); value = packageFilename.GetAssetFullName(); } break; case TOKEN_Package_PackageFile_Classification: { MOG_Filename packageFilename = (mPackageFileInfo != null) ? mPackageFileInfo.mPackageAssetFilename : new MOG_Filename(MOG_ControllerPackage.GetPackageName(mPackageAssignment)); value = packageFilename.GetAssetClassification(); } break; case TOKEN_Package_PackageFile_Label: { MOG_Filename packageFilename = (mPackageFileInfo != null) ? mPackageFileInfo.mPackageAssetFilename : new MOG_Filename(MOG_ControllerPackage.GetPackageName(mPackageAssignment)); value = packageFilename.GetAssetLabel(); } break; case TOKEN_Package_PackageFile_Platform: { MOG_Filename packageFilename = (mPackageFileInfo != null) ? mPackageFileInfo.mPackageAssetFilename : new MOG_Filename(MOG_ControllerPackage.GetPackageName(mPackageAssignment)); value = packageFilename.GetAssetPlatform(); } break; case TOKEN_Package_PackageFile_Group: value = MOG_ControllerPackage.GetPackageGroups(mPackageAssignment); break; case TOKEN_Package_PackageFile_Object: value = MOG_ControllerPackage.GetPackageObjects(mPackageAssignment); break; // Inbox Tokens case TOKEN_Inbox_UserName: value = mAssetFilename.GetUserName(); break; case TOKEN_Inbox_UserPath: value = mAssetFilename.GetUserPath(); break; case TOKEN_Inbox_BoxName: value = mAssetFilename.GetBoxName(); break; case TOKEN_Inbox_BoxPath: value = mAssetFilename.GetBoxPath(); break; // Asset Tokens case TOKEN_Asset_AssetName_Path: value = mAssetFilename.GetPath(); break; case TOKEN_Asset_AssetName_FullName: value = mAssetFilename.GetAssetFullName(); break; case TOKEN_Asset_AssetName_Classification: value = mAssetFilename.GetAssetClassification(); break; case TOKEN_Asset_AssetName_Name: value = mAssetFilename.GetAssetName(); break; case TOKEN_Asset_AssetName_PlatformName: value = mAssetFilename.GetAssetPlatform(); break; case TOKEN_Asset_AssetName_Label: value = mAssetFilename.GetAssetLabel(); break; case TOKEN_Asset_ImportedFile: case TOKEN_Asset_RippedFile: value = ResolveToken_AssetFile(token); break; case TOKEN_Asset_Property: value = ResolveToken_Property(token); break; case TOKEN_Asset_ClassificationPath: value = MOG_Filename.GetClassificationPath(mAssetFilename.GetAssetClassification()); break; case TOKEN_Asset_VersionTimeStamp: value = mAssetFilename.GetVersionTimeStamp(); break; } // Check if we have a command? if (parts[2] != ".") { } } } return(value); }
private void MogControl_PackageTreeView_AfterLabelEdit(object sender, System.Windows.Forms.NodeLabelEditEventArgs e) { // Encapsulate all of this in a try-catch, since we don't want to crash MOG try { if (!CheckLabelEdit(e)) { return; } // Disable further label editing e.Node.TreeView.LabelEdit = false; // Find our parent package TreeNode package = FindPackage(e.Node); TreeNode parent = e.Node.Parent; string nodeText = e.Node.Text.ToLower(); ArrayList packagePlatforms = GetPackageLabelEditPlatforms(e, ref nodeText); // Switch base on what our nodeText was before the user editted it switch (nodeText.ToLower()) { case "newgroup": #region new-group if (package != null) { // Get the new edited label name //string groupName = e.Label; MOG_Filename packageAsset = new MOG_Filename(((Mog_BaseTag)package.Tag).FullFilename); string groupName = GetQualifiedGroupName(e, package); // If we have a duplicate, do not add it if (ValidateNodeIsNotDuplicate(e.Node.Parent, groupName) == true) { MOG_Prompt.PromptResponse("Duplicate Entry!", "The group, " + groupName + ", " + "already exists! Group not added."); e.Node.Remove(); return; } // Add group to Database if (!AddGroupToDatabase(groupName, packageAsset)) { // We need to clean up the unsuccessfull add to the database e.Node.Remove(); // Show error MOG_Prompt.PromptMessage("Create group", "We were unable to add this group to the database. Aborting"); } AttachValidatedTagToNewObjectOrGroup(package, e.Node, PackageNodeTypes.Group); // Go ahead and select our node e.Node.TreeView.SelectedNode = e.Node; } #endregion newgroup break; case "(newpackageobject)": #region new-package-object if (package != null) { // Get the new edited label name string objectName = e.Label; e.Node.Text = "(" + objectName + ")"; // If we have a duplicate, do not add it if (ValidateNodeIsNotDuplicate(e.Node.Parent, e.Node.Text) == true) { MOG_Prompt.PromptResponse("Duplicate Entry!", "The object, (" + objectName + "), " + "already exists! Package object not added."); e.Node.Remove(); return; } MOG_Filename packageAsset = new MOG_Filename(((Mog_BaseTag)package.Tag).FullFilename); string groupPath = GetQualifiedGroupName(e, package); // Add group to Database if (!AddGroupToDatabase(groupPath, packageAsset)) { // We need to clean up the unsuccessfull add to the database e.Node.Remove(); // Show error MOG_Prompt.PromptMessage("Create object", "We were unable to add this object to the database. Aborting"); } else { e.CancelEdit = true; AttachValidatedTagToNewObjectOrGroup(package, e.Node, PackageNodeTypes.Object); // Go ahead and select our node e.Node.TreeView.SelectedNode = e.Node; } } #endregion new-package-object break; case "newpackage": #region new-package // Get the new package name string nodeFullname = MOG_Filename.JoinClassificationString(e.Node.FullPath, e.Label); // Construct a valid filename MOG_Filename[] packages = new MOG_Filename[packagePlatforms.Count]; bool duplicateExists = false; string duplicates = ""; for (int i = 0; i < packages.Length && i < packagePlatforms.Count; ++i) { MOG_Filename packageName = MOG_Filename.CreateAssetName(e.Node.Parent.FullPath, (string)packagePlatforms[i], e.Label); packages[i] = packageName; // If we have a duplicate package, store if ((duplicateExists |= ValidateNodeIsNotDuplicate(e.Node.Parent, packageName.GetAssetName())) == true) { duplicates += packageName + "\r\n"; } } // If we had duplicates, warn user and exit if (duplicateExists) { MOG_Prompt.PromptResponse("Duplicate Entry(ies) Detected!", "The following were already exist:\r\n\r\n" + duplicates); e.Node.Remove(); return; } // If we did not get a ValidPackageName (or the user decided to abort...) foreach (MOG_Filename packageName in packages) { if (!ValidatePackageExtension(e, packageName)) { return; } } bool problemAdding = false; string packageErrorPrompt = "Did not complete package add for the following: \r\n"; // Go backwards through our packages (so we can get the right platforms. for (int i = packages.Length - 1; i > -1; --i) { MOG_Filename packageName = packages[i]; // Did we get a valid package name? if (packageName != null) { // Create the package MOG_Filename createdPackage = CreatePackageForPlatform(e, packageName, parent); // If the user cancelled some part of the process or we had an error... if (createdPackage == null) { // Remove the node packageErrorPrompt += "\t" + packageName + "."; problemAdding = true; break; } TreeNode newPackageNode; // For our first platform, we've already got a node, use it... if (i == 0) { e.Node.Text = createdPackage.GetAssetName(); e.Label.ToString(); newPackageNode = e.Node; } // For subsequent platforms, add a new node... else { newPackageNode = e.Node.Parent.Nodes.Add(createdPackage.GetAssetName()); } // Now that we've got our initial information, add our tag newPackageNode.Tag = new Mog_BaseTag(newPackageNode, createdPackage.GetEncodedFilename(), this.FocusForAssetNodes, true); ((Mog_BaseTag)newPackageNode.Tag).PackageNodeType = PackageNodeTypes.Package; ((Mog_BaseTag)newPackageNode.Tag).PackageFullName = createdPackage.GetAssetFullName(); SetImageIndices(newPackageNode, GetAssetFileImageIndex(createdPackage.GetEncodedFilename())); } } // If we had a problem, let the user know and remove our package if (problemAdding) { MOG_Prompt.PromptMessage("Unable to Add Package(s)", packageErrorPrompt); e.Node.Remove(); foreach (MOG_Filename packageName in packages) { RemovePackage(packageName); } } else // Else, we were OK, so go ahead and select this node... { e.Node.TreeView.SelectedNode = e.Node; foreach (MOG_Filename packageName in packages) { // Add this package to the list of newly added packages this.CreatedPackages.Add(packageName); } // Fire the after package create event if (AfterPackageCreate != null) { AfterPackageCreate(this, EventArgs.Empty); } } #endregion new-package break; } } catch (Exception ex) { MOG_Report.ReportMessage("TreeNode Error!", "Error committing change to package, group, or package object label:\n" + ex.Message, ex.StackTrace, MOG.PROMPT.MOG_ALERT_LEVEL.ERROR); if (e.Node != null) { e.Node.Remove(); } } }
private void PackageRemoveMenuItem_Click(object sender, System.EventArgs e) { try { TreeNode selectedNode = ProjectPackagesTreeView.SelectedNode; // If we have not expanded this node, go ahead and do so... if (selectedNode != null && !selectedNode.IsExpanded) { // Get rid of any Blank node selectedNode.Expand(); } // Make sure we have a selected node and that that node does not have sub nodes other than the blank node if (selectedNode != null && selectedNode.Nodes.Count == 0) { Mog_BaseTag packageTag = (Mog_BaseTag)ProjectPackagesTreeView.SelectedNode.Tag; // Are we a package? if (packageTag.PackageNodeType == PackageNodeTypes.Asset || packageTag.PackageNodeType == PackageNodeTypes.Package) { RemovePackageFromProject(packageTag); return; } // Are we a classification? else if (packageTag.PackageNodeType == PackageNodeTypes.Class) { MessageBox.Show(this, "Cannot remove a Classification node. Please go to Project Tab | Project Trees " + "to be able to do this."); return; } string removeCandidate = ProjectPackagesTreeView.SelectedNode.Text; // Find our parent package TreeNode package = ProjectPackagesTreeView.FindPackage(ProjectPackagesTreeView.SelectedNode); if (package != null) { MOG_Filename packageAsset = new MOG_Filename(((Mog_BaseTag)package.Tag).FullFilename); // Remove the classification from our fullPath string objectPath = ProjectPackagesTreeView.SelectedNode.FullPath.Replace(packageAsset.GetAssetClassification() + "/", ""); // First, get the index of our package name int assetNameIndex = objectPath.IndexOf(packageAsset.GetAssetName()); // If we have a valid index for the package's name... if (assetNameIndex > -1) { // Remove everything before our package name objectPath = objectPath.Substring(assetNameIndex); } // Now remove our package name objectPath = objectPath.Replace(packageAsset.GetAssetName(), ""); // Add back in our Group/Object separator objectPath = objectPath.Replace("~", "/"); // If we have an initial forward slash... if (objectPath.IndexOf("/") == 0) { // Get rid of it objectPath = objectPath.Substring(1); } // If we can remove it from the databse, remove the treenode? if (ProjectPackagesTreeView.RemoveGroupFromDatabase(objectPath, packageAsset)) { // Remove the node ProjectPackagesTreeView.SelectedNode.Remove(); } } } else { MOG_Prompt.PromptMessage("Remove node", "Could not remove this node because:\n\tNode must not contain any sub-nodes before removal."); } } catch (Exception ex) { MOG_Report.ReportMessage("Remove node", "MOG encountered an unexpected problem. Aborting node remove.\nSystem Message:" + ex.Message, ex.StackTrace, MOG.PROMPT.MOG_ALERT_LEVEL.CRITICAL); } }
private static void UpdateLocalProgress_Worker(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; int autoCount = 0; int userCount = 0; // Suspend the auto packaging WorkspaceManager.SuspendPackaging(true); // Begin this GetLatest WorkspaceManager.ModifyLocalWorkspace_Begin(); while (true) { MOG_Filename filename = new MOG_Filename(); bool userInitiated = false; lock (mAutoUpdateQueue) { // See if there are any auto update items needing to be processed? if (mAutoUpdateQueue.Count > 0) { filename = mAutoUpdateQueue.Dequeue(); autoCount++; } // See if there are any user initiated items needing to be processed? else if (mUserUpdateQueue.Count > 0) { filename = mUserUpdateQueue.Dequeue(); userCount++; userInitiated = true; } } // Recalulate total within this loop because it can be changing outside of us in another thread... int total = (mAutoUpdateQueue.Count + autoCount) + (mUserUpdateQueue.Count + userCount); string message = "Updating:\n" + " " + filename.GetAssetClassification() + "\n" + " " + filename.GetAssetName(); worker.ReportProgress((autoCount + userCount) * 100 / total, message); // Only allow updates of valid assets if (filename.GetFilenameType() == MOG_FILENAME_TYPE.MOG_FILENAME_Asset || filename.GetFilenameType() == MOG_FILENAME_TYPE.MOG_FILENAME_Group) { // Add this asset to all of our active workspaces WorkspaceManager.AddAssetToWorkspaces(filename, userInitiated, worker); } lock (mUpdateQueueLock) { if (mAutoUpdateQueue.Count == 0 && mUserUpdateQueue.Count == 0) { mAutoUpdateQueue = null; mUserUpdateQueue = null; break; } // Check if the user canceled things? if (worker.CancellationPending) { mAutoUpdateQueue = null; mUserUpdateQueue = null; break; } } } // Restore the auto packaging WorkspaceManager.SuspendPackaging(false); // End this GetLatest WorkspaceManager.ModifyLocalWorkspace_Complete(); }
public static void BlessAssets_Worker(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; List <object> parameters = e.Argument as List <object>; List <MOG_Filename> filenames = parameters[0] as List <MOG_Filename>; string comment = parameters[1] as string; bool maintainLock = (bool)parameters[2]; bool bUserAltered = false; string loginUser = MOG_ControllerProject.GetUser().GetUserName(); string activeUser = MOG_ControllerProject.GetActiveUser().GetUserName(); // Make sure the inbox that we are in matches the logged in user if (string.Compare(MOG_ControllerProject.GetUser().GetUserName(), MOG_ControllerProject.GetActiveUser().GetUserName(), true) != 0) { // Login as this user so that his bless targets will be respected during this bless! MOG_ControllerProject.LoginUser(MOG_ControllerProject.GetActiveUser().GetUserName()); bUserAltered = true; } // Obtain a unique bless jobLabel string timestamp = MOG_Time.GetVersionTimestamp(); string jobLabel = "Bless." + MOG_ControllerSystem.GetComputerName() + "." + timestamp; // Changed to a for-loop to facilitate the loop breakout box on bless failure below for (int assetIndex = 0; assetIndex < filenames.Count; assetIndex++) { MOG_Filename asset = filenames[assetIndex] as MOG_Filename; if (asset != null) { string message = "Blessing:\n" + " " + asset.GetAssetClassification() + "\n" + " " + asset.GetAssetName(); worker.ReportProgress(assetIndex * 100 / filenames.Count, message); // Try to bless each asset and report if there is a failure try { if (MOG_ControllerInbox.BlessAsset(asset, comment, maintainLock, jobLabel, worker)) { WorkspaceManager.MarkLocalAssetBlessed(asset, timestamp); } else { // If there are more assets to bless, ask the user how to proceed if (assetIndex < filenames.Count - 1) { MOGPromptResult result = MOG_Prompt.PromptResponse("Bless Error", "An error has occurred while blessing " + asset.GetAssetFullName() + "\nWould you like to continue blessing assets?", MOGPromptButtons.YesNo); if (result == MOGPromptResult.Yes) { // continue with the next asset continue; } else if (result == MOGPromptResult.No) { // bail return; } } } } catch (Exception ex) { // Send this Exception back to the server MOG_Report.ReportMessage("Bless", ex.Message, ex.StackTrace, MOG_ALERT_LEVEL.CRITICAL); // Check if we are logged in an anyone? if (MOG_ControllerProject.IsUser()) { // Send a notification to the ofending user MOG_Report.ReportMessage("Bless", ex.Message, ex.StackTrace, MOG_ALERT_LEVEL.CRITICAL); } } } } // Start the job MOG_ControllerProject.StartJob(jobLabel); // Restore user if changed if (bUserAltered) { MOG_ControllerProject.LoginUser(loginUser); MOG_ControllerProject.SetActiveUserName(activeUser); } }
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 void InitializeAssetName(MOG_Filename mogFilename) { InitializePlatformComboBox(); InitializeTextBoxes(mogFilename.GetAssetClassification(), mogFilename.GetAssetPlatform(), mogFilename.GetAssetName()); }