/// <summary>
        /// This method generates a session to a webdav share via username and password
        /// </summary>
        /// <param name="token"></param>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public override IStorageProviderSession CreateSession(ICloudStorageAccessToken token, ICloudStorageConfiguration configuration)
        {
            // cast the creds to the right type
            WebDavConfiguration config = configuration as WebDavConfiguration;

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

            // check if url available
            int          status = (int)HttpStatusCode.OK;
            WebException e      = null;

            svc.PerformSimpleWebCall(config.ServiceLocator.ToString(), WebRequestMethodsEx.WebDAV.Options, (token as ICredentials).GetCredential(null, null), null, out status, out e);
            if (status == (int)HttpStatusCode.Unauthorized)
            {
                throw new UnauthorizedAccessException();
            }
            else if (HttpUtilityEx.IsSuccessCode(status))
            {
                return(new WebDavStorageProviderSession(token, config, this));
            }
            else
            {
                return(null);
            }
        }
예제 #2
0
        /// <summary>
        /// This method removes a specific resource from a webdav share
        /// </summary>
        /// <param name="session"></param>
        /// <param name="entry"></param>
        public override Boolean DeleteResource(IStorageProviderSession session, ICloudFileSystemEntry entry)
        {
            // get the credentials
            var creds = session.SessionToken as ICredentials;

            // build url
            var uriString = GetResourceUrl(session, entry, null);
            var uri       = new Uri(uriString);

            // create the service
            var svc = new DavService();

            // create the webrequest
            int          errorCode;
            WebException e;

            svc.PerformSimpleWebCall(uri.ToString(), WebRequestMethodsEx.WebDAV.Delete, creds.GetCredential(null, null), null, out errorCode, out e);
            if (!HttpUtilityEx.IsSuccessCode(errorCode))
            {
                return(false);
            }

            // remove from parent
            var parentDir = entry.Parent as BaseDirectoryEntry;

            if (parentDir != null)
            {
                parentDir.RemoveChildById(entry.Id);
            }

            return(true);
        }
        /// <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);
            }
        }