Exemplo n.º 1
0
        internal override Response GetResponse()
        {
            Response response;

            switch (_code)
            {
            case HttpStatusCodes.SuccessCreated: {
                response = new Response(_code);
                return(response);
            }

            case HttpStatusCodes.SuccessMultistatus: {
                String str;
                try {
                    str = FileManager.GetInstanse().GetDirInfo(_mFileName).Exists
                                    ? PropFindHelper.GetFilesPropInDir(_mFileName, 0)
                                    : PropFindHelper.GetFilesProp(_mFileName);
                    response = new Response(HttpStatusCodes.SuccessMultistatus);
                } catch (DirectoryNotFoundException) {
                    str      = "";
                    response = new Response(HttpStatusCodes.ClientErrorNotFound);
                }
                Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(str));
                response.SetContentLength(stream.Length);
                response.SetData(stream);
                response.AddHeaderValue("Content-Type", "application/xml; charset=\"utf-8\"");
                return(response);
            }

            default:
                throw new Exception("Bad code " + _code);
            }
        }
Exemplo n.º 2
0
        public void GetProp()
        {
            FileManager.Init("");
            const string fileName = "test.txt";
            var          file     = File.Create(fileName);

            file.Close();
            var curRes = PropFindHelper.GetFilesProp(fileName);
            //<d:status>HTTP/1.1 200 OK</d:status>
            var pos = curRes.IndexOf("<d:status>HTTP/1.1 200 OK</d:status>", StringComparison.Ordinal);

            Assert.AreEqual(true, pos > 0);
        }
        public void LockRequest()
        {
            const string uri   = "a.txt";
            const string token = "aaaa";
            const string user  = "******";
            var          info  = new LockInfo(uri, LockType.Write, LockScope.Exclusive, 0, user, token);
            var          res   = PropFindHelper.GetLockDiscovery(info);
            var          pos   = res.IndexOf("<d:href>" + token + "</d:href>", StringComparison.Ordinal);

            Assert.IsTrue(pos > 0);
            pos = res.IndexOf("<d:depth>" + 0 + "</d:depth>", StringComparison.Ordinal);
            Assert.IsTrue(pos > 0);
            pos = res.IndexOf("<d:href>" + user + "</d:href>", StringComparison.Ordinal);
            Assert.IsTrue(pos > 0);
        }
Exemplo n.º 4
0
        internal override Response GetResponse()
        {
            var response = new Response(_code);
            var lockInfo = LockManager.GetInstanse().GetLockInfo(_mFileName);

            if (null == lockInfo)
            {
                return(response);
            }
            var xmlContent = PropFindHelper.GetLockDiscovery(lockInfo);

            Logger.Trace("RESPONSE " + xmlContent);
            Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(xmlContent));

            response.SetContentLength(stream.Length);
            response.SetData(stream);
            return(response);
        }
Exemplo n.º 5
0
        internal override Response GetResponse()
        {
            Response response;
            String   str;

            try {
                str = FileManager.GetInstanse().GetDirInfo(_mPath).Exists ?
                      PropFindHelper.GetFilesPropInDir(_mPath, _mDepth) : PropFindHelper.GetFilesProp(_mPath);
                response = new Response(HttpStatusCodes.SuccessMultistatus);
                Logger.Trace(str);
            } catch (DirectoryNotFoundException) {
                str      = "";
                response = new Response(HttpStatusCodes.ClientErrorNotFound);
            }
            Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(str));

            response.SetContentLength(stream.Length);
            response.SetData(stream);
            response.AddHeaderValue("Content-Type", "application/xml; charset=\"utf-8\"");
            return(response);
        }