Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        /// <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

                    return true;

                }

                return false;

            }
        }
Пример #6
0
        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);
        }
Пример #7
0
        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;
            }
        }
Пример #8
0
        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);
        }
Пример #9
0
        /// <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);
        }
Пример #10
0
        /// <summary>
        /// Creates an QueueEntry for storing some bytes at a single position
        /// </summary>
        /// <param name="myPosition">a single position of the data wihtin the filesystem</param>
        /// <param name="myPaddedLength">some bytes for padding</param>
        /// <param name="mySerializedData">the data</param>
        public QueueEntry(Byte[] myData, UInt64 myPosition, UInt64 myPaddedLength)
        {
            //ObjectDatastream myObjectStream;
            //ObjectExtent _ObjectExtent;

            _Data                           = myData;
            _DataLength                     = myData.ULongLength();
            _RWQueueStreams                 = new List<ObjectExtent>();
            _FlushAfterWrite                = false;

            var _ObjectExtent               = new ObjectExtent();
            _ObjectExtent.LogicalPosition   = 0;
            _ObjectExtent.StorageUUID       = new StorageUUID(1UL);
            _ObjectExtent.PhysicalPosition  = myPosition;
            _ObjectExtent.Length            = _DataLength;

            //myObjectStream                   = new ObjectDatastream();
            //myObjectStream.StreamLength      = _DataLength;
            //myObjectStream.ReservedLength    = myPaddedLength - _DataLength;
            //myObjectStream.Add(myObjectExtent);

            _RWQueueStreams.Add(_ObjectExtent);
        }
Пример #11
0
        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;
        }
Пример #12
0
        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;
        }
Пример #13
0
        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);
            }
        }
Пример #14
0
        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);
        }
Пример #15
0
        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);
        }
Пример #16
0
        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

                }

            }

            #endregion

            Byte[] HeaderBytes = respHeader.ToBytes();
            HTTPServer.HTTPContext.WriteToResponseStream(HeaderBytes, 0, HeaderBytes.Length);
            HTTPServer.HTTPContext.WriteToResponseStream(content, 0, content.Length);
        }
Пример #17
0
        public void DoGET(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 (_DestinationObjectStreamTypes == null)
            {
                respHeader = CreateHeader(HTTPStatusCodes.NotFound, 0);
            }

            else if (_DestinationObjectStreamTypes.Contains(FSConstants.INLINEDATA))
            {
                content = CreateGetInlineDataResponse(DirectoryHelper.GetObjectPath(header.Destination), DirectoryHelper.GetObjectName(header.Destination));

                respHeader = CreateHeader(HTTPStatusCodes.OK, content.ULongLength(), new ContentType(MediaTypeNames.Application.Octet));
            }

            else if (_DestinationObjectStreamTypes.Contains(FSConstants.FILESTREAM))
            {
                content = CreateGetFileResponse(header);

                respHeader = CreateHeader(HTTPStatusCodes.OK, content.ULongLength(), new ContentType(MediaTypeNames.Application.Octet));
            }

            else
            {
                respHeader = CreateHeader(HTTPStatusCodes.BadRequest, content.ULongLength(), new ContentType(MediaTypeNames.Application.Octet));
            }

            Byte[] HeaderBytes = respHeader.ToBytes();
            HTTPServer.HTTPContext.WriteToResponseStream(HeaderBytes, 0, HeaderBytes.Length);
            HTTPServer.HTTPContext.WriteToResponseStream(content, 0, content.Length);
        }
Пример #18
0
        public void DoCOPY(string destination)
        {
            var content = new Byte[0];
            var body = HTTPServer.HTTPContext.RequestBody;
            var header = HTTPServer.HTTPContext.RequestHeader;
            HTTPHeader respHeader = null;

            if (header.Headers["Destination"] != null)
            {
                String NewLocation = header.Headers["Destination"].Replace(header.GetFullHTTPHost(), "").Trim();
                /*
                Boolean Overwrite = false;
                if (Header.Headers["Overwrite"] != null && Header.Headers["Overwrite"] == "PT")
                    Overwrite = true;
                */
                #region Copy a Directory

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

                    if (_AGraphDSSharp.isIDirectoryObject(ObjectLocation.ParseString(NewLocation)).Value != Trinary.TRUE)
                    {
                        _AGraphDSSharp.CreateDirectoryObject(ObjectLocation.ParseString(NewLocation));

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

                    }
                    else
                    {

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

                    }
                }

                #endregion

                #region Copy a File

                else if (_AGraphDSSharp.ObjectStreamExists(ObjectLocation.ParseString(header.Destination), FSConstants.FILESTREAM).Value)
                {

                    if (_AGraphDSSharp.ObjectStreamExists(ObjectLocation.ParseString(NewLocation), FSConstants.FILESTREAM).Value != Trinary.TRUE)
                    {

                        AFSObject FileObject = _AGraphDSSharp.GetFSObject<FileObject>(ObjectLocation.ParseString(header.Destination), FSConstants.FILESTREAM, null, null, 0, false).Value;
                        FileObject.ObjectLocation = ObjectLocation.ParseString(NewLocation);
                        _AGraphDSSharp.StoreFSObject(FileObject, true);

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

                    }
                    else
                    {

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

                    }
                }

                #endregion

                else
                {

                    respHeader = CreateHeader(HTTPStatusCodes.NotFound, 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);
        }
Пример #19
0
        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);

                    _MemoryStream.Seek((Int64)_ObjectExtent.PhysicalPosition, SeekOrigin.Begin);
                    _MemoryStream.Write(_ByteArray, 0, (Int32) _ObjectExtent.Length);

                }

                return true;

            }

            catch
            {
                return false;
            }
        }