示例#1
0
 public static void ResetRunningJobs()
 {
     using (ReportingDataContext data = new ReportingDataContext())
     {
         data.ResetExecutionQueue();
     }
 }
示例#2
0
        protected override void DoHandle(CargoHandledMessage message)
        {
            HandlingEventType lastKnownEvent    = (HandlingEventType)message.LastKnownEventType;
            HandlingEventType?nextExpectedEvent = null;

            if (message.NextExpectedEventType != null)
            {
                nextExpectedEvent = (HandlingEventType)message.NextExpectedEventType;
            }
            ReportingDataContext context = new ReportingDataContext();
            Cargo cargo = context.Cargos.First(x => x.TrackingId == message.TrackingId);

            cargo.UpdateHistory(
                nextExpectedEvent,
                message.NextExpectedLocation,
                lastKnownEvent,
                message.LastKnownLocation,
                (RoutingStatus)message.RoutingStatus,
                (TransportStatus)message.TransportStatus,
                message.EstimatedTimeOfArrival,
                message.IsUnloaded,
                message.IsMisdirected,
                message.CalculatedAt);

            context.SubmitChanges();
        }
        /// <summary>
        /// Returns a list of all defined shipping locations in format acceptable by MVC framework
        /// drop down list.
        /// </summary>
        /// <returns>A list of shipping locations.</returns>
        public IList <SelectListItem> ListShippingLocations()
        {
            ReportingDataContext context = new ReportingDataContext();

            return(context.Locations.Select(x => new SelectListItem {
                Text = x.Name, Value = x.UnLocode
            }).ToList());
        }
        protected override void DoHandle(CargoRegisteredMessage message)
        {
            Cargo cargo = new Cargo(message.TrackingId, message.Origin, message.Destination, message.ArrivalDeadline);
            ReportingDataContext context = new ReportingDataContext();

            context.Cargos.InsertOnSubmit(cargo);

            context.SubmitChanges();
        }
示例#5
0
        protected override void DoHandle(CargoAssignedToRouteMessage message)
        {
            ReportingDataContext context = new ReportingDataContext();
            Cargo cargo = context.Cargos.First(x => x.TrackingId == message.TrackingId);

            cargo.RouteSpecification = message.Legs;

            context.SubmitChanges();
        }
示例#6
0
        protected override void DoHandle(CargoDestinationChangedMessage message)
        {
            ReportingDataContext context = new ReportingDataContext();
            Cargo cargo = context.Cargos.First(x => x.TrackingId == message.TrackingId);

            cargo.UpdateRouteSpecification(message.Origin, message.Destination, message.ArrivalDeadline);

            context.SubmitChanges();
        }
        /// <summary>
        /// Loads DTO of cargo for cargo routing function.
        /// </summary>
        /// <param name="trackingId">Cargo tracking id.</param>
        /// <returns>DTO.</returns>
        public Reporting.Cargo LoadCargoForRouting(string trackingId)
        {
            ReportingDataContext context = new ReportingDataContext();

            Reporting.Cargo c = context.Cargos.FirstOrDefault(x => x.TrackingId == trackingId);
            if (c == null)
            {
                throw new ArgumentException("Cargo with specified tracking id not found.");
            }
            return(c);
        }
        public ActionResult Track(string trackingId)
        {
            ReportingDataContext context = new ReportingDataContext();

            Reporting.Cargo cargo = context.Cargos.FirstOrDefault(x => x.TrackingId == trackingId);
            if (cargo == null)
            {
                ViewData.ModelState.AddModelError("trackingId", "Provided tracking id is invalid.");
                return(View());
            }
            return(View(new CargoTrackingViewAdapter(cargo)));
        }
示例#9
0
        public static ReportExecution GetNextJob()
        {
            ReportExecution exec = null;

            #region logging

            Logger.TraceEvent(
                TraceEventType.Verbose,
                0,
                "{0}: BEGIN GetNextJob()",
                System.Threading.Thread.CurrentThread.ManagedThreadId);

            #endregion

            try
            {
                using (ReportingDataContext data = new ReportingDataContext())
                {
                    //get the next execution from the queue
                    var execRow =
                        (from e in data.GetExecutionFromQueue()
                         where e.ScheduledStartDate.HasValue
                         select e).FirstOrDefault();

                    if (execRow == null)
                    {
                        return(null);
                    }

                    try
                    {
                        var format       = data.GetFormat(execRow.ReportFormatID).FirstOrDefault();
                        var report       = data.GetReport(execRow.ReportID, execRow.EnvironmentID).FirstOrDefault();
                        var subscription = data.GetSubscription(execRow.ReportSubscriptionID).FirstOrDefault();
                        exec = GetReportExecutionFromRow(execRow, format, report, subscription);
                    }
                    catch (Exception ex)
                    {
                        //WI #2889: mark the execution for retry on exception
                        data.SetExecutionRetry(
                            execRow.ReportExecutionID,
                            execRow.Name,
                            null,
                            null,
                            ex.ToString(),
                            null,
                            execRow.ErrorCount + 1,
                            execRow.ScheduledStartDate,
                            "SYSTEM",
                            DateTime.Now);

                        //re-throw exception
                        throw;
                    }
                }
            }

            #region logging

            finally
            {
                Logger.TraceEvent(
                    TraceEventType.Verbose,
                    0,
                    "{0}: END GetNextJob(id={1}, state={2}, run={3}, nextRun={4}, subscription={5}, reportId={6}, path={7}, formatId={8}, format={9})",
                    System.Threading.Thread.CurrentThread.ManagedThreadId,
                    exec != null ? exec.Id : null,
                    exec != null ? (ReportExecutionStateEnum?)exec.State : null,
                    exec != null ? exec.ScheduledRunTime : null,
                    exec != null ? exec.NextScheduledRunTime : null,
                    exec != null ? exec.SubscriptionId : null,
                    exec != null ? (int?)exec.ReportId : null,
                    exec != null ? exec.ReportPath : null,
                    exec != null ? (int?)exec.FormatId : null,
                    exec != null ? exec.Format : null);
            }

            #endregion

            return(exec);
        }
示例#10
0
        public static void CompleteExecution(ReportExecution execution)
        {
            #region logging

            execution.Log(TraceEventType.Verbose, "BEGIN CompleteExecution()");

            #endregion

            try
            {
                int executionId = int.Parse(execution.Id);
                if (execution.State != ReportExecutionStateEnum.Failed &&
                    execution.State != ReportExecutionStateEnum.Succeeded)
                {
                    throw new InvalidOperationException(string.Format("Execution {0} cannot be completed from its current state: {1}", executionId, execution.State));
                }
                if (execution.State == ReportExecutionStateEnum.Succeeded &&
                    execution.Data == null)
                {
                    throw new InvalidOperationException(string.Format("Execution {0} is in the 'Succeeded' state but it does not have any data", executionId));
                }

                using (ReportingDataContext content = new ReportingDataContext("Emdat.InVision.ReportContent"))
                    using (ReportingDataContext data = new ReportingDataContext())
                    {
                        //only update content if the data has been set
                        if (execution.State == ReportExecutionStateEnum.Succeeded &&
                            execution.Data != null)
                        {
                            #region logging

                            execution.Log(
                                TraceEventType.Verbose,
                                "Setting execution data (fileType={0}, dataLength={1})",
                                execution.FileType,
                                execution.Data != null ? execution.Data.Length : 0);

                            #endregion

                            try
                            {
                                //save the report data
                                var result = content.SetExecutionData(executionId, execution.FileType, execution.Data);
                                if (result < 1)
                                {
                                    throw new ApplicationException(string.Format("The execution data could not be set: {0}", executionId));
                                }
                            }
                            catch (Exception ex)
                            {
                                //TFS #13667: retry if there are problems saving the report content
                                execution.Log(TraceEventType.Warning, "Exception saving report content: {0}", ex.Message);
                                execution.Log(TraceEventType.Information, "{0}", ex);
                                execution.Error = ex;
                                execution.ErrorCount++;
                                data.SetExecutionRetry(
                                    executionId,
                                    execution.Name,
                                    execution.StartTime,
                                    execution.EndTime,
                                    execution.ErrorDescription,
                                    execution.ErrorCode.HasValue ? (int?)execution.ErrorCode.Value : null,
                                    execution.ErrorCount,
                                    execution.ScheduledRunTime,
                                    "SYSTEM",
                                    DateTime.Now);
                                return;
                            }
                        }

                        //only fail if success or the error code is set, otherwise, retry
                        if (execution.State == ReportExecutionStateEnum.Succeeded ||
                            execution.ErrorCode.HasValue)
                        {
                            string nextPrmsXml = ReportParametersHelper.GetParameterValuesXml(execution.NextScheduledRunParameters);

                            #region logging

                            execution.Log(
                                TraceEventType.Verbose,
                                "Setting execution status (name={0}, startTime={1:s}, endTime={2:s}, state={3}, errorCode={4}, errorCount={5}, usedHistory={6}, nextRun={7:s}, nextPrms={8}, report={9}, subscription={10}, format={11})",
                                execution.Name,
                                execution.StartTime,
                                execution.EndTime,
                                execution.State,
                                execution.ErrorCode,
                                execution.ErrorCount,
                                !string.IsNullOrEmpty(execution.HistoryId),
                                execution.NextScheduledRunTime,
                                nextPrmsXml,
                                execution.ReportId,
                                execution.SubscriptionId,
                                execution.FormatId);

                            #endregion

                            //update execution state
                            data.SetExecutionStatus(
                                reportExecutionID: executionId,
                                name: execution.Name,
                                startDate: execution.StartTime,
                                endDate: execution.EndTime,
                                reportExecutionStatusID: (int)execution.State,
                                errorDescription: execution.ErrorDescription,
                                errorCount: execution.ErrorCount,
                                reportExecutionErrorID: execution.ErrorCode.HasValue ? (int?)execution.ErrorCode.Value : null,
                                usedHistory: !string.IsNullOrEmpty(execution.HistoryId),
                                nextExecutionDate: execution.NextScheduledRunTime,
                                nextExecutionParameters: nextPrmsXml,
                                nextExecutionReportID: execution.ReportId,
                                nextExecutionSubscriptionID: execution.SubscriptionId,
                                nextExecutionFormatID: execution.FormatId,
                                modifiedUser: "******",
                                modifiedDate: DateTime.Now);
                        }
                        else
                        {
                            #region logging

                            execution.Log(
                                TraceEventType.Verbose,
                                "Setting execution retry (name={0}, startTime={1:s}, endTime={2:s}, state={3}, errorCode={4}, errorCount={5}, run={6})",
                                execution.Name,
                                execution.StartTime,
                                execution.EndTime,
                                execution.State,
                                execution.ErrorCode,
                                execution.ErrorCount,
                                execution.ScheduledRunTime);

                            #endregion

                            //retry
                            data.SetExecutionRetry(
                                executionId,
                                execution.Name,
                                execution.StartTime,
                                execution.EndTime,
                                execution.ErrorDescription,
                                execution.ErrorCode.HasValue ? (int?)execution.ErrorCode.Value : null,
                                execution.ErrorCount,
                                execution.ScheduledRunTime,
                                "SYSTEM",
                                DateTime.Now);
                        }
                    }
            }

            #region logging

            finally
            {
                execution.Log(TraceEventType.Verbose, "END CompleteExecution()");
            }

            #endregion
        }
        /// <summary>
        /// Returns a complete list of cargos stored in the system.
        /// </summary>
        /// <returns>A collection of cargo DTOs.</returns>
        public IList <Reporting.Cargo> ListAllCargos()
        {
            ReportingDataContext context = new ReportingDataContext();

            return(context.Cargos.ToList());
        }