public void Change(int id, NaesbEventProcess obj)
        {
            obj.Id = id;
            //map from domain obj to entity
            var entity = new Nomination.Persistence.Common.ModelFactory().Map(obj);

            base.Change(entity);
        }
        public int Create(NaesbEventProcess obj)
        {
            //map from domain obj to entity
            var entity = new Nomination.Persistence.Common.ModelFactory().Map(obj);

            base.Add(entity);

            return(Convert.ToInt32(entity.EventProcessId));
        }
        private static void ProcessRequestForConfirmation(RequestForConfirmation rfc, DateTime processStart)
        {
            string naesbFileName = string.Empty;
            int    id            = 0;

            try
            {
                if (rfc != null)
                {
                    Console.WriteLine("==Processing:  1. Retrieved rfc from the repository for Gas Day: " + rfc.GasDay.ToShortDateString());

                    //create an Naesb file name
                    naesbFileName = FormatNaesbRequestForConfirmationFileName(rfc);

                    //create request for confirmation
                    id = Container.Resolve <INaesbRequestForConfirmationCreate>().Invoke(processStart, naesbFileName, rfc);
                    Console.WriteLine("==Processing:  2. Created request for confirmation naesb event process: [Id: " + id + "] [Cycle: " + rfc.Cycle + "] [Utility: " + rfc.PartyIndentificaton.UtilityEntity + "] [Pipeline: " + rfc.PartyIndentificaton.PipelineEntity + "]");

                    //map domain rfc model to the Naesb rfc model.
                    NaesbRequestForConfirmation nrfc = Container.Resolve <INaesbRequestForConfirmationGet>().Invoke(rfc);

                    //get the newly created naesb event process that was processed
                    NaesbEventProcess obj = Container.Resolve <INaesbEventProcessGet>().Invoke(id);
                    if (obj != null)
                    {
                        //save rfc mxl file to BizConnect
                        SaveNaesbRequestForConfirmationFile(nrfc, naesbFileName);
                        Console.WriteLine("==Processing:  3. Created rfc naesb file: [" + Properties.Settings.Default.NaesbOutboundUnc + naesbFileName + "]");
                    }
                    else
                    {
                        Console.WriteLine("==Processing:  The request for confirmation was NOT created");
                    }
                }
                else
                {
                    Console.WriteLine("==Processing: No rfc to process");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("==Processing Error:");
                Console.WriteLine(ex);

                if (id > 0) //if the id == 0 it failed before the naesbEventProcess row was created
                {
                    string stacktrace = Stacktrace(ex);

                    Container.Resolve <INaesbEventProcessError>().Invoke(id, "RFC", stacktrace);
                }

                CreateIncident(ex, null);
            }
        }
        private int CreateConfirmationResponse(DateTime processStart, string fileName, NaesbConfirmationResponse naesbObj, XmlDocument naesbXml)
        {
            //map NaesbConfirmationResponse to ConfirmationResponse
            Nomination.Domain.ConfirmationResponse.ConfirmationResponse cr = _confirmationResponseGetService.Invoke(naesbObj);

            //serialize to xml
            XmlDocument domainXml = CS.Common.Utilities.XmlTransformer.XmlSerialize(cr, true);

            //instantiate naesb event process
            NaesbEventProcess obj = new NaesbEventProcess
            {
                Type         = "CR",
                GasDay       = cr.GasDay,
                Cycle        = cr.Cycle,
                Pipeline     = cr.PartyIndentificaton.PipelineEntity,
                Utility      = cr.PartyIndentificaton.UtilityEntity,
                ProcessStart = processStart,
                EdiFileName  = fileName,
                EdiData      = naesbXml.InnerXml,
                DomainData   = domainXml.InnerXml,
                UserId       = _settings.UserId
            };

            //get the naesb event
            var naesbEvent = _naesbEventGetService.Invoke("CR", obj.Pipeline, obj.Utility, obj.Cycle);

            if (naesbEvent != null && naesbEvent.On == true) //if null then the pipeline/utility/cycle doesn't exist in Pegasys
            {
                //create naesb event process
                int eventProcessId = _naesbEventProcessCreateService.Invoke(obj);

                //create the ConfirmationResponse
                _confirmationResponseCreateService.Invoke(cr);

                //TODO: maybe make this use its own class instead of generic -> NaesbEventProcessCompletion
                //update ProcessEnd timestamp
                _naesbEventProcessUpdateService.Invoke(eventProcessId, new KeyValuePair <string, DateTime>("ProcessEnd", DateTime.Now));

                return(eventProcessId);
            }

            throw new NaesbError
                  {
                      ReasonCode = "101",
                      Value      = "Pipeline/Utility/Cycle naesb event not found."
                  };
        }
        private static NaesbEventProcess ProcessScheduledQuantity(FileInfo file, DateTime processStart)
        {
            int id = 0;

            try
            {
                //create operator scheduled quantities naesb event process
                id = Container.Resolve <INaesbOperatorScheduledQuantitiesCreate>().Invoke(processStart, file);

                //get the newly created naesb event process that was processed
                NaesbEventProcess obj = Container.Resolve <INaesbEventProcessGet>().Invoke(id);
                if (obj != null)
                {
                    Console.WriteLine("==Processing:  1. Created operator scheduled quantities naesb event process: [Id: " + id + "] [Cycle: " + obj.Cycle + "] [Utility: " + obj.Utility + "] [Pipeline: " + obj.Pipeline + "]");
                }
                else
                {
                    Console.WriteLine("==Processing:  The operator scheduled quantities was NOT created");
                }

                return(obj);
            }
            catch (NaesbError ex)
            {
                if (ex.ReasonCode == "101")
                {
                    Console.WriteLine("==Processing: **Pipeline/Utility/Cycle naesb event not found.**");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("==Processing Error:");
                Console.WriteLine(ex);

                if (id > 0) //if the id == 0 it failed before the naesbEventProcess row was created
                {
                    string stacktrace = Stacktrace(ex);
                    Container.Resolve <INaesbEventProcessError>().Invoke(id, "OSQ", stacktrace);
                }

                CreateIncident(ex, file);
            }

            return(null);
        }
 public int Invoke(NaesbEventProcess obj)
 {
     return(_repository.Create(obj));
 }
 public void Invoke(int id, NaesbEventProcess obj)
 {
     _repository.Update(id, obj);
 }
        private static void ProcessScheduledQuantities(DateTime processStart)
        {
            //get all of the OperatorScheduledQuantity files from BizConnect
            var files = GetFiles("OperatorScheduledQuantity");

            if (files != null && files.Count > 0)
            {
                Console.WriteLine("==Processing:[" + Properties.Settings.Default.EventType + "'s] [File Count: " + files.Count + "]");

                int i = 1;
                foreach (var file in files)
                {
                    NaesbEventProcess nep = null;

                    try
                    {
                        Console.WriteLine("==Processing: [" + Properties.Settings.Default.EventType + "] [" + i + " of " + files.Count + "] [File: " + file.DirectoryName + "\\" + file.Name + "]");

                        //check if the naesb event flag is on for this event/pipeline/utility/cycle
                        var naesbEvent = GetOsqNaesbEvent(file);
                        if (naesbEvent != null && naesbEvent.On == true)
                        {
                            nep = ProcessScheduledQuantity(file, processStart);

                            if (nep != null)
                            {
                                //update naesb event
                                DateTime now = DateTime.Now;
                                Container.Resolve <INaesbEventUpdate>().Invoke(naesbEvent.Id, now);
                                Console.WriteLine("==Processing:  2. Updated the naesb event process 'ProcessedTime': [" + now + "]");

                                //delete the file
                                DeleteNaesbFile(file, i, files.Count);

                                Console.WriteLine("==Processing: [" + Properties.Settings.Default.EventType + "] <<SUCCESSFUL>>");
                            }
                            else
                            {
                                //archive the file
                                ArchiveNaesbFile(file, i, files.Count);

                                Console.WriteLine("==Processing: [" + Properties.Settings.Default.EventType + "] <<UNSUCCESSFUL>>");
                            }
                        }
                        else
                        {
                            Console.WriteLine("==Processing: [" + Properties.Settings.Default.EventType + "]  **Naesb event: [Cycle: " + naesbEvent?.Cycle + "] [Utility: " + naesbEvent?.Utility + "] [Pipeline: " + naesbEvent?.Pipeline + "] is not active or does not exist.)");

                            //archive the file
                            ArchiveNaesbFile(file, i, files.Count);

                            Console.WriteLine("==Processing: [" + Properties.Settings.Default.EventType + "] <<SUCCESSFUL with WARNING>>");
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("==Processing Error:");
                        Console.WriteLine(ex);

                        if (nep?.Id > 0) //if the id == 0 it failed before the naesbEventProcess row was created
                        {
                            string stacktrace = Stacktrace(ex);
                            Container.Resolve <INaesbEventProcessError>().Invoke(nep.Id, "OSQ", stacktrace);
                        }

                        CreateIncident(ex, file);

                        //archive the file
                        ArchiveNaesbFile(file, i, files.Count);

                        Console.WriteLine("==Processing: [" + Properties.Settings.Default.EventType + "] <<UNSUCCESSFUL>>");
                    }

                    i++;
                }
            }
            else
            {
                Console.WriteLine("==Processing:[" + Properties.Settings.Default.EventType + "'s] None to Process");
            }

            Console.WriteLine("============================================================================");
        }