Ejemplo n.º 1
0
        private void RunUploadLauncher(UploadLauncher uploadLauncher)
        {
            if (File.Exists(LogFileName))
            {
                File.Delete(LogFileName);
            }


            IEnumerable <IUploadEventHandler> ehs = new List <IUploadEventHandler>()
            {
                new ConsoleEventHandler(),
                new TextFileEventHandler(LogFileName)
            };
            IUploadEventHandler eh = new CompositeEventHandler(ehs);


            TestContext.WriteLine(String.Format("{0} ; {1}", DateTime.Now.ToLongTimeString(), "Begin"));
            uploadLauncher.TableProcessor.TableProcessorBegin     += eh.HandleTableProcessorBegin;
            uploadLauncher.TableProcessor.TableProcessorEnd       += eh.HandleTableProcessorEnd;
            uploadLauncher.TableProcessor.TableProcessorException += eh.HandleTableProcessorException;
            uploadLauncher.Launch();
            TestContext.WriteLine(String.Format("{0} ; {1}", DateTime.Now.ToLongTimeString(), "End"));
            TestContext.WriteLine("Done");
        }
Ejemplo n.º 2
0
        public void Upload()
        {
            var    appSettings = ConfigurationManager.AppSettings;
            String restartConnection, restartTable;

            restartConnection = appSettings[Constants.AppSettingKeys.RestartConnectionName];
            restartTable      = appSettings[Constants.AppSettingKeys.RestartTableName];

            RestartParameter restartParm;

            restartParm = null;
            if (!String.IsNullOrEmpty(restartConnection) && !String.IsNullOrEmpty(restartTable))
            {
                System.Console.WriteLine(String.Format("Configured to restart on {0}/{1}", restartConnection, restartTable));
                System.Console.WriteLine("Is this correct? (Y/N)");
                System.Console.Beep();
                String response = System.Console.ReadLine().Trim().ToUpper();
                if (response == "Y")
                {
                    restartParm = new RestartParameter();
                    restartParm.ConnectionName = restartConnection;
                    restartParm.TableName      = restartTable;
                }
                else
                {
                    System.Console.WriteLine("App.Config must be corrected.  Processing is terminated");
                    System.Console.Read();
                    return;
                }
            }


            IDictionary <String, String> connStrs = new Dictionary <String, String>();
            String connName;

            connName = VfpToSqlBulkCopy.Utility.Constants.ConnectionNames.Host;
            connStrs.Add(connName, GetConnectionString(connName, true));
            connName = VfpToSqlBulkCopy.Utility.Constants.ConnectionNames.Sql;
            connStrs.Add(connName, GetConnectionString(connName, true));

            connName = VfpToSqlBulkCopy.Utility.Constants.ConnectionNames.POS;
            String connStr = GetConnectionString(connName, false);

            if (!String.IsNullOrEmpty(connStr))
            {
                connStrs.Add(connName, connStr);
            }


            String logFileName = null;

            try
            {
                logFileName = appSettings[Constants.TableProcessorEventsFileNameAppSettingsKey];
            }
            catch (ConfigurationErrorsException)
            {
                logFileName = "TableProcessorEvents.Log";
            }


            IList <IUploadEventHandler> eventHandlers = new List <IUploadEventHandler>()
            {
                new ConsoleEventHandler(),
                new TextFileEventHandler(logFileName)
            };


            eventHandlers.Add(new VfpToSqlBulkCopy.Utility.Events.SqlEventHandler());

            IUploadEventHandler eventHandler = new CompositeEventHandler(eventHandlers);

            UploadLauncher uploadLauncher = new UploadLauncher(connStrs, null, restartParm);

            uploadLauncher.BeginUpload += eventHandler.HandleUploadBegin;
            uploadLauncher.TableProcessor.TableProcessorBegin     += eventHandler.HandleTableProcessorBegin;
            uploadLauncher.TableProcessor.TableProcessorEnd       += eventHandler.HandleTableProcessorEnd;
            uploadLauncher.TableProcessor.TableProcessorException += eventHandler.HandleTableProcessorException;
            uploadLauncher.EndUpload += eventHandler.HandleUploadEnd;
            uploadLauncher.Launch();
        }