Esempio n. 1
0
        public void DisplayCatalog(Catalog cat)
        {
            DateTime start = DateTime.Now;

            this.Nodes.Clear();

            TreeNode[] nodes = BrowseCatalogFolders(cat);
            TreeNode catNode = new TreeNode(cat.Name, nodes);
            catNode.ImageIndex = catNode.SelectedImageIndex = 0;
            
            this.Nodes.Add(catNode);
            catNode.Expand();

            this.SelectedNode = catNode;
        }
Esempio n. 2
0
        public override void ShowProperties(List<string> strItems, object additionalData)
        {
            this.cat = additionalData as Catalog;
            this.strItems = strItems;

            pgProperties.SelectedObjects = null;

            if (cat != null)
            {
                lci = new List<object>();

                // The objects in strItems are vpaths.
                foreach (string vpath in strItems)
                {
                    if (vpath == Catalog.CatalogVPath)
                    {
                        cat.CatalogSchemaVersion = Translator.TranslateTaggedString(cat.CatalogSchemaVersion);
                        pgProperties.SelectedObjects = new object[] { cat };

                        break;
                    }
                    else
                    {
                        CatalogItem ci = cat.GetByVPath(vpath);
                        if (ci != null)
                        {
                            ci.Description = Translator.TranslateTaggedString(ci.Description).Replace("::", ":");
                            ci.ItemTypeDesc = Translator.TranslateTaggedString(ci.ItemTypeDesc);
                            ci.Save();

                            lci.Add(ci);
                        }
                    }
                }
            }

            if (lci != null && lci.Count > 0)
            {
                FileAttributesBrowser.ProcessObjectAttributes(lci);

                pgProperties.SelectedObjects = lci.ToArray();
            }
        }
Esempio n. 3
0
        public override StepDetail RunNextStep()
        {
            StepDetail detail = new StepDetail();
            detail.Description = string.Format("Importing from {0} ...", SourcePath);

            _abortScan = false;

            try
            {
                Catalog cat = new Catalog(CatalogPath);
                CatalogItem parent = cat.GetByItemID(InsertionPointID);

                ScanFolder(cat, new System.IO.DirectoryInfo(SourcePath), parent);

                finished = true;

                if (!_abortScan)
                {
                    cat.CatalogDescription = CatalogDescription;
                    cat.Save(CatalogPath);
                }

                detail.Results = (_abortScan) ? Translator.Translate("TXT_ABORTED") : Translator.Translate("TXT_SUCCESS");
                detail.IsSuccess = !_abortScan;
            }
            catch(Exception ex)
            {
                detail.Results = ex.Message;
                detail.IsSuccess = false;
            }
            finally
            {
                finished = true;
            }

            return detail;
        }
Esempio n. 4
0
        private void ScanFile(Catalog cat, FileInfo file, CatalogItem parent)
        {
            if (!CanContinue()) 
                return;

            ReportPseudoStepInit("TXT_SCANNING: " + file.FullName);

            try
            {
                CatalogItem ci = new CatalogItem(cat);
                ci.IsRoot = false;
                ci.ItemType = cat.CatalogItemType_GetByTypeCode("FIL").TypeID; // is a file
                ci.Name = file.Name;

                DriveInfo di = new DriveInfo(file.Directory.Root.FullName);
                if (di.DriveType == DriveType.Removable || di.DriveType == DriveType.CDRom)
                {
                    ci.OrigItemPath = file.FullName.Replace(file.Directory.Root.FullName, "$:/");
                    if (PathUtils.DirectorySeparator != "/")
                        ci.OrigItemPath = ci.OrigItemPath.Replace(PathUtils.DirectorySeparator, "/");
                }
                else
                {
                    ci.OrigItemPath = file.FullName;
                }

                ci.RootItemLabel = di.VolumeLabel;
                ci.RootSerialNumber = Kernel32.GetVolumeSerialNumber(di.RootDirectory.FullName);
                ci.ParentItemID = parent.ItemID;

                try
                {
                    NativeFileInfo nfi = NativeFileInfoFactory.FromPath(file.FullName);
                    if (nfi != null)
                    {
                        ci.Description = nfi.Details;
                    }
                }
                catch(Exception ex)
                {
                    Logger.LogException(ex);
                }

                ci.Save();

                RaiseTaskProgressEvent(null, _currentStep++);
            }
            catch (Exception ex)
            {
                ConfirmScanAbortOnException(ex);
            }

            Application.DoEvents();
        }
Esempio n. 5
0
        public void ScanFolder(Catalog cat, DirectoryInfo dir, CatalogItem parent)
        {
            if (!CanContinue()) 
                return;

            ReportPseudoStepInit("TXT_SCANNING: "  + dir.FullName);

            try
            {
                DriveInfo di = new DriveInfo(dir.Root.FullName);

                CatalogItem ci = new CatalogItem(cat);

                if (di.DriveType == DriveType.Removable || di.DriveType == DriveType.CDRom)
                {
                    ci.OrigItemPath = dir.FullName.Replace(dir.Root.FullName, "$:/");
                    if (PathUtils.DirectorySeparator != "/")
                        ci.OrigItemPath = ci.OrigItemPath.Replace(PathUtils.DirectorySeparator, "/");
                }
                else
                {
                    ci.OrigItemPath = dir.FullName;
                }

                ci.IsRoot = (parent == null);
                ci.RootItemLabel = di.VolumeLabel;
                ci.RootSerialNumber = Kernel32.GetVolumeSerialNumber(di.RootDirectory.FullName);

                ci.Name = GetName(dir, di);
                
                if (parent != null)
                {
                    ci.ParentItemID = parent.ItemID;
                }
                                
                if (ci.IsRoot)
                {
                    // This is a disk
                    ci.ItemType = (byte)di.DriveType;
                    ci.Description = EntryDescription;
                }
                else
                {
                    ci.ItemType = cat.CatalogItemType_GetByTypeCode("FLD").TypeID; // is a folder
                }

                ci.Save();

                Application.DoEvents();

                IEnumerable<string> strDirs = Directory.EnumerateDirectories(dir.FullName, "*", SearchOption.TopDirectoryOnly);
                if (strDirs != null)
                {
                    foreach (string dirPath in strDirs)
                    {
                        ScanFolder(cat, new DirectoryInfo(dirPath), ci);
                    }
                }

                IEnumerable<string> strFiles = Directory.EnumerateFiles(dir.FullName, "*", SearchOption.TopDirectoryOnly);
                if (strFiles != null)
                {
                    foreach (string filePath in strFiles)
                    {
                        ScanFile(cat, new FileInfo(filePath), ci);
                    }
                }

                RaiseTaskProgressEvent(null, _currentStep++);
            }
            catch(Exception ex)
            {
                ConfirmScanAbortOnException(ex);
            }
        }
Esempio n. 6
0
        private void MigrateDataToLatestVersion()
        {
            ConsistencyCheck();

            if (CatalogInfoTable.Rows.Count < 1)
            {
                // If catalog info does not exist, we create it.
                CatalogInfoTable.AddCatalogInfoRow(CatalogInfoTable.NewCatalogInfoRow());
                CatalogInfoTable.AcceptChanges();

                _info = new CatalogInfo(this);
            }
            else
            {
                if (_info == null)
                {
                    _info = new CatalogInfo(this);
                }

                string latestVersion = new Catalog().CatalogSchemaVersion;
                if (CatalogSchemaVersion != latestVersion)
                {
                    (CatalogInfoTable.Rows[0] as CatalogDataset.CatalogInfoRow).Version = latestVersion;
                    (CatalogInfoTable.Rows[0] as CatalogDataset.CatalogInfoRow).AcceptChanges();

                    version = latestVersion;
                }
            }
        }
Esempio n. 7
0
        private void DisplayCatalogContents(object state)
        {
            Catalog cat = null;

            try
            {
                ShowWaitDialog("TXT_WAIT_LOADING_CATALOG");

                string path = (BkgTask as Task).CatalogPath;
                NativeFileInfo nfi = new NativeFileInfo(path, false);
                if (nfi.IsValid)
                {
                    cat = new Catalog(path);
                }
                else if (!string.IsNullOrEmpty(path))
                {
                    cat = new Catalog();
                    cat.Save(path);
                }
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }
            finally
            {
                if (cat != null && cat.IsValid)
                {
                    DisplayCatalog(cat);
                }
                CloseWaitDialog();
            }
        }
Esempio n. 8
0
        private TreeNode[] BuildChildren(Catalog cat, CatalogItem folder)
        {
            DateTime start = DateTime.Now;

            //Application.DoEvents();

            List<TreeNode> firstLevelNodes = new List<TreeNode>();

            if (folder.IsFolder)
            {
                CatalogItem[] children = cat.FindItems(folder, "FLD", string.Empty, string.Empty, true);

                List<CatalogItem> childList = new List<CatalogItem>(children);

                childList.Sort(delegate(CatalogItem ci1, CatalogItem ci2)
                {
                    if (ci1 == null && ci2 == null)
                        return 0;
                    if (ci1 == null)
                        return -1;
                    if (ci2 == null)
                        return 1;

                    if (ci1.ParentItemID == ci2.ParentItemID)
                    {
                        return (int)(ci1.ItemID - ci2.ItemID);
                    }
                    else
                    {
                        return (int)(ci1.ParentItemID - ci2.ParentItemID);
                    }
                });

                Dictionary<long, TreeNode> treeNodes = new Dictionary<long, TreeNode>();

                for (int i = 0; i < childList.Count; i++)
                {
                    TreeNode node = new TreeNode(childList[i].Name);
                    node.Name = childList[i].VPath;
                    node.Tag = childList[i];
                    node.ImageIndex = node.SelectedImageIndex = (int)childList[i].ItemType + 1;

                    if (treeNodes.ContainsKey(childList[i].ParentItemID))
                    {
                        treeNodes[childList[i].ParentItemID].Nodes.Add(node);
                    }
                    
                    if (!treeNodes.ContainsKey(childList[i].ItemID))
                    {
                        treeNodes.Add(childList[i].ItemID, node);
                    }

                    if (childList[i].ParentItemID == folder.ItemID)
                    {
                        firstLevelNodes.Add(node);
                    }
                }
            }

            return firstLevelNodes.ToArray();
        }
Esempio n. 9
0
 private void CreateNewCatalog()
 {
     _cat = new Catalog();
     DisplayCatalog();
 }
Esempio n. 10
0
 public CatalogInfo(Catalog cat)
 {
     currentRow = cat.CatalogInfoTable.Rows[0] as CatalogDataset.CatalogInfoRow;
 }
Esempio n. 11
0
        public CatalogItem(Catalog cat, CatalogDataset.CatalogItemsRow row)
        {
            currentRow = row;
            _cat = cat;

#if HAVE_COUNTERS_DISPLAY
            _totalChildrenCount = -1;
#endif
        }
Esempio n. 12
0
        public CatalogItem(Catalog cat)
        {
            currentRow = cat.CatalogItems.NewCatalogItemsRow();
            currentRow.DateCreated = DateTime.Now;
            cat.CatalogItems.AddCatalogItemsRow(currentRow);
            _cat = cat;

#if HAVE_COUNTERS_DISPLAY
            _totalChildrenCount = -1;
#endif        
        }
Esempio n. 13
0
        public void DisplayCatalogFolder(Catalog cat, CatalogItem folder, CatalogItem prevFolder = null)
        {
            this.Items.Clear();

            _cat = cat;

            if (folder != null)
            {
                CatalogItem[] children = cat.GetByParentItemID(folder.ItemID);
                foreach (CatalogItem child in children)
                {
                    int imgIndex = 0;

                    if (child.IsFolder)
                    {
                        imgIndex = (int)child.ItemType + 1;
                    }
                    else
                    {
                        string ext = PathUtils.GetExtension(child.OrigItemPath);
                        if (ilItems.Images.ContainsKey(ext))
                        {
                            imgIndex = ilItems.Images.IndexOfKey(ext);
                        }
                        else
                        {
                            Image img = ImageProvider.GetIconOfFileType(ext);
                            if (img != null)
                            {
                                ilItems.Images.Add(ext, img);
                                imgIndex = ilItems.Images.Count - 1;
                            }
                        }
                    }

                    string[] data = new string[]
                    {
                        child.Name,
                        child.DateCreated,
                        child.OrigItemPath
                    };

                    ListViewItem item = new ListViewItem(data);
                    item.ImageIndex = imgIndex;
                    item.Tag = child;

                    this.Items.Add(item);
                }

                bool selectFirst = (this.Items.Count > 0);
                int lastVisibleIndex = 0;

                foreach (ListViewItem item in this.Items)
                {
                    CatalogItem ci = item.Tag as CatalogItem;
                    if (ci != null && prevFolder != null && ci.VPath == prevFolder.VPath)
                    {
                        item.Selected = true;
                        item.Focused = true;

                        lastVisibleIndex = item.Index;
                        selectFirst = false;

                        break;
                    }
                }

                if (selectFirst)
                {
                    Items[0].Selected = true;
                    Items[0].Focused = true;
                }
                else
                {
                    EnsureVisible(lastVisibleIndex);
                }

                this.Select();
                this.Focus();
            }
        }
Esempio n. 14
0
        public void DisplayCatalogRoots(Catalog cat)
        {
            this.Items.Clear();

            _cat = cat;

            CatalogItem[] roots = cat.GetRoots();
            foreach (CatalogItem root in roots)
            {
                string[] data = new string[]
                {
                    root.Name,
                    root.DateCreated,
                    root.OrigItemPath
                };

                ListViewItem item = new ListViewItem(data);
                item.ImageIndex = (int)root.ItemType + 1;
                item.Tag = root;

                this.Items.Add(item);
            }
        }
Esempio n. 15
0
 void BackgroundOpen(object sender, DoWorkEventArgs e)
 {
     _cat = new Catalog(e.Argument as string);
 }
Esempio n. 16
0
        private void HandleAction(ToolAction action)
        {
            if (!IsToolActionEnabled(action))
                return;

            switch (action)
            {
                case ToolAction.ToolActionReload:
                    GlobalReload();
                    break;

                case ToolAction.ToolActionNew:
                    CreateNewCatalog();
                    break;
                case ToolAction.ToolActionOpen:
                    OpenCatalog();
                    break;

                case ToolAction.ToolActionSave:
                    if (_cat != null && _cat.IsInDefaultLocation)
                    {
                        goto case ToolAction.ToolActionSaveAs;
                    }
                    else
                    {
                        SaveCatalogNoDialog();
                    }
                    break;

                case ToolAction.ToolActionSaveAs:
                    SaveCatalogWithDialog();
                    break;

                case ToolAction.ToolActionDelete:
                    List<string> sel = GetSelectedVPaths();
                    foreach (string vpath in sel)
                    {
                        CatalogItem item = _cat.GetByVPath(vpath);
                        if (item != null)
                        {
                            if (item.IsFolder)
                            {
                                // Only folders in tree view
                                tvCatalog.RemoveItem(item);
                            }

                            lvCatalogFolder.RemoveItem(item);

                            item.Delete();
                        }
                    }
                    break;

                case ToolAction.ToolActionMerge:
                    MergeCatalog();
                    break;

                case ToolAction.ToolActionCatalog:
                    {
                        Task task = null;

                        if (_cat != null)
                        {
                            task = new Task();
                            task.CatalogPath = _cat.Path;
                        }

                        if (ImportWizardMain.Execute(ref task) == DialogResult.OK)
                        {
                            _cat = new Catalog((task as Task).CatalogPath);
                            DisplayCatalog();
                        }
                    }
                    break;

                case ToolAction.ToolActionBack:
                    ExploreBack();
                    break;

                case ToolAction.ToolActionFwd:
                    ExploreForward();
                    break;

                case ToolAction.ToolActionUp:
                    NavigateUp();
                    break;

                case ToolAction.ToolActionSearch:
                    SearchWizard.Tasks.Task taskSearch = new SearchWizard.Tasks.Task();
                    taskSearch.Catalog = _cat;
                    taskSearch.SearchPath = (_curFolder != null) ? _curFolder.VPath : null;
                    if (SearchWizardMain.Execute(taskSearch) == DialogResult.OK)
                    {
                        switch (taskSearch.Action)
                        {
                            case ToolAction.ToolActionProTONEEnqueue:
                                RunProTONEActionOnVPaths(taskSearch.MatchingItems,
                                    OPMedia.Runtime.ProTONE.RemoteControl.CommandType.EnqueueFiles);
                                break;

                            case ToolAction.ToolActionProTONEPlay:
                                RunProTONEActionOnVPaths(taskSearch.MatchingItems,
                                    OPMedia.Runtime.ProTONE.RemoteControl.CommandType.PlayFiles);
                                break;

                            case ToolAction.ToolActionJumpToItem:
                                if (taskSearch.MatchingItems.Count > 0)
                                {
                                    JumpToItem(taskSearch.MatchingItems[0]);
                                }
                                break;

                            case ToolAction.ToolActionDelete:
                                foreach (string vpath in taskSearch.MatchingItems)
                                {
                                    CatalogItem item = _cat.GetByVPath(vpath);
                                    if (item != null)
                                    {
                                        if (item.IsFolder)
                                        {
                                            // Only folders in tree view
                                            tvCatalog.RemoveItem(item);
                                        }

                                        lvCatalogFolder.RemoveItem(item);

                                        item.Delete();
                                    }
                                }
                                break;
                        }
                    }
                    break;

                case ToolAction.ToolActionProTONEEnqueue:
                    RunProTONEActionOnVPaths(GetSelectedVPaths(),
                        OPMedia.Runtime.ProTONE.RemoteControl.CommandType.EnqueueFiles);
                    break;

                case ToolAction.ToolActionProTONEPlay:
                    RunProTONEActionOnVPaths(GetSelectedVPaths(),
                        OPMedia.Runtime.ProTONE.RemoteControl.CommandType.PlayFiles);
                    break;

                case ToolAction.ToolActionRename:
                    lvCatalogFolder.Rename();
                   break;
            }
        }
Esempio n. 17
0
        public void MergeCatalog(string origCatalogPath)
        {
            Catalog origCatalog = new Catalog(origCatalogPath);
            if (!origCatalog.IsValid)
            {
                throw new CatalogException("TXT_ERROR_INVALID_CATALOG", origCatalogPath);
            }
                
            if (origCatalog.Path.ToLowerInvariant() == this.Path.ToLowerInvariant())
            {
                throw new CatalogException("TXT_ERROR_MERGE_SAME_CATALOG", origCatalogPath);
            }

            try
            {
                CatalogItem[] roots = origCatalog.GetRoots();
                if (roots != null)
                {
                    foreach (CatalogItem root in roots)
                    {
                        MergeCatalogItem(origCatalog, root, null);
                        Application.DoEvents();
                    }
                }
            }
            catch (Exception ex)
            {
                throw new CatalogException("TXT_ERR_MERGE_FAILED", ex.Message);
            }
        }
Esempio n. 18
0
        private TreeNode[] BrowseCatalogFolders(Catalog cat)
        {
            //Application.DoEvents();

            CatalogItem[] roots = cat.GetRoots();
            TreeNode[] nodes = new TreeNode[roots.Length];

            for (int i = 0; i < roots.Length; i++)
            {
                TreeNode[] rootChildren = BuildChildren(cat, roots[i]);

                nodes[i] = new TreeNode(roots[i].Name, rootChildren);
                nodes[i].Name = roots[i].VPath;
                nodes[i].ImageIndex = nodes[i].SelectedImageIndex = (int)roots[i].ItemType + 1;
                nodes[i].Tag = roots[i];
            }

            return nodes;
        }
Esempio n. 19
0
        private void MergeCatalogItem(Catalog origCatalog, CatalogItem origItem, CatalogItem parentItem)
        {
 	        // We create a new CatalogItem, because the existing one
            // belongs to other catalog, and all its relations are based
            // on that catalog. We need, though, an item related to this catalog.
            CatalogItem newItem = new CatalogItem(this);

            // After creation we migrate all properties.
            newItem.OrigItemPath = origItem.OrigItemPath;
            newItem.IsRoot = origItem.IsRoot;
            newItem.RootItemLabel = origItem.RootItemLabel;
            newItem.RootSerialNumber = origItem.RootSerialNumber;
            newItem.Name = origItem.Name;
            newItem.ItemType = origItem.ItemType;
            newItem.Description = origItem.Description;

            if (parentItem != null)
            {
                newItem.ParentItemID = parentItem.ItemID;
            }

            // Explore children if any
            if (origItem.IsFolder)
            {
                CatalogItem[] children = origCatalog.GetByParentItemID(origItem.ItemID);
                if (children != null)
                {
                    foreach (CatalogItem child in children)
                    {
                        MergeCatalogItem(origCatalog, child, newItem);
                        Application.DoEvents();
                    }
                }
            }

            // Save changes.
            newItem.Save();
        }
Esempio n. 20
0
 public static bool IsNullOrEmpty(Catalog cat)
 {
     return cat == null ||
         cat.CatalogItems == null ||
         cat.CatalogItems.Rows == null ||
         cat.CatalogItems.Rows.Count <= 0;
 }
Esempio n. 21
0
        private void DisplayCatalog(Catalog cat)
        {
            if (InvokeRequired)
            {
                Invoke(new DisplayCatalogDG(DisplayCatalog), cat);
                return;
            }

            try
            {
                string path = (BkgTask as Task).CatalogPath;
                lblCatalogPath.Text = path;

                tvCatFolders.Nodes.Clear();

                if (cat.IsValid && !cat.IsInDefaultLocation)
                {
                    txtCatDesc.Text = Translator.TranslateTaggedString(cat.CatalogDescription);
                    tvCatFolders.DisplayCatalog(cat);

                    // At this time Enabled = false so we really can't set CanMoveNext
                    // Must enable the control first.
                    this.Enabled = true;
                    Wizard.CanMoveNext = true;
                }
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }
        }