Example #1
0
        public static async Task PerformFullSync()
        {
            var baseUri = (AppSettings.GovDelivery.Server == GovDeliveryServer.Main)
                ? GovDeliveryApiService.MAIN_URI
                : GovDeliveryApiService.STAGING_URI;

            var service = new GovDeliveryApiService(
                baseUri,
                AppSettings.GovDelivery.AccountCode,
                AppSettings.GovDelivery.Username,
                AppSettings.GovDelivery.Password
                );

            var ctx = new GovDeliveryContext();

            Console.WriteLine("Beginning sync...");

            Console.WriteLine("Syncing Topics...");
            await BusinessTasks.SyncTopics(service, ctx);

            Console.WriteLine("Topic sync Successful");

            Console.WriteLine("Syncing Categories...");
            await BusinessTasks.SyncCategories(service, ctx);

            Console.WriteLine("Category sync successful...");

            Console.WriteLine(" Syncing Subscribers and Subscriptions...");
            await BusinessTasks.UpdateSubscribers(service, ctx);

            Console.WriteLine("");
        }
Example #2
0
        public static void ImportSubscribers(string filePath, GovDeliveryContext ctx)
        {
            var importer = new CsvImporter();

            var subscribers = importer.ImportSubscribersAsync(filePath).Result;

            Console.WriteLine($"Found {subscribers.Count()} subscribers to import.");

            var entities = subscribers.Select(s => new Subscriber
            {
                Id    = Guid.NewGuid(),
                Email = s.Type == SubscriberType.Email ? s.Contact : null,
                Phone = s.Type == SubscriberType.Phone ? s.Contact : null,
            });

            ctx.AddRange(entities);

            ctx.SaveChanges();
        }