コード例 #1
0
        /// <summary>
        /// Gets the next active command to be processed.
        /// </summary>
        /// <param name="sessionGroupId">The GUID that's used as the unique Id of the subject session group.</param>
        /// <returns>The next active command; NULL if there is a command being processed or no active command.</returns>
        public PipelineSyncCommand?GetNextActiveCommand(Guid sessionGroupId)
        {
            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                int newStateValue        = (int)PipelineSyncCommandState.New;
                int processingStateValue = (int)PipelineSyncCommandState.Processing;

                var cmdQuery = from c in context.RTOrchestrationCommandSet
                               where (c.Status == newStateValue || c.Status == processingStateValue) &&
                               c.SessionGroup.GroupUniqueId.Equals(sessionGroupId)
                               orderby c.Id
                               select c;

                if (cmdQuery.Count() == 0 ||
                    cmdQuery.First().Status == processingStateValue)
                {
                    return(null);
                }

                RTOrchestrationCommand nextCmd = cmdQuery.First();
                nextCmd.Status = (int)PipelineSyncCommandState.Processing;

                context.TrySaveChanges();

                return((PipelineSyncCommand)nextCmd.Command);
            }
        }
コード例 #2
0
 /// <summary>
 /// Add a new sync command to the queue for processing.
 /// </summary>
 /// <param name="sessionGroupId">The GUID that's used as the unique Id of the subject session group.</param>
 /// <param name="newCmd">The new command to be appended to the queue.</param>
 public void AddCommand(Guid sessionGroupId, PipelineSyncCommand newCmd)
 {
     using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
     {
         var sessionGroupQuery =
             from sg in context.RTSessionGroupSet
             where sg.GroupUniqueId.Equals(sessionGroupId)
             select sg;
         Debug.Assert(sessionGroupQuery.Count() == 1, "sessionGroupQuery.Count() != 1");
         if (sessionGroupQuery.Count() != 1)
         {
             // [teyang] TODO add exception desc
             throw new InvalidOperationException();
         }
         var rtSessionGroup             = sessionGroupQuery.First();
         RTOrchestrationCommand command = RTOrchestrationCommand.CreateRTOrchestrationCommand(
             0,                                 // identity column id is auto-generated
             (int)newCmd,
             (int)PipelineSyncCommandState.New);
         command.SessionGroup = rtSessionGroup;
         context.AddToRTOrchestrationCommandSet(command);
         context.TrySaveChanges();
     }
 }