当前位置: 首页>>代码示例>>C#>>正文


C# Byte.ULongLength方法代码示例

本文整理汇总了C#中System.Byte.ULongLength方法的典型用法代码示例。如果您正苦于以下问题:C# Byte.ULongLength方法的具体用法?C# Byte.ULongLength怎么用?C# Byte.ULongLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Byte的用法示例。


在下文中一共展示了Byte.ULongLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoOPTIONS

        public void DoOPTIONS(string destination)
        {
            var content = new Byte[0];
            var body = HTTPServer.HTTPContext.RequestBody;
            var header = HTTPServer.HTTPContext.RequestHeader;
            HTTPHeader respHeader = null;

            #region OPTIONS

            if (header.ClientType == ClientTypes.SVN)
            {

                content = Encoding.UTF8.GetBytes("<?xml version=\"1.0\" encoding=\"utf-8\"?><D:options-response xmlns:D=\"DAV:\"><D:activity-collection-set><D:href>" + DirectoryHelper.Combine(header.Destination, "!svn/act/") + "</D:href></D:activity-collection-set></D:options-response>");

                respHeader = CreateHeader(HTTPStatusCodes.OK, content.ULongLength(), new ContentType(MediaTypeNames.Text.Xml + "; charset=utf-8"));

                respHeader.Headers.Add("Allow", "OPTIONS, GET, HEAD, POST, DELETE, TRACE, PROPFIND, PROPPATCH, COPY, MOVE, LOCK, UNLOCK, CHECKOUT ");
                respHeader.Headers.Add("DAV", "version-control,checkout,working-resource");
                respHeader.Headers.Add("DAV", "http://subversion.tigris.org/xmlns/dav/svn/depth");
                respHeader.Headers.Add("DAV", "http://subversion.tigris.org/xmlns/dav/svn/log-revprops");
                respHeader.Headers.Add("DAV", "http://subversion.tigris.org/xmlns/dav/svn/partial-replay");
                respHeader.Headers.Add("DAV", "http://subversion.tigris.org/xmlns/dav/svn/mergeinfo");
                respHeader.Headers.Add("DAV", "<http://apache.org/dav/propset/fs/1>");

            }
            else
            {

                respHeader = CreateHeader(HTTPStatusCodes.OK, 0, new ContentType(MediaTypeNames.Text.Plain + "; charset=utf-8"));
                //HeaderString.AppendLine("Allow: OPTIONS, GET, POST, HEAD, COPY, PROPFIND, BROWSE, INDEX, PUT, DELETE, MOVE, SAVE, MKCOL, MKDIR, RMDIR ");
                respHeader.Headers.Add("Allow", "OPTIONS, GET, HEAD, COPY, PROPFIND, PUT, MOVE, MKCOL, DELETE ");

            }

            #endregion

            Byte[] HeaderBytes = respHeader.ToBytes();
            HTTPServer.HTTPContext.WriteToResponseStream(HeaderBytes, 0, HeaderBytes.Length);
            HTTPServer.HTTPContext.WriteToResponseStream(content, 0, content.Length);
        }
开发者ID:TheByte,项目名称:sones,代码行数:40,代码来源:GraphDSWebDAV_Service.cs

示例2: DoPROPFIND

        public void DoPROPFIND(string destination)
        {
            var content = new Byte[0];
            var _Body = HTTPServer.HTTPContext.RequestBody;
            var header = HTTPServer.HTTPContext.RequestHeader;
            HTTPHeader respHeader = null;

            var destinationObjectStreamTypes = GetDestinationObjectStreamTypes(header);

            if (header.HttpStatusCode != HTTPStatusCodes.OK)
            {
                respHeader = CreateHeader(HTTPStatusCodes.NotImplemented, 0);
            }
            else if (destinationObjectStreamTypes == null)
            {
                respHeader = CreateHeader(HTTPStatusCodes.NotFound, 0);
            }
            else
            {
                PropfindProperties PropfindProperties = PropfindProperties.NONE;
                if (_Body.Length > 0)
                {
                    PropfindProperties = ParsePropfindBody(_Body);
                }

                content = CreatePropfindResponse(header, PropfindProperties, destinationObjectStreamTypes);

                // Clients may submit a Depth Header with a value of "0", "1", "1,noroot" or "infinity". A PROPFIND Method without a Depth Header acts as if a Depth Header value of "infinity" was included.
                respHeader = CreateHeader(HTTPStatusCodes.MultiStatus, content.ULongLength(), new ContentType(MediaTypeNames.Text.Xml + "; charset=utf-8"));

            }

            Byte[] HeaderBytes = respHeader.ToBytes();

            //Byte[] Response = new Byte[HeaderBytes.Length + content.Length];

            HTTPServer.HTTPContext.WriteToResponseStream(HeaderBytes, 0, HeaderBytes.Length);
            HTTPServer.HTTPContext.WriteToResponseStream(content, 0, content.Length);

            //Array.Copy(HeaderBytes, Response, HeaderBytes.Length);
            //Array.Copy(content, 0, Response, HeaderBytes.Length, content.Length);

            //HTTPServer.HTTPContext.WriteToResponseStream(Response, 0, Response.Length);
        }
开发者ID:TheByte,项目名称:sones,代码行数:44,代码来源:GraphDSWebDAV_Service.cs

示例3: DoLOCK

        public void DoLOCK(string destination)
        {
            var content = new Byte[0];
            var body = HTTPServer.HTTPContext.RequestBody;
            var header = HTTPServer.HTTPContext.RequestHeader;
            HTTPHeader respHeader = null;

            if (RessourceLock.RessourceIsLocked(header.Destination))
            {
                respHeader = CreateHeader(HTTPStatusCodes.Locked, 0, new ContentType(MediaTypeNames.Text.Plain + "; charset=utf-8"));
            }
            else
            {

                // A successful lock request to an unmapped URL MUST result in the creation of a locked (non-collection)
                // resource with empty content
                if (_AGraphDSSharp.ObjectStreamExists(ObjectLocation.ParseString(header.Destination), FSConstants.FILESTREAM).Value != Trinary.TRUE)
                    _AGraphDSSharp.StoreFSObject(new FileObject() { ObjectLocation = ObjectLocation.ParseString(header.Destination), ObjectData = new Byte[0] }, true);

                //sones.Graph.Lib.Networking
                content = CreateLockResponse(header, body, header.GetDepth());

                respHeader = CreateHeader(HTTPStatusCodes.OK, content.ULongLength(), new ContentType(MediaTypeNames.Text.Plain + "; charset=utf-8"));

            }

            Byte[] HeaderBytes = respHeader.ToBytes();
            HTTPServer.HTTPContext.WriteToResponseStream(HeaderBytes, 0, HeaderBytes.Length);
            HTTPServer.HTTPContext.WriteToResponseStream(content, 0, content.Length);
        }
开发者ID:TheByte,项目名称:sones,代码行数:30,代码来源:GraphDSWebDAV_Service.cs

示例4: DoMKCOL

        public void DoMKCOL(string destination)
        {
            var content = new Byte[0];
            var _Body = HTTPServer.HTTPContext.RequestBody;
            var header = HTTPServer.HTTPContext.RequestHeader;
            HTTPHeader respHeader = null;

            var destinationObjectStreamTypes = GetDestinationObjectStreamTypes(header);

            if (header.HttpStatusCode != HTTPStatusCodes.OK)
            {
                respHeader = CreateHeader(HTTPStatusCodes.NotImplemented, 0);
            }

            #region MKCOL - Create Directory

            if (_AGraphDSSharp.isIDirectoryObject(ObjectLocation.ParseString(header.Destination)).Value != Trinary.TRUE)
            {

                var _CreateDirectoryExceptional = _AGraphDSSharp.CreateDirectoryObject(ObjectLocation.ParseString(header.Destination));

                if (_CreateDirectoryExceptional == null || _CreateDirectoryExceptional.Failed())
                {
                    respHeader = CreateHeader(HTTPStatusCodes.FailedDependency, content.ULongLength(), new ContentType(MediaTypeNames.Text.Plain + "; charset=utf-8"));
                }

                else
                {
                    respHeader = CreateHeader(HTTPStatusCodes.Created, content.ULongLength(), new ContentType(MediaTypeNames.Text.Plain + "; charset=utf-8"));
                    respHeader.Headers.Add("Location", header.FullHTTPDestinationPath());
                }

            }
            else
            {
                respHeader = CreateHeader(HTTPStatusCodes.PreconditionFailed, content.ULongLength(), new ContentType(MediaTypeNames.Text.Plain + "; charset=utf-8"));
            }

            #endregion

            Byte[] HeaderBytes = respHeader.ToBytes();

            //Byte[] Response = new Byte[HeaderBytes.Length + content.Length];

            HTTPServer.HTTPContext.WriteToResponseStream(HeaderBytes, 0, HeaderBytes.Length);
            HTTPServer.HTTPContext.WriteToResponseStream(content, 0, content.Length);
        }
开发者ID:TheByte,项目名称:sones,代码行数:47,代码来源:GraphDSWebDAV_Service.cs

示例5: FormatStorage

        /// <summary>
        /// Creates a new FileStorage
        /// </summary>
        /// <param name="myStorage">The location of the image file, e.g. file://myFileStorage.fs</param>
        /// <param name="myNumberOfBytes">The initial size of the image file in byte.</param>
        /// <param name="myBufferSize">The size of the internal buffer during formating the image file.</param>
        /// <param name="myOverwriteExistingFilesystem">Delete an existing image file?</param>
        /// <param name="myAction">An action called to indicate to progress on formating the image file.</param>
        /// <returns>true for success</returns>
        public override Boolean FormatStorage(String myStorageLocation, UInt64 myNumberOfBytes, UInt32 myBufferSize, Boolean myAllowOverwrite, Action<Double> myAction)
        {
            lock (this)
            {

                if (_FileStream == null)
                {

                    #region Sanity Checks

                        _StorageLocation   = myStorageLocation;
                    var _ImageFileLocation = GetImageFileLocation(myStorageLocation);

                    // Check if the image file already exists!
                    if (File.Exists(_ImageFileLocation))
                    {

                        if (!myAllowOverwrite)
                            throw new StorageEngineException("FileStorage \"" + _StorageLocation + "\" already exists!");

                        File.Delete(_ImageFileLocation);

                    }

                    #endregion

                    #region Open image file

                    try
                    {

                        _FileStream = new FileStream(_ImageFileLocation, FileMode.Create);

                        // Set the overall size of the file
                        //newFile.SetLength((Int64)myNumberOfBytes);

                    }
                    catch (Exception e)
                    {
                        throw new StorageEngineException(e.Message);
                    }

                    #endregion

                    #region Format image file

                    // Initialize the buffer with 0xAA
                    var _buffer = new Byte[myBufferSize];

                    for (var i = 0UL; i < _buffer.ULongLength(); i++)
                    {
                        _buffer[i] = 0xAA;
                    }

                    UInt64 _NumberOfBlocks = 0;
                    UInt64 _RemainingBytes = 0;
                    if (myBufferSize != 0)
                    {
                        _NumberOfBlocks = myNumberOfBytes / (UInt64)myBufferSize;
                        _RemainingBytes = myNumberOfBytes % (UInt64) myBufferSize;
                    }

                    try
                    {

                        for (var i = 0UL; i < _NumberOfBlocks; i++)
                        {

                            _FileStream.Write(_buffer, 0, (Int32)myBufferSize);

                            if (myAction != null)
                                myAction(100 * i / _NumberOfBlocks);

                        }

                        _FileStream.Write(_buffer, 0, (Int32) _RemainingBytes);

                    }
                    catch (Exception e)
                    {
                        throw new StorageEngineException(e.Message);
                    }

                    #endregion

                    #region Close image file

                    _FileStream.Close();
                    _FileStream = null;

                    #endregion
//.........这里部分代码省略.........
开发者ID:TheByte,项目名称:sones,代码行数:101,代码来源:FileStorage.cs

示例6: DoHEAD

        public void DoHEAD(string destination)
        {
            var content = new Byte[0];
            var body = HTTPServer.HTTPContext.RequestBody;
            var header = HTTPServer.HTTPContext.RequestHeader;
            HTTPHeader respHeader = null;

            #region HEAD - is a GET without a body

            var destinationObjectStreamTypes = GetDestinationObjectStreamTypes(header);
            if (destinationObjectStreamTypes == null)
            {
                respHeader = CreateHeader(HTTPStatusCodes.NotFound, 0);
            }
            if (destinationObjectStreamTypes.Contains(FSConstants.INLINEDATA))
            {
                respHeader = CreateHeader(HTTPStatusCodes.OK, content.ULongLength(), new ContentType(MediaTypeNames.Application.Octet));
            }
            else if (destinationObjectStreamTypes.Contains(FSConstants.FILESTREAM))
            {
                respHeader = CreateHeader(HTTPStatusCodes.OK, content.ULongLength(), new ContentType(MediaTypeNames.Application.Octet));
            }

            #endregion

            Byte[] HeaderBytes = respHeader.ToBytes();
            HTTPServer.HTTPContext.WriteToResponseStream(HeaderBytes, 0, HeaderBytes.Length);
            HTTPServer.HTTPContext.WriteToResponseStream(content, 0, content.Length);
        }
开发者ID:TheByte,项目名称:sones,代码行数:29,代码来源:GraphDSWebDAV_Service.cs

示例7: WriteExtents

        public override Boolean WriteExtents(Byte[] myByteArray, ObjectExtentsList myObjectExtentsList)
        {
            try
            {
                UInt64 copyLength;
                Byte[] byteArray = null;
                UInt64 myByteArrayLength = myByteArray.ULongLength();

                foreach (var _ObjectExtent in myObjectExtentsList)
                {
                    byteArray = new Byte[_ObjectExtent.Length];

                    copyLength = _ObjectExtent.Length;
                    if (_ObjectExtent.LogicalPosition + copyLength > myByteArrayLength)
                    {
                        copyLength = (myByteArrayLength - _ObjectExtent.LogicalPosition);
                    }

                    Array.Copy(myByteArray, (Int32)_ObjectExtent.LogicalPosition, byteArray, 0, (Int32)copyLength);

                    //do the writing
                    WritePosition(byteArray, _ObjectExtent.PhysicalPosition);

                }
                return true;
            }
            catch
            {
                return false;
            }
        }
开发者ID:ipbi,项目名称:sones,代码行数:31,代码来源:MemoryMappedFileStorage.cs

示例8: DoUNLOCK

        public void DoUNLOCK(string destination)
        {
            var content = new Byte[0];
            var body = HTTPServer.HTTPContext.RequestBody;
            var header = HTTPServer.HTTPContext.RequestHeader;
            HTTPHeader respHeader = null;

            if (header.Headers["Lock-Token"] != null)
            {

                String LockToken = RessourceLock.ParseToken(header.Headers["Lock-Token"]);
                if (RessourceLock.Contains(LockToken))
                {
                    RessourceLock.UnLockRessource(LockToken);

                    respHeader = CreateHeader(HTTPStatusCodes.OK, content.ULongLength(), new ContentType(MediaTypeNames.Text.Plain + "; charset=utf-8"));
                }
                else
                {
                    respHeader = CreateHeader(HTTPStatusCodes.PreconditionFailed, content.ULongLength(), new ContentType(MediaTypeNames.Text.Plain + "; charset=utf-8"));
                }

            }

            Byte[] HeaderBytes = respHeader.ToBytes();
            HTTPServer.HTTPContext.WriteToResponseStream(HeaderBytes, 0, HeaderBytes.Length);
            HTTPServer.HTTPContext.WriteToResponseStream(content, 0, content.Length);
        }
开发者ID:TheByte,项目名称:sones,代码行数:28,代码来源:GraphDSWebDAV_Service.cs

示例9: QueueEntry

        /// <summary>
        /// Creates an QueueEntry for storing all kinds of filesystem structures and objects.
        /// </summary>
        /// <param name="myObjectLocator">The object locator</param>
        /// <param name="myObjectStream">The ObjectStream (stream ID and Type) of the object (will be used to find the right streams)</param>
        /// <param name="myObjectEdition">the Name of the object edition</param>
        /// <param name="myObjectRevision">the requested metatdata object revision timestamp</param>
        /// <param name="mySerializedObject">the serialized data of the object</param>
        public QueueEntry(Byte[] mySerializedObject, ObjectExtentsList myExtentsList)
        {
            _DataLength       = mySerializedObject.ULongLength();
            _Data             = mySerializedObject;
            _RWQueueStreams   = new List<ObjectExtent>();
            _FlushAfterWrite  = false;

            if (_DataLength > myExtentsList.StreamLength)
                throw new Exception("[QueueEntry] The ObjectSize given in the ObjectStream is smaller than the size of the given data!");

            // Add this ObjectStream to the list of streams
            foreach (var _ObjectExtents in myExtentsList)
                _RWQueueStreams.Add(_ObjectExtents);
        }
开发者ID:TheByte,项目名称:sones,代码行数:22,代码来源:QueueEntry.cs

示例10: WritePositions

        public override Boolean WritePositions(Byte[] myByteArray, IEnumerable<UInt64> myPhysicalPositions)
        {
            try
            {

                var _ListOfExtendedPositions = new List<ExtendedPosition>();

                foreach (var _PhysicalPosition in myPhysicalPositions)
                {
                    _ByteCache.Cache(_PhysicalPosition, myByteArray);
                    _ListOfExtendedPositions.Add(new ExtendedPosition(_PhysicalPosition));
                }

                _WriteQueue.Write(new QueueEntry(myByteArray, _ListOfExtendedPositions, myByteArray.ULongLength()));

            }
            catch (Exception e)
            {

                var _Positions = "";

                foreach (var _PhysicalPosition in myPhysicalPositions)
                    _Positions = _PhysicalPosition + ", ";

                _Positions = _Positions.Remove(_Positions.Length - 2, 2);

                throw new FileStorageException("Error writing " + myByteArray.ULongLength() + " bytes at positions " + _Positions + "! " + e.Message);

            }

            return true;
        }
开发者ID:TheByte,项目名称:sones,代码行数:32,代码来源:FileStorage.cs

示例11: WritePosition

        public override Boolean WritePosition(Byte[] myByteArray, UInt64 myPhysicalPosition)
        {
            try
            {

                _ByteCache.Cache(myPhysicalPosition, myByteArray);
                _WriteQueue.Write(new QueueEntry(myByteArray, new List<ExtendedPosition> { new ExtendedPosition(myPhysicalPosition) }, myByteArray.ULongLength()));

            }
            catch (Exception e)
            {
                throw new FileStorageException("Error writing " + myByteArray.ULongLength() + " bytes at position " + myPhysicalPosition + "! " + e.Message);
            }

            return true;
        }
开发者ID:TheByte,项目名称:sones,代码行数:16,代码来源:FileStorage.cs

示例12: WriteExtents

        public override Boolean WriteExtents(Byte[] myByteArray, ObjectExtentsList myObjectExtentsList)
        {
            try
            {

                UInt64 _CopyLength;
                Byte[] _ByteArray = null;
                UInt64 _myByteArrayLength = myByteArray.ULongLength();

                foreach (var _ObjectExtent in myObjectExtentsList)
                {

                    _ByteArray = new Byte[_ObjectExtent.Length];

                    _CopyLength = _ObjectExtent.Length;
                    if (_ObjectExtent.LogicalPosition + _CopyLength > _myByteArrayLength)
                        _CopyLength = (_myByteArrayLength - _ObjectExtent.LogicalPosition);

                    Array.Copy(myByteArray, (Int32)_ObjectExtent.LogicalPosition, _ByteArray, 0, (Int32)_CopyLength);

                    _ByteCache.Cache(_ObjectExtent.PhysicalPosition, _ByteArray);
                    _WriteQueue.Write(new QueueEntry(myByteArray, myObjectExtentsList));

                }

                return true;

            }

            catch (Exception e)
            {
                throw new FileStorageException("Error writing " + myByteArray.ULongLength() + " bytes using extents " + myObjectExtentsList.ToString() + "! " + e.Message);
            }
        }
开发者ID:TheByte,项目名称:sones,代码行数:34,代码来源:FileStorage.cs

示例13: DoPROPPATCH

        public void DoPROPPATCH(string destination)
        {
            var content = new Byte[0];
            var body = HTTPServer.HTTPContext.RequestBody;
            var header = HTTPServer.HTTPContext.RequestHeader;
            HTTPHeader respHeader = null;

            #region PROPPATCH

            #region PROPPATCH with an previous LOCK (from file creation)

            if (header.Headers["If"] != null)
            {
                String IfCondition = header.Headers["If"];
                if (IfCondition.Contains("opaquelocktoken"))
                {
                    String LockToken = RessourceLock.ParseToken(IfCondition);
                    if (RessourceLock.Contains(LockToken))
                    {

                        //TODO: Parse FileAttributes and save them
                        content = CreateProppatchResponse(header, "Win32FileAttributes", "Win32LastModifiedTime", "Win32CreationTime", "Win32LastAccessTime");

                        respHeader = CreateHeader(HTTPStatusCodes.MultiStatus, content.ULongLength(), new ContentType(MediaTypeNames.Text.Xml + "; charset=utf-8"));

                    }
                    else
                    {

                        respHeader = CreateHeader(HTTPStatusCodes.PreconditionFailed, content.ULongLength(), new ContentType(MediaTypeNames.Text.Plain + "; charset=utf-8"));

                    }
                }
                else
                {

                    respHeader = CreateHeader(HTTPStatusCodes.PreconditionFailed, content.ULongLength(), new ContentType(MediaTypeNames.Text.Plain + "; charset=utf-8"));

                }
            }

            #endregion

            #region PROPPATCH without an previous LOCK (from directory creation)

            else
            {

                //TODO: Parse FileAttributes and save them
                content = CreateProppatchResponse(header, "Win32FileAttributes", "Win32LastModifiedTime", "Win32CreationTime", "Win32LastAccessTime");

                respHeader = CreateHeader(HTTPStatusCodes.MultiStatus, content.ULongLength(), new ContentType(MediaTypeNames.Text.Xml + "; charset=utf-8"));

            }

            #endregion

            #endregion PROPPATCH

            Byte[] HeaderBytes = respHeader.ToBytes();
            HTTPServer.HTTPContext.WriteToResponseStream(HeaderBytes, 0, HeaderBytes.Length);
            HTTPServer.HTTPContext.WriteToResponseStream(content, 0, content.Length);
        }
开发者ID:TheByte,项目名称:sones,代码行数:63,代码来源:GraphDSWebDAV_Service.cs

示例14: DoDELETE

        public void DoDELETE(string destination)
        {
            var content = new Byte[0];
            var _Body = HTTPServer.HTTPContext.RequestBody;
            var header = HTTPServer.HTTPContext.RequestHeader;
            HTTPHeader respHeader = null;

            if (_AGraphDSSharp.ObjectExists(ObjectLocation.ParseString(header.Destination)).Value == Trinary.TRUE)
            {
                var isDir = _AGraphDSSharp.isIDirectoryObject(ObjectLocation.ParseString(header.Destination));
                if (isDir.Success() && isDir.Value == Trinary.TRUE)
                {
                    _AGraphDSSharp.RemoveDirectoryObject(ObjectLocation.ParseString(header.Destination), true);
                    respHeader = CreateHeader(HTTPStatusCodes.NoContent, content.ULongLength());
                }
                else
                {

                    var isFile = _AGraphDSSharp.ObjectStreamExists(ObjectLocation.ParseString(header.Destination), FSConstants.FILESTREAM);
                    if (isFile.Success() && isFile.Value == Trinary.TRUE)
                    {
                        _AGraphDSSharp.RemoveFSObject(ObjectLocation.ParseString(header.Destination), FSConstants.FILESTREAM, null, null);
                        respHeader = CreateHeader(HTTPStatusCodes.NoContent, content.ULongLength());
                    }
                    else
                    {
                        #region NotImplemented
                        respHeader = CreateHeader(HTTPStatusCodes.NotImplemented, content.ULongLength(), new ContentType(MediaTypeNames.Text.Plain + "; charset=utf-8"));
                        #endregion
                    }
                }
            }
            else
            {
                respHeader = CreateHeader(HTTPStatusCodes.PreconditionFailed, content.ULongLength(), new ContentType(MediaTypeNames.Text.Plain + "; charset=utf-8"));
            }

            Byte[] HeaderBytes = respHeader.ToBytes();
            HTTPServer.HTTPContext.WriteToResponseStream(HeaderBytes, 0, HeaderBytes.Length);
            HTTPServer.HTTPContext.WriteToResponseStream(content, 0, content.Length);
        }
开发者ID:TheByte,项目名称:sones,代码行数:41,代码来源:GraphDSWebDAV_Service.cs

示例15: DoPUT

        public void DoPUT(string destination)
        {
            var content = new Byte[0];
            var _Body = HTTPServer.HTTPContext.RequestBody;
            var header = HTTPServer.HTTPContext.RequestHeader;
            HTTPHeader respHeader = null;

            #region Second PUT request containing the Data - the Header contains an If condition with the LockToken

            if (header.Headers["If"] != null)
            {

                String LockToken = RessourceLock.ParseToken(header.Headers["If"]);

                if (RessourceLock.Contains(LockToken))
                {

                    try
                    {

                        _AGraphDSSharp.StoreFSObject(new FileObject() { ObjectLocation = ObjectLocation.ParseString(header.Destination), ObjectData = _Body }, true);

                    }
                    catch (Exception Ex)
                    {
                        Console.WriteLine(Ex);
                        throw Ex;
                    }

                    respHeader = CreateHeader(HTTPStatusCodes.OK, content.ULongLength(), new ContentType(MediaTypeNames.Text.Plain + "; charset=utf-8"));
                    respHeader.Headers.Add("Lock-Token", String.Concat("opaquelocktoken:", LockToken, TimestampNonce.AsString(S_DATETIME_FORMAT)));

                }
                else
                {

                    respHeader = CreateHeader(HTTPStatusCodes.PreconditionFailed, content.ULongLength(), new ContentType(MediaTypeNames.Text.Plain + "; charset=utf-8"));

                }

                //if (HeaderInfos["Lock-Token"].Split(new char[]{))

            }

            #endregion

            else

            #region First PUT request - just create an empty FILESTREAM ressource

            {
                Exceptional<Trinary> FileExists = null;
                try
                {
                    FileExists = _AGraphDSSharp.ObjectStreamExists(ObjectLocation.ParseString(header.Destination), FSConstants.FILESTREAM);
                }
                catch (GraphFSException_ObjectNotFound)
                {
                    //_Logger.ErrorException(Header.Destination, E);
                    respHeader = CreateHeader(HTTPStatusCodes.Conflict, content.ULongLength(), new ContentType(MediaTypeNames.Text.Plain + "; charset=utf-8"));
                }

                if (FileExists.Success() && FileExists.Value != Trinary.TRUE)
                {

                    #region Store file

                    try
                    {

                        _AGraphDSSharp.StoreFSObject(new FileObject() { ObjectLocation = ObjectLocation.ParseString(header.Destination), ObjectData = _Body }, true);

                    }
                    catch (Exception Ex)
                    {
                        Console.WriteLine(Ex);
                        throw Ex;
                    }

                    // This is just a dummy LockToken
                    String LockToken = RessourceLock.CreateLockToken();
                    //RessourceLock.LockRessource(LockToken, _Destination);

                    respHeader = CreateHeader(HTTPStatusCodes.Created, content.ULongLength(), new ContentType(MediaTypeNames.Text.Plain + "; charset=utf-8"));
                    respHeader.Headers.Add("Location", header.FullHTTPDestinationPath());
                    respHeader.Headers.Add("Lock-Token", String.Concat("opaquelocktoken:", LockToken, TimestampNonce.AsString(S_DATETIME_FORMAT)));

                    #endregion

                }
                else
                {

                    #region The PUT request neither contains the If condition nor the file is new and does not exist

                    respHeader = CreateHeader(HTTPStatusCodes.PreconditionFailed, content.ULongLength(), new ContentType(MediaTypeNames.Text.Plain + "; charset=utf-8"));

                    #endregion

                }
//.........这里部分代码省略.........
开发者ID:TheByte,项目名称:sones,代码行数:101,代码来源:GraphDSWebDAV_Service.cs


注:本文中的System.Byte.ULongLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。