예제 #1
0
 private void ThrowIfViolatingWipLimit(WorkItemTransition transition)
 {
     if (!WipLimitChecker.CanAcceptWorkItem(transition.WorkItem.MoveTo(transition.WorkStep, _timeSource.GetTime())))
     {
         throw new WipLimitViolationException(transition.WorkItem, transition.WorkStep);
     }
 }
예제 #2
0
 // Update is called once per frame
 private void Update()
 {
     if (_playing)
     {
         _wrapper.ReadFrame(VideoGap + TimeSource.GetTime(), _buffer);
         _texture.LoadRawTextureData(_buffer);
         _texture.Apply();
     }
 }
        private void Create(WorkItem newWorkItem)
        {
            var leafStep = WorkflowRepository.GetLeafStep(newWorkItem.Path);

            if (leafStep.Type != WorkStepType.Begin)
            {
                throw new InvalidOperationException("Can only create work items in begin step");
            }

            var classes = WorkflowRepository.GetWorkItemClasses(leafStep);

            newWorkItem = newWorkItem.MoveTo(leafStep, _timeSource.GetTime()).UpdateClasses(classes);

            WorkStep transientStep;

            if (WorkflowRepository.IsWithinTransientStep(leafStep, out transientStep))
            {
                var parentItem = GetTransientParentWorkItem(transientStep);
                WorkflowRepository.UpdateWorkItem(parentItem.UpdateStatus(WorkItemStatus.ExpandLocked));

                newWorkItem = newWorkItem.MoveTo(leafStep, _timeSource.GetTime()).UpdateParent(parentItem, WorkItemParentType.Expanded);

                foreach (var workItemClass in newWorkItem.Classes)
                {
                    foreach (var rootClass in WorkItemClass.FindRootClasses(workItemClass))
                    {
                        newWorkItem = newWorkItem.AddClass(rootClass);
                    }
                }
            }
            else if (WorkflowRepository.IsWithinExpandStep(leafStep))
            {
                throw new InvalidOperationException("Cannot create item directly under expand step");
            }

            if (!newWorkItem.Ordinal.HasValue)
            {
                newWorkItem = newWorkItem.UpdateOrdinal(WorkflowRepository.GetNextOrdinal(newWorkItem));
            }

            WorkflowRepository.CreateWorkItem(newWorkItem);
        }
예제 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IdGenerator"/> class.
        /// </summary>
        /// <param name="generatorId">The Id of the generator.</param>
        /// <param name="epoch">The Epoch of the generator.</param>
        /// <param name="maskConfig">The <see cref="MaskConfig"/> of the generator.</param>
        /// <param name="timeSource">The time-source to use when acquiring time data.</param>
        /// <exception cref="ArgumentNullException">Thrown when either maskConfig or timeSource is null.</exception>
        /// <exception cref="InvalidOperationException">Thrown when maskConfig defines a non-63 bit bitmask.</exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Thrown when GeneratorId or Sequence masks are >31 bit, GeneratorId exceeds maximum value or epoch in future.
        /// </exception>
        public IdGenerator(int generatorId, DateTime epoch, MaskConfig maskConfig, ITimeSource timeSource)
        {
            if (maskConfig == null)
            {
                throw new ArgumentNullException("maskConfig");
            }

            if (timeSource == null)
            {
                throw new ArgumentNullException("timeSource");
            }

            if (maskConfig.TotalBits != 63)
            {
                throw new InvalidOperationException("Number of bits used to generate Id's is not equal to 63");
            }

            if (maskConfig.GeneratorIdBits > 31)
            {
                throw new ArgumentOutOfRangeException("GeneratorId cannot have more than 31 bits");
            }

            if (maskConfig.SequenceBits > 31)
            {
                throw new ArgumentOutOfRangeException("Sequence cannot have more than 31 bits");
            }

            if (epoch > timeSource.GetTime())
            {
                throw new ArgumentOutOfRangeException("Epoch in future");
            }

            // Precalculate some values
            MASK_TIME      = GetMask(maskConfig.TimestampBits);
            MASK_GENERATOR = GetMask(maskConfig.GeneratorIdBits);
            MASK_SEQUENCE  = GetMask(maskConfig.SequenceBits);

            if (generatorId < 0 || generatorId > MASK_GENERATOR)
            {
                throw new ArgumentOutOfRangeException(string.Format("GeneratorId must be between 0 and {0} (inclusive).", MASK_GENERATOR));
            }

            SHIFT_TIME      = maskConfig.GeneratorIdBits + maskConfig.SequenceBits;
            SHIFT_GENERATOR = maskConfig.SequenceBits;

            // Store instance specific values
            _maskconfig  = maskConfig;
            _timesource  = timeSource;
            _epoch       = epoch;
            _generatorId = generatorId;
        }
예제 #5
0
        private void MoveWorkStepRecursively(WorkStep stepToMove, WorkStep toStep)
        {
            var leafDirectory = WorkflowPath.GetLeafDirectory(stepToMove.Path);

            var newPath = WorkflowPath.CombinePath(toStep.Path, leafDirectory);

            var newStep = stepToMove.UpdatePath(newPath);

            _workflowRepository.CreateWorkStep(newStep);

            foreach (var workItem in _workflowRepository.GetWorkItems(stepToMove.Path))
            {
                _workflowRepository.UpdateWorkItem(workItem.MoveTo(newStep, _timeSource.GetTime()));
            }

            foreach (var childWorkStep in _workflowRepository.GetChildWorkSteps(stepToMove.Path))
            {
                MoveWorkStep(childWorkStep, newStep);
            }

            _workflowRepository.DeleteWorkStep(stepToMove.Path);
        }
예제 #6
0
 private long GetTimestamp()
 {
     return((long)(_timesource.GetTime() - _epoch).TotalMilliseconds);
 }