Esempio n. 1
0
        public List <ISPCFolder> GetFolders(EUSiteSetting siteSetting, ISPCFolder parentFolder)
        {
            Login(siteSetting.User, siteSetting.Password);
            List <ISPCFolder>  folders = new List <ISPCFolder>();
            DocumentsListQuery query   = new DocumentsListQuery();

            if (parentFolder.UniqueIdentifier != String.Empty)
            {
                query = new FolderQuery(parentFolder.UniqueIdentifier);
            }
            query.ShowFolders = true;
            DocumentsFeed feed = service.Query(query);

            foreach (DocumentEntry entry in feed.Entries)
            {
                if (entry.IsFolder)
                {
                    if (parentFolder == null || parentFolder.UniqueIdentifier == String.Empty)
                    {
                        if (entry.ParentFolders.Count > 0)
                        {
                            continue;
                        }
                    }
                    ISPCFolder folder = new GFolder(siteSetting, entry.ResourceId, entry.Title.Text, entry.Id.AbsoluteUri);
                    folders.Add(folder);
                }
            }
            return(folders);
        }
Esempio n. 2
0
        private DocumentEntry createFolder(string folderName, DocumentEntry parentFolder)
        {
            if (cancel())
            {
                return(null);
            }
            DocumentEntry currentFolder = findFolder(folderName, parentFolder);

            if (cancel())
            {
                return(null);
            }
            if (currentFolder != null)
            {
                return(currentFolder);
            }
            FolderQuery   contentQuery = new FolderQuery(parentFolder.ResourceId);
            DocumentEntry subfolder    = new DocumentEntry();

            subfolder.IsFolder   = true;
            subfolder.Title.Text = folderName;
            if (cancel())
            {
                return(null);
            }
            DocumentEntry newFolder = m_service.Insert(contentQuery.Uri, subfolder);

            return(newFolder);
        }
Esempio n. 3
0
        public List <ISPCItem> GetItems(EUSiteSetting siteSetting, ISPCFolder parentFolder)
        {
            Login(siteSetting.User, siteSetting.Password);
            List <ISPCItem> items = new List <ISPCItem>();

            DocumentsListQuery query = new DocumentsListQuery();

            if (parentFolder.UniqueIdentifier != String.Empty)
            {
                query = new FolderQuery(parentFolder.UniqueIdentifier);
            }
            DocumentsFeed feed = service.Query(query);

            foreach (DocumentEntry entry in feed.Entries)
            {
                if (entry.IsFolder == false)
                {
                    if (parentFolder == null || parentFolder.UniqueIdentifier == String.Empty)
                    {
                        if (entry.ParentFolders.Count > 0)
                        {
                            continue;
                        }
                    }
                    ISPCItem item = new GItem(siteSetting, entry.ResourceId, entry.Title.Text, entry.AlternateUri.ToString());
                    items.Add(item);
                }
            }
            return(items);
        }
Esempio n. 4
0
        private int countFoldersAndFiles(DocumentEntry folder)
        {
            if (cancel())
            {
                return(0);
            }
            int         count        = 1;
            FolderQuery contentQuery = new FolderQuery(folder.ResourceId);

            contentQuery.ShowFolders = true;
            DocumentsFeed contents = m_service.Query(contentQuery);

            foreach (DocumentEntry entry in contents.Entries)
            {
                if (cancel())
                {
                    return(0);
                }
                if (!entry.IsFolder)
                {
                    if (m_fileFilters.ContainsKey(Path.GetExtension(entry.Title.Text)))
                    {
                        count++;
                    }
                }
                else
                {
                    count += countFoldersAndFiles(entry);
                }
            }
            return(count);
        }
Esempio n. 5
0
        public List <IItem> GetListItems(ISiteSetting siteSetting, string webUrl, string listName, bool isRecursive)
        {
            Login(siteSetting.Username, siteSetting.Password);
            List <IItem> items = new List <IItem>();

            DocumentsListQuery query = new DocumentsListQuery();

            if (string.IsNullOrEmpty(webUrl) == false)
            {
                query = new FolderQuery(webUrl);
            }
            DocumentsFeed feed = service.Query(query);

            foreach (DocumentEntry entry in feed.Entries)
            {
                if (entry.IsFolder == false)
                {
                    if (String.IsNullOrEmpty(webUrl) == true)
                    {
                        if (entry.ParentFolders.Count > 0)
                        {
                            continue;
                        }
                    }
                    IItem item = new GItem(siteSetting.ID, entry.ResourceId, entry.Title.Text, entry.AlternateUri.ToString());
                    item.Properties.Add("ows_Editor", entry.LastModified.Name);
                    item.Properties.Add("ows_Modified", entry.Edited.DateValue.ToString());
                    items.Add(item);
                }
            }
            return(items);
        }
Esempio n. 6
0
        public async Task SavePreviewData()
        {
            await CommandBus.Execute(new SaveFolderCommand(new FolderModel {
                Id = Guid.NewGuid(), Name = "Inbox", Color = "#0063AF"
            }));

            await CommandBus.Execute(new SaveFolderCommand(new FolderModel {
                Id = Guid.NewGuid(), Name = "Work", Color = "#0F893E"
            }));

            await CommandBus.Execute(new SaveFolderCommand(new FolderModel {
                Id = Guid.NewGuid(), Name = "Shopping list", Color = "#AC008C"
            }));

            await CommandBus.Execute(new SaveFolderCommand(new FolderModel {
                Id = Guid.NewGuid(), Name = "Vacation", Color = "#F7630D"
            }));

            var folders = await FolderQuery.GetAll();

            var folder  = folders.FirstOrDefault();
            var folder2 = folders.Skip(1).FirstOrDefault();
            await CommandBus.Execute(new SaveNoteCommand(new NoteModel {
                Id = Guid.NewGuid(), FolderId = folder.Id, Title = "Buy milk"
            }));

            await CommandBus.Execute(new SaveNoteCommand(new NoteModel
            {
                Id = Guid.NewGuid(),
                FolderId = folder.Id,
                Title = "Walk Max with bike",
                Reminder = new ReminderModel
                {
                    DateTime = DateTime.Today + TimeSpan.FromHours(7.25),
                    Recurrence = new DaysOfWeekRecurrenceModel
                    {
                        Every = 2,
                        DaysOfWeek = DaysOfWeek.Weekends
                    }
                }
            }));

            await CommandBus.Execute(new SaveNoteCommand(new NoteModel {
                Id = Guid.NewGuid(), FolderId = folder.Id, Title = "Call mom", Reminder = new ReminderModel {
                    DateTime = DateTime.Today + TimeSpan.FromHours(15)
                }, IsFlagged = true
            }));

            await CommandBus.Execute(new SaveNoteCommand(new NoteModel
            {
                Id = Guid.NewGuid(),
                FolderId = folder.Id,
                Title = "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
                Text = "Proin et diam at lorem egestas ullamcorper. Curabitur non eleifend mi. Praesent eu sem elementum, rutrum neque id, sollicitudin dolor. Proin molestie ullamcorper sem a hendrerit. Integer ac sapien erat. Morbi vehicula venenatis dolor, non aliquet nibh mattis sed.",
            }));

            await CommandBus.Execute(new SaveNoteCommand(new NoteModel {
                Id = Guid.NewGuid(), FolderId = folder2.Id, Title = "Test note", IsFlagged = true
            }));
        }
Esempio n. 7
0
        /// <summary>
        /// Locates a folder with the name provided, will return the id if found. Otherwise, it will return 0.
        /// </summary>
        /// <param name="folderName">
        /// The name of the folder you are looking for.
        /// </param>
        /// <param name="ignoreCase">
        /// Whether or not this methods needs to ignore case when looking for the folder name or not.
        /// </param>
        /// <returns></returns>
        public long GetIdByName(string folderName, bool ignoreCase)
        {
            var query = new FolderQuery {
                PageSize = 500
            };
            var folder = GetList <Folder>(query).FirstOrDefault(f => String.Compare(f.Name, folderName, ignoreCase) == 0);

            return(folder == null ? 0 : folder.Id);
        }
Esempio n. 8
0
        public DocumentsFeed GetFolderList(string folderID)
        {
            FolderQuery query = new FolderQuery(folderID);

            query.ShowFolders = false;
            DocumentsFeed feed = service.Query(query);

            return(feed);
        }
Esempio n. 9
0
        public ParaEntityList <TFolder> GetList <TFolder>()
            where TFolder : Folder, new()
        {
            var eq = new FolderQuery()
            {
                RetrieveAllRecords = true
            };

            return(GetList <TFolder>(eq));
        }
Esempio n. 10
0
        public Api()
        {
            dataService = new DataService();

            EventBus   = new EventBus();
            CommandBus = new CommandBus(EventBus, dataService);

            FolderQuery = new FolderQuery(dataService.GetQueryRepository <FolderData>());
            NoteQuery   = new NoteQuery(dataService.GetQueryRepository <NoteData>());
        }
Esempio n. 11
0
        /// <summary>
        /// Locates a folder with the name provided and which has the parent folder of your choice, will return the id if found. Otherwise, it will return 0.
        /// </summary>
        /// <param name="folderName">
        /// The name of the folder you are looking for.
        /// </param>
        /// <param name="ignoreCase">
        /// Whether or not this methods needs to ignore case when looking for the folder name or not.
        /// </param>
        /// <param name="parentFolderId">
        /// The parent folder under which to look for a folder by name.
        /// </param>
        /// <returns></returns>
        public long GetIdByName(string folderName, bool ignoreCase, long parentFolderId)
        {
            var fQuery = new FolderQuery();

            fQuery.AddStaticFieldFilter(FolderQuery.FolderStaticFields.ParentFolder, ParaEnums.QueryCriteria.Equal,
                                        parentFolderId.ToString());
            fQuery.PageSize = 500;
            var folder = GetList <Folder>(fQuery).FirstOrDefault(f => String.Compare(f.Name, folderName, ignoreCase) == 0);

            return(folder == null ? 0 : folder.Id);
        }
Esempio n. 12
0
        private void downloadDirectory(DocumentEntry folder, string downloadTo)
        {
            if (cancel())
            {
                return;
            }
            string currentFolderName = Path.Combine(downloadTo, folder.Title.Text);

            Directory.CreateDirectory(currentFolderName);
            reportProgress("Dowloaded/Updated " + folder.Title.Text);
            FolderQuery contentQuery = new FolderQuery(folder.ResourceId);

            contentQuery.ShowFolders = true;
            DocumentsFeed contents = m_service.Query(contentQuery);

            foreach (DocumentEntry entry in contents.Entries)
            {
                if (cancel())
                {
                    return;
                }
                if (!entry.IsFolder)
                {
                    if (m_fileFilters.ContainsKey(Path.GetExtension(entry.Title.Text)))
                    {
                        string downloadUrl = entry.Content.Src.Content;
                        if (cancel())
                        {
                            return;
                        }
                        Stream stream = m_service.Query(new Uri(downloadUrl));
                        if (cancel())
                        {
                            return;
                        }
                        string     fileName         = Path.Combine(currentFolderName, entry.Title.Text);
                        FileStream outputFileStream = new FileStream(fileName, FileMode.Create);
                        stream.CopyTo(outputFileStream);
                        outputFileStream.Close();
                        reportProgress("Downloaded/Updated " + entry.Title.Text);
                        if (cancel())
                        {
                            return;
                        }
                    }
                }
                else
                {
                    downloadDirectory(entry, currentFolderName);
                }
            }
        }
Esempio n. 13
0
        public ParaEntityList <TFolder> GetList <TFolder>(FolderQuery query)
            where TFolder : Folder, new()
        {
            var folderList = new ParaEntityList <TFolder>();
            var ar         = ApiCallFactory.ObjectGetList <TFolder>(Credentials, query.BuildQueryArguments());

            if (ar.HasException == false)
            {
                folderList = ParaEntityParser.FillList <TFolder>(ar.XmlReceived);
            }
            folderList.ApiCallResponse = ar;

            // Checking if the system needs to recursively call all of the data returned.
            if (query.RetrieveAllRecords)
            {
                bool continueCalling = true;
                while (continueCalling)
                {
                    if (folderList.TotalItems > folderList.Data.Count)
                    {
                        // We still need to pull data

                        // Getting next page's data
                        query.PageNumber = query.PageNumber + 1;

                        ar = ApiCallFactory.ObjectGetList <TFolder>(Credentials, query.BuildQueryArguments());

                        var objectlist = ParaEntityParser.FillList <TFolder>(ar.XmlReceived);

                        if (objectlist.Data.Count == 0)
                        {
                            continueCalling = false;
                        }

                        folderList.Data.AddRange(objectlist.Data);
                        folderList.ResultsReturned = folderList.Data.Count;
                        folderList.PageNumber      = query.PageNumber;
                    }
                    else
                    {
                        // That is it, pulled all the items.
                        continueCalling            = false;
                        folderList.ApiCallResponse = ar;
                    }
                }
            }

            return(folderList);
        }
Esempio n. 14
0
        private DocumentEntry findFolder(string folderName, DocumentEntry parentFolder = null)
        {
            if (cancel())
            {
                return(null);
            }
            FolderQuery query = (parentFolder == null ? new FolderQuery() : new FolderQuery(parentFolder.ResourceId));

            query.TitleExact = true;
            query.Title      = folderName;
            DocumentsFeed feed = m_service.Query(query);

            if (feed.Entries.Count == 0)
            {
                return(null);
            }
            return((DocumentEntry)feed.Entries[0]);
        }
Esempio n. 15
0
        private void getListOfFoldersInternal(string downloadFrom)
        {
            listOfFolders = new List <string>();
            DocumentEntry parentFolder = locateFolder(downloadFrom, null);

            if (!string.IsNullOrWhiteSpace(downloadFrom) && parentFolder == null)
            {
                return;
            }
            FolderQuery contentQuery = new FolderQuery(parentFolder.ResourceId);

            contentQuery.ShowFolders = true;
            DocumentsFeed contents = m_service.Query(contentQuery);

            foreach (DocumentEntry entry in contents.Entries)
            {
                if (entry.IsFolder)
                {
                    listOfFolders.Add(entry.Title.Text);
                }
            }
        }
Esempio n. 16
0
        public void uploadFile(string fileName, DocumentEntry parentFolder)
        {
            if (cancel())
            {
                return;
            }
            string fileExtension = System.IO.Path.GetExtension(fileName).ToLower();

            if (!m_fileFilters.ContainsKey(fileExtension))
            {
                return;
            }
            int CHUNK_SIZE       = 1;
            ResumableUploader ru = new ResumableUploader(CHUNK_SIZE);

            ru.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(this.OnDone);
            ru.AsyncOperationProgress  += new AsyncOperationProgressEventHandler(this.OnProgress);

            // Check if entry exists
            FolderQuery contentQuery = new FolderQuery(parentFolder.ResourceId);

            contentQuery.Title      = Path.GetFileName(fileName);
            contentQuery.TitleExact = true;
            DocumentsFeed contents   = m_service.Query(contentQuery);
            bool          fileExists = contents.Entries.Count > 0;
            DocumentEntry entry      = fileExists?contents.Entries[0] as DocumentEntry:new DocumentEntry();

            entry.Title.Text = Path.GetFileName(fileName);
            string mimeType = m_fileFilters[fileExtension];

            entry.MediaSource = new MediaFileSource(fileName, mimeType);
            // Define the resumable upload link
            string notConvert = "?convert=false";
            Uri    createUploadUrl;

            if (parentFolder == null)
            {
                createUploadUrl = new Uri("https://docs.google.com/feeds/upload/create-session/default/private/full" + notConvert);
            }
            else
            {
                createUploadUrl = new Uri("https://docs.google.com/feeds/upload/create-session/default/private/full/" + parentFolder.ResourceId + "/contents" + notConvert);
            }
            AtomLink link = new AtomLink(createUploadUrl.AbsoluteUri);

            link.Rel = ResumableUploader.CreateMediaRelation;
            entry.Links.Add(link);

            // Set the service to be used to parse the returned entry
            entry.Service = m_service;

            // Instantiate the ResumableUploader component.
            ResumableUploader uploader = new ResumableUploader();

            // Set the handlers for the completion and progress events
            uploader.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(OnDone);
            uploader.AsyncOperationProgress  += new AsyncOperationProgressEventHandler(OnProgress);
            ClientLoginAuthenticator cla = new ClientLoginAuthenticator("uploader", ServiceNames.Documents, m_username, m_password);

            // Start the upload process
            if (cancel())
            {
                return;
            }
            if (fileExists)
            {
                uploader.UpdateAsync(cla, entry, new Object());
            }
            else
            {
                uploader.InsertAsync(cla, entry, new Object());
            }
        }