예제 #1
0
        private void LoadFolders(DMSFolderLogicModel rootLogicModel, List <DMSFolder> allfolders)
        {
            var rootCount = AllFolders.Count(x => x.DmsFolderType == DmsFolderType.Root);

            CommUtils.Assert(rootCount < 2, "根结点数大于2, DMSGuid=[{0}]", m_dms.Guid);

            //初始化根结点文件夹
            DMSFolder rootFolder = null;

            if (rootCount == 0)
            {
                rootFolder                = new DMSFolder();
                rootFolder.DMSId          = m_dms.Id;
                rootFolder.Name           = "root";
                rootFolder.Description    = "root";
                rootFolder.ParentFolderId = null;
                rootFolder.DmsFolderType  = DmsFolderType.Root;
                var now = DateTime.Now;
                rootFolder.CreateUserName     = UserName;
                rootFolder.CreateTime         = now;
                rootFolder.LastModifyUserName = UserName;
                rootFolder.LastModifyTime     = now;
                rootFolder = m_dbAdapter.DMSFolder.Create(rootFolder);
            }
            else
            {
                rootFolder = AllFolders.Single(x => x.DmsFolderType == DmsFolderType.Root);
            }

            rootLogicModel.Instance = rootFolder;
            LoadSubFolders(rootLogicModel, allfolders, 0);
        }
예제 #2
0
 public async Task SearchFolders(FolderTree source, string keyword, SortBy criterion)
 {
     AllFolders.SetTo(await Task.Run(() => SearchHelper.SearchFolders(source, keyword, criterion)));
     Folders.SetTo(AllFolders.Take(FolderLimit));
     FoldersTextBlock.Text           = Settings.settings.ShowCount ? Helper.LocalizeText("FoldersWithCount", AllFolders.Count) : Helper.LocalizeText("Folders");
     FoldersViewAllButton.Visibility = AllFolders.Count > FolderLimit ? Visibility.Visible : Visibility.Collapsed;
     SortFoldersButton.Visibility    = AllFolders.Count < 2 ? Visibility.Collapsed : Visibility.Visible;
 }
예제 #3
0
        private void FillSubFoldersRecursive(ref PGFolder folder, PGFolderComparer defaultSortingComparer, out List <string> filenames_cache)
        {
            filenames_cache = new List <string>();

            DirectoryInfo directory = new DirectoryInfo(folder.PhysicalPath);

            if (!directory.Exists)
            {
                throw new DirectoryNotFoundException(string.Format("Directory {0} not found", directory));
            }
            else
            {
                //1. READ INFO FILE
                folder.ReadFolder();

                Images.AddRange(folder.Images);     //cache images for easy access
                Comments.AddRange(folder.Comments); //cache comments for easy access.

                //2. LOAD SUB FOLDERS from disk (RECURSIVE)
                folder.SubFolders = new List <PGFolder>();

                defaultSortingComparer = PGFolderComparer.GetComparerBySortAction(folder.SortAction, defaultSortingComparer);

                //3. subfolder recursive
                foreach (DirectoryInfo subDirectory in directory.GetDirectories())
                {
                    if (!IsDirectoryIgnored(subDirectory.FullName))
                    {
                        PGFolder subfolder = new PGFolder()
                        {
                            Name = subDirectory.Name, PhysicalPath = subDirectory.FullName
                        };
                        subfolder.ParentFolder = folder;

                        List <string> filename_cache_subfolder = new List <string>();
                        FillSubFoldersRecursive(ref subfolder, defaultSortingComparer, out filename_cache_subfolder);
                        filenames_cache.AddRange(filename_cache_subfolder);
                        folder.SubFolders.Add(subfolder);
                        folder.NumberNestedImages += subfolder.NumberNestedImages; //todo refactor, inside pgfolder.
                    }
                }

                //4. Sorting?
                folder.SortSubFolders(folder.SortAction, ref defaultSortingComparer);

                AllFolders.Add(folder); //index for faster access

                filenames_cache.Add(folder.FolderInfoFileLocation());
            }

            //5. WRITE if necessary
            if (!folder.ExistFolderInfoFile())
            {
                folder.WriteFolderFileInfo();
            }
        }
예제 #4
0
 private void SortFoldersButton_Click(object sender, RoutedEventArgs e)
 {
     MenuFlyoutHelper.SetSortByMenu(sender, Settings.settings.SearchFoldersCriterion, FoldersCriteria,
                                    async item =>
     {
         Settings.settings.SearchFoldersCriterion = item;
         LoadingProgress.Visibility = Visibility.Visible;
         AllFolders.SetTo(await Task.Run(() => SearchHelper.SortFolders(AllFolders, CurrentKeyword.Text, item).ToList()));
         Folders.SetTo(AllFolders.Take(Folders.Count));
         LoadingProgress.Visibility = Visibility.Collapsed;
     });
 }
예제 #5
0
 protected void BizTalkFactoryProcessFixtureTestFixtureSetUp()
 {
     AllFolders.Each(
         d => {
         if (!Directory.Exists(d))
         {
             _logger.FineFormat("Creating folder '{0}'.", d);
             Directory.CreateDirectory(d);
         }
     });
     AllDependantOrchestrationTypes.Each(ot => { new Orchestration(ot).EnsureStarted(); });
 }
예제 #6
0
        public void AssertHasFile(string relativeName)
        {
            relativeName = relativeName.Replace("\\", "/");
            var file = findFile(relativeName);

            if (file == null)
            {
                var files = AllFolders.SelectMany(x => FindFiles(FileSet.Deep("*"))).Select(x => x.Path);

                var description = "Could not find " + relativeName;
                files.Each(x => description += "\n" + x);

                throw new ApplicationException(description);
            }
        }
예제 #7
0
파일: NocsService.cs 프로젝트: ipriel/nocs2
        /// <summary>
        /// Creates a new folder in Google Docs.
        /// </summary>
        /// <param name="folderName">Name for the new folder.</param>
        public static void CreateNewFolder(string folderName)
        {
            try
            {
                var request    = new DocumentsRequest(_settings);
                var reqFactory = (GDataRequestFactory)request.Service.RequestFactory;
                reqFactory.Proxy = GetProxy();

                var newFolder = new Document
                {
                    Type  = Document.DocumentType.Folder,
                    Title = folderName
                };
                newFolder = request.CreateDocument(newFolder);

                // let's add the new directory to our folder dictionary
                if (newFolder != null)
                {
                    AllFolders.Add(newFolder.ResourceId, newFolder);
                }
            }
            catch (GDataRequestException exRequest)
            {
                var error = !string.IsNullOrEmpty(exRequest.ResponseString) ? exRequest.ResponseString : exRequest.Message;
                if (exRequest.ResponseString == null && error.ToLowerInvariant().Contains("execution of request failed"))
                {
                    throw new GDataRequestException("Couldn't create folder - internet down?");
                }

                Trace.WriteLine(DateTime.Now + " - NocsService - couldn't create folder: " + error);
                throw new GDataRequestException(string.Format("Couldn't create folder: {0} - {1}", folderName, Tools.TrimErrorMessage(error)));
            }
            catch (Exception ex)
            {
                var error = GetErrorMessage(ex);
                Trace.WriteLine(DateTime.Now + " - NocsService - couldn't create folder: " + error);
                throw new Exception(string.Format("Couldn't create folder: {0} - {1}", folderName, error));
            }
        }
예제 #8
0
파일: NocsService.cs 프로젝트: ipriel/nocs2
        /// <summary>
        /// Fetches/updates all DocumentEntries in a Dictionary and wraps them in a Noc class.
        /// </summary>
        /// <returns>Dictionary of ResourceId's and Noc objects.</returns>
        public static void UpdateAllEntries()
        {
            if (AllDocuments == null)
            {
                AllDocuments = new Dictionary <string, Document>();
            }

            if (AllFolders == null)
            {
                AllFolders = new Dictionary <string, Document>();
            }

            // let's first make sure the user is authenticated
            if (_settings == null)
            {
                throw new Exception("User hasn't been authenticated - internet down?");
            }

            try
            {
                var request = new DocumentsRequest(_settings)
                {
                    Service = { ProtocolMajor = 3 }
                    //BaseUri = DocumentsListQuery.documentsAclUri
                };
                var reqFactory = (GDataRequestFactory)request.Service.RequestFactory;
                reqFactory.Proxy = GetProxy();

                // we'll fetch all entries
                AllEntriesFeed = request.GetEverything();

                // if we've already retrieved items, let's clear the dictionaries before updating them
                if (AllDocuments.Count > 0)
                {
                    AllDocuments.Clear();
                }
                if (AllFolders.Count > 0)
                {
                    AllFolders.Clear();
                }

                foreach (var entry in AllEntriesFeed.Entries)
                {
                    // let's only add documents and folders
                    if (entry.Type == Document.DocumentType.Document)
                    {
                        AllDocuments.Add(entry.ResourceId, entry);
                    }
                    else if (entry.Type == Document.DocumentType.Folder)
                    {
                        AllFolders.Add(entry.ResourceId, entry);
                    }
                }
            }
            catch (GDataNotModifiedException)
            {
                // since doclist updates timestamps on feeds based on access,
                // etags are useless here and we shouldn't get here
                return;
            }
            catch (GDataRequestException exRequest)
            {
                var error = GetErrorMessage(exRequest);
                if (exRequest.ResponseString == null && error.ToLowerInvariant().Contains("execution of request failed"))
                {
                    throw new GDataRequestException("Couldn't fetch all entries - internet down?");
                }

                Trace.WriteLine(string.Format("\n{0} - NocsService: couldn't fetch all entries: {1}\n", DateTime.Now, error));
                throw new GDataRequestException(Tools.TrimErrorMessage(error));
            }
            catch (Exception ex)
            {
                var error = GetErrorMessage(ex);
                Trace.WriteLine(string.Format("\n{0} - NocsService: couldn't fetch all entries: {1}\n", DateTime.Now, error));
                throw new Exception(error);
            }
        }
예제 #9
0
파일: NocsService.cs 프로젝트: ipriel/nocs2
        /// <summary>
        /// Deletes an entry with a given id.
        /// </summary>
        /// <param name="entryId">ResourceId of the entry to be deleted.</param>
        /// <param name="entryType">Type of the entry (Document or Folder).</param>
        public static void DeleteEntry(string entryId, Document.DocumentType entryType)
        {
            Working = true;

            // we will only rename documents and folders
            if (entryType != Document.DocumentType.Document && entryType != Document.DocumentType.Folder)
            {
                throw new ArgumentException(string.Format("Invalid entryType ({0})", entryType));
            }

            var doc           = entryType == Document.DocumentType.Document ? AllDocuments[entryId] : AllFolders[entryId];
            var entryToDelete = doc.DocumentEntry;

            try
            {
                _documentService.ProtocolMajor = 3;
                entryToDelete.Delete();
            }
            catch (GDataRequestException exRequest)
            {
                var response = exRequest.Response as HttpWebResponse;
                if (response != null && response.StatusCode == HttpStatusCode.PreconditionFailed &&
                    exRequest.ResponseString.ToLowerInvariant().Contains("etagsmismatch"))
                {
                    // ETags don't match -> this document has been updated outside this instance of Nocs
                    // or it was just saved -> let's update it and try renaming again
                    Debug.WriteLine(string.Format("ETags don't match, couldn't find {0} - updating it and trying delete again..", doc.ETag));
                    doc = GetUpdatedDocument(doc);
                    DeleteEntry(doc.ResourceId, doc.Type);
                }
                else
                {
                    var error = GetErrorMessage(exRequest);
                    if (exRequest.ResponseString == null && error.ToLowerInvariant().Contains("execution of request failed"))
                    {
                        throw new GDataRequestException("Couldn't delete entry, connection timed out");
                    }

                    var knownIssues = ConsecutiveKnownIssuesOccurred(DeleteEntryLock, "DeleteEntry", doc, error, ref _deleteEntryAttempts, 1);
                    if (knownIssues == KnownIssuesResult.Retry)
                    {
                        doc = GetUpdatedDocument(doc);
                        DeleteEntry(doc.ResourceId, doc.Type);
                        doc.Summary          = null;
                        _deleteEntryAttempts = 0;
                        return;
                    }
                    else if (knownIssues == KnownIssuesResult.LimitReached)
                    {
                        return;
                    }

                    Trace.WriteLine(string.Format("Couldn't delete {0}: {1} - {2}", entryType, doc.DocumentEntry.Title.Text, Tools.TrimErrorMessage(error)));
                    throw new GDataRequestException(string.Format("Couldn't delete {0}: {1} - {2}", entryType, doc.DocumentEntry.Title.Text, Tools.TrimErrorMessage(error)));
                }
            }
            catch (Exception ex)
            {
                var error = GetErrorMessage(ex);
                throw new Exception(string.Format("Couldn't delete entry: {0} - {1}", doc.DocumentEntry.Title.Text, error));
            }
            finally
            {
                Working = false;
            }

            // let's update the appropriate dictionary
            if (entryType == Document.DocumentType.Document)
            {
                AllDocuments.Remove(entryId);
            }
            else
            {
                AllFolders.Remove(entryId);
            }
        }
예제 #10
0
파일: NocsService.cs 프로젝트: ipriel/nocs2
        /// <summary>
        /// Creates a new document in Google Docs.
        /// </summary>
        /// <param name="folderId">An entry id for any given folder in which the new document is to be saved.</param>
        /// <param name="title">Title for the new document.</param>
        /// <param name="content">HTML content for the new document.</param>
        /// <param name="createDefaultDirectory">
        /// true = create a default directory ('Nocs')
        /// fales = don't create a default directory
        /// </param>
        /// <returns>A newly created Document.</returns>
        public static Document CreateNewDocument(string folderId, string title, string content, bool createDefaultDirectory)
        {
            DocumentEntry newEntry;
            Document      newDocument;

            content = Tools.FormatEditorContentToHtml(title, content);

            try
            {
                var request    = new DocumentsRequest(_settings);
                var reqFactory = (GDataRequestFactory)request.Service.RequestFactory;
                reqFactory.Proxy = GetProxy();

                // we'll first create a default 'Nocs'-folder if one isn't already created
                if (createDefaultDirectory)
                {
                    var defaultFolder = new Document
                    {
                        Type  = Document.DocumentType.Folder,
                        Title = "Nocs"
                    };
                    defaultFolder = request.CreateDocument(defaultFolder);

                    // if we created our default directory, let's add it to our folder dictionary
                    if (defaultFolder != null)
                    {
                        AllFolders.Add(defaultFolder.ResourceId, defaultFolder);
                        folderId = defaultFolder.ResourceId;
                    }
                }

                SetupService(null, null, 3, null, null);
                var textStream = new MemoryStream(Encoding.UTF8.GetBytes(content));

                // we might be creating this document inside a particular folder
                var postUri = !string.IsNullOrEmpty(folderId) ?
                              new Uri(string.Format(DocumentsListQuery.foldersUriTemplate, folderId))
                              : new Uri(DocumentsListQuery.documentsBaseUri);

                newEntry = _documentService.Insert(postUri, textStream, DocumentContentType, title) as DocumentEntry;
            }
            catch (GDataRequestException exRequest)
            {
                var error = !string.IsNullOrEmpty(exRequest.ResponseString) ? exRequest.ResponseString : exRequest.Message;
                if (exRequest.ResponseString == null && error.ToLowerInvariant().Contains("execution of request failed"))
                {
                    throw new GDataRequestException("Couldn't create document - internet down?");
                }


                // we'll also check for InvalidEntryException: Could not convert document
                // - assuming it's a known problem in GData API related to sharing, we will just ignore it
                if (error.ToLowerInvariant().Contains("could not convert document"))
                {
                    Debug.WriteLine(string.Format("Couldn't convert document while creating a document: {0}", title));
                    return(null);
                }

                Trace.WriteLine(string.Format("{0} - Couldn't create a new document: {1} - {2}", DateTime.Now, title, error));
                throw new GDataRequestException(string.Format("Couldn't create a new document: {0} - {1}", title, Tools.TrimErrorMessage(error)));
            }
            catch (Exception ex)
            {
                var error = GetErrorMessage(ex);
                Trace.WriteLine(DateTime.Now + " - NocsService - couldn't create a new document: " + error);
                throw new Exception(string.Format("Couldn't create document: {0} - {1}", title, error));
            }

            // let's create a new Document
            if (newEntry != null)
            {
                newEntry.IsDraft = false;

                newDocument = new Document
                {
                    AtomEntry = newEntry,
                    Title     = title,
                    Content   = Tools.ParseContent(content)
                };

                // let's add the new document to our document dictionary and return it
                AllDocuments.Add(newDocument.ResourceId, newDocument);
                return(newDocument);
            }

            // we should never get here
            throw new Exception((string.Format("Couldn't create document: {0} - internet down?", title)));
        }