public UpdateProgressViewModel(UpdateManager updateManger,IProductUpdate productUpdate)
 {
     _updateManger = updateManger;
     _productUpdate = productUpdate;
     _dispatcherTimer = new DispatcherTimer(DispatcherPriority.Normal, Dispatcher.CurrentDispatcher);
     StartUpdateProgressTimer();
 }
        public UserControl CreateUpdateInfoControl(IProductUpdate productUpdate)
        {
            var updateInfoControl = new Updating.Userinterface.UpdateInfoControl();

            updateInfoControl.DataContext = productUpdate;

            return updateInfoControl;
        }
        public UpdatePropopsalViewModel(IViewModelInteraction viewModelInteraction ,UpdateManager updateManager, IProductUpdate productUpdate)
        {
            if (productUpdate == null)
                throw new ProductUpdateFailedException(new NullReferenceException("ProductUpdate!"));

            _viewModelInteraction = viewModelInteraction;
            _productUpdate = productUpdate;
            _updateManager = updateManager;
            _userInterfaceFactory = new UpdateUserInterfaceFactory(_updateManager);


            ShowUpdateInfo();
            
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="usercontrol"></param>
        /// <returns>false if the user skipped.</returns>
        public Task<bool> AwaitUpdater(UserControl usercontrol, IProductUpdate productUpdate)
        {
            var updateSkeletonControl = usercontrol as Updating.Userinterface.UpdateSkeletonControl;

            if(updateSkeletonControl == null)
                throw new InvalidCastException("Control is not an UpdateSkeletonControl");

            if(updateSkeletonControl.DataContext == null)
                throw new NullReferenceException("Datacontext of UpdateSkeletonControl not set");

            var updatePropopsalViewModel =  updateSkeletonControl.DataContext as UpdatePropopsalViewModel;

            if(updatePropopsalViewModel == null)
                throw new InvalidCastException("Datacontext of UpdateSkeletonControl is not of type UpdateProposalViewModel");

            var manualResetEvent = new ManualResetEvent(false);

            updatePropopsalViewModel.ViewModelInteraction.CloseWindow = () => manualResetEvent.Set();

            var awaiterTask = new Task<bool>(() =>
            {
                // Wait for the async task to complete.
                manualResetEvent.WaitOne();

                // Dispose the manual reset event.
                manualResetEvent.Dispose();

                // Determine if we should close.
                return productUpdate.IsManadatory;

            });

            awaiterTask.Start();

            return awaiterTask;
        }
        public UserControl CreateUpdateProgressControl(IProductUpdate productUpdate)
        {
            var updateProgressControl = new Updating.Userinterface.UpdateProgressControl();
            updateProgressControl.DataContext = new UpdateProgressViewModel(_updateManager, productUpdate);

            return updateProgressControl;
        }
        public UserControl CreateUpdateSkeletonControl(ViewModelActionDelegater viewModelActionDelegater,IProductUpdate productUpdate)
        {
            var updatePanel = new Updating.Userinterface.UpdateSkeletonControl();
            var updateProposalViewModel = new UpdatePropopsalViewModel(viewModelActionDelegater, _updateManager, productUpdate);

            updatePanel.DataContext = updateProposalViewModel;

            return updatePanel;
        }
Ejemplo n.º 7
0
 public void ShowUpdateAcceptation(IProductUpdate productUpdate)
 {
     _updateProposalViewModel = new UpdatePropopsalViewModel(this,_updateManager,productUpdate);
     Content = _userInterfaceFactory.CreateUpdateSkeletonControl(_updateProposalViewModel);
 }
Ejemplo n.º 8
0
        private IProductUpdate DownloadProductUpdateFile(IProductUpdate productUpdate)
        {
            var myProductUpdate = productUpdate as ProductUpdate;

            if (myProductUpdate == null)
                throw new InvalidCastException("Invallid ProductUpdate class");

            try
            {
                var webRequest = WebRequest.Create(myProductUpdate.Url);
                webRequest.Timeout = MaximumSearchTimeOut * 1000;

                using (var webResponse = webRequest.GetResponse())
                using (var responseStream = webResponse.GetResponseStream())
                {
                    string extension = string.Empty;

                    var fileName = myProductUpdate.Url.Segments.LastOrDefault();
                    if (fileName != null && fileName.Split('.').Length > 0)
                        extension = fileName.Split('.').Last();

                    var tempDirectory = System.IO.Path.GetTempPath();
                    var productFile = string.Format("{0}.{1}", AssemblyHelper.GetCurrentAssemblyName(), extension);

                    var productFilePath = Path.Combine(tempDirectory, productFile);

                    // Make sure any old installation files are removed before trying to write a new one.
                    if (File.Exists(productFilePath))
                        File.Delete(productFilePath);

                    using (var streamCopier = new FileStreamCopier(responseStream, productFilePath))
                    {
                        var downloadCompleted = streamCopier.CopyStream(myProductUpdate, _updateCancellationTokenSource.Token,webResponse.ContentLength);
                        myProductUpdate.DownloadCompleted = downloadCompleted;

                    }

                    return myProductUpdate;

                }

            }

            catch (Exception ex)
            {
                _log.Error("Failed to retrieve update", ex);
            }

            return null;
        }
Ejemplo n.º 9
0
        public Task<ProductUpdateResult> UpdateProduct(IProductUpdate productUpdate)
        {
            var downloadTask = new Task<IProductUpdate>(() =>
            {
                var productUpdateResult = DownloadProductUpdateFile(productUpdate);

                if (productUpdateResult == null)
                    throw new ProductUpdateFailedException(new Exception("Failed to retrieve download."));

                return productUpdate;

            });

            var fileExecutionTask = downloadTask.ContinueWith((pu) =>
            {
                if (pu.Exception != null)
                    return ProductUpdateResult.DownloadFailed;

                var productUpdateResult = pu.Result as ProductUpdate;

                if (productUpdateResult == null)
                    return ProductUpdateResult.DownloadFailed;

                productUpdateResult.Execute();

                return ProductUpdateResult.Updating;
            });

            downloadTask.Start();

            return fileExecutionTask;
        }