コード例 #1
0
        public static async System.Threading.Tasks.Task <IEnumerable <Bag> > ImportBagsAsync(DocumentClient client, IImageRepository imageUploadService, List <Thee> thees, List <Merk> meerkens)
        {
            var brands = await ImportBrandsAsync(client, meerkens);

            var countries = await ImportCountriesAsync(client, thees);

            var bagTypes = await ImportBagTypesAsync(client, thees);

            var images = await ImportImagesAsync(client, thees, imageUploadService);

            var translater = new TheeToBagTranslator(countries, brands, bagTypes, images);

            var bagsRepository = new CreateRepository <Bag>(client, DocumentDBConstants.DatabaseId, DocumentDBConstants.Collections.Bags);
            var bags           = thees.Select(thee => {
                var newBag = translater.Translate(thee);
                return(newBag);
            }).ToList();

            System.Console.WriteLine($"Attempting to insert {bags.Count()} bags out of {thees.Count()} thees");
            var insertCounter = 0;
            await bags.ToList().ForEachAsync(async bag => {
                var bagid = await bagsRepository.CreateItemAsync(bag);
                insertCounter++;
                if (insertCounter > 0 && insertCounter % 100 == 0)
                {
                    System.Console.WriteLine($"Inserted bag#: {insertCounter}");
                }
            });

            System.Console.WriteLine($"Completed inserting {insertCounter} bags");
            return(bags);
        }
コード例 #2
0
        static async System.Threading.Tasks.Task <IList <Brand> > ImportBrandsAsync(DocumentClient client, List <Merk> meerken)
        {
            var translator = new MerkToBrandTranslator();
            var brands     = meerken.Select(merk => {
                var newBrand = translator.Translate(merk);
                return(newBrand);
            }).ToList();

            var brandsRepository = new CreateRepository <Brand>(client, DocumentDBConstants.DatabaseId, DocumentDBConstants.Collections.Brands);
            var insertCounter    = 0;
            var insertedBrands   = new List <Brand>();

            foreach (var brand in brands)
            {
                var id = await brandsRepository.CreateItemAsync(brand);

                insertedBrands.Add(new Brand(id, brand.Name));
                insertCounter++;
                if (insertCounter > 0 && insertCounter % 100 == 0)
                {
                    System.Console.WriteLine($"Inserted brand#: {insertCounter}");
                }
            }

            System.Console.WriteLine($"Completed inserting {insertCounter} brands");
            return(insertedBrands);
        }
コード例 #3
0
        private static async System.Threading.Tasks.Task <List <Image> > ImportImages2Async(DocumentClient client, IEnumerable <Bag> bags, IImageRepository imageservice)
        {
            var images          = bags.Where(bag => File.Exists($"{ImageFilesystemRepository.Path}{bag.MainID}.jpg")).Select(thee => { return(new Image(null, $"{thee.MainID}.jpg", null)); }).ToList();
            var imageRepository = new CreateRepository <Image>(client, DocumentDBConstants.DatabaseId, DocumentDBConstants.Collections.Images);
            var insertCounter   = 0;
            var insertedImages  = new List <Image>();

            foreach (var image in images)
            {
                var fileImageService = new ImageFilesystemRepository();
                var uri = "";
                using (var bitmap = await fileImageService.Get(image.Filename)) {
                    using (var imageStream = new MemoryStream()) {
                        bitmap.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                        imageStream.Seek(0, SeekOrigin.Begin);
                        uri = await imageservice.Upload(imageStream, image.Filename);
                    }
                }

                var id = await imageRepository.CreateItemAsync(image);

                insertedImages.Add(new Image(id, image.Filename, uri));
                insertCounter++;
                if (insertCounter > 0 && insertCounter % 250 == 0)
                {
                    System.Console.WriteLine($"Inserted image#: {insertCounter}");
                }
            }

            System.Console.WriteLine($"Completed inserting {insertCounter} images");
            return(insertedImages);
        }
コード例 #4
0
        public static string PopulateJsonDataForNewPublicRepository(string repositoryName, String description)
        {
            CreateRepository createRepository = new CreateRepository();

            createRepository.description  = description;
            createRepository.name         = repositoryName;
            createRepository.has_issues   = true;
            createRepository.homepage     = "https://github.com";
            createRepository.has_projects = true;
            createRepository.has_wiki     = true;

            return(JsonConvert.SerializeObject(createRepository));
        }
コード例 #5
0
        public ActionResult Create()
        {
            var repo      = new CreateRepository();
            var viewmodel = repo.CreateLieu();

            var programme = GetProgramme();
            var numProg   = Convert.ToInt32(programme.First().Discipline);

            var listeOrdreDuJour = GetOrdreDuJourSelonModele(numProg);

            viewmodel.OrdreDuJour = listeOrdreDuJour.Last();

            return(View(viewmodel));
        }
コード例 #6
0
ファイル: LinkToData.cs プロジェクト: adiNeata/App
        public static void PassString(string passed)
        {
            if (Valid.ValidUsers(passed))
            {
                using (CreateRepository cr = new CreateRepository())
                {
                    cr.InsertField("Roles", passed);
                }

                MessageBox.Show("Succesful op");
            }
            else
            {
                MessageBox.Show("Enter valid user!!");
            }
        }
コード例 #7
0
        private static async System.Threading.Tasks.Task <List <BagType> > ImportBagTypesAsync(DocumentClient client, List <Thee> thees)
        {
            var bagTypes          = thees.Select(thee => thee.TheeSoortzakje.Trim()).Distinct().Where(bagType => bagType.Length > 0).Select(type => { return(new BagType(null, type)); }).ToList();
            var bagTypeRepository = new CreateRepository <BagType>(client, DocumentDBConstants.DatabaseId, DocumentDBConstants.Collections.BagTypes);
            var insertCounter     = 0;
            var insertedBagTypes  = new List <BagType>();

            foreach (var bagType in bagTypes)
            {
                var id = await bagTypeRepository.CreateItemAsync(bagType);

                insertedBagTypes.Add(new BagType(id, bagType.Name));
                insertCounter++;
            }

            System.Console.WriteLine($"Completed inserting {insertCounter} bagtypes");
            return(insertedBagTypes);
        }
コード例 #8
0
        private static async System.Threading.Tasks.Task <List <Country> > ImportCountriesAsync(DocumentClient client, List <Thee> thees)
        {
            var countries         = thees.Select(thee => thee.TheeLandvanherkomst.Trim()).Distinct().Where(country => country.Length > 0).Select(country => { return(new Country(null, country)); }).ToList();
            var countryRepository = new CreateRepository <Country>(client, DocumentDBConstants.DatabaseId, DocumentDBConstants.Collections.Countries);
            var insertCounter     = 0;
            var insertedCountries = new List <Country>();

            foreach (var country in countries)
            {
                var id = await countryRepository.CreateItemAsync(country);

                insertedCountries.Add(new Country(id, country.Name));
                insertCounter++;
            }

            System.Console.WriteLine($"Completed inserting {insertCounter} countries");
            return(insertedCountries);
        }
コード例 #9
0
        public static async Task <Repository> CreateRepository(CreateRepository createParams)
        {
            HttpClient client = GetHttpClient();

            using (client)
            {
                HttpResponseMessage response =
                    await client.PostAsJsonAsync("api/v1/repos", createParams);

                if (response.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    throw new Exception(string.Format(
                                            "API Status Code {0}. Expected OK.", response.StatusCode));
                }

                return(await response.Content.ReadAsAsync <Repository>());
            }
        }
コード例 #10
0
        static void CreateRepository()
        {
            Console.Write("Write a name for the repository: ");
            string name = Console.ReadLine();

            Console.Write("Write the direction of the server: ");
            string server = Console.ReadLine();

            CreateRepository action = new CreateRepository()
            {
                Name   = name,
                Server = server
            };

            Repository newRepo = ApiUtils.CreateRepository(action).Result;

            Console.Write(string.Format("Repository {0} successfully created!", newRepo.Name));
        }
コード例 #11
0
        public async Task <ICommandResult> ExecuteAsync(CreateCommand <TViewModel> command)
        {
            var activity = await ActivityRepository.SearchItemsAsync(x => x.Name == $"{typeof(TViewModel)}{nameof(CreateCommandHandler<CreateCommand<TViewModel>, TEntity>)}");

            if (await Authorizer.IsAuthorized(activity.FirstOrDefault()))
            {
                return(new ForbidResult());
            }

            if (command == null)
            {
                return(new ErrorResult("New item cannot be null"));
            }

            var entity = Translator.Translate(command.Data);
            var id     = await CreateRepository.CreateItemAsync(entity);

            return(new CreateResult(id));
        }
コード例 #12
0
        public async Task <ICommandResult> ExecuteAsync(TCommand command)
        {
            var activity = await ActivityRepository.SearchItemsAsync(x => x.Name == $"{typeof(TEntity)}{nameof(CreateOwnedCommandHandler<TCommand, TEntity>)}");

            if (await Authorizer.IsAuthorized(activity.FirstOrDefault()))
            {
                return(new ForbidResult());
            }

            if (command == null)
            {
                return(new ErrorResult("New item cannot be null"));
            }

            var entity = Translator.Translate(command);

            entity.OwnerId = ApplicationUser.Id;
            var id = await CreateRepository.CreateItemAsync(entity);

            return(new CreateResult(id));
        }
コード例 #13
0
        private static async System.Threading.Tasks.Task <string> ImportImageAsync(DocumentClient client, Thee thee, IImageRepository imageservice)
        {
            if (File.Exists($"{ImageFilesystemRepository.Path}{thee.MainID}.jpg") == false)
            {
                return(null);
            }

            var image            = new Image(null, $"{thee.MainID}.jpg", null);
            var fileImageService = new ImageFilesystemRepository();
            var uri = "";

            using (var bitmap = await fileImageService.Get(image.Filename)) {
                using (var imageStream = new MemoryStream()) {
                    bitmap.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                    imageStream.Seek(0, SeekOrigin.Begin);
                    uri = await imageservice.Upload(imageStream, image.Filename);
                }
            }

            var imageRepository = new CreateRepository <Image>(client, DocumentDBConstants.DatabaseId, DocumentDBConstants.Collections.Images);

            return(await imageRepository.CreateItemAsync(image));
        }
コード例 #14
0
 public void get_employees_list_test()
 {
     CreateRepository repo = new CreateRepository();
 }
コード例 #15
0
 /// <summary>
 /// Insert a list of objects into the database as Bulk.
 /// </summary>
 /// <param name="entityList"></param>
 public async Task <bool> BulkInsert(List <T> entityList)
 {
     return(await CreateRepository.Insert(entityList));
 }
コード例 #16
0
 /// <summary>
 /// Insert a single object into the database.
 /// </summary>
 /// <param name="entity"></param>
 /// <returns>bool</returns>
 public async Task <bool> Insert(T entity)
 {
     return(await CreateRepository.Insert(entity));
 }