public override void RefreshResource(IStorageProviderSession session, ICloudFileSystemEntry resource)
        {
            // nothing to do for files
            if (!(resource is ICloudDirectoryEntry))
            {
                return;
            }

            // build url
            String uriString = GetResourceUrl(session, resource, null);

            // get the data
            List <BaseFileEntry> childs = null;

            RequestResourceFromWebDavShare(session, uriString, out childs);

            // set the new childs collection
            BaseDirectoryEntry dirEntry = resource as BaseDirectoryEntry;

            dirEntry.ClearChilds();

            // add the new childs
            if (childs != null)
            {
                dirEntry.AddChilds(childs);
            }
        }
        public void RefreshDirectoryContent(IStorageProviderSession session, BaseDirectoryEntry entry)
        {
            if (entry == null)
            {
                return;
            }

            var url        = String.Format(GoogleDocsConstants.GoogleDocsContentsUrlFormat, entry.Id.ReplaceFirst("_", "%3a"));
            var parameters = new Dictionary <string, string> {
                { "max-results", "1000" }
            };

            try
            {
                while (!String.IsNullOrEmpty(url))
                {
                    var request  = CreateWebRequest(session, url, "GET", parameters);
                    var response = (HttpWebResponse)request.GetResponse();
                    var rs       = response.GetResponseStream();

                    var feedXml = new StreamReader(rs).ReadToEnd();
                    var childs  = GoogleDocsXmlParser.ParseEntriesXml(session, feedXml);
                    entry.AddChilds(childs);

                    url = GoogleDocsXmlParser.ParseNext(feedXml);
                }
            }
            catch (WebException)
            {
            }
        }
Exemplo n.º 3
0
        public override ICloudFileSystemEntry RequestResource(IStorageProviderSession session, String nameOrID, ICloudDirectoryEntry parent)
        {
            /* In this method name could be either requested resource name or it's ID.
             * In first case just refresh the parent and then search child with an appropriate.
             * In second case it does not matter if parent is null or not a parent because we use only resource ID. */

            if (SkyDriveHelpers.HasResourceID(nameOrID) || nameOrID.Equals("/") && parent == null)
            //If request by ID or root folder requested
            {
                var id  = SkyDriveHelpers.GetResourceID(nameOrID);
                var uri = id != String.Empty
                                 ? String.Format("{0}/{1}", SkyDriveConstants.BaseAccessUrl, id)
                                 : SkyDriveConstants.RootAccessUrl;

                if (SkyDriveHelpers.IsFolderID(id))
                {
                    var contents             = new List <ICloudFileSystemEntry>();
                    BaseDirectoryEntry entry = null;

                    /*var completeContent = new AutoResetEvent(false);
                     * ThreadPool.QueueUserWorkItem(state =>
                     *  {
                     *      contents.AddRange(RequestContentByUrl(session, uri + "/files"));
                     *      ((AutoResetEvent) state).Set();
                     *  }, completeContent);
                     *
                     * var completeEntry = new AutoResetEvent(false);
                     * ThreadPool.QueueUserWorkItem(state =>
                     *  {
                     *      entry = RequestResourseByUrl(session, uri) as BaseDirectoryEntry;
                     *      ((AutoResetEvent) state).Set();
                     *  }, completeEntry);
                     *
                     * WaitHandle.WaitAll(new WaitHandle[] {completeContent, completeEntry});*/

                    entry = RequestResourseByUrl(session, uri) as BaseDirectoryEntry;
                    contents.AddRange(RequestContentByUrl(session, uri + "/files"));

                    if (entry != null && contents.Any())
                    {
                        entry.AddChilds(contents.Cast <BaseFileEntry>());
                    }

                    return(entry);
                }

                return(RequestResourseByUrl(session, uri));
            }
            else
            {
                String uri;
                if (SkyDriveHelpers.HasParentID(nameOrID))
                {
                    uri = String.Format(SkyDriveConstants.FilesAccessUrlFormat, SkyDriveHelpers.GetParentID(nameOrID));
                }
                else if (parent != null)
                {
                    uri = String.Format(SkyDriveConstants.FilesAccessUrlFormat, parent.GetPropertyValue(SkyDriveConstants.InnerIDKey));
                }
                else
                {
                    uri = SkyDriveConstants.RootAccessUrl + "/files";
                }

                nameOrID = Path.GetFileName(nameOrID);
                var entry = RequestContentByUrl(session, uri).FirstOrDefault(x => x.Name.Equals(nameOrID));
                return(entry);
            }
        }