Ejemplo n.º 1
0
        private ListViewItem CreateListViewItemForFile(string localFile)
        {
            ListViewItem item = null;

            // Only put the asset in the list if it is actually a library asset
            if (MOG_ControllerLibrary.IsPathWithinLibrary(localFile))
            {
                item = new ListViewItem(Path.GetFileName(localFile));

                string classification = MOG_ControllerLibrary.ConstructLibraryClassificationFromPath(localFile);
                string localTimestamp = GetLocalFileTimestamp(localFile);
                string fullname       = localFile;
                string status         = "Unknown";
                string extension      = DosUtils.PathGetExtension(localFile);

                // Populate the item
                item.ImageIndex = MogUtil_AssetIcons.GetFileIconIndex(localFile);
                item.SubItems.Add(extension);               // Extension
                item.SubItems.Add(classification);          // Classification
                item.SubItems.Add("");                      // User
                item.SubItems.Add("");                      // Comment
                item.SubItems.Add(localTimestamp);          // Local TimeStamp
                item.SubItems.Add("");                      // Server Timestamp
                item.SubItems.Add(status);                  // Status
                item.SubItems.Add(fullname);                // Fullname
                item.SubItems.Add(localFile);               // LocalFile
                item.SubItems.Add("");                      // RepositoryFile

                UpdateListViewItemColors(item, status);
            }

            return(item);
        }
Ejemplo n.º 2
0
        public static MOG_Property RepairProperty(MOG_Property propertyObject)
        {
            MOG_Property fixedPropertyObject = null;

            string key             = propertyObject.mKey;
            string section         = propertyObject.mSection;
            string propertySection = propertyObject.mPropertySection;
            string propertyKey     = propertyObject.mPropertyKey;
            string propertyValue   = propertyObject.mPropertyValue;

            MOG_Property tempProperty           = MOG_PropertyFactory.MOG_Relationships.New_RelationshipAssignment("", "", "", "");
            MOG_Property tempPackageProperty    = MOG_PropertyFactory.MOG_Relationships.New_PackageAssignment("", "", "");
            MOG_Property tempSourceFileProperty = MOG_PropertyFactory.MOG_Relationships.New_AssetSourceFile("");

            // Check if this property is a package relationship?
            if (string.Compare(section, tempPackageProperty.mSection, true) == 0)
            {
                string assetName = MOG_ControllerPackage.GetPackageName(propertyKey);
                string groups    = MOG_ControllerPackage.GetPackageGroups(propertyKey);
                string objects   = MOG_ControllerPackage.GetPackageObjects(propertyKey);

                // Remap various properties making sure we correct any problem areas
                MOG_Filename assetFilename = null;

                // Check if this property is a SourceFile relationship?
                if (string.Compare(propertySection, tempSourceFileProperty.mPropertySection, true) == 0)
                {
                    // Check if the specified file is within the library?
                    if (MOG_ControllerLibrary.IsPathWithinLibrary(propertyKey))
                    {
                        // Map this library file to a real asset name
                        assetFilename = MOG_ControllerProject.MapFilenameToLibraryAssetName(assetName, MOG_ControllerProject.GetPlatformName());
                        if (assetFilename != null)
                        {
                            fixedPropertyObject = MOG_PropertyFactory.MOG_Relationships.New_AssetSourceFile(assetFilename.GetFullFilename());
                        }
                    }
                }
                else
                {
                    // Try to find the assetname for the specified asset
                    ArrayList assets = MOG_ControllerProject.MapFilenameToAssetName(assetName, MOG_ControllerProject.GetPlatformName(), MOG_ControllerProject.GetWorkspaceDirectory());
                    if (assets == null || assets.Count == 0)
                    {
                        // The package could not be found
                        if (string.Compare(propertySection, tempPackageProperty.mPropertySection, true) == 0)
                        {
                            // Check if we actually had something specified?
                            if (assetName.Length > 0)
                            {
                                // Set the deafult packageFilename info
                                string assetClassification = "";
                                string assetPlatformName   = "All";
                                string assetLabel          = DosUtils.PathGetFileNameWithoutExtension(assetName);
                                string syncTargetPath      = DosUtils.PathGetDirectoryPath(assetName);

                                // Check if the assetName was already a valid MOG_Filename?
                                MOG_Filename packageFilename = new MOG_Filename(assetName);
                                if (packageFilename.GetAssetClassification().Length > 0)
                                {
                                    assetClassification = MOG_Filename.AppendAdamObjectNameOnClassification(packageFilename.GetAssetClassification());
                                }
                                if (packageFilename.GetAssetPlatform().Length > 0)
                                {
                                    assetPlatformName = packageFilename.GetAssetPlatform();
                                }
                                if (packageFilename.GetAssetLabel().Length > 0)
                                {
                                    assetLabel = packageFilename.GetAssetLabel();
                                }

                                // Prompt user to complete the unknown information about this packageFile
                                string         message = "MOG has detected a new package assignment to a previously non-existing package.  Please complete the following red fields so that a proper package can be created in MOG.";
                                PackageCreator creator = new PackageCreator();
                                creator.Classification = assetClassification;
                                creator.PackageName    = assetLabel;
                                creator.SyncTarget     = syncTargetPath;
                                creator.Platform       = assetPlatformName;
                                if (creator.ShowDialog() == DialogResult.OK)
                                {
                                    // Use this newly created packageFilename as our assetFilename to be fixed
                                    assetFilename = creator.AssetName;
                                }
                                else
                                {
                                    // The PackageName is invalid
                                    message = "New Package Not Created.\n" +
                                              "The user chose not to create a new package.";
                                    MOG_Report.ReportMessage("Package Assignment", message, Environment.StackTrace, MOG_ALERT_LEVEL.ERROR);
                                }
                            }
                            else
                            {
                                // The PackageName is invalid
                                string message = "Invalid PackageName specified.\n" +
                                                 "The packaged asset was not assigned to a package.";
                                MOG_Report.ReportMessage("Package Assignment", message, Environment.StackTrace, MOG_ALERT_LEVEL.ERROR);
                            }
                        }
                    }
                    else
                    {
                        // Always use the first one
                        assetFilename = assets[0] as MOG_Filename;
                        MOG_ControllerProject.MapFilenameToAssetName_WarnAboutAmbiguousMatches(assetName, assets);
                    }

                    // Now do we finally have a package asset name?
                    if (assetFilename != null)
                    {
                        // Replace the propertyObject with the fixed up one
                        fixedPropertyObject = MOG_PropertyFactory.MOG_Relationships.New_RelationshipAssignment(propertySection, assetFilename.GetAssetFullName(), groups, objects);
                    }
                }
            }

            // Check if we fixed the property?
            if (fixedPropertyObject != null)
            {
                return(fixedPropertyObject);
            }
            return(propertyObject);
        }
        public static bool PromptUserForConfirmation(string[] filenames, string classification)
        {
            bool bProceed = true;

            // Make sure we have valid information?
            if (filenames == null || filenames.Length == 0)
            {
                MOG_Prompt.PromptMessage("Add Files", "Unable to add files because no files were specified.");
                bProceed = false;
            }
            else if (string.IsNullOrEmpty(classification))
            {
                MOG_Prompt.PromptMessage("Add Files", "Unable to add files because no classification was specified.");
                bProceed = false;
            }
            else
            {
                // Check if this file is already located within the library
                if (MOG_ControllerLibrary.IsPathWithinLibrary(Path.GetDirectoryName(filenames[0])))
                {
                    // Assume all the files have the same path and construct a classification from the path of the first file
                    string libraryClassification = MOG_ControllerLibrary.ConstructLibraryClassificationFromPath(Path.GetDirectoryName(filenames[0]));
                    if (libraryClassification != classification)
                    {
                        // Prompt the user about what they want
                        string message = "This file is located elsewhere within the 'Library Working Folder'.\n\n" +
                                         "Are you sure you want to add this file to this new location as well?";
                        if (filenames.Length > 2)
                        {
                            message = "These files are located elsewhere within the 'Library Working Folder'.\n\n" +
                                      "Are you sure you want to add these files to this new location as well?";
                        }
                        if (MOG_Prompt.PromptResponse("Add Files", message, MOGPromptButtons.YesNo) == MOGPromptResult.No)
                        {
                            // Early out because they clicked cancel
                            bProceed = false;
                        }
                    }
                }
                else
                {
                    // Ask user for confirmation that they really want
                    string msg = "";
                    if (filenames.Length < 20)
                    {
                        msg += "Are you sure you want to import the following?\n\n";

                        // Build a file/dir list for the confirmation message
                        foreach (string filename in filenames)
                        {
                            msg += Path.GetFileName(filename) + "\n";
                        }
                    }
                    else
                    {
                        // There are too many files to display in a MessageBox, so just ask for generic confirmation
                        msg = "Are you sure you want to import these " + filenames.Length.ToString() + " items?";
                    }

                    if (MOG_Prompt.PromptResponse("Confirm File Importation", msg, MOGPromptButtons.YesNo) == MOGPromptResult.No)
                    {
                        bProceed = false;
                    }
                }
            }

            return(bProceed);
        }
Ejemplo n.º 4
0
        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();
            }
        }
Ejemplo n.º 5
0
        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);
                    }
                }
            }
        }