Beispiel #1
0
 public WuStateCompleted(WuStateId id, string DisplayName, IUpdateCollection updates, int hResult) : base(id, DisplayName)
 {
     if (updates == null)
     {
         throw new ArgumentNullException(nameof(updates));
     }
     Updates = updates;
     HResult = hResult;
 }
Beispiel #2
0
        public void Should_ContainSpecifiedObjects_When_CreateWuProcessState()
        {
            string         displayName = "a display name";
            WuStateId      id          = WuStateId.UserInputRequired;
            WuProcessState state       = new WuProcessStateMock(id, displayName);

            Assert.AreEqual(displayName, state.DisplayName);
            Assert.AreEqual(id, state.StateId);
        }
Beispiel #3
0
        public WuProcessState(WuStateId id, string displayName)
        {
            if (String.IsNullOrWhiteSpace(displayName))
            {
                throw new ArgumentNullException(nameof(displayName));
            }

            _displayName = displayName;
            StateId      = id;
        }
        public void Should_ContainSpecifiedValues_When_CreateProgressChangedEventArgs()
        {
            WuStateId           state    = WuStateId.DownloadFailed;
            ProgressDescription progress = new ProgressDescription();

            ProgressChangedEventArgs eventArgs = new ProgressChangedEventArgs(state, progress);

            Assert.AreEqual(state, eventArgs.StateId);
            Assert.AreEqual(progress, eventArgs.Progress);
        }
        public void Should_ContainSpecifiedValues_When_CreateAsyncOperationCompletedEventArgs()
        {
            WuStateId      result = WuStateId.DownloadFailed;
            AsyncOperation op     = AsyncOperation.Installing;

            AsyncOperationCompletedEventArgs eventArgs = new AsyncOperationCompletedEventArgs(op, result);

            Assert.AreEqual(result, eventArgs.Result);
            Assert.AreEqual(op, eventArgs.Operation);
        }
        public void Should_ContainSpecifiedValues_When_CreateStateChangedEventArgs()
        {
            WuStateId s1 = WuStateId.Downloading;
            WuStateId s2 = WuStateId.DownloadCompleted;

            StateChangedEventArgs eventArgs = new StateChangedEventArgs(s1, s2);

            Assert.AreEqual(s1, eventArgs.OldState);
            Assert.AreEqual(s2, eventArgs.NewState);
        }
        public void Should_FireStateChangedEvent_When_StateHasChanged()
        {
            var session = new UpdateSessionFake(true);

            using (WuApiController wu = new WuApiController(session, UpdateCollectionFactory, SystemInfo))
            {
                bool      validEventState  = false;
                WuStateId oldStateExpected = WuStateId.Searching;
                WuStateId newStateExpected = WuStateId.SearchCompleted;
                wu.OnStateChanged += (sender, args) => validEventState = (args.OldState == oldStateExpected && args.NewState == newStateExpected) ? true : false;

                wu.BeginSearchUpdates();
                WaitForStateChange(wu, WuStateId.SearchCompleted);
                Assert.IsTrue(validEventState);
            }
        }
            public void OnStateChanged(WuStateId newState, WuStateId oldState)
            {
                lock (EndpointLock)
                {
                    if (Endpoint == null)
                    {
                        return;
                    }
                    Log.Debug($"State changed callback from {Endpoint.FQDN}. new: {newState} old: {oldState}.");
#pragma warning disable 4014
                    if (!Endpoint.IsDisposed)
                    {
                        Endpoint.RefreshStateAsync();                       // do not wait for the result
                    }
#pragma warning restore 4014
                }
            }
        /// <param name="id">Id of the state.</param>
        /// <param name="displayName">Displayname of the state.</param>
        /// <param name="timeoutSec">Seconds, after the asynchronous task should be aborted.</param>
        /// <param name="timeoutCallback">Callback to report, that the task was aborted because of a timeout.</param>
        /// <param name="progressCallback">Callback to report, that the task makes progress.</param>
        public WuStateAsyncJob(WuStateId id, string displayName, int timeoutSec, TimeoutCallback timeoutCallback, ProgressChangedCallback progressCallback) : base(id, displayName)
        {
            if (timeoutSec < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(timeoutSec), "Negative timeout is not allowed.");
            }
            if (timeoutSec > int.MaxValue / 1000)
            {
                throw new ArgumentOutOfRangeException(nameof(timeoutSec), $"Max timeout is {int.MaxValue / 1000} sec.");
            }
            if (timeoutCallback == null)
            {
                throw new ArgumentNullException(nameof(timeoutCallback));
            }

            TimeoutSec = timeoutSec;
            TimeoutCallbackDelegate         = timeoutCallback;
            ProgressChangedCallbackDelegate = progressCallback;
        }
Beispiel #10
0
        public void Should_NotAllowEmptyDisplayNames_When_CreateWuProcessState()
        {
            string    displayName1 = String.Empty;
            string    displayName2 = null;
            WuStateId id           = WuStateId.UserInputRequired;

            try
            {
                WuProcessState state = new WuProcessStateMock(id, displayName1);
                Assert.Fail("exception expected");
            }
            catch (ArgumentException) { }

            try
            {
                WuProcessState state = new WuProcessStateMock(id, displayName2);
                Assert.Fail("exception expected");
            }
            catch (ArgumentException) { }
        }
 public void OnProgressChanged(ProgressDescription progress, WuStateId currentState)
 {
     lock (EndpointLock)
     {
         if (Endpoint == null)
         {
             return;
         }
         Log.Debug($"Progress changed callback from {Endpoint.FQDN}. Percent: {progress.Percent} Indeterminate: {progress.IsIndeterminate}.");
         lock (Endpoint.StateLock)
         {
             if (progress.CurrentUpdate != null)
             {
                 Endpoint.State.Description = progress.CurrentUpdate.Title;
                 if (currentState == WuStateId.Downloading)
                 {
                     Endpoint.State.Description += $" ({BytesToHumanReadableConverter.GetBytesReadable(progress.CurrentUpdate.MaxByteSize)})";
                 }
                 Endpoint.State.Progress = progress;
             }
         }
         Endpoint.OnPropertyChanged("State");
     }
 }
 public AsyncOperationCompletedEventArgs(AsyncOperation operation, WuStateId result)
 {
     Operation = operation;
     Result    = result;
 }
Beispiel #13
0
 public StateChangedEventArgs(WuStateId oldState, WuStateId newState)
 {
     OldState = oldState;
     NewState = newState;
 }
            public void OnAsyncOperationCompleted(WuDataContract.Enums.AsyncOperation operation, WuStateId newState)
            {
                lock (EndpointLock)
                {
                    if (Endpoint == null)
                    {
                        return;
                    }
                    Log.Debug($"Async operation completed callback from {Endpoint.FQDN}. Operation: {operation}. New state: {newState}.");
#pragma warning disable 4014
                    Endpoint.RefreshUpdatesAsync(); // do not wait for the result
#pragma warning restore 4014
                }
            }
Beispiel #15
0
 public WuStateAsyncJobProxy(WuStateId id, string displayName, int timeoutSec) : base(id, displayName, timeoutSec, (a, b) => { }, (a, b, c, d, e) => { })
 {
 }
Beispiel #16
0
 public WuStateAsyncJobProxy(WuStateId id, string displayName, int timeoutSec, TimeoutCallback timeoutCallback, ProgressChangedCallback progressCallback)
     : base(id, displayName, timeoutSec, timeoutCallback, progressCallback)
 {
 }
 public WuStateFailed(WuStateId id, string DisplayName, IUpdateExceptionCollection warnings, string reason = null) : base(id, DisplayName)
 {
     Warnings  = warnings;
     Reason    = reason;
     StateDesc = "Failure: " + Reason;
 }
 public ProgressChangedEventArgs(WuStateId stateId, ProgressDescription progress)
 {
     StateId  = stateId;
     Progress = progress;
 }
 public WuProcessStateMock(WuStateId id, string displayName) : base(id, displayName)
 {
 }