Example #1
0
 public void AdvertiseUploadPack(Stream output)
 {
     using (var repository = GetRepository()) {
         var pack = new UploadPack(repository);
         pack.sendAdvertisedRefs(new RefAdvertiser.PacketLineOutRefAdvertiser(new PacketLineOut(output)));
     }
 }
Example #2
0
 public void Upload(Stream inputStream, Stream outputStream)
 {
     using (var repository = GetRepository()) {
         using (var pack = new UploadPack(repository)) {
             pack.setBiDirectionalPipe(false);
             pack.Upload(inputStream, outputStream, outputStream);
         }
     }
 }
Example #3
0
        public async Task <IActionResult> UploadPack([FromForm] UploadPack body)
        {
            User user = _userService.UserFromContext(HttpContext);

            if (!user.Role.HasFlag(TradeSaberRole.Admin))
            {
                return(Unauthorized());
            }

            long size = body.Cover.Length;

            if (size > 15000000 || size == 0)
            {
                return(BadRequest());
            }

            List <ProbabilityDatum> probData   = Newtonsoft.Json.JsonConvert.DeserializeObject <List <ProbabilityDatum> >(body.ProbData);
            List <string>           cardData   = Newtonsoft.Json.JsonConvert.DeserializeObject <List <string> >(body.CardData);
            List <Rarity>           rarityData = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Rarity> >(body.RarityData);

            Pack pack = new Pack
            {
                Name               = body.Name,
                Description        = body.Description,
                GuaranteedCards    = cardData,
                GuaranteedRarities = rarityData,
                LockedCardPool     = probData,
                Count              = body.Count,
                Theme              = body.Theme
            };

            _cardDispatcher.Create(pack);

            var path = Path.Combine(Directory.GetCurrentDirectory(), "Images");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            try
            {
                string newPath = path + "/" + pack.Id + Path.GetExtension(body.Cover.FileName);
                using StreamReader sr = new StreamReader(body.Cover.OpenReadStream());
                using Stream stream   = System.IO.File.Create(newPath);
                await body.Cover.CopyToAsync(stream);

                pack.CoverURL = "/images/" + pack.Id + Path.GetExtension(body.Cover.FileName);;
                _cardDispatcher.Update(pack);

                return(Ok(pack));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
        public static void Upload(string path, Stream input, Stream output)
        {
            var repositoryPath = RepositoryPath.Resolve(path);

            using (var repository = new Repository(repositoryPath.AbsoluteRootPath))
            {
                var pack = new UploadPack(repository);
                pack.setBiDirectionalPipe(false);
                pack.Upload(input, output, output);
            }
        }
        public static void AdvertiseUploadPack(string path, Stream output)
        {
            var repositoryPath = RepositoryPath.Resolve(path);

            var repository =
                Directory.Exists(path)
                    ? new Repository(repositoryPath.AbsoluteRootPath)
                    : Repository.Init(repositoryPath.AbsoluteRootPath);

            using (repository)
            {
                var pack = new UploadPack(repository);

                pack.sendAdvertisedRefs(
                    new RefAdvertiser.PacketLineOutRefAdvertiser(
                        new PacketLineOut(output)));
            }
        }
Example #6
0
        private ActionResult GetInfoRefs(String project, String service)
        {
            Response.StatusCode = 200;

            Response.ContentType = String.Format("application/x-{0}-advertisement", service);
            SetNoCache();
            Response.Write(FormatMessage(String.Format("# service={0}\n", service)));
            Response.Write(FlushMessage());

            var directory = GetDirectoryInfo(project);

            if (GitSharp.Repository.IsValid(directory.FullName, true))
            {
                using (var repository = new GitSharp.Repository(directory.FullName))
                {
                    if (String.Equals("git-receive-pack", service, StringComparison.InvariantCultureIgnoreCase))
                    {
                        using (var pack = new ReceivePack(repository))
                        {
                            pack.SendAdvertisedRefs(new RefAdvertiser.PacketLineOutRefAdvertiser(new PacketLineOut(Response.OutputStream)));
                        }
                    }
                    else if (String.Equals("git-upload-pack", service, StringComparison.InvariantCultureIgnoreCase))
                    {
                        using (var pack = new UploadPack(repository))
                        {
                            pack.SendAdvertisedRefs(new RefAdvertiser.PacketLineOutRefAdvertiser(new PacketLineOut(Response.OutputStream)));
                        }
                    }
                }

                return(new EmptyResult());
            }
            else
            {
                return(new HttpNotFoundResult());
            }
        }
Example #7
0
        private ActionResult ExecuteUploadPack(string project)
        {
            Response.ContentType = "application/x-git-upload-pack-result";
            SetNoCache();

            var directory = GetDirectoryInfo(project);

            if (GitSharp.Repository.IsValid(directory.FullName, true))
            {
                using (var repository = new GitSharp.Repository(directory.FullName))
                    using (var pack = new UploadPack(repository))
                    {
                        pack.setBiDirectionalPipe(false);
                        pack.Upload(GetInputStream(), Response.OutputStream, Response.OutputStream);
                    }

                return(new EmptyResult());
            }
            else
            {
                return(new HttpNotFoundResult());
            }
        }