private void LibraryExploreButton_Click(object sender, EventArgs e)
 {
     if (MOG_ControllerLibrary.GetWorkingDirectory() != "")
     {
         guiCommandLine.ShellSpawn(MOG_ControllerLibrary.GetWorkingDirectory());
     }
 }
Example #2
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);
        }
Example #3
0
        private void LibraryListView_BeforeLabelEdit(object sender, LabelEditEventArgs e)
        {
            ListViewItem renamedAsset = LibraryListView.Items[e.Item];
            string       fullName     = GetItemFullName(renamedAsset);

            // We can only rename assets that are not checked into MOG
            if (fullName.StartsWith(MOG_ControllerLibrary.GetWorkingDirectory()) == false)
            {
                e.CancelEdit = true;
            }
        }
        override public void Refresh()
        {
            // We only need to call the ListView's Deinitialize becasue the TreeView will eventually cause it to be repopulated
            LibraryListView.DeInitialize();
            // Refresh the tree view
            LibraryTreeView.DeInitialize();
            LibraryTreeView.Initialize();

            // Show our sync target
            this.LibraryTargetTextBox.Text = "(" + MOG_ControllerLibrary.GetWorkingDirectory() + ")";
            this.LibraryTargetTextBox.Tag  = MOG_ControllerLibrary.GetWorkingDirectory();

            base.Refresh();
        }
        private void LibraryTreeView_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
        {
            base.Refresh();

            // We do not allow any items to be shown in classifications that are not in the library folder
            if (e.Node.FullPath.ToLower().IndexOf("library") != -1)
            {
                LibraryListView.Populate(e.Node.FullPath);
            }
            else
            {
                LibraryListView.LibraryListView.Items.Clear();
            }

            LibraryTargetTextBox.Text = "(" + MOG_ControllerLibrary.GetWorkingDirectory() + ")" + "\\" + e.Node.FullPath.Replace("~", "\\");
        }
        // Copy a list of files and/or directories from a drag-drop operation to the user's local working directory
        public static void CopyFiles(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;
            List <object>    args   = e.Argument as List <object>;

            string[] filenames      = args[0] as string[];
            string   classification = args[1] as string;

            if (filenames != null && filenames.Length > 0)
            {
                try
                {
                    // Sort files and dirs
                    ArrayList fileList = new ArrayList();
                    ArrayList dirList  = new ArrayList();
                    foreach (string filename in filenames)
                    {
                        if (Directory.Exists(filename))
                        {
                            dirList.Add(filename);
                        }
                        else if (File.Exists(filename))
                        {
                            fileList.Add(filename);
                        }
                    }

                    string targetPath = MOG_ControllerLibrary.ConstructPathFromLibraryClassification(classification);

                    // Simply copy the files
                    foreach (string dirname in dirList)
                    {
                        string target = Path.Combine(targetPath, Path.GetFileName(dirname));
                        MOG_ControllerSystem.DirectoryCopyEx(dirname, target, worker);
                    }
                    // Simply copy the files
                    foreach (string filename in fileList)
                    {
                        string target = Path.Combine(targetPath, Path.GetFileName(filename));
                        MOG_ControllerSystem.FileCopyEx(filename, target, true, true, worker);
                    }
                }
                catch
                {
                }
            }
        }
        private void LibraryBrowseButton_Click(object sender, System.EventArgs e)
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog();

            dialog.RootFolder          = Environment.SpecialFolder.Desktop;
            dialog.ShowNewFolderButton = true;
            dialog.SelectedPath        = MOG_ControllerLibrary.GetWorkingDirectory();
            dialog.Description         = "Select a location to be the Library target.";

            DialogResult result = dialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                MOG_ControllerLibrary.SetWorkingDirectory(dialog.SelectedPath);
                LibraryTargetTextBox.Text = "(" + MOG_ControllerLibrary.GetWorkingDirectory() + ")";
                LibraryTargetTextBox.Tag  = MOG_ControllerLibrary.GetWorkingDirectory();

                MogUtils_Settings.MogUtils_Settings.SaveSetting("Library", "TargetDirectory", dialog.SelectedPath);
            }
        }
        // Import a list of files and/or directories from a drag-drop operation to a specific classification
        public static void ImportFiles(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;
            List <object>    args   = e.Argument as List <object>;

            string[] filenames      = args[0] as string[];
            string   classification = args[1] as string;

            if (filenames != null && filenames.Length > 0)
            {
                try
                {
                    // Sort files and dirs
                    ArrayList fileList = new ArrayList();
                    ArrayList dirList  = new ArrayList();
                    foreach (string filename in filenames)
                    {
                        if (Directory.Exists(filename))
                        {
                            dirList.Add(filename);
                        }
                        else if (File.Exists(filename))
                        {
                            fileList.Add(filename);
                        }
                    }

                    // Add each directory seperately
                    foreach (string dirname in dirList)
                    {
                        MOG_ControllerLibrary.AddDirectory(dirname, classification);
                    }

                    // Add all the files
                    MOG_ControllerLibrary.AddFiles(fileList, classification);
                }
                catch
                {
                }
            }
        }
Example #9
0
        private ListViewItem CreateListViewItemForAsset(MOG_Filename asset)
        {
            ListViewItem item = null;

            // Only put the asset in the list if it is actually a library asset
            if (asset.IsLibrary())
            {
                // Make sure we have something valid in our Filename
                if (asset.GetAssetLabel().Length > 0)
                {
                    item = new ListViewItem(asset.GetAssetLabel());

                    // Get the source imported file
                    MOG_Filename repositoryAssetFilename = MOG_ControllerRepository.GetAssetBlessedVersionPath(asset, asset.GetVersionTimeStamp());
                    string       repositoryFile          = MOG_ControllerLibrary.ConstructBlessedFilenameFromAssetName(repositoryAssetFilename);
                    string       localFile = MOG_ControllerLibrary.ConstructLocalFilenameFromAssetName(repositoryAssetFilename);
                    string       extension = DosUtils.PathGetExtension(localFile);

                    // Populate the item
                    item.SubItems.Add(extension);                                   // Extension
                    item.SubItems.Add(asset.GetAssetClassification());              // Classification
                    item.SubItems.Add("");                                          // User
                    item.SubItems.Add("");                                          // Comment
                    item.SubItems.Add("");                                          // Local TimeStamp
                    item.SubItems.Add(asset.GetVersionTimeStampString(""));         // Server Timestamp
                    item.SubItems.Add("New");                                       // Status
                    item.SubItems.Add(asset.GetAssetFullName());                    // Fullname
                    item.SubItems.Add(localFile);                                   // LocalFile
                    item.SubItems.Add(repositoryFile);                              // RepositoryFile

                    // Update the item
                    UpdateItem(item);
                }
            }

            return(item);
        }
        public void Initialize(MethodInvoker onCompletedEvent)
        {
            this.LibraryListView.Initialize();
            this.LibraryListView.LibraryExplorer = this;

            // Initialize the icons
            this.LibraryTreeView.ImageList = MOG_ControlsLibrary.Utils.MogUtil_AssetIcons.Images;

            // Show our sync target
            string workingDir = guiUserPrefs.LoadPref("Library", "TargetDirectory");

            if (workingDir == null || workingDir.Length == 0)
            {
                workingDir = @"C:\MOG_Library";
                MogUtils_Settings.MogUtils_Settings.SaveSetting("Library", "TargetDirectory", workingDir);
            }

            MOG_ControllerLibrary.SetWorkingDirectory(workingDir);
            LibraryTargetTextBox.Text = "(" + workingDir + ")";
            LibraryTargetTextBox.Tag  = workingDir;

            this.LibraryTreeView.Initialize(onCompletedEvent);
            this.LibraryTreeView.LibraryExplorer = this;
        }
        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);
        }
Example #12
0
        public void RefreshItem(MOG_Command command)
        {
            // No reason to bother if they have no library working directory
            if (MOG_ControllerLibrary.GetWorkingDirectory().Length == 0)
            {
                return;
            }

            // Make sure this contains an encapsulated command?
            MOG_Command encapsulatedCommand = command.GetCommand();

            if (encapsulatedCommand != null)
            {
                // No reason to bother if they are in a different project
                if (string.Compare(MOG_ControllerProject.GetProjectName(), encapsulatedCommand.GetProject(), true) != 0)
                {
                    return;
                }

                // Check if this encapsulatedCommand contains a valid assetFilename?
                if (encapsulatedCommand.GetAssetFilename().GetFilenameType() == MOG_FILENAME_TYPE.MOG_FILENAME_Asset)
                {
                    // No reason to bother if this asset's classification doesn't match their mCurrentClassification
                    if (string.Compare(CurrentClassification, encapsulatedCommand.GetAssetFilename().GetAssetClassification(), true) != 0)
                    {
                        return;
                    }
                }

                // Can we find the asset node of this file?
                int itemid = FindListItem(encapsulatedCommand.GetAssetFilename().GetAssetFullName());
                if (itemid == -1)
                {
                    // Check if this was a post command?
                    if (encapsulatedCommand.GetCommandType() == MOG_COMMAND_TYPE.MOG_COMMAND_Post)
                    {
                        // Create a new item
                        ListViewItem item = CreateListViewItemForAsset(encapsulatedCommand.GetAssetFilename());
                        if (item != null)
                        {
                            LibraryListView.Items.Add(item);
                            itemid = FindListItem(encapsulatedCommand.GetAssetFilename().GetAssetFullName());
                        }
                    }
                }

                // Now check if we finally found our itemid?
                if (itemid != -1)
                {
                    ListViewItem item = LibraryListView.Items[itemid];
                    if (item != null)
                    {
                        int classificationIdx  = FindColumn("Classification");
                        int nameIdx            = FindColumn("Name");
                        int statusIdx          = FindColumn("Status");
                        int userIdx            = FindColumn("User");
                        int commentIdx         = FindColumn("Comment");
                        int localFileIdx       = FindColumn("LocalFile");
                        int repositoryFileIdx  = FindColumn("RepositoryFile");
                        int localTimestampIdx  = FindColumn("Local Timestamp");
                        int serverTimestampIdx = FindColumn("Server Timestamp");
                        int fullname           = FindColumn("Fullname");
                        int extensionIdx       = FindColumn("Extension");

                        // Determin the type of encapsulated command
                        switch (encapsulatedCommand.GetCommandType())
                        {
                        case MOG_COMMAND_TYPE.MOG_COMMAND_LockWriteRelease:
                        case MOG_COMMAND_TYPE.MOG_COMMAND_LockReadRelease:
                            UpdateItem(item);
                            break;

                        case MOG_COMMAND_TYPE.MOG_COMMAND_LockWriteRequest:
                        case MOG_COMMAND_TYPE.MOG_COMMAND_LockReadRequest:
                            string status   = "";
                            string comment  = encapsulatedCommand.GetDescription();
                            string username = encapsulatedCommand.GetUserName();
                            if (String.Compare(MOG_ControllerProject.GetUserName(), encapsulatedCommand.GetUserName(), true) == 0)
                            {
                                status = "CheckedOut";
                            }
                            else
                            {
                                status = "Locked";
                            }

                            item.ImageIndex = MogUtil_AssetIcons.GetLockedBinaryIcon(item.SubItems[repositoryFileIdx].Text);
                            item.SubItems[commentIdx].Text = comment;
                            item.SubItems[userIdx].Text    = username;
                            item.SubItems[statusIdx].Text  = status;

                            UpdateListViewItemColors(item, status);
                            break;

                        case MOG_COMMAND_TYPE.MOG_COMMAND_Post:
                            item.SubItems[repositoryFileIdx].Text = MOG_ControllerLibrary.ConstructBlessedFilenameFromAssetName(encapsulatedCommand.GetAssetFilename());
                            UpdateItem(item);
                            break;

                        case MOG_COMMAND_TYPE.MOG_COMMAND_RemoveAssetFromProject:
                            // Make sure to remove this file just incase it had been previously synced
                            MOG_ControllerLibrary.Unsync(encapsulatedCommand.GetAssetFilename());
                            // Proceed to delete this item
                            RemoveItem(itemid);
                            break;
                        }

                        // Update the item's colors
                        UpdateListViewItemColors(item, item.SubItems[statusIdx].Text);
                    }
                }
            }
        }
Example #13
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);
                    }
                }
            }
        }
Example #14
0
        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            = "";
            }
        }
Example #15
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();
            }
        }
Example #16
0
        /// <summary>
        /// Scans the local branches data to locate all binaries that do not have a counterpart in the project database
        /// </summary>
        private bool LocateNonMogAssetsScanFiles(BackgroundWorker worker, string path, ArrayList rogueFiles, HybridDictionary MergeableAssets, string targetProjectPath, MOG_Properties classificationProperties)
        {
            // Check if this is a library path?
            if (MOG_ControllerLibrary.GetWorkingDirectory().Length > 0 &&
                path.StartsWith(MOG_ControllerLibrary.GetWorkingDirectory(), StringComparison.CurrentCultureIgnoreCase))
            {
                // Build us our library classification for this library path
                string classification = MOG_ControllerLibrary.ConstructLibraryClassificationFromPath(path);
                // Check if this library classification exists?
                if (MOG_ControllerProject.IsValidClassification(classification))
                {
                    // Obtain the properties for this library classification
                    classificationProperties = new MOG_Properties(classification);
                }
            }

            // Get all the files withing this directory
            FileInfo [] files = DosUtils.FileGetList(path, "*.*");
            if (files != null)
            {
                // For each file, check to see if we have a DB link for that filename
                foreach (FileInfo file in files)
                {
                    if (worker.CancellationPending)
                    {
                        return(false);
                    }

                    try
                    {
                        // Check to see if we have a DB link for that filename
                        if (MergeableAssets.Contains(file.FullName) == false)
                        {
                            // Check if we have a classificationProperties?
                            if (classificationProperties != null)
                            {
                                // Make sure this does not violate the classification filters
                                // Check the classification's inclusion filter.
                                if (classificationProperties.FilterInclusions.Length > 0)
                                {
                                    FilePattern inclusions = new FilePattern(classificationProperties.FilterInclusions);
                                    if (inclusions.IsFilePatternMatch(file.FullName) == false)
                                    {
                                        // Skip this file as it is not included
                                        continue;
                                    }
                                }
                                // Check the classification's exclusion filter.
                                if (classificationProperties.FilterExclusions.Length > 0)
                                {
                                    FilePattern exclusions = new FilePattern(classificationProperties.FilterExclusions);
                                    if (exclusions.IsFilePatternMatch(file.FullName) == true)
                                    {
                                        // Skip this file as it is excluded
                                        continue;
                                    }
                                }
                            }

                            // Make sure it is not hidden
                            if (Convert.ToBoolean(file.Attributes & FileAttributes.Hidden) == false)
                            {
                                // If no match was found, add to our list of rogue assets
                                rogueFiles.Add(file.FullName);
                            }
                        }
                    }
                    catch
                    {
                        // Needed just in case we have some files larger than 260 in length
                    }
                }
            }

            // Now check all these subDirs
            DirectoryInfo [] dirs = DosUtils.DirectoryGetList(path, "*.*");
            if (dirs != null)
            {
                foreach (DirectoryInfo dir in dirs)
                {
                    // Make sure it is not hidden
                    if (Convert.ToBoolean(dir.Attributes & FileAttributes.Hidden) == false)
                    {
                        // Scan their respective files
                        if (!LocateNonMogAssetsScanFiles(worker, dir.FullName, rogueFiles, MergeableAssets, targetProjectPath, classificationProperties))
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Example #17
0
        private void LocateNonMogAssets_Worker(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;
            string           path   = e.Argument as string;

            // Determin our workspaceDirectory and platformName
            string workspaceDirectory = "";
            string relativePath       = "";
            string platformName       = "";

            // Check if this is a library path?
            if (MOG_ControllerLibrary.GetWorkingDirectory().Length > 0 &&
                path.StartsWith(MOG_ControllerLibrary.GetWorkingDirectory(), StringComparison.CurrentCultureIgnoreCase))
            {
                // Determin proper settings for the library
                workspaceDirectory = MOG_ControllerLibrary.GetWorkingDirectory();
                relativePath       = path.Substring(workspaceDirectory.Length).Trim("\\".ToCharArray());
                platformName       = "All";

                // Get the list of known MOG files within the workspace
                string    classification  = MOG_ControllerLibrary.ConstructLibraryClassificationFromPath(path);
                ArrayList containedAssets = MOG_DBAssetAPI.GetAllAssetsByParentClassification(classification);
                foreach (MOG_Filename thisAsset in containedAssets)
                {
                    string thisPath     = MOG_ControllerLibrary.ConstructPathFromLibraryClassification(thisAsset.GetAssetClassification());
                    string thisFilename = Path.Combine(thisPath, thisAsset.GetAssetLabel());
                    mKnownSyncFiles.Add(thisFilename, thisFilename);
                    mKnownSyncFiles_ArrayList.Add(thisFilename);
                }
            }
            // Check if this is a workspace path?
            else
            {
                workspaceDirectory = MOG_ControllerSyncData.DetectWorkspaceRoot(path);
                if (workspaceDirectory.Length > 0)
                {
                    relativePath = path.Substring(workspaceDirectory.Length).Trim("\\".ToCharArray());
                    MOG_ControllerSyncData sync = MOG_ControllerProject.GetCurrentSyncDataController();
                    if (sync != null)
                    {
                        platformName = sync.GetPlatformName();

                        // Get the list of known MOG files within the workspace
                        ArrayList allFiles = MOG_DBAssetAPI.GetAllProjectSyncTargetFilesForPlatform(platformName);
                        foreach (string thisFile in allFiles)
                        {
                            // Trim thisFile just in case it has an extra '\' at the beginning (Needed for BioWare's formulaic sync target booboo)
                            string tempFile = thisFile.Trim("\\".ToCharArray());
                            // Check if this relative directory matches?
                            if (tempFile.StartsWith(relativePath, StringComparison.CurrentCultureIgnoreCase))
                            {
                                string filename = Path.Combine(workspaceDirectory, tempFile);
                                mKnownSyncFiles[filename] = filename;
                                mKnownSyncFiles_ArrayList.Add(filename);
                            }
                        }
                    }
                }
            }

            // Continue as long as we got at least one asset from the database
            ArrayList rogueFiles = new ArrayList();

            LocateNonMogAssetsScanFiles(worker, path, rogueFiles, mKnownSyncFiles, path, null);
            e.Result = rogueFiles;
        }
Example #18
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);
        }
Example #19
0
        /// <summary>
        /// Shows Assets based on MOG_Property(s) assigned to PropertyList
        /// </summary>
        private void ExpandPropertyTreeDown(TreeNode node)
        {
            BeginUpdate();

            List <string> classificationsToAdd = GetSubClassifications(node);

            string thisClassification     = node.FullPath;
            string thisClassificationPath = MOG_ControllerLibrary.ConstructPathFromLibraryClassification(thisClassification);

            // Check for any local directories
            if (thisClassificationPath.Length > 0)
            {
                DirectoryInfo[] directories = DosUtils.DirectoryGetList(thisClassificationPath, "*.*");
                if (directories != null && directories.Length > 0)
                {
                    foreach (DirectoryInfo directory in directories)
                    {
                        // If we don't already have this classification, add it.
                        if (!classificationsToAdd.Contains(directory.Name))
                        {
                            classificationsToAdd.Add(directory.Name);
                        }
                    }
                }
            }

            // Sort our classifications alphabetically
            classificationsToAdd.Sort();

            // Foreach classification, add it
            foreach (string classification in classificationsToAdd)
            {
                string fullClassification = MOG_Filename.JoinClassificationString(node.FullPath, classification);

                // Only add library classifications
                if (MOG_Filename.IsParentClassificationString(fullClassification, MOG_Filename.GetProjectLibraryClassificationString()))
                {
                    TreeNode classificationNode = new TreeNode(classification);

                    // Is this a non-MOG folder?
                    if (!MOG_ControllerProject.IsValidClassification(fullClassification))
                    {
                        classificationNode.ForeColor = Color.LightGray;
                    }

                    // 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));
                }
            }

            EndUpdate();
        }