예제 #1
0
파일: Program.cs 프로젝트: bizx/HubSpotSync
        public void Start(bool interactive)
        {
            var config = new HubSpotManager.Configuration()
            {
                ApiKey = Configuration.HubSpotApiKey,
                MaxDailyRequests = Configuration.MaxDailyRequests,
                StoragePath = GetStoragePath(Configuration.StoragePath),
                MaxRecordCount = Configuration.MaxRecordCount,
                DelayHttpRetry = Configuration.DelayHttpRetry,
                CalendarPreviousDayCount = Configuration.CalendarPreviousDayCount,
                CalendarUpcomingDayCount = Configuration.CalendarUpcomingDayCount
            };

            Console.WriteLine("ApiKey: {0}", config.ApiKey);
            Console.WriteLine("MaxDailyRequests: {0}", config.MaxDailyRequests);
            Console.WriteLine("StoragePath: {0}", config.StoragePath);
            Console.WriteLine("MaxRecordCount: {0}", config.MaxRecordCount);
            Console.WriteLine("DelayHttpRetry: {0}", config.DelayHttpRetry);
            Console.WriteLine("CalendarPreviousDayCount: {0}", config.CalendarPreviousDayCount);
            Console.WriteLine("CalendarUpcomingDayCount: {0}", config.CalendarUpcomingDayCount);

            if (interactive)
            {
                ConsoleWriteLine("Backup will run with the above configuration.  Type \"start\" and press <enter> to continue; anything else to quit.  Run the program with \"/start\" to suppress this.", ConsoleColor.Cyan);
                Console.Write("> ");
                string result = Console.ReadLine();
                if (!result.Equals("start", StringComparison.OrdinalIgnoreCase))
                {
                    return;
                }
            }

            // Assert there is no downloaded information currently in the file system before downloading it
            if (Directory.Exists(config.StoragePath) && Directory.GetDirectories(config.StoragePath).Length > 0)
            {
                Console.WriteLine("The storage folder you specified contains files.  Ensure the folder is empty before continuing");
                return;
            }

            ConsoleWriteLine("Starting backup...", ConsoleColor.Cyan);

            m_manager = new HubSpotManager.Manager(config, this.OutputText);

            m_manager.ProgressUpdated += OnProgressUpdated;

            Task t = m_manager.BackupRemoteHubSpot();

            try
            {
                t.Wait();
            }
            catch(Exception ex)
            {
                ConsoleWriteLine(ex.ToString(), ConsoleColor.Red);
            }

            ConsoleWriteLine("Backup complete", ConsoleColor.Green);
        }
예제 #2
0
        private void InitializeModel()
        {
            if (m_manager != null)
            {
                return;
            }

            this.groupBoxConfiguration.Enabled = false;

            var config = new HubSpotManager.Configuration()
            {
                ApiKey = this.textBoxApiKey.Text,
                MaxDailyRequests = Convert.ToInt32(this.textBoxTotalDailyRequests.Text),
                StoragePath = GetStoragePath(),
                MaxRecordCount = Convert.ToInt32(this.textBoxMaxRecordCount.Text),
                DelayHttpRetry = this.checkBoxDelayRetry.Checked,
                CalendarPreviousDayCount = Convert.ToInt32(this.numericUpDownCalendarPreviousDays.Value),
                CalendarUpcomingDayCount = Convert.ToInt32(this.numericUpDownCalendarUpcomingDays.Value)
            };

            m_manager = new HubSpotManager.Manager(config, this.OutputText);

            m_manager.ProgressUpdated += OnProgressUpdated;
        }