public int Create(TerminationRequest o)
 {
     using (var db = new BillingDbContext())
     {
         db.ServiceRequests.Add(o);
         return(db.SaveChanges());
     }
 }
Ejemplo n.º 2
0
        /******************************************************************************************
        * From domain model to value object
        ******************************************************************************************/
        public TerminationRequestDTO ToRequestDTO(TerminationRequest o)
        {
            var vo = new TerminationRequestDTO();

            ClassCopier.Instance.Copy(o, vo);

            if (o.RequestInfo != null)
            {
                vo.RequestInfo = ToRequestInfoDTO(o.RequestInfo);
            }
            if (o.Routing != null)
            {
                vo.Routing = ToRoutingInfoDTO(o.Routing);
            }

            return(vo);
        }
Ejemplo n.º 3
0
        /******************************************************************************************
        * From value object to domain model
        ******************************************************************************************/
        public TerminationRequest ToRequest(TerminationRequestDTO vo)
        {
            var o = new TerminationRequest();

            ClassCopier.Instance.Copy(vo, o);

            if (vo.RequestInfo != null)
            {
                o.RequestInfo = ToRequestInfo(vo.RequestInfo);
            }
            if (vo.Routing != null)
            {
                o.Routing = ToRoutingInfo(vo.Routing);
            }

            return(o);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Processes post condition rules on an activity, and returns a sequencing request and/or a termination request.
 /// </summary>
 /// <param name="activity">Activity to perform post condition rules on.</param>
 /// <param name="seqRequest">Sequencing request to perform based on the post condition rules, or null if none.</param>
 /// <param name="termRequest">Termination request to perform based on the post condition rules, or null if none.</param>
 /// <remarks>Corresponds to TB.2.2 in the SCORM 2004 Sequencing/Navigation manual, appendix C.</remarks>
 private void SequencingPostConditionRules(Activity activity, out SequencingRequest? seqRequest, out TerminationRequest? termRequest)
 {
     seqRequest = null;
     termRequest = null;
     Resources.Culture = LocalizationManager.GetCurrentCulture();
     if(activity.DataModel.ActivityIsSuspended)
     {
         return;
     }
     SequencingRuleAction? action = SequencingRulesCheck(activity, activity.Sequencing.PostConditionRules);
     switch(action)
     {
     case SequencingRuleAction.Retry:
         // Attempt to override any pending sequencing request with this one
         m_navigator.LogSequencing(SequencingEventType.IntermediateNavigation, m_command, Resources.SequencingPostConditionRuleResult, activity.Key, Resources.SequencingPostConditionRuleRequestRetry);
         seqRequest = SequencingRequest.Retry;
         return;
     case SequencingRuleAction.Continue:
         // Attempt to override any pending sequencing request with this one
         m_navigator.LogSequencing(SequencingEventType.IntermediateNavigation, m_command, Resources.SequencingPostConditionRuleResult, activity.Key, Resources.SequencingPostConditionRuleRequestContinue);
         seqRequest = SequencingRequest.Continue;
         return;
     case SequencingRuleAction.Previous:
         // Attempt to override any pending sequencing request with this one
         m_navigator.LogSequencing(SequencingEventType.IntermediateNavigation, m_command, Resources.SequencingPostConditionRuleResult, activity.Key, Resources.SequencingPostConditionRuleRequestPrevious);
         seqRequest = SequencingRequest.Previous;
         return;
     case SequencingRuleAction.ExitParent:
         // Terminate the appropriate activity(s)
         m_navigator.LogSequencing(SequencingEventType.IntermediateNavigation, m_command, Resources.SequencingPostConditionRuleResult, activity.Key, Resources.SequencingPostConditionRuleRequestExitParent);
         termRequest = TerminationRequest.ExitParent;
         return;
     case SequencingRuleAction.ExitAll:
         // Terminate the appropriate activity(s)
         m_navigator.LogSequencing(SequencingEventType.IntermediateNavigation, m_command, Resources.SequencingPostConditionRuleResult, activity.Key, Resources.SequencingPostConditionRuleRequestExitAll);
         termRequest = TerminationRequest.ExitAll;
         return;
     case SequencingRuleAction.RetryAll:
         // Terminate all active activities and move the current activity to the root of the activity tree; then perform an 'in-process' start
         m_navigator.LogSequencing(SequencingEventType.IntermediateNavigation, m_command, Resources.SequencingPostConditionRuleResult, activity.Key, Resources.SequencingPostConditionRuleRequestRetryAll);
         seqRequest = SequencingRequest.Retry;
         termRequest = TerminationRequest.ExitAll;
         return;
     }
 }
Ejemplo n.º 5
0
            SequencingRequest? ProcessTerminationRequest(TerminationRequest termRequest)
            {
                if(termRequest != TerminationRequest.AbandonAll && m_navigator.CurrentActivity == null)
                {
                    throw new SequencingException(SequencingExceptionCode.TB_2_3__1);
                }
                // If the current activity has already been terminated, there is nothing to terminate
                if((termRequest == TerminationRequest.Exit || termRequest == TerminationRequest.Abandon) &&
                    !m_navigator.CurrentActivity.DataModel.ActivityIsActive)
                {
                    throw new SequencingException(SequencingExceptionCode.TB_2_3__2);
                }
                SequencingRequest? seqRequest = null;
                switch(termRequest)
                {
                case TerminationRequest.Exit:
                    // Ensure the state of the current activity is up to date
                    EndAttemptProcess(m_navigator.CurrentActivity);

                    // Check if any of the current activity's ancestors need to terminate
                    SequencingExitActionRules(m_navigator.CurrentActivity);

                    bool processedExit;
                    do
                    {
                        processedExit = false;
                        TerminationRequest? newTermRequest;
                        SequencingPostConditionRules(m_navigator.CurrentActivity, out seqRequest, out newTermRequest);
                        if(newTermRequest == TerminationRequest.ExitAll)
                        {
                            // Process an Exit All Termination Request
                            goto exitAllLabel;
                        }
                        else if(newTermRequest == TerminationRequest.ExitParent)
                        {
                            // If we exit the parent of the current activity, move 
                            // the current activity to the parent of the current activity.
                            if(m_navigator.CurrentActivity == m_navigator.RootActivity)
                            {
                                // The root of the activity tree does not have a parent to exit
                                throw new SequencingException(SequencingExceptionCode.TB_2_3__4);
                            }
                            m_navigator.CurrentActivity = m_navigator.CurrentActivity.Parent;
                            EndAttemptProcess(m_navigator.CurrentActivity);
                            processedExit = true;
                        }
                        else
                        {
                            // If the attempt on the root of the Activity Tree is ending without a 
                            // Retry, the Sequencing Session also ends
                            if(m_navigator.CurrentActivity == m_navigator.RootActivity && seqRequest != SequencingRequest.Retry)
                            {
                                seqRequest = SequencingRequest.Exit;
                            }
                        }
                    } while(processedExit);
                    break;
                case TerminationRequest.ExitAll:
exitAllLabel:
                    if(m_navigator.CurrentActivity.DataModel.ActivityIsActive)
                    {
                        EndAttemptProcess(m_navigator.CurrentActivity);
                    }
                    TerminateDescendentAttempts(m_navigator.CurrentActivity, m_navigator.RootActivity);
                    EndAttemptProcess(m_navigator.RootActivity);
                    m_navigator.CurrentActivity = m_navigator.RootActivity;
                    if(seqRequest == null)
                    {
                        seqRequest = SequencingRequest.Exit;
                    }
                    break;
                case TerminationRequest.SuspendAll:
                    // If the current activity is active or already suspended, suspend it and all of its descendents
                    if(m_navigator.CurrentActivity.DataModel.ActivityIsActive || m_navigator.CurrentActivity.DataModel.ActivityIsSuspended)
                    {
                        m_navigator.SuspendedActivity = m_navigator.CurrentActivity;
                    }
                    else
                    {
                         // Make sure the current activity is not the root of the activity tree
                        if(m_navigator.CurrentActivity != m_navigator.RootActivity)
                        {
                            m_navigator.SuspendedActivity = m_navigator.CurrentActivity.Parent;
                        }
                        else
                        {
                             // Nothing to suspend
                            throw new SequencingException(SequencingExceptionCode.TB_2_3__3);
                        }
                    }
                    for(Activity a = m_navigator.SuspendedActivity ; a != null ; a = a.Parent)
                    {
                        a.DataModel.ActivityIsSuspended = true;
                        a.DataModel.ActivityIsActive = false;
                        ExtendedRollup(a);
                    }
                    if(m_navigator.SuspendedActivity.IsLeaf)
                    {
                        FinalizeDataModelPriorToExit(m_navigator.SuspendedActivity);
                    }
                    m_navigator.CurrentActivity = m_navigator.RootActivity;
                    seqRequest = SequencingRequest.Exit;
                    break;
                case TerminationRequest.Abandon:
                    m_navigator.CurrentActivity.DataModel.ActivityIsActive = false;
                    ExtendedRollup(m_navigator.CurrentActivity);
                    break;
                case TerminationRequest.AbandonAll:
                    for(Activity a = m_navigator.CurrentActivity ; a != null ; a = a.Parent)
                    {
                        a.DataModel.ActivityIsActive = false;
                        ExtendedRollup(a);
                    }
                    m_navigator.CurrentActivity = m_navigator.RootActivity;
                    seqRequest = SequencingRequest.Exit;
                    break;
                }
                return seqRequest;
            }
Ejemplo n.º 6
0
            private void ProcessNavigationRequest(Activity destination, out SequencingRequest? seqRequest, 
                out TerminationRequest? termRequest)
            {
                seqRequest = null;
                termRequest = null;
                switch(m_command)
                {
                case NavigationCommand.Abandon:
                    if(m_navigator.CurrentActivity != null)
                    {
                        if(m_navigator.CurrentActivity.DataModel.ActivityIsActive)
                        {
                            termRequest = TerminationRequest.Abandon;
                            seqRequest = SequencingRequest.Exit;
                        }
                        else
                        {
                            throw new SequencingException(SequencingExceptionCode.NB_2_1__12);
                        }
                    }
                    else
                    {
                        throw new SequencingException(SequencingExceptionCode.NB_2_1__2);
                    }
                    break;
                case NavigationCommand.AbandonAll:
                    // the check for CurrentActivity != null was removed
                    // so this function should always succeed
                    termRequest = TerminationRequest.AbandonAll;
                    seqRequest = SequencingRequest.Exit;
                    break;
                case NavigationCommand.Choose:
                    if(destination == m_navigator.RootActivity || destination.Parent.Sequencing.Choice)
                    {
                        if(m_navigator.CurrentActivity == null)
                        {
                            seqRequest = SequencingRequest.Choice;
                            return;
                        }
                        // We are always allowed to choose a sibling of the current activity - INCORRECT DESPITE BEING IN THE SCORM PSEUDOCODE
                        // if(destination.Parent != m_navigator.CurrentActivity.Parent)
                        {
                            // The common ancestor will not terminate as a result of processing the choice sequencing request, 
                            // unless the common ancestor is the CurrentActivity - the current activity should always 
                            // be included in the activity path
                            Activity ancestor = FindCommonAncestor(m_navigator.CurrentActivity, destination);
                            Activity final;
                            if(ancestor == m_navigator.CurrentActivity)
                            {
                                final = ancestor.Parent;
                            }
                            else
                            {
                                final = ancestor;
                            }

                            // Make sure that 'choosing' the target will not force an active activity to terminate, 
                            // if that activity does not allow choice to terminate it
                            for(Activity a = m_navigator.CurrentActivity ; a != final ; a = a.Parent)
                            {
                                if(a.DataModel.ActivityIsActive && !a.Sequencing.ChoiceExit)
                                {
                                    throw new SequencingException(SequencingExceptionCode.NB_2_1__8);
                                }
                            }
                        }
                        if(m_navigator.CurrentActivity.DataModel.ActivityIsActive)
                        {
                            termRequest = TerminationRequest.Exit;
                        }
                        seqRequest = SequencingRequest.Choice;
                    }
                    else
                    {
                        throw new SequencingException(SequencingExceptionCode.NB_2_1__10);
                    }
                    break;
                case NavigationCommand.Continue:
                    if(m_navigator.CurrentActivity == null)
                    {
                        throw new SequencingException(SequencingExceptionCode.NB_2_1__2);
                    }
                    // Validate that a 'flow' sequencing request can be processed from the current activity
                    if(m_navigator.CurrentActivity != m_navigator.RootActivity && m_navigator.CurrentActivity.Parent.Sequencing.Flow)
                    {
                        seqRequest = SequencingRequest.Continue;

                        // If the current activity has not been terminated, terminate the current the activity
                        if(m_navigator.CurrentActivity.DataModel.ActivityIsActive)
                        {
                            termRequest = TerminationRequest.Exit;
                        }
                    }
                    else
                    {
                        // Flow is not enabled or the current activity is the root of the activity tree
                        throw new SequencingException(SequencingExceptionCode.NB_2_1__4);
                    }
                    break;
                case NavigationCommand.ExitAll:
                    if(m_navigator.CurrentActivity != null)
                    {
                        // If the sequencing session has already begun, unconditionally terminate all active activities
                        termRequest = TerminationRequest.ExitAll;
                        seqRequest = SequencingRequest.Exit;
                    }
                    else
                    {
                        throw new SequencingException(SequencingExceptionCode.NB_2_1__2);
                    }
                    break;
                case NavigationCommand.Previous:
                    if(m_navigator.CurrentActivity == null)
                    {
                        throw new SequencingException(SequencingExceptionCode.NB_2_1__2);
                    }
                    // Validate that a 'flow' sequencing request can be processed from the current activity
                    if(m_navigator.CurrentActivity != m_navigator.RootActivity)
                    {
                        if(m_navigator.CurrentActivity.Parent.Sequencing.Flow && !m_navigator.CurrentActivity.Parent.Sequencing.ForwardOnly)
                        {
                            seqRequest = SequencingRequest.Previous;

                            // If the current activity has not been terminated, terminate the current the activity
                            if(m_navigator.CurrentActivity.DataModel.ActivityIsActive)
                            {
                                termRequest = TerminationRequest.Exit;
                            }
                        }
                        else
                        {
                            // Violates control mode
                            throw new SequencingException(SequencingExceptionCode.NB_2_1__5);
                        }
                    }
                    else
                    {
                        // // Cannot move backward from the root of the activity tree
                        throw new SequencingException(SequencingExceptionCode.NB_2_1__6);
                    }
                    break;
                case NavigationCommand.ResumeAll:
                    if(m_navigator.CurrentActivity == null)
                    {
                        if(m_navigator.SuspendedActivity != null)
                        {
                            seqRequest = SequencingRequest.ResumeAll;
                        }
                        else
                        {
                            throw new SequencingException(SequencingExceptionCode.NB_2_1__3);
                        }
                    }
                    else
                    {
                        throw new SequencingException(SequencingExceptionCode.NB_2_1__1);
                    }
                    break;
                case NavigationCommand.Start:
                    if(m_navigator.CurrentActivity != null)
                    {
                        throw new SequencingException(SequencingExceptionCode.NB_2_1__1);
                    }
                    seqRequest = SequencingRequest.Start;
                    break;
                case NavigationCommand.SuspendAll:
                    if(m_navigator.CurrentActivity != null)
                    {
                        termRequest = TerminationRequest.SuspendAll;
                        seqRequest = SequencingRequest.Exit;
                    }
                    else
                    {
                        throw new SequencingException(SequencingExceptionCode.NB_2_1__2);
                    }
                    break;
                case NavigationCommand.UnqualifiedExit:
                    if(m_navigator.CurrentActivity == null)
                    {
                        throw new SequencingException(SequencingExceptionCode.NB_2_1__2);
                    }
                    if(m_navigator.CurrentActivity.DataModel.ActivityIsActive)
                    {
                        termRequest = TerminationRequest.Exit;
                        seqRequest = SequencingRequest.Exit;
                    }
                    else
                    {
                        throw new SequencingException(SequencingExceptionCode.NB_2_1__12);
                    }
                    break;
                default:
                    throw new LearningComponentsInternalException("SSN0001");
                }
            }
 public int Update(TerminationRequest o)
 {
     using (var db = new BillingDbContext())
     {
         var ori = Select(o.No, true);
         if (ori == null)
         {
             return(0);
         }
         if (o.RequestInfo != null)
         {
             var ri = o.RequestInfo;
             if (ri.No == 0)
             {
                 ori.RequestInfo    = ri;
                 db.Entry(ri).State = EntityState.Added;
             }
             else
             {
                 db.RequestInfos.Attach(ori.RequestInfo);
                 ClassCopier.Instance.Copy(ri, ori.RequestInfo);
                 if (ri.Terminations.Count > 0)
                 {
                     var list1 = ri.Terminations;
                     foreach (var ti in list1)
                     {
                         if (ti.No == 0)
                         {
                             ori.RequestInfo.Terminations.Add(ti);
                             db.Entry(ti).State = EntityState.Added;
                         }
                         else
                         {
                             var list2 = ori.RequestInfo.Terminations;
                             var term  = list2.Find(x => x.No == ti.No);
                             db.Terminations.Attach(term);
                             db.Entry(term).CurrentValues.SetValues(ti);
                             db.Entry(term).State = EntityState.Modified;
                         }
                     }
                 }
             }
         }
         if (o.Routing != null)
         {
             var ri = o.Routing;
             if (ri.No == 0)
             {
                 ori.Routing        = ri;
                 db.Entry(ri).State = EntityState.Added;
             }
             else
             {
                 ClassCopier.Instance.Copy(o.Routing, ori.Routing);
                 db.Entry(ori.Routing).State = EntityState.Modified;
                 if (ri.Routings.Count > 0)
                 {
                     var list2 = ri.Routings;
                     foreach (var ri1 in list2)
                     {
                         if (ri1.No == 0)
                         {
                             ori.Routing.Routings.Add(ri1);
                             db.Entry(ri1).State = EntityState.Added;
                         }
                         else
                         {
                             var oriri = ori.Routing.Routings.Find(x => x.No == ri1.No);
                             db.RoutingItems.Attach(oriri);
                             db.Entry(oriri).CurrentValues.SetValues(ri1);
                             db.Entry(oriri).State = EntityState.Modified;
                         }
                     }
                 }
                 if (ri.Terminations.Count > 0)
                 {
                     var list3 = ri.Terminations;
                     foreach (var ti in list3)
                     {
                         if (ti.No == 0)
                         {
                             ori.Routing.Terminations.Add(ti);
                             db.Entry(ti).State = EntityState.Added;
                         }
                         else
                         {
                             var oriti = ori.Routing.Terminations.Find(y => y.No == ti.No);
                             db.Terminations.Attach(oriti);
                             if (ti.TerminatedContract != null)
                             {
                                 var tc = ti.TerminatedContract;
                                 if (tc.No == 0)
                                 {
                                     oriti.TerminatedContract = tc;
                                     db.Entry(tc).State       = EntityState.Added;
                                 }
                                 else
                                 {
                                     db.Entry(oriti.TerminatedContract).CurrentValues.SetValues(tc);
                                     db.Entry(tc).State = EntityState.Modified;
                                 }
                             }
                         }
                     }
                 }
             }
         }
         db.Entry(o).State = EntityState.Modified;
         return(db.SaveChanges());
     }
 }