Exemplo n.º 1
0
 protected void InvokeAllCompleted(GlobalEvents globalEvent, PullersEventArgs e)
 {
     if (AllCompleted != null)
     {
         AllCompleted(new GlobalEventArgs(Name, globalEvent, e));
     }
 }
Exemplo n.º 2
0
        private string DataSourceInformation(PullersEventArgs e)
        {
            string dsInfo = string.Format("DataSource Id = {0}{1}", e.Job.DataSource.Id, Environment.NewLine);

            dsInfo += string.Format("DataSource Name = {0}{1}", e.Job.DataSource.Name, Environment.NewLine);
            return(dsInfo);
        }
Exemplo n.º 3
0
        public void ExecuteCommand(PullersEventArgs e)
        {
            PusherDosCommands pdc = new PusherDosCommands();

            pdc.Process(e, DosCommands);
            OnExecuteCommand(e);
            Trace.WriteLine("GEC:Commands executed '{0}'", Name);
        }
Exemplo n.º 4
0
 public void Complete(int dataSourceId, PullersEventArgs e)
 {
     foreach (var item in this)
     {
         if (item.HasEntry(dataSourceId))
         {
             item.Complete(dataSourceId, e);
         }
     }
 }
Exemplo n.º 5
0
        protected override void OnComplete(int dataSourceId, PullersEventArgs e)
        {
            if (DataSources.ContainsKey(dataSourceId))
            {
                DataSources[dataSourceId] = true;
                ExtensionMethods.TraceInformation("GEC:Completed:{0}", dataSourceId);
            }

            else
            {
                ExtensionMethods.TraceInformation("GEC:The data source {0} was not registered with global event '{1}'! This operation was ignored.",
                                                  dataSourceId, Name);
            }

            CheckIfAllCompleted(e);
        }
Exemplo n.º 6
0
        private bool EvaluateIf(PullersEventArgs e, string command, ref string updatedCommand)
        {
            Regex  regex = new Regex("_if\\((.*?)\\)");
            Match  match = regex.Match(command);
            string full  = match.Groups[0].ToString();
            string processVariableName = match.Groups[1].ToString();

            updatedCommand = command.Replace(full, string.Empty).Trim();

            if (e.Job.ProcessVariables.ContainsKey(processVariableName))
            {
                return(e.Job.ProcessVariables[processVariableName].ToString().ParseBool());
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Uploads processed file into FTP
        /// </summary>
        /// <param name="e">PullerEventArgs</param>
        public override void FileProcessed(PullersEventArgs e)
        {
            string ftpRemoteLocation = string.Empty;
            string ftpUserName       = string.Empty;
            string ftpPassword       = string.Empty;
            string onlyFileName      = Path.GetFileName(e.OutputFileName);

            if (e.Job.DataSource.PusherTypeFullName.Contains("|"))
            {
                if (e.Job.DataSource.PusherTypeFullName.Split("|".ToCharArray()).Length == 3)
                {
                    ftpRemoteLocation = e.Job.DataSource.PusherTypeFullName.Split("|".ToCharArray())[0];
                    ftpUserName       = e.Job.DataSource.PusherTypeFullName.Split("|".ToCharArray())[1];
                    ftpPassword       = e.Job.DataSource.PusherTypeFullName.Split("|".ToCharArray())[2];
                }
            }

            if ((string.IsNullOrEmpty(ftpRemoteLocation)) ||
                (string.IsNullOrEmpty(ftpRemoteLocation)) ||
                (string.IsNullOrEmpty(ftpRemoteLocation)))
            {
                e.Job.TraceError("Ftp pusher was not configured correctly! Upload failed for " + e.OutputFileName);
                return;
            }

            FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpRemoteLocation + "/" + onlyFileName);

            request.Credentials = new NetworkCredential(ftpUserName, ftpPassword);
            request.Method      = WebRequestMethods.Ftp.UploadFile;
            StreamReader sourceStream = new StreamReader(e.OutputFileName);

            byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
            sourceStream.Close();
            request.ContentLength = fileContents.Length;

            Stream requestStream = request.GetRequestStream();

            requestStream.Write(fileContents, 0, fileContents.Length);
            requestStream.Close();

            FtpWebResponse response = (FtpWebResponse)request.GetResponse();

            response.Close();
        }
Exemplo n.º 8
0
        private void Execute(PullersEventArgs e, string command)
        {
            List <string> output = new List <string>();
            List <string> error  = new List <string>();

            command = ParseCommand(e, command);
            Eyedia.Core.Windows.Utilities.WindowsUtility.ExecuteDosCommand(command, true, ref output, ref error);

            #region Error Handling

            if (error.Count != 0)
            {
                if (!ErrorCanBeIgnored(command, error))
                {
                    string commandError = error.ToLine("<br />");
                    commandError = PostMan.__errorStartTag + commandError + PostMan.__errorEndTag;

                    string errorMessage = "Error while executing pusher commands!" + Environment.NewLine;
                    errorMessage += string.Format("Command executed = '{0}'", command);
                    errorMessage += string.Format(". The error was {0}", commandError);
                    errorMessage += DataSourceInformation(e);
                    new PostMan(e.Job, true).Send(errorMessage, "Pusher Failed");
                    ExtensionMethods.TraceInformation(errorMessage);
                }
            }

            if (ValidateExecution(output) != true)
            {
                string commandError = output.ToLine("<br />");
                commandError = PostMan.__errorStartTag + commandError + PostMan.__errorEndTag;

                string errorMessage = "Error while executing pusher commands!" + Environment.NewLine;
                errorMessage += string.Format("Command executed = '{0}'", command);
                errorMessage += string.Format(". The error was {0}", commandError);
                errorMessage += DataSourceInformation(e);
                new PostMan(e.Job, true).Send(errorMessage, "Pusher Failed");
                ExtensionMethods.TraceInformation(errorMessage);
            }

            #endregion Error Handling
        }
Exemplo n.º 9
0
        public void Process(PullersEventArgs e, string rawCommands)
        {
            List <string> commands = new List <string>(rawCommands.Split(Environment.NewLine.ToCharArray()));

            commands = commands.RemoveEmptyStrings();

            foreach (string command in commands)
            {
                if (command.StartsWith("_if", StringComparison.OrdinalIgnoreCase))
                {
                    string updatedCommand = string.Empty;
                    if (EvaluateIf(e, command, ref updatedCommand))
                    {
                        Execute(e, updatedCommand);
                    }
                }
                else
                {
                    Execute(e, command);
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Executes DOS commands
        /// </summary>
        /// <param name="e">PullersEventArgs</param>
        public override void FileProcessed(PullersEventArgs e)
        {
            List <string> commands = new List <string>(e.Job.DataSource.PusherTypeFullName.Split(Environment.NewLine.ToCharArray()));

            commands = commands.RemoveEmptyStrings();

            foreach (string command in commands)
            {
                if (command.StartsWith("_if", StringComparison.OrdinalIgnoreCase))
                {
                    string updatedCommand = string.Empty;
                    if (EvaluateIf(e, command, ref updatedCommand))
                    {
                        Execute(e, updatedCommand);
                    }
                }
                else
                {
                    Execute(e, command);
                }
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Executes SQL query
        /// </summary>
        /// <param name="e">PullerEventArgs</param>
        public override void FileProcessed(PullersEventArgs e)
        {
            if (e.Job.DataSource.PusherTypeFullName.Contains("|"))
            {
                string[] info = e.Job.DataSource.PusherTypeFullName.Split("|".ToCharArray());

                string connectionStringKeyNameDesign = info[0];
                string connectionStringKeyName       = info[1];
                string updateQuery = info[2];

                IdpeKey connectionStringKey = null;
                if (!string.IsNullOrEmpty(connectionStringKeyName))
                {
                    string connectionKeyNameRuntime = e.Job.GetProcessVariableValue(connectionStringKeyName).ToString();
                    if (string.IsNullOrEmpty(connectionKeyNameRuntime))
                    {
                        throw new Exception(string.Format("Database writer run time connection string '{0}' was not defined!", connectionStringKeyName));
                    }
                    connectionStringKey = e.Job.DataSource.Keys.GetKey(connectionKeyNameRuntime);
                }
                else
                {
                    connectionStringKey = e.Job.DataSource.Keys.GetKey(connectionStringKeyNameDesign);
                }

                if (connectionStringKey == null)
                {
                    throw new Exception("Database writer connection string was not defined!");
                }

                if (!string.IsNullOrEmpty(updateQuery))
                {
                    ExecuteQuery(e.Job.DataSource, connectionStringKey, updateQuery);
                }
            }
        }
Exemplo n.º 12
0
        private void CheckIfAllCompleted(PullersEventArgs e)
        {
            string yetToComplete = string.Empty;

            foreach (var item in DataSources)
            {
                if (item.Value == false)
                {
                    yetToComplete += item.Key + ",";
                }
            }

            if (!string.IsNullOrEmpty(yetToComplete))
            {
                yetToComplete = yetToComplete.Substring(0, yetToComplete.Length - 1);
                ExtensionMethods.TraceInformation("GEC:Yet to complete:{0}", yetToComplete);
            }
            else
            {
                ExtensionMethods.TraceInformation("GEC: all tasks completed!");
                InvokeAllCompleted(this, e);
            }
            Trace.Flush();
        }
Exemplo n.º 13
0
 /// <summary>
 /// Overridden method to send output to desired destination. Just for testing, do not use.
 /// </summary>
 /// <param name="e"></param>
 public override void FileProcessed(PullersEventArgs e)
 {
     base.FileProcessed(e);
 }
Exemplo n.º 14
0
 /// <summary>
 /// This method will get called once a file has been processed. Override this method to push output to your desired destination.
 /// The base method deletes the file.
 /// </summary>
 /// <param name="e"></param>
 public virtual void FileProcessed(PullersEventArgs e)
 {
     //File.Delete(e.FileName);
     Trace.Flush();
 }
Exemplo n.º 15
0
 private string ParseCommand(PullersEventArgs e, string command)
 {
     return(new CommandParser(e.Job.DataSource).Parse(command, e.Job.FileName, e.OutputFileName));
 }
Exemplo n.º 16
0
 public void Complete(int dataSourceId, PullersEventArgs e)
 {
     CheckIfTimedOut();
     OnComplete(dataSourceId, e);
 }
Exemplo n.º 17
0
 protected virtual void OnComplete(int dataSourceId, PullersEventArgs e)
 {
 }
Exemplo n.º 18
0
 protected virtual void OnExecuteCommand(PullersEventArgs e)
 {
 }
Exemplo n.º 19
0
        internal void InvokeFileProcessed(int datasourceId, string jobId, List <IdpeKey> appKeys, string fileName, string outputFolder, string zipUniqueId)
        {
            Trace.TraceInformation("Invoke");
            Trace.Flush();
            Trace.TraceInformation("datasourceId:{0}, JobId:{1},appkeys={2},filename={3},outputfolder={4},zipuniqueid={5}",
                                   datasourceId, jobId, appKeys.Count, fileName, outputFolder, zipUniqueId);
            Trace.Flush();

            Job currentJob = null;

            if ((!(string.IsNullOrEmpty(jobId))) &&
                (Registry.Instance.Entries.ContainsKey(jobId)))
            {
                currentJob = Registry.Instance.Entries[jobId] as Job;
            }

            #region Handling ZipFile

            ZipFileInformation zipInfo = null;
            if (!string.IsNullOrEmpty(zipUniqueId))
            {
                zipInfo = Registry.Instance.ZipFiles[zipUniqueId];
                if (zipInfo.TotalFiles == zipInfo.TotalProcessedFiles)
                {
                    return;
                }
                else
                {
                    zipInfo.TotalProcessedFiles = zipInfo.TotalProcessedFiles + 1;
                }
            }

            #endregion Handling ZipFile

            #region Handling Pusher

            if ((currentJob != null) &&
                (!string.IsNullOrEmpty(currentJob.DataSource.PusherTypeFullName)))
            {
                ExtensionMethods.TraceInformation("Pullers - Initializing '{0}' Pusher '{1}'.", currentJob.DataSource.Name, currentJob.DataSource.PusherTypeFullName);
                object objPusher = null;
                if (currentJob.DataSource.PusherType == PusherTypes.Ftp)
                {
                    objPusher = new PusherFtp();
                }
                else if (currentJob.DataSource.PusherType == PusherTypes.DosCommands)
                {
                    objPusher = new PusherDosCommands();
                }
                else if (currentJob.DataSource.PusherType == PusherTypes.SqlQuery)
                {
                    objPusher = new PusherSqlQuery();
                }
                else if (currentJob.DataSource.PusherType == PusherTypes.Custom)
                {
                    objPusher = Activator.CreateInstance(Type.GetType(currentJob.DataSource.PusherTypeFullName));
                }
                if (objPusher != null)
                {
                    if ((currentJob.Errors.Count == 0) &&
                        (currentJob.DataSource.OutputWriter.IsErrored == false))
                    {
                        ((Pushers)objPusher).FileProcessed(new PullersEventArgs(datasourceId, jobId, appKeys, fileName, outputFolder, zipUniqueId, zipInfo));
                        ExtensionMethods.TraceInformation("Pullers - Pusher called!");
                    }
                    else if ((currentJob.Errors.Count > 0) &&
                             (currentJob.DataSource.DataFeederType == DataFeederTypes.PullSql))
                    {
                        new SqlWatcherHelper(currentJob).ExecuteRecoveryScript();
                    }
                    else
                    {
                        if (currentJob.DataSource.AllowPartial())
                        {
                            ((Pushers)objPusher).FileProcessed(new PullersEventArgs(datasourceId, jobId, appKeys, fileName, outputFolder, zipUniqueId, zipInfo));
                            ExtensionMethods.TraceInformation("Pullers - Pusher called!");
                        }
                        else
                        {
                            string message = "Pullers - There were error(s) while processing, the pusher was not called. Please study the error(s) and do the needful.";
                            ExtensionMethods.TraceError(message);
                        }
                    }
                }
            }
            #endregion Handling Pusher

            #region Logging History

            if (currentJob != null)
            {
                string subFileName = null;
                if (!string.IsNullOrEmpty(zipUniqueId))
                {
                    subFileName = Path.GetFileName(fileName);
                    //removing output extension
                    if (subFileName.Contains("."))
                    {
                        subFileName = subFileName.Substring(0, subFileName.LastIndexOf("."));
                    }
                }
                new Manager().SaveLog(currentJob.FileName, subFileName, datasourceId,
                                      currentJob.TotalRowsToBeProcessed, currentJob.TotalValid, currentJob.StartedAt, DateTime.Now, SreEnvironmentDetails());
            }

            #endregion Logging History

            #region Sending Email

            if (currentJob != null)
            {
                //send email in positive scenario. If would have failed, an error email would have automatically sent.
                ExtensionMethods.TraceInformation("Pullers - A job processed, total rows to be processed = {0}, total valid rows = {1}", currentJob.TotalRowsToBeProcessed, currentJob.TotalValid);
                Trace.Flush();
                string strEmailAfterFileProcessed = currentJob.DataSource.Keys.GetKeyValue(IdpeKeyTypes.EmailAfterFileProcessed);
                string strEmailAfterFileProcessedAttachInputFile  = currentJob.DataSource.Keys.GetKeyValue(IdpeKeyTypes.EmailAfterFileProcessedAttachInputFile);
                string strEmailAfterFileProcessedAttachOutputFile = currentJob.DataSource.Keys.GetKeyValue(IdpeKeyTypes.EmailAfterFileProcessedAttachOutputFile);

                if (strEmailAfterFileProcessed.ParseBool())
                {
                    string strEmailAfterFileProcessedAttachOtherFiles = currentJob.DataSource.Keys.GetKeyValue(IdpeKeyTypes.EmailAfterFileProcessedAttachOtherFiles);

                    string message = string.Format("Pullers - A file from '{0}' was just processed with {1} record(s)!",
                                                   currentJob.DataSource.Name, currentJob.TotalRowsProcessed);

                    if (string.IsNullOrEmpty(strEmailAfterFileProcessedAttachOtherFiles))
                    {
                        List <string> outFile = new List <string>();
                        if (strEmailAfterFileProcessedAttachOutputFile.ParseBool())
                        {
                            outFile.Add(fileName);
                            new PostMan(currentJob, false).Send(message, "File Processed", !strEmailAfterFileProcessedAttachInputFile.ParseBool(), outFile);
                        }
                        else
                        {
                            new PostMan(currentJob, false).Send(message, "File Processed", !strEmailAfterFileProcessedAttachInputFile.ParseBool(), outFile);
                        }
                    }
                    else
                    {
                        List <string> otherFiles = new List <string>(strEmailAfterFileProcessedAttachOtherFiles.Split(",".ToCharArray()));
                        new PostMan(currentJob, false).Send(message, "File Processed", !strEmailAfterFileProcessedAttachInputFile.ParseBool(), otherFiles);
                    }
                }
            }

            #endregion Sending Email

            #region Handling Global Events

            if ((currentJob != null) && (currentJob.ErroredByPusher == false))
            {
                PullersEventArgs e = new PullersEventArgs(datasourceId, jobId, appKeys, fileName, outputFolder, zipUniqueId, zipInfo);
                Registry.Instance.GlobalEventsOnCompletes.Complete(datasourceId, e);
            }

            #endregion Handling Global Events

            if (currentJob != null)
            {
                currentJob.PerformanceCounter.PrintTrace(jobId);
            }
        }
Exemplo n.º 20
0
 public GlobalEventArgs(string globalEventName, GlobalEvents globalEvent, PullersEventArgs pullersEventArgs = null)
 {
     this.GlobalEventName  = globalEventName;
     this.GlobalEvent      = globalEvent;
     this.PullersEventArgs = pullersEventArgs;
 }