コード例 #1
0
        protected String GetLocalDestinationFilePathFromRequest(
            HttpRequest request,
            LocalRepositoryState repoState)
        {
            String escapedDestRepoPathString =
                request.Headers[RemoteRepositoryProxy.DestinationPathHeaderName];

            String destRepoPathString =
                System.Uri.UnescapeDataString(escapedDestRepoPathString);

            // Remove the leading './' from the relative path
            destRepoPathString =
                destRepoPathString.Substring(2, destRepoPathString.Length - 2);

            string[] pathParts = destRepoPathString.Split(new char[] { '/' });

            String filePath = repoState.RootDirectory.FullName;

            for (int i = 0; i < pathParts.Length; i++)
            {
                filePath = Path.Combine(filePath, pathParts[i]);
            }

            return(filePath);
        }
コード例 #2
0
        protected void HandleDeleteRequest(
            HttpClientContext context,
            HttpRequest request)
        {
            try
            {
                LocalRepositoryState repoState = GetRepositoryFromRequest(request);

                // TODO: Authenticate based on request address

                String filePath = GetLocalFilePathFromRequest(request);
                File.Delete(filePath);

                HttpResponse response = (HttpResponse)request.CreateResponse(context);
                response.ContentType = "application/octet-stream";

                lock (repoState.Manifest)
                {
                    ManifestFileInfo manFileInfo =
                        GetOrMakeManifestFileInfoFromRequest(
                            repoState.Manifest,
                            request,
                            false);

                    if (manFileInfo == null)
                    {
                        throw new Exception(
                                  "File not registered:  " +
                                  filePath);
                    }

                    manFileInfo.ParentDirectory.Files.Remove(
                        manFileInfo.Name);

                    repoState.SetManifestChanged();
                }

                context.Respond(
                    "HTTP/1.0",
                    HttpStatusCode.OK,
                    "File accepted",
                    "",
                    "text/plain");
            }
            catch (Exception ex)
            {
                context.Respond(
                    "HTTP/1.0",
                    HttpStatusCode.InternalServerError,
                    "Internal server error",
                    ex.ToString(),
                    "text/plain");
            }
        }
コード例 #3
0
        protected void HandleSetFileInfoRequest(
            HttpClientContext context,
            HttpRequest request)
        {
            try
            {
                LocalRepositoryState repoState = GetRepositoryFromRequest(request);

                // TODO: Authenticate based on request address
                // ...delete temp file if not authenticated...
                // Better to authenticate when the headers are received...

                String   newFilePath = GetLocalFilePathFromRequest(request);
                FileInfo newFile     = new FileInfo(newFilePath);

                lock (repoState.Manifest)
                {
                    ManifestFileInfo manFileInfo =
                        GetOrMakeManifestFileInfoFromRequest(
                            repoState.Manifest,
                            request,
                            false);

                    SetManifestFileInfo(manFileInfo, request, newFile);

                    newFile.LastWriteTimeUtc =
                        manFileInfo.LastModifiedUtc;

                    repoState.SetManifestChanged();
                }

                context.Respond(
                    "HTTP/1.0",
                    HttpStatusCode.OK,
                    "Info accepted",
                    "",
                    "text/plain");
            }
            catch (Exception ex)
            {
                context.Respond(
                    "HTTP/1.0",
                    HttpStatusCode.InternalServerError,
                    "Internal server error",
                    ex.ToString(),
                    "text/plain");

                System.Console.WriteLine(ex.ToString());
            }
        }
コード例 #4
0
        protected String GetTempFilePathFromRequest(HttpRequest request)
        {
            Guid manifestGuid = GetRepositoryGuidFromRequest(request);
            LocalRepositoryState repoState = GetRepositoryFromGuid(manifestGuid);

            // TODO: Authenticate based on request address

            string[] fileHashParts =
                request.Headers[RemoteRepositoryProxy.FileHashHeaderName].Split(
                    new char[] { ':' });

            string tempFilePath = Path.Combine(
                repoState.TempDirectory.FullName,
                fileHashParts[1]);

            return(tempFilePath);
        }
コード例 #5
0
        protected void HandleSetManifestInfoRequest(
            HttpClientContext context,
            HttpRequest request)
        {
            try
            {
                LocalRepositoryState repoState = GetRepositoryFromRequest(request);

                // TODO: Authenticate based on request address
                // ...delete temp file if not authenticated...
                // Better to authenticate when the headers are received...

                Stream infoStream = request.Body;
                infoStream.Seek(0, SeekOrigin.Begin);

                Manifest dummyManifest =
                    Manifest.ReadManifestStream(infoStream);

                lock (repoState.Manifest)
                {
                    repoState.Manifest.CopyManifestInfoFrom(dummyManifest);
                    repoState.SetManifestChanged();
                }

                context.Respond(
                    "HTTP/1.0",
                    HttpStatusCode.OK,
                    "Info accepted",
                    "",
                    "text/plain");
            }
            catch (Exception ex)
            {
                // TODO: Make this a method
                context.Respond(
                    "HTTP/1.0",
                    HttpStatusCode.InternalServerError,
                    "Internal server error",
                    ex.ToString(),
                    "text/plain");

                System.Console.WriteLine(ex.ToString());
            }
        }
コード例 #6
0
        protected void HandleCopyOrMoveRequest(
            HttpClientContext context,
            HttpRequest request)
        {
            try
            {
                LocalRepositoryState repoState = GetRepositoryFromRequest(request);

                // TODO: Authenticate based on request address

                FileInfo sourceFileInfo =
                    new FileInfo(GetLocalFilePathFromRequest(request));

                String destFilePath =
                    GetLocalDestinationFilePathFromRequest(request, repoState);

                String destDirPath =
                    Path.GetDirectoryName(destFilePath);

                if (Directory.Exists(destDirPath) == false)
                {
                    Directory.CreateDirectory(destDirPath);
                }

                if (request.Method == "MOVE")
                {
                    sourceFileInfo.MoveTo(destFilePath);
                }
                else
                {
                    // Must be copy
                    sourceFileInfo.CopyTo(destFilePath);
                }

                FileInfo destFile = new FileInfo(destFilePath);
                SetFileInfoFromRequest(destFile, request);

                lock (repoState.Manifest)
                {
                    if (request.Method == "MOVE")
                    {
                        ManifestFileInfo removeFileInfo =
                            GetOrMakeManifestFileInfoFromRequest(
                                repoState.Manifest,
                                request,
                                false);

                        if (removeFileInfo != null)
                        {
                            // If this is ever null, something weird is happening
                            // but we already copied the file so might as well
                            // proceed.
                            removeFileInfo.ParentDirectory.Files.Remove(
                                removeFileInfo.Name);
                        }
                    }

                    ManifestFileInfo manFileInfo =
                        GetOrMakeDestinationManifestFileInfoFromRequest(
                            repoState.Manifest,
                            request);

                    SetManifestFileInfo(manFileInfo, request, destFile);

                    repoState.SetManifestChanged();
                }

                context.Respond(
                    "HTTP/1.0",
                    HttpStatusCode.OK,
                    "File accepted",
                    "",
                    "text/plain");
            }
            catch (Exception ex)
            {
                context.Respond(
                    "HTTP/1.0",
                    HttpStatusCode.InternalServerError,
                    "Internal server error",
                    ex.ToString(),
                    "text/plain");

                System.Console.WriteLine(ex.ToString());
            }
        }
コード例 #7
0
        protected void HandlePutRequest(
            HttpClientContext context,
            HttpRequest request)
        {
            try
            {
                // Close the file
                request.Body.Close();

                LocalRepositoryState repoState = GetRepositoryFromRequest(request);

                // TODO: Authenticate based on request address
                // ...delete temp file if not authenticated...
                // Better to authenticate when the headers are received...

                string   tempFilePath = GetTempFilePathFromRequest(request);
                FileInfo tempFile     = new FileInfo(tempFilePath);

                String newFilePath   = GetLocalFilePathFromRequest(request);
                String directoryPath = Path.GetDirectoryName(newFilePath);

                try
                {
                    if (Directory.Exists(directoryPath) == false)
                    {
                        Directory.CreateDirectory(directoryPath);
                    }

                    if (File.Exists(newFilePath))
                    {
                        File.Delete(newFilePath);
                    }

                    SetFileInfoFromRequest(tempFile, request);

                    tempFile.MoveTo(newFilePath);
                }
                catch (Exception ex)
                {
                    tempFile.Delete();
                    throw ex;
                }

                FileInfo newFile = new FileInfo(newFilePath);

                lock (repoState.Manifest)
                {
                    ManifestFileInfo manFileInfo =
                        GetOrMakeManifestFileInfoFromRequest(
                            repoState.Manifest,
                            request);

                    SetManifestFileInfo(manFileInfo, request, newFile);

                    repoState.SetManifestChanged();
                }

                context.Respond(
                    "HTTP/1.0",
                    HttpStatusCode.OK,
                    "File accepted",
                    "",
                    "text/plain");
            }
            catch (Exception ex)
            {
                context.Respond(
                    "HTTP/1.0",
                    HttpStatusCode.InternalServerError,
                    "Internal server error",
                    ex.ToString(),
                    "text/plain");

                System.Console.WriteLine(ex.ToString());
            }
        }