/// <summary>
 /// Constructor
 /// </summary>
 /// <param name="lane"></param>
 public StayInLaneState(ArbiterLane lane, Probability confidence, IState previous)
 {
     this.Lane = lane;
     this.internalLaneState  = new InternalState(lane.LaneId, lane.LaneId, confidence);
     this.IgnorableWaypoints = new List <IgnorableWaypoint>();
     this.CheckPreviousState(previous);
 }
Beispiel #2
0
 public ObjectState(BjSJsonReader reader, Action <BjSJsonObject> onDone)
 {
     _reader      = reader;
     _onDone      = onDone;
     _curr        = new BjSJsonObject();
     _internState = InternalState.WaitForName;
 }
Beispiel #3
0
        public override void Complete()
        {
            switch (_state)
            {
            case InternalState.IncompleteBufferWriter:
                _state = InternalState.CompleteBufferWriter;

                if (!DirectSerializationSupported)
                {
                    CompatibilityHelpers.Assert(_bufferWriter != null, "Buffer writer has been set to get to this state.");

                    var data = _bufferWriter.WrittenSpan;

                    GrpcCallLog.SerializedMessage(_call.Logger, _call.RequestType, data.Length);
                    WriteMessage(data);
                }
                else
                {
                    GrpcCallLog.SerializedMessage(_call.Logger, _call.RequestType, _payloadLength.GetValueOrDefault());
                }
                break;

            default:
                ThrowInvalidState(_state);
                break;
            }
        }
Beispiel #4
0
 public MovementController()
 {
     internalState     = InternalState.NONE;
     movementDirection = Direction.NONE;
     distToMove        = 0.0f;
     starterDistToMove = 0.0f;
 }
Beispiel #5
0
        private static void Compress(InternalState internalState, byte[] block, int start)
        {
            var m = new UInt64[16];

            Buffer.BlockCopy(block, start, m, 0, BlockSizeBytes);


            var v = new UInt64[16];

            Array.Copy(internalState.H, v, internalState.H.Length);
            Array.Copy(IVs, 0, v, 8, IVs.Length);

            v[12] ^= internalState.Counter.Low;
            v[13] ^= internalState.Counter.High;
            v[14] ^= internalState.FinalizationFlags[0];
            v[15] ^= internalState.FinalizationFlags[1];


            ComputeRounds(v, m);

            //Finalization
            internalState.H[0] ^= v[0] ^ v[8];
            internalState.H[1] ^= v[1] ^ v[9];
            internalState.H[2] ^= v[2] ^ v[10];
            internalState.H[3] ^= v[3] ^ v[11];
            internalState.H[4] ^= v[4] ^ v[12];
            internalState.H[5] ^= v[5] ^ v[13];
            internalState.H[6] ^= v[6] ^ v[14];
            internalState.H[7] ^= v[7] ^ v[15];
        }
Beispiel #6
0
        public void Abort()
        {
            if ((state == InternalState.PENDING) || (state == InternalState.RUNNING))
            {
                try
                {
                    if (state == InternalState.RUNNING)
                    {
                        StopDevice();
                    }

                    state = InternalState.IDLE;
                    StateChanged?.Invoke(this, State);
                    Log.Status("Test [{0}] aborted", Name);
                }
                catch (Exception e)
                {
                    Log.Debug(e.Message);
                }
            }
            else
            {
                Log.Debug("Attempted to abort test while it was in {0} state", state.ToString());
            }
        }
Beispiel #7
0
    /// <summary>
    ///     Determines whether the current XPathNavigator is at the same position as the specified XPathNavigator.
    /// </summary>
    /// <param name="nav">The XPathNavigator to compare to this XPathNavigator.</param>
    /// <returns>true if the two XPathNavigator objects have the same position; otherwise, false.</returns>
    public override bool IsSamePosition(XPathNavigator nav)
    {
        DebugEnter("IsSamePosition");
        bool isSame;

        switch (InternalState.Position)
        {
        case StatePosition.PropertyXml:
            isSame = InternalState.XmlFragmentNavigator?.IsSamePosition(nav) ?? false;
            break;

        case StatePosition.Attribute:
        case StatePosition.Element:
        case StatePosition.PropertyElement:
        case StatePosition.PropertyText:
        case StatePosition.Root:
            var other = nav as NavigableNavigator;
            isSame = other != null && other._source == _source && InternalState.IsSamePosition(other.InternalState);
            break;

        default:
            throw new InvalidOperationException("Invalid position.");
        }

        DebugReturn(isSame);
        return(isSame);
    }
Beispiel #8
0
        void processStatePausing()
        {
            if (glSurfaceAvailable)
            {
                // Surface we are using needs to go away
                DestroyGLSurface();

                if (loaded)
                {
                    OnUnload(EventArgs.Empty);
                }
            }

            // trigger callbacks, must pause openAL device here
            var d = OnPauseGameThread;

            if (d != null)
            {
                d(this, EventArgs.Empty);
            }

            // go to next state
            lock (_lockObject)
            {
                _internalState = InternalState.Paused_GameThread;
            }
        }
Beispiel #9
0
        /// <summary>Called automatically in <see cref="OnDestroy"/></summary>
        protected virtual void Dispose()
        {
            Initialized = false;

            if (_Params != null && _Params.scrollRect)
            {
                _Params.scrollRect.onValueChanged.RemoveListener(OnScrollViewValueChanged);
            }

            if (_SmoothScrollCoroutine != null)
            {
                try { StopCoroutine(_SmoothScrollCoroutine); } catch { }

                _SmoothScrollCoroutine = null;
            }

            ClearCachedRecyclableItems();
            _RecyclableItems = null;

            ClearVisibleItems();
            _VisibleItems = null;

            _Params        = null;
            _InternalState = null;

            if (ItemsRefreshed != null)
            {
                ItemsRefreshed = null;
            }
        }
Beispiel #10
0
        public override void Complete()
        {
            switch (_state)
            {
            case InternalState.IncompleteBufferWriter:
                _state = InternalState.CompleteBufferWriter;

                if (!DirectSerializationSupported)
                {
                    Debug.Assert(_bufferWriter != null, "Buffer writer has been set to get to this state.");

                    var data = _bufferWriter.WrittenSpan;

                    GrpcServerLog.SerializedMessage(_serverCallContext.Logger, typeof(object), data.Length);
                    WriteMessage(data);
                }
                else
                {
                    GrpcServerLog.SerializedMessage(_serverCallContext.Logger, _serverCallContext.ResponseType, _payloadLength.GetValueOrDefault());
                }
                break;

            default:
                ThrowInvalidState(_state);
                break;
            }
        }
Beispiel #11
0
        public GameState Play(FieldCoordinates action)
        {
            if (action == FieldCoordinates.Pass)
            {
                if (PreviousMove == FieldCoordinates.Pass)
                {
                    return(new GameState(CurrentPlayer.Opposite, InternalState.Pass()));
                }
                else
                {
                    return(new GameState(FieldCoordinates.Pass, CurrentPlayer.Opposite, InternalState.Pass()));
                }
            }
            else
            {
                GameStateInternal nextState = InternalState.Play(action.X, action.Y, CurrentPlayer);

                if (nextState == null)
                {
                    throw new Exception();
                }
                else
                {
                    return(new GameState(action, CurrentPlayer.Opposite, nextState));
                }
            }
        }
Beispiel #12
0
        private void InitiateUnload()
        {
            var unloading = Unloading;

            Unloading = null;
            unloading?.Invoke(this);

            // When in Unloading state, we are not supposed to be called on the finalizer
            // as the native side is holding a strong reference after calling Unload
            lock (unloadLock)
            {
                if (!_isProcessExiting)
                {
                    Debug.Assert(state == InternalState.Alive);

                    var thisStrongHandle    = GCHandle.Alloc(this, GCHandleType.Normal);
                    var thisStrongHandlePtr = GCHandle.ToIntPtr(thisStrongHandle);
                    // The underlying code will transform the original weak handle
                    // created by InitializeLoadContext to a strong handle
                    PrepareForAssemblyLoadContextRelease(m_pNativeAssemblyLoadContext, thisStrongHandlePtr);
                }

                state = InternalState.Unloading;
            }

            if (!_isProcessExiting)
            {
                lock (ContextsToUnload)
                {
                    ContextsToUnload.Remove(id);
                }
            }
        }
Beispiel #13
0
        protected override IntelligenceInput NextInput()
        {
            if (Output.Object == outputs[goodidx])
            {
                state = (InternalState)(Math.Min((int)(state + 1), numStates));
            }
            else
            {
                state = (InternalState)(Math.Max((int)(state - 1), 1));
            }
            // toggle it
            goodidx = (goodidx + 1) % outputs.Length;

            switch (state)
            {
            //case InternalState.Intermediate1:
            //case InternalState.Intermediate3:
            //case InternalState.Intermediate2:
            //case InternalState.Intermediate4:
            //    return new IntelligenceInput { Object = 5, Contentment = 0.5 };

            case InternalState.HappyPlace:
                return(new IntelligenceInput {
                    Object = 1, Contentment = 1.0
                });

            case InternalState.SadPlace:
            default:
                return(new IntelligenceInput {
                    Object = 9, Contentment = 0.0
                });
            }
        }
Beispiel #14
0
        public MultiTaskController(
            [NotNull] GameControlInfo gameControlInfo,
            int threadCount,
            [NotNull] ICollection <Func <TResult> > tasks)
        {
            if (threadCount <= 0)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(threadCount),
                          threadCount,
                          @"The value must be positive.");
            }

            if (tasks is null)
            {
                throw new ArgumentNullException(nameof(tasks));
            }

            if (tasks.Any(item => item is null))
            {
                throw new ArgumentException(@"The collection contains a null element.", nameof(tasks));
            }

            _syncLock        = new object();
            _gameControlInfo = gameControlInfo ?? throw new ArgumentNullException(nameof(gameControlInfo));
            _taskSlots       = tasks.Select(obj => new TaskSlot(obj)).ToArray();
            _threads         = Enumerable.Range(1, threadCount).Select(index => CreateThread(index, threadCount)).ToArray();
            _exceptions      = new List <Exception>();

            _state     = InternalState.Ready;
            _taskIndex = 0;
        }
Beispiel #15
0
 private void ValidateIsNotIn(InternalState internalState)
 {
     if (_internalState == internalState)
     {
         ThrowByInternalState();
     }
 }
Beispiel #16
0
 private void ValidateIsIn(InternalState state)
 {
     if (_internalState != state)
     {
         ThrowByInternalState();
     }
 }
Beispiel #17
0
        internal Core(ISettings settings, IInteractionService interactionService, IDispatcher dispatcher)
        {
            _logger.Info("Creating new core instance");
            var state = new InternalState(settings);

            var services = new ServiceProvider();

            services.Add <IAsyncVoidExecutor>(new AsyncVoidExecutor());
            services.Add(Types.Default);
            services.Add(dispatcher);
            services.Add(interactionService);
            services.Add <IDialogService>(new DialogService(services));
            services.Add <IEventManager>(new EventManager());
            services.Add <IRepositoryStateService>(new RepositoryStateService(services));

            // TODO: should this be registered somewhere?
            new PresetGeneratorService(services);

            var model = new Model.Model(state, services, state.CheckIsFirstStart());

            services.Add <IModel>(model);

            // TODO: should we use different service providers to avoid accidental abuse?
            _viewModel = new ViewModel.ViewModel(services);
            model.Load();
        }
Beispiel #18
0
        public void SwitchState(CoordinateAlignerStates newState)
        {
            myPrevState = newState;
            switch (newState)
            {
            case CoordinateAlignerStates.Idle:
                break;

            case CoordinateAlignerStates.CaptureInitialPair:
                myInternalState = InternalState.Show_Message_Space;
                break;

            case CoordinateAlignerStates.CapturingFinalpair:
                break;

            case CoordinateAlignerStates.CaptureFinalPair:
                if (myDriver.initialPoints.Count > myDriver.minSamplePointsNeeded)
                {
                    myInternalState         = InternalState.Show_Message_CompleteCapture1;
                    myDriver.myCurrentState = CoordinateAlignerStates.PendingAlignment;
                }
                else
                {
                    myInternalState = InternalState.Show_Message_CompleteCapture0;
                }
                break;

            case CoordinateAlignerStates.Reset:
                break;

            case CoordinateAlignerStates.Calculating:
                myInternalState = InternalState.Show_Message_CalculatingAlignment0;
                break;
            }
        }
        private void InitiateUnload()
        {
            RaiseUnloadEvent();

            // When in Unloading state, we are not supposed to be called on the finalizer
            // as the native side is holding a strong reference after calling Unload
            lock (_unloadLock)
            {
                Debug.Assert(_state == InternalState.Alive);

                var thisStrongHandle    = GCHandle.Alloc(this, GCHandleType.Normal);
                var thisStrongHandlePtr = GCHandle.ToIntPtr(thisStrongHandle);
                // The underlying code will transform the original weak handle
                // created by InitializeLoadContext to a strong handle
                PrepareForAssemblyLoadContextRelease(_nativeAssemblyLoadContext, thisStrongHandlePtr);

                _state = InternalState.Unloading;
            }

            Dictionary <long, WeakReference <AssemblyLoadContext> > allContexts = AllContexts;

            lock (allContexts)
            {
                allContexts.Remove(_id);
            }
        }
Beispiel #20
0
        public override IBufferWriter <byte> GetBufferWriter()
        {
            switch (_state)
            {
            case InternalState.Initialized:
                // When writing directly to the buffer the header with message size needs to be written first
                if (DirectSerializationSupported)
                {
                    Debug.Assert(_payloadLength != null, "A payload length is required for direct serialization.");

                    EnsureMessageSizeAllowed(_payloadLength.Value);

                    WriteHeader(ResponseBufferWriter, _payloadLength.Value, compress: false);
                }

                _state = InternalState.IncompleteBufferWriter;
                return(ResolveBufferWriter());

            case InternalState.IncompleteBufferWriter:
                return(ResolveBufferWriter());

            default:
                ThrowInvalidState(_state);
                return(default !);
            }
        }
Beispiel #21
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="lane"></param>
 public StayInSupraLaneState(SupraLane lane, IState previous)
 {
     this.Lane = lane;
     this.internalLaneState  = new InternalState(lane.Initial.LaneId, lane.Final.LaneId);
     this.IgnorableWaypoints = new List <IgnorableWaypoint>();
     this.CheckPreviousState(previous);
 }
Beispiel #22
0
        protected void WorkerThreadFrameDispatcher(SynchronizationContext uiThreadSyncContext)
        {
            Threading.ResetThread(Thread.CurrentThread.ManagedThreadId);
            try
            {
                stopWatch      = System.Diagnostics.Stopwatch.StartNew();
                tick           = 0;
                prevUpdateTime = DateTime.Now;

                while (!cts.IsCancellationRequested)
                {
                    // either use UI thread to render one frame or this worker thread
                    bool pauseThread = false;
                    if (RenderOnUIThread)
                    {
                        uiThreadSyncContext.Send((s) =>
                        {
                            pauseThread = RunIteration(cts.Token);
                        }, null);
                    }
                    else
                    {
                        pauseThread = RunIteration(cts.Token);
                    }


                    if (pauseThread)
                    {
                        _waitForPausedStateProcessed.Set();
                        _waitForMainGameLoop.WaitOne(); // pause this thread
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error("AndroidGameView", ex.ToString());
            }
            finally
            {
                bool c = cts.IsCancellationRequested;

                cts = null;

                if (glSurfaceAvailable)
                {
                    DestroyGLSurface();
                }

                if (glContextAvailable)
                {
                    DestroyGLContext();
                    ContextLostInternal();
                }

                lock (_lockObject)
                {
                    _internalState = InternalState.Exited_GameThread;
                }
            }
        }
Beispiel #23
0
    public override Entity Create(EntityManager entityManager, List <Entity> entities)
    {
        var entity = CreateCharBehavior(entityManager);

        entities.Add(entity);

        // Ability components
        var internalState = new InternalState
        {
            rayQueryId = -1
        };
        var predictedState = new PredictedState
        {
            action     = Action.Idle,
            ammoInClip = settings.clipSize,
            COF        = settings.minCOF,
        };

        entityManager.AddComponentData(entity, settings);
        entityManager.AddComponentData(entity, internalState);
        entityManager.AddComponentData(entity, predictedState);
        entityManager.AddComponentData(entity, new InterpolatedState());

        return(entity);
    }
Beispiel #24
0
        private bool CanChangeTo(InternalState newInternalState)
        {
            if (newInternalState == this.internalState)
            {
                return(false);
            }

            switch (newInternalState)
            {
            case InternalState.None:
            {
                return(true);
            }

            case InternalState.Stopped:
            {
                return((this.internalState == InternalState.None) || (this.internalState == InternalState.Playing) || (this.internalState == InternalState.Paused));
            }

            case InternalState.Playing:
            {
                return((this.internalState == InternalState.Stopped) || (this.internalState == InternalState.Paused));
            }

            case InternalState.Paused:
            {
                return(this.internalState == InternalState.Playing);
            }

            default:
            {
                return(false);
            }
            }
        }
Beispiel #25
0
        private void MaintainSate(InternalState state)
        {
            switch (state)
            {
            case InternalState.Created:
                ToggleUi(InternalState.Created);
                _saved = false;
                break;

            case InternalState.Saved:
                ToggleUi(InternalState.Saved);
                _saved = true;
                break;

            case InternalState.Loaded:
                ToggleUi(InternalState.Loaded);
                _saved = false;
                break;

            case InternalState.Failed:
                _customersClassesList = new ObservableCollection <CustomerClassFields>();
                ClassesView           = new ListCollectionView(_customersClassesList);
                ToggleUi(InternalState.Failed);
                _saved = false;
                break;

            case InternalState.Loading:
                ToggleUi(InternalState.Loading);
                _saved = false;
                break;

            default:
                break;
            }
        }
Beispiel #26
0
        public void Accept()
        {
            if (state == InternalState.PENDING)
            {
                var result = GetResult();

                if (result != null)
                {
                    result.ID    = ID;
                    result.Name  = Name;
                    result.Index = Index;
                    Session.Active.Add(result);
                    state = InternalState.IDLE;
                    StateChanged?.Invoke(this, State);
                    Log.Status("Test [{0}] completed", Name);
                }
                else
                {
                    throw new InvalidOperationException("result is null");
                }
            }
            else
            {
                Log.Debug("Attempted to accept test while it was in {0} state", state.ToString());
            }
        }
Beispiel #27
0
        public override IBufferWriter <byte> GetBufferWriter()
        {
            switch (_state)
            {
            case InternalState.Initialized:
                var bufferWriter = ResolveBufferWriter();

                // When writing directly to the buffer the header with message size needs to be written first
                if (DirectSerializationSupported)
                {
                    CompatibilityHelpers.Assert(_payloadLength != null, "A payload length is required for direct serialization.");

                    EnsureMessageSizeAllowed(_payloadLength.Value);

                    WriteHeader(_buffer, _payloadLength.Value, compress: false);
                    _bufferPosition += GrpcProtocolConstants.HeaderSize;
                }

                _state = InternalState.IncompleteBufferWriter;
                return(bufferWriter);

            case InternalState.IncompleteBufferWriter:
                return(ResolveBufferWriter());

            default:
                ThrowInvalidState(_state);
                return(default !);
            }
        }
Beispiel #28
0
    public void PlanAndExecute(Bot bot, InternalState internalState)
    {
        bot.GetCurrentGoal().FlushCurrentActions();
        GoalState goalWithInternalState = bot.GetGoals().Find(goal => goal.internalState == internalState);

        PlanAndExecute(bot, goalWithInternalState);
    }
        public void Init()
        {
            Canvas.ForceUpdateCanvases();

            _Collocation.InitIfNeeded(this);

            if (_Collocation.scrollRect.horizontalScrollbar != null || _Collocation.scrollRect.verticalScrollbar != null)
            {
                throw new UnityException("SmartScrollView only works with a " + typeof(SmartScrollViewScrollbar).Name + " component added to the Scrollbar and the ScrollRect shouldn't have any scrollbar set up in the inspector (it hooks up automatically)");
            }

            _ItemsDesc     = new ItemsDescriptor(_Collocation.DefaultItemSize);
            _InternalState = InternalState.CreateFromSourceParamsOrThrow(_Collocation, _ItemsDesc);

            _VisibleItems         = new List <UILoopSmartItem>();
            _AVGVisibleItemsCount = 0;

            Refresh();
            _InternalState.UpdateLastProcessedCTVirtualInsetFromParentStart();
            SetVirtualAbstractNormalizedScrollPosition(1f, false);             // scroll to start
            _Collocation.scrollRect.onValueChanged.AddListener(OnScrollViewValueChanged);

            if (ScrollPositionChanged != null)
            {
                ScrollPositionChanged(GetNormalizedPosition());
            }

            Initialized = true;
        }
 public void Attach(DocumentHandleInfo handleInfo)
 {
     if (!InternalState.IsValidHandle(handleInfo.Handle))
     {
         RaiseEvent(new DocumentHandleAttached(handleInfo.Handle));
     }
 }
Beispiel #31
0
 public void Initialize(InternalState state)
 {
     hashedLength = state.hashedLength;
     A = state.A;
     B = state.B;
     C = state.C;
     D = state.D;
     buffer = (byte[])state.Buffer.Clone();
 }
Beispiel #32
0
 /// <summary>
 /// Clear internal state. 
 /// </summary>
 internal void ClearInternalState()
 {
     this.internalState = null;
 }
 // Sets or Unsets the required flag based on
 // the bool argument
 private void WriteInternalState(InternalState reqFlag, bool set)
 {
     if (set)
     {
         _state |= reqFlag;
     }
     else
     {
         _state &= (~reqFlag);
     }
 }
		private static void Compress(InternalState internalState, byte[] block, int start)
		{
            var m = new UInt64[16];
		    Buffer.BlockCopy(block, start, m, 0, BlockSizeBytes);


            var v = new UInt64[16];
            Array.Copy(internalState.H, v, internalState.H.Length);
            Array.Copy(IVs, 0, v, 8, IVs.Length);

			v[12] ^= internalState.Counter.Low;
			v[13] ^= internalState.Counter.High;
			v[14] ^= internalState.FinalizationFlags[0];
			v[15] ^= internalState.FinalizationFlags[1];


            ComputeRounds(v, m);

			//Finalization
			internalState.H[0] ^= v[0] ^ v[8];
			internalState.H[1] ^= v[1] ^ v[9];
			internalState.H[2] ^= v[2] ^ v[10];
			internalState.H[3] ^= v[3] ^ v[11];
			internalState.H[4] ^= v[4] ^ v[12];
			internalState.H[5] ^= v[5] ^ v[13];
			internalState.H[6] ^= v[6] ^ v[14];
			internalState.H[7] ^= v[7] ^ v[15];
		}
		private void ReinitializeLocator(InternalState previousState)
		{
			var newState = new InternalState
			{
				CurrentNodes = previousState.CurrentNodes,
				IsVbucket = false,
				OpFactory = previousState.OpFactory,
				Locator = this.configuration.CreateNodeLocator()
			};

			if (log.IsDebugEnabled) log.Debug("Initializing the locator with the list of working nodes.");

			newState.Locator.Initialize(newState.CurrentNodes.Where(n => n.IsAlive).ToArray());

			Interlocked.Exchange(ref this.state, newState);

			if (log.IsDebugEnabled) log.Debug("Replaced the internal state.");
		}
		void IDisposable.Dispose()
		{
			GC.SuppressFinalize(this);

			if (this.state != null)
				lock (this.DeadSync)
				{
					if (this.state != null)
					{
						var currentNodes = this.state.CurrentNodes;
						this.state = null;

						this.configListener.Stop();
						this.configListener = null;

						if (this.resurrectTimer != null)
							using (this.resurrectTimer)
								this.resurrectTimer.Change(Timeout.Infinite, Timeout.Infinite);

						this.resurrectTimer = null;

						// close the pools
						if (currentNodes != null)
							for (var i = 0; i < currentNodes.Length; i++)
								currentNodes[i].Dispose();
					}
				}
		}
        private static void ProcessBytes(InternalState internalState, byte[] array, int start, int count)
        {
			int bufferRemaining = BlockSizeBytes - internalState.BufferFilled;

			if (internalState.BufferFilled > 0 && count > bufferRemaining)
			{
				Array.Copy(
                    array, start, 
                    internalState.Buffer, internalState.BufferFilled, 
                    bufferRemaining);


				internalState.Counter += BlockSizeBytes;
				
                Compress(internalState, internalState.Buffer, 0);

				start += bufferRemaining;
				count -= bufferRemaining;
				internalState.BufferFilled = 0;
			}

			while (count > BlockSizeBytes)
			{
				internalState.Counter += BlockSizeBytes;
				
				Compress(internalState, array, start);
				
                start += BlockSizeBytes;
				count -= BlockSizeBytes;
			}

			if (count > 0)
			{
				Array.Copy(
                    array, start, 
                    internalState.Buffer, internalState.BufferFilled, 
                    count);

				internalState.BufferFilled += count;
			}
		}
Beispiel #38
0
 StreamingClient(TwitterAccount[] accounts, IStreamingHandler target, bool dummy)
 {
     Accounts = new TwitterAccount[accounts.Length];
     _states = new InternalState[accounts.Length];
     for (int i = 0; i < accounts.Length; i ++) {
         Accounts[i] = accounts[i];
         Accounts[i].StreamingClient = this;
         _states[i] = new InternalState (accounts[i]);
         if (dummy)
             _states[i].ConnectionState = StreamingState.UpdatingFriendList;
     }
     SearchKeywords = string.Empty;
     Target = target;
 }
 // Extracts the required flag and returns
 // bool to indicate if it is set or unset
 private bool ReadInternalState(InternalState reqFlag)
 {
     return (_state & reqFlag) != 0;
 }
		private static byte[] Final(int hashSize, InternalState internalState)
		{
			//Last compression
			internalState.Counter += (UInt32) internalState.BufferFilled;
			internalState.FinalizationFlags[0] = UInt64.MaxValue;

			for (int i = internalState.BufferFilled; i < internalState.Buffer.Length; i++)
				internalState.Buffer[i] = 0;

			Compress(internalState, internalState.Buffer, 0);


			byte[] hash = new byte[64];

            for (int i = 0; i < 8; ++i)
            {
                Array.Copy(
                    BitConverter.GetBytes(internalState.H[i]), 0, 
                    hash, i * 8, 
                    8);
            }


            if (hash.Length != hashSize / 8)
			{
                var result = new byte[hashSize / 8];

				Array.Copy(
                    hash, 
                    result, result.Length);


				return result;
			}

			return hash;
		}
 public ExitConditionException(IExitCondition exitCondition, InternalState internalState, LifecycleEventType eventType)
 {
     this.ExitCondition = exitCondition;
     this.InternalState = internalState;
     this.EventType = eventType;
 }
 protected void CancellationConfirmed()
 {
     this.FInternalState |= InternalState.CancellationConfirmed;
 }
 public void StopActing()
 {
     _action_list.Clear();
     _state = InternalState.idle;
 }
		/// <inheritdoc />
		protected override async Task<byte[]> ComputeHashAsyncInternal(UnifiedData data)
		{
            var internalState = new InternalState(HashSize, _originalKeyLength, _salt, _personalization);


            if (_originalKeyLength > 0)
                ProcessBytes(internalState, _key, 0, _key.Length);

			await data.ForEachGroupAsync(
                BlockSizeBytes,
                (array, start, count) => ProcessBytes(internalState, array, start, count),
                (array, start, count) => ProcessBytes(internalState, array, start, count));

			return Final(HashSize, internalState);
		}
        void IDisposable.Dispose()
        {
            log.WarnFormat("Disposing {0}", this);
            GC.SuppressFinalize(this);

            if (this.state != null && this.state != InternalState.Empty)
                lock (_syncObj)
                {
                    if (this.state != null && this.state != InternalState.Empty)
                    {
                        var currentNodes = this.state.CurrentNodes;
                        this.state = null;

                        this.configListener.Stop();
                        this.configListener = null;

                        if (this.resurrectTimer != null)
                            using (this.resurrectTimer)
                                this.resurrectTimer.Change(Timeout.Infinite, Timeout.Infinite);

                        this.resurrectTimer = null;

                        // close the pools
                        if (currentNodes != null)
                        {
                            foreach (var node in currentNodes)
                            {
                                node.Dispose();
                            }
                        }
                    }
                }
        }
        private void _do_next_action()
        {
            if (this.Username == string.Empty || this.Username == null || this.Password == string.Empty || this.Password == null)
                return;
            if (_state != InternalState.idle)
                return;
            if (_action_list.Count == 0)
                return;

            _state = InternalState.unknown;
            _activity_timer.Enabled = false;

            Action a = _action_list[0];
            _action_list.Remove(a);
            _current_action = a;

            if (a.VideoID == null)
            {
                _get_cookies();
                return;
            }
            else if (_cookie_jar == null)
            {
                _get_cookies();
                _current_action = new Action(null, false);
                _action_list.Add(a);
                return;
            }

            _enable = a.Enable;
            _raise_status_change(InternalState.get_settings);
            _video_id = a.VideoID;
            _do_get_request("http://www.youtube.com/my_videos_edit?video_id=" + a.VideoID, _cookie_jar);
        }
 public void Cancel()
 {
     this.CheckDisposed();
     this.FInternalState |= InternalState.CancellationRequested;
 }
        private void _raise_status_change(InternalState s)
        {
            _state = s;
            if (OnStatusChange != null)
                OnStatusChange(this, s);

            if (s == InternalState.idle)
                if (_action_list.Count > 0)
                    _do_next_action();
                else
                    _activity_timer.Enabled = true;
        }