Пример #1
0
        public static async Task <int> SyncTopics(IGovDeliveryApiService service, GovDeliveryContextFactory factory)
        {
            Console.WriteLine("Syncing Topics...");
            await BusinessTasks.SyncTopics(service, factory.CreateDbContext(), s => Console.WriteLine(s));

            Console.WriteLine("Topic sync Successful.");

            return(0);
        }
Пример #2
0
        static void Main(string[] args)
        {
            using (var reader = File.OpenText($@"{AppContext.BaseDirectory}\appSettings.json"))
            {
                var appSettingsText = reader.ReadToEnd();
                AppSettings = JsonConvert.DeserializeObject <AppSettings>(appSettingsText);
            }

            Service = new GovDeliveryApiService(
                AppSettings.GovDelivery.Server,
                AppSettings.GovDelivery.AccountCode,
                AppSettings.GovDelivery.Username,
                AppSettings.GovDelivery.Password
                );

            var builderOptions = new DbContextOptionsBuilder()
                                 .UseSqlServer(AppSettings.ConnectionStrings.GovDelivery);

            ContextFactory = new GovDeliveryContextFactory(builderOptions);

            Importer = new CsvImporter();

            ConfigureCli(args);
        }
Пример #3
0
        public static async Task <int> PerformFullSync(IGovDeliveryApiService service, GovDeliveryContextFactory factory)
        {
            Console.WriteLine("Beginning sync...");

            await SyncTopics(service, factory);
            await SyncCategories(service, factory);
            await SyncSubscribers(service, factory);

            Console.WriteLine("Sync successful.");

            return(0);
        }
Пример #4
0
        public static async Task <int> SyncSubscribers(IGovDeliveryApiService service, GovDeliveryContextFactory factory)
        {
            Console.WriteLine(" Syncing Subscribers and Subscriptions...");
            await BusinessTasks.UpdateSubscribersAsync(service, factory, s => Console.WriteLine(s));

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

            return(0);
        }
Пример #5
0
        /// Only handles email subscribers.
        public static async Task <int> ImportSubscribers(string filePath, ICsvImporter importer, GovDeliveryContextFactory factory)
        {
            var ctx = factory.CreateDbContext();

            if (string.IsNullOrWhiteSpace(filePath))
            {
                Console.WriteLine("Path to a .csv file must be provided.");
                return(1);
            }

            Console.WriteLine($"Attempting to import subscribers from {filePath}...");

            var subscribers = await importer.ImportSubscribersAsync(filePath);

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

            var importedSubscribers = subscribers
                                      .Where(s => s.Type == SubscriberType.Email)
                                      .Select(s => new Subscriber {
                Id = Guid.NewGuid(), Email = s.Contact
            });

            var localSubscribers = ctx.Subscribers.ToList();

            var newSubscribers = importedSubscribers
                                 .Where(s => !localSubscribers.Any(ls => ls.Email == s.Email));

            ctx.Subscribers.AddRange(newSubscribers);
            await ctx.SaveChangesAsync();

            Console.WriteLine("Successfully imported subscribers.");

            return(0);
        }