コード例 #1
0
        /// <summary>
        /// tests moving a document in and out of folders
        /// </summary>
        [Test] public void ModelTestMoveDocuments()
        {
            const string folderTitle = "That is a new & weird folder";
            const string docTitle    = "that's the doc";

            RequestSettings settings = new RequestSettings(this.ApplicationName, this.userName, this.passWord);
            // settings.PageSize = 15;
            DocumentsRequest r = new DocumentsRequest(settings);

            Document folder = new Document();

            folder.Type  = Document.DocumentType.Folder;
            folder.Title = folderTitle;

            /// first create the folder
            folder = r.CreateDocument(folder);

            Assert.IsTrue(folder.Title == folderTitle);

            // let's create a document

            Document doc = new Document();

            doc.Type  = Document.DocumentType.Document;
            doc.Title = docTitle;

            doc = r.CreateDocument(doc);

            // create the child
            r.MoveDocumentTo(folder, doc);

            // get the folder content list

            Feed <Document> children = r.GetFolderContent(folder);

            bool fFound = false;

            foreach (Document child in children.Entries)
            {
                if (child.ResourceId == doc.ResourceId)
                {
                    fFound = true;
                    break;
                }
            }
            Assert.IsTrue(fFound, "should have found the document in the folder");
        }
コード例 #2
0
ファイル: NocsService.cs プロジェクト: ipriel/nocs2
        /// <summary>
        /// Moves an entry (document or folder) into a folder.
        /// </summary>
        /// <param name="folder">A Document object representing the folder where the given entry will be moved.</param>
        /// <param name="entryToBeMoved">A Document object representing the entry (document or folder) that will be moved.</param>
        public static void MoveEntry(Document folder, Document entryToBeMoved)
        {
            DocumentsRequest request;
            Document         movedEntry;

            try
            {
                request = new DocumentsRequest(_settings)
                {
                    Service = { ProtocolMajor = 3 }
                };

                var reqFactory = (GDataRequestFactory)request.Service.RequestFactory;
                reqFactory.CustomHeaders.Clear();
                reqFactory.Proxy = GetProxy();

                movedEntry = request.MoveDocumentTo(folder, entryToBeMoved);
            }
            catch (GDataRequestException exRequest)
            {
                var error = GetErrorMessage(exRequest);
                if (exRequest.ResponseString == null && error.ToLowerInvariant().Contains("execution of request failed"))
                {
                    throw new GDataRequestException("Couldn't move entry - internet down?");
                }

                Trace.WriteLine(DateTime.Now + " - NocsService - couldn't move entry: " + error);
                throw new GDataRequestException(string.Format("Couldn't move entry: {0} - {1}", entryToBeMoved.DocumentEntry.Title.Text, Tools.TrimErrorMessage(error)));
            }
            catch (Exception ex)
            {
                var error = GetErrorMessage(ex);
                throw new Exception(string.Format("Couldn't move entry: {0} - {1}", entryToBeMoved.DocumentEntry.Title.Text, error));
            }

            // let's update dictionaries
            if (movedEntry.Type == Document.DocumentType.Folder)
            {
                AllFolders[entryToBeMoved.ResourceId] = movedEntry;
            }
            else
            {
                AllDocuments[entryToBeMoved.ResourceId] = movedEntry;
            }
        }
コード例 #3
0
        /// <summary>
        /// tests moving a document in and out of folders
        /// </summary>
        [Test] public void ModelTestMoveDocuments()
        {
            const string folderTitle = "That is a new & weird folder";
            const string docTitle = "that's the doc";

            RequestSettings settings = new RequestSettings(this.ApplicationName, this.userName, this.passWord);
            // settings.PageSize = 15;
            DocumentsRequest r = new DocumentsRequest(settings);

            Document folder = new Document();
            folder.Type = Document.DocumentType.Folder;
            folder.Title = folderTitle;

            /// first create the folder
            folder = r.CreateDocument(folder);

            Assert.IsTrue(folder.Title == folderTitle);

            // let's create a document

            Document doc = new Document();
            doc.Type = Document.DocumentType.Document;
            doc.Title = docTitle;

            doc = r.CreateDocument(doc);

            // create the child
            r.MoveDocumentTo(folder, doc);

            // get the folder content list

            Feed<Document> children = r.GetFolderContent(folder);

            bool fFound = false;
            foreach (Document child in children.Entries )
            {
                if (child.DocumentId == doc.DocumentId)
                {
                    fFound = true;
                    break;
                }
            }
            Assert.IsTrue(fFound, "should have found the document in the folder");


        }
コード例 #4
0
        /// <summary>
        /// tests etag refresh on an entry level
        /// </summary>
        [Test] public void ModelTestFolders()
        {
            const string testTitle = "That is a new & weird subfolder";
            const string parentTitle = "Granddaddy folder";

            string parentID;
            string folderID;

            RequestSettings settings = new RequestSettings(this.ApplicationName, this.userName, this.passWord);
            // settings.PageSize = 15;
            DocumentsRequest r = new DocumentsRequest(settings);

            Document folder = new Document();
            folder.Type = Document.DocumentType.Folder;
            folder.Title = testTitle;

            /// first create the folder
            folder = r.CreateDocument(folder);

            Assert.IsTrue(folder.Title == testTitle);

            r.Delete(folder);

            // let's create a hierarchy

            Document parent = new Document();
            parent.Type = Document.DocumentType.Folder;
            parent.Title = parentTitle;

            parent = r.CreateDocument(parent);
            parentID = parent.Id;

            // create the child

            folder = new Document();
            folder.Type = Document.DocumentType.Folder;
            folder.Title = testTitle;

            /// first create the folder
            folder = r.CreateDocument(folder);
            folderID = folder.Id;

            // now move the folder into the parent
            r.MoveDocumentTo(parent, folder);


            // now get the folder list
            Feed<Document> folders = r.GetFolders();

            int iVerify = 2; 

            List<Document> list = new List<Document>();
            foreach (Document f in folders.Entries )
            {
                list.Add(f);
            }

            
            
            bool found = false; 

            foreach (Document f in list )
            {
                Assert.IsTrue(f.Type == Document.DocumentType.Folder, "this should be a folder");
                if (f.Id == parentID)
                {
                    iVerify--;
                }
                if (f.Id == folderID)
                {
                    iVerify--;
                    
                    // let's find the guy again.
                    foreach (Document d in list)
                    {
                        if (f.ParentFolders.Contains(d.Self))
                        {
                            found = true;
                            break;
                        }
                    }
                }
            }
            Assert.IsTrue(found, "we did not find the parent folder");

            Assert.IsTrue(iVerify==0, "We should have found both folders"); 
        }
コード例 #5
0
        /// <summary>
        /// tests etag refresh on an entry level
        /// </summary>
        [Test] public void ModelTestFolders()
        {
            const string testTitle   = "That is a new & weird subfolder";
            const string parentTitle = "Granddaddy folder";

            string parentID;
            string folderID;

            RequestSettings settings = new RequestSettings(this.ApplicationName, this.userName, this.passWord);
            // settings.PageSize = 15;
            DocumentsRequest r = new DocumentsRequest(settings);

            Document folder = new Document();

            folder.Type  = Document.DocumentType.Folder;
            folder.Title = testTitle;

            /// first create the folder
            folder = r.CreateDocument(folder);

            Assert.IsTrue(folder.Title == testTitle);

            r.Delete(folder);

            // let's create a hierarchy

            Document parent = new Document();

            parent.Type  = Document.DocumentType.Folder;
            parent.Title = parentTitle;

            parent   = r.CreateDocument(parent);
            parentID = parent.Id;

            // create the child

            folder       = new Document();
            folder.Type  = Document.DocumentType.Folder;
            folder.Title = testTitle;

            /// first create the folder
            folder   = r.CreateDocument(folder);
            folderID = folder.Id;

            // now move the folder into the parent
            r.MoveDocumentTo(parent, folder);


            // now get the folder list
            Feed <Document> folders = r.GetFolders();

            int iVerify = 2;

            List <Document> list = new List <Document>();

            foreach (Document f in folders.Entries)
            {
                list.Add(f);
            }



            bool found = false;

            foreach (Document f in list)
            {
                Assert.IsTrue(f.Type == Document.DocumentType.Folder, "this should be a folder");
                if (f.Id == parentID)
                {
                    iVerify--;
                }
                if (f.Id == folderID)
                {
                    iVerify--;

                    // let's find the guy again.
                    foreach (Document d in list)
                    {
                        if (f.ParentFolders.Contains(d.Self))
                        {
                            found = true;
                            break;
                        }
                    }
                }
            }
            Assert.IsTrue(found, "we did not find the parent folder");

            Assert.IsTrue(iVerify == 0, "We should have found both folders");
        }