コード例 #1
0
        private BaseFileEntry RequestResourceFromWebDavShare(IStorageProviderSession session, String resourceUrl, out List<BaseFileEntry> childs)
        {
            // get the credebtials
            ICredentials creds = session.SessionToken as ICredentials;

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

            // the result
            WebDavRequestResult RequestResult;

            try
            {
                // create the web request
                WebRequest request = svc.CreateWebRequestPROPFIND(resourceUrl, creds.GetCredential(null, null));

                // get the response
                using (HttpWebResponse response = svc.GetWebResponse(request) as HttpWebResponse)
                {
                    if (response.StatusCode == HttpStatusCode.Moved)
                    {
                        // get the new uri
                        String newUri = response.Headers["Location"];

                        // close the response
                        response.Close();

                        // redo it
                        return RequestResourceFromWebDavShare(session, newUri, out childs);
                    }
                    else
                    {
                        // get the response stream
                        using (Stream data = svc.GetResponseStream(response))
                        {
                            if (data == null)
                            {
                                childs = null;
                                return null;
                            }

                            // build the file entries
                            RequestResult = WebDavRequestParser.CreateObjectsFromNetworkStream(data, resourceUrl, this, session, WebDavNameBaseFilterCallback);

                            // close the stream
                            data.Close();
                        }

                        // close the response
                        response.Close();
                    }
                }

                // get the request fileentry and fill the childs
                if (RequestResult.Self == null)
                {
                    childs = null;
                    return null;
                }

                // set the childs
                childs = RequestResult.Childs;

                // go ahead
                return RequestResult.Self;
            }
            catch (WebException)
            {
                childs = null;
                return null;
            }
        }
コード例 #2
0
        public override Stream CreateDownloadStream(IStorageProviderSession session, ICloudFileSystemEntry fileSystemEntry)
        {
            // build the url 
            string url = GetResourceUrl(session, fileSystemEntry, null);

            // get the session creds
            ICredentials creds = session.SessionToken as ICredentials;

            // Build the service
            DavService svc = new DavService();

            // create the webrequest
            WebRequest request = svc.CreateWebRequest(url, WebRequestMethodsEx.Http.Get, creds.GetCredential(null, null), false, null);

            // create the response
            WebResponse response = svc.GetWebResponse(request);

            // get the data 
            Stream orgStream = svc.GetResponseStream(response);

            BaseFileEntryDownloadStream dStream = new BaseFileEntryDownloadStream(orgStream, fileSystemEntry);

            // put the disposable on the stack
            dStream._DisposableObjects.Push(response);

            // go ahead
            return dStream;
        }