Esempio n. 1
0
        /// <summary>
        /// Entry point to CDR Delta Extractor. Takes parameters defined by an XML string based
        /// on the parameters.XSD schema.
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public static void Main(string[] args)
        {
            Parameters parameters = new Parameters();

            try
            {
                Version v   = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
                string  XML = args[0];
                if (!XML.StartsWith("<?xml version="))
                {
                    byte[] base64ByteArr = Convert.FromBase64String(args[0]);
                    XML = System.Text.UnicodeEncoding.Unicode.GetString(base64ByteArr);
                }

                parameters = Parameters.DeSerializefromXml(XML);
                //Enable ETLController loging
                //EventLoggerDE de = EventLoggerDE.Create();
                debug = parameters.Debug;

                if (parameters.HeaderType == HeaderType.ETLHeader)
                {
                    //de.SetEventContext(new Dictionary<string, string>()
                    //{
                    //    {"CS",String.Format(@"Data Source={0};Initial Catalog={1};Integrated Security=SSPI;",parameters.ETLHeader.Controller.Server,parameters.ETLHeader.Controller.Database)},
                    //    {"Timeout",parameters.ETLHeader.Controller.QueryTimeout.ToString()},
                    //    {"prcPrint", "dbo.prc_Print"}
                    //});

                    ETLController.Connect(parameters.ETLHeader);
                }

                PrintOutput.PrintToOutput(String.Format(CultureInfo.InvariantCulture, "Running DE v.{0} ({1})bit", v.ToString(), 8 * IntPtr.Size));
                PrintOutput.PrintToOutput("Executing as: " + WindowsIdentity.GetCurrent().Name.ToString(), DERun.Debug);

                PrintOutput.PrintToOutput("DE XML: " + XML, DERun.Debug);


                DEController.Execute(parameters);
            }
            catch (Exception ex)
            {
                PrintOutput.PrintToError(ex.Message);
                Environment.Exit(1);
            }
            Environment.Exit(0);
        }
        /// <summary>
        /// Prints text to console with timestamp
        /// </summary>
        /// <param name="in_strOutputMessage"> Text to output </param>
        /// <param name="loggingEnabled"> determines whether what is passed in is written to a log file</param>
        /// <param name="verbose">whether to print the message to Console</param>
        ///
        //private static readonly string LOG_MESSAGE_SOURCE = "DeltaExtractor";

        //private static Dictionary<string, EventLogger> s_loggers = new Dictionary<string, EventLogger>() ;

        //public static void AddEventLogger(string loggerName, EventLogger logger)
        //{
        //    if (!(s_loggers.ContainsKey(loggerName)))
        //    {
        //        s_loggers.Add(loggerName, logger) ;
        //    }
        //}

        public static void PrintToOutput(string in_strOutputMessage, int in_err, bool loggingEnabled)
        {
            if (!loggingEnabled)
            {
                return;
            }

            //if (s_loggers.Count > 0)
            //{
            //    foreach (EventLogger l in s_loggers.Values)
            //    {
            //        l.LogEvent(LOG_MESSAGE_SOURCE, in_strOutputMessage, in_err, null);
            //    }
            //}

            if (ETLController.Connected)
            {
                ETLController.LogMessage(in_strOutputMessage, in_err);
            }
            else
            {
                Console.WriteLine(String.Format("Err={0}:{1}", in_err, in_strOutputMessage));
            }
        }
Esempio n. 3
0
        private static void MoveDataRun(Parameters p)
        {
            System.Diagnostics.Debug.Assert(p != null);

            MoveData action = p.MoveData;

            //Check the Source
            if (action.DataSource.Type == SourceType.Unknown)
            {
                throw new UnknownSourceType();
            }
            PrintOutput.PrintToOutput(action.DataSource.Description, p.Debug);

            //Check destinations
            int numValidDestinations = action.DataDestination.Test();

            if (numValidDestinations == 0)
            {
                throw new InvalidDestinations("Error: No Valid destinations found");
            }
            if (numValidDestinations != action.DataDestination.Destinations.Count)
            {
                throw new InvalidDestinations("Error: Invalid destinations found");
            }

            //create and configure the package
            DESSISPackage Extractor = new DESSISPackage(action);
            Package       pkg       = Extractor.LoadPackage();

            if (pkg == null)
            {
                throw new DeltaExtractorBuildException("Failed to Load or Build the SSIS Package");
            }

            ExecutePackageWithEvents(pkg);

            int rowCount = Convert.ToInt32(pkg.Variables["RowCount"].Value, CultureInfo.InvariantCulture);

            PrintOutput.PrintToOutput("DE extracted " + rowCount.ToString() + " rows from the Source.");
            PrintOutput.PrintToOutput("DE Package completed.");
            ETLController.CounterSet("RowsExtracted", rowCount.ToString());


            //if this is a staging extract, then call the upload sproc for each DB Destination
            //staging value defines which upsert type to use

            //IEnumerable<object> res = action.DataDestination.Destinations.Where(d => ((IDeDestination)d).Type == DestinationType.OleDb);
            foreach (object odest in action.DataDestination.Destinations)
            {
                IDeDestination dest = (IDeDestination)odest;
                if (dest.StagingBlock != null)
                {
                    if (dest.StagingBlock.Staging)
                    {
                        if (dest.DbSupportObject == null)
                        {
                            throw new DeltaExtractorBuildException("Staging support is not available for this destination");
                        }
                        IDeStagingSupport supp = (IDeStagingSupport)dest.DbSupportObject;
                        if (String.IsNullOrEmpty(dest.StagingBlock.StagingTableName))
                        {
                            if (!supp.CreateStagingTable(false))
                            {
                                throw new CouldNotCreateStagingTableException(dest.StagingBlock.StagingTableName);
                            }
                        }
                        if (!supp.UploadStagingTable(p.RunID))
                        {
                            throw new CouldNotUploadStagingTableException(dest.StagingBlock.StagingTableName);
                        }
                    }
                }
            }
        }