Exemple #1
0
        /// <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);
            }
        }