/// <summary>
        /// This method renames a given filesystem object (file or folder)
        /// </summary>
        /// <param name="fsentry"></param>
        /// <param name="newName"></param>
        /// <returns></returns>
        public bool RenameFileSystemEntry(ICloudFileSystemEntry fsentry, string newName)
        {
            // save the old name
            String renamedId = fsentry.Id;

            // rename the resource
            if (_Service.RenameResource(_Session, fsentry, newName))
            {
                // get the parent
                BaseDirectoryEntry p = fsentry.Parent as BaseDirectoryEntry;

                // remove the old childname
                p.RemoveChildById(renamedId);

                // readd the child
                p.AddChild(fsentry as BaseFileEntry);

                // go ahead
                return(true);
            }
            else
            {
                return(false);
            }
        }
        private void RefreshChildsOfDirectory(IStorageProviderSession session, BaseDirectoryEntry dir)
        {
            // get the location
            var reslocation = GetResourceUrl(session, dir, null);

            // ensure that we have a trailing slash
            reslocation = reslocation.TrimEnd('/');
            reslocation = reslocation + "/";

            // build the uri
            var resUri = new Uri(reslocation);

            // convert BaseDir to DirInfo
            var dInfo = new DirectoryInfo(resUri.LocalPath);

            // clear childs
            dir.ClearChilds();

            // get all childs
            foreach (var fInfo in dInfo.GetFileSystemInfos())
            {
                var f = CreateEntryByFileSystemInfo(fInfo, session);
                dir.AddChild(f);
            }
        }
Exemple #3
0
        private static Boolean BuildDirectyEntry(BaseDirectoryEntry dirEntry, JsonHelper jh, IStorageProviderService service, IStorageProviderSession session)
        {
            // build the file entry part
            if (!BuildFileEntry(dirEntry, jh))
            {
                return(false);
            }

            // now take the content
            var content = jh.GetListProperty("contents");

            if (content.Count == 0)
            {
                return(true);
            }

            // remove all childs
            dirEntry.ClearChilds();

            // add the childs
            foreach (var jsonContent in content)
            {
                // parse the item
                var jc = new JsonHelper();
                if (!jc.ParseJsonMessage(jsonContent))
                {
                    continue;
                }

                // check if we have a directory
                var isDir = jc.GetBooleanProperty("is_dir");

                BaseFileEntry fentry;

                if (isDir)
                {
                    fentry = new BaseDirectoryEntry("Name", 0, DateTime.Now, service, session);
                }
                else
                {
                    fentry = new BaseFileEntry("Name", 0, DateTime.Now, service, session);
                }

                // build the file attributes
                BuildFileEntry(fentry, jc);

                // establish parent child realtionship
                dirEntry.AddChild(fentry);
            }

            // set the length
            dirEntry.Length = dirEntry.Count;

            // go ahead
            return(true);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="session"></param>
        /// <param name="objectToMove"></param>
        /// <param name="newParent"></param>
        public static void MoveFileSystemEntry(IStorageProviderSession session, ICloudFileSystemEntry objectToMove, ICloudDirectoryEntry newParent)
        {
            // readjust parent
            BaseDirectoryEntry oldParent = objectToMove.Parent as BaseDirectoryEntry;

            oldParent.RemoveChild(objectToMove as BaseFileEntry);

            BaseDirectoryEntry newParentObject = newParent as BaseDirectoryEntry;

            newParentObject.AddChild(objectToMove as BaseFileEntry);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="session"></param>
        /// <param name="Name"></param>
        /// <param name="modifiedDate"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        public static ICloudDirectoryEntry CreateDirectoryEntry(IStorageProviderSession session, string Name, DateTime modifiedDate, ICloudDirectoryEntry parent)
        {
            // build up query url
            BaseDirectoryEntry newObj = new BaseDirectoryEntry(Name, 0, modifiedDate, session.Service, session);

            // case the parent if possible
            if (parent != null)
            {
                BaseDirectoryEntry objparent = parent as BaseDirectoryEntry;
                objparent.AddChild(newObj);
            }

            return(newObj);
        }
        /// <summary>
        /// This method request information about a resource
        /// </summary>
        /// <param name="session"></param>
        /// <param name="Name"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        public override ICloudFileSystemEntry RequestResource(IStorageProviderSession session, string Name, ICloudDirectoryEntry parent)
        {
            // build url
            String uriString = GetResourceUrl(session, parent, null);

            uriString = PathHelper.Combine(uriString, Name);

            // get the data
            List <BaseFileEntry> childs          = null;
            BaseFileEntry        requestResource = RequestResourceFromWebDavShare(session, uriString, out childs);

            // check errors
            if (requestResource == null)
            {
                return(null);
            }

            // rename the root
            if (Name.Equals("/"))
            {
                requestResource.Name = "/";
            }

            // init parent child relation
            if (parent != null)
            {
                BaseDirectoryEntry parentDir = parent as BaseDirectoryEntry;
                parentDir.AddChild(requestResource);
            }

            // check if we have to add childs
            if (!(requestResource is BaseDirectoryEntry))
            {
                return(requestResource);
            }
            else
            {
                BaseDirectoryEntry requestedDir = requestResource as BaseDirectoryEntry;

                // add the childs
                foreach (BaseFileEntry child in childs)
                {
                    requestedDir.AddChild(child);
                }
            }

            // go ahead
            return(requestResource);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="session"></param>
        /// <param name="Name"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        public override ICloudFileSystemEntry CreateResource(IStorageProviderSession session, string Name, ICloudDirectoryEntry parent)
        {
            // get the credentials
            ICredentials creds = session.SessionToken as ICredentials;

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

            uriString = PathHelper.Combine(uriString, Name);

            Uri uri = new Uri(uriString);

            // build the DavService
            DavService svc = new DavService();

            // create the webrequest
            int          errorCode;
            WebException e;

            svc.PerformSimpleWebCall(uri.ToString(), WebRequestMethodsEx.Http.MkCol, creds.GetCredential(null, null), null, out errorCode, out e);
            if (errorCode != (int)HttpStatusCode.Created)
            {
                return(null);
            }
            else
            {
                BaseDirectoryEntry newDir = new BaseDirectoryEntry(Name, 0, DateTime.Now, this, session);

                // init parent child relation
                if (parent != null)
                {
                    BaseDirectoryEntry parentDir = parent as BaseDirectoryEntry;
                    parentDir.AddChild(newDir);
                }

                return(newDir);
            }
        }
Exemple #8
0
        public override ICloudFileSystemEntry CreateResource(IStorageProviderSession session, string Name, ICloudDirectoryEntry parent)
        {
            // get the parent
            BaseDirectoryEntry parentDir = parent as BaseDirectoryEntry;

            // build new folder object
            var newFolder = new BaseDirectoryEntry(Name, 0, DateTime.Now, this, session);

            parentDir.AddChild(newFolder);

            // build the path for resource
            String resourcePath = GenericHelper.GetResourcePath(newFolder);

            // build the json parameters
            var parameters = new Dictionary <string, string>
            {
                { "path", resourcePath },
                { "root", GetRootToken(session as DropBoxStorageProviderSession) }
            };

            // request the json object via oauth
            int code;
            var res = DropBoxRequestParser.RequestResourceByUrl(GetUrlString(DropBoxCreateFolder, session.ServiceConfiguration), parameters, this, session, out code);

            if (res.Length == 0)
            {
                parentDir.RemoveChild(newFolder);
                return(null);
            }
            else
            {
                // update the folder object
                DropBoxRequestParser.UpdateObjectFromJsonString(res, newFolder, this, session);
            }

            // go ahead
            return(newFolder);
        }
Exemple #9
0
        /// <summary>
        /// This method moves a resource from one webdav location to an other
        /// </summary>
        /// <param name="session"></param>
        /// <param name="fsentry"></param>
        /// <param name="newParent"></param>
        /// <returns></returns>
        public override bool MoveResource(IStorageProviderSession session, ICloudFileSystemEntry fsentry, ICloudDirectoryEntry newParent)
        {
            // build the targte url
            String uriStringTarget = this.GetResourceUrl(session, newParent, null);

            uriStringTarget = PathHelper.Combine(uriStringTarget, fsentry.Name);

            if (MoveResource(session, fsentry, uriStringTarget))
            {
                // readjust parent
                BaseDirectoryEntry oldParent = fsentry.Parent as BaseDirectoryEntry;
                oldParent.RemoveChild(fsentry as BaseFileEntry);

                BaseDirectoryEntry newParentObject = newParent as BaseDirectoryEntry;
                newParentObject.AddChild(fsentry as BaseFileEntry);

                return(true);
            }
            else
            {
                return(false);
            }
        }
        private void CommitUploadOperation(object[] args)
        {
            var session = args[0] as IStorageProviderSession;
            var request = args[1] as WebRequest;
            var entry   = args[2] as BaseFileEntry;

            var responce = (HttpWebResponse)request.GetResponse();
            var stream   = responce.GetResponseStream();

            var xml = new StreamReader(stream).ReadToEnd();

            var uploaded = GoogleDocsXmlParser.ParseEntriesXml(session, xml).First();

            BaseDirectoryEntry parent = null;

            if (entry.Parent != null)
            {
                parent = entry.Parent as BaseDirectoryEntry;
                parent.RemoveChild(entry); //this may be virtual one
            }

            //copy uploaded entry's info to old one
            entry.Name     = uploaded.Name;
            entry.Id       = uploaded.Id;
            entry.Length   = uploaded.Length;
            entry.Modified = uploaded.Modified;
            entry.SetPropertyValue(GoogleDocsConstants.DownloadUrlProperty, uploaded.GetPropertyValue(GoogleDocsConstants.DownloadUrlProperty));
            entry.SetPropertyValue(GoogleDocsConstants.EtagProperty, uploaded.GetPropertyValue(GoogleDocsConstants.EtagProperty));
            entry.SetPropertyValue(GoogleDocsConstants.KindProperty, uploaded.GetPropertyValue(GoogleDocsConstants.KindProperty));
            entry.SetPropertyValue(GoogleDocsConstants.ResEditMediaProperty, uploaded.GetPropertyValue(GoogleDocsConstants.ResCreateMediaProperty));

            if (parent != null)
            {
                parent.AddChild(entry);
            }
        }