Example #1
0
        public void Dispose()
        {
            _stopwatch.Stop();

            var entryType = Info.IsRoot ? ContextLogEntryType.ContextEnd : ContextLogEntryType.ChildContextEnd;

            Logger.LogAsType(Settings.ContextEndMessageLevel,
                             $"Context {Info.ContextName} has ended.", entryType);

            _stack.Pop();

            Logger.CompleteIfRoot();
            Logger.TrySetContext(_parent);

            if (_stack.IsEmpty)
            {
                // Logger = null;
                // State = null;

                _namedStacks.Remove(Info.ContextGroupName, out _);

                if (!_namedStacks.Any())
                {
                    _asyncLocalStacks.Value = null;
                }
            }

            OnDispose?.Invoke(this);
            Unloaded?.Invoke(this);
        }
 private void OnUnload(WorkflowApplicationEventArgs arg)
 {
     Log.DebugFormat("OnUnload()");
     InstanceId = arg.InstanceId;
     Unloaded.Set();
     SynchronizationContext.CompleteWork();
 }
Example #3
0
        public void Dispose()
        {
            State = ScreenState.Finished;

            _uiController?.Dispose();
            Unloaded?.Invoke(this);
        }
Example #4
0
 private void ViewBase_Unloaded(object sender, RoutedEventArgs e)
 {
     if (_isLeaving == false)
     {
         Unloaded?.Invoke(sender, e);
     }
 }
Example #5
0
        /// <summary>
        /// Called when the fragment is paused.
        /// </summary>
        public override void OnPause()
        {
            base.OnPause();

            Unloaded.SafeInvoke(this);

            UninitializeBindingContext();
        }
 /// <summary>
 /// Starts the specified workflow.
 /// </summary>
 /// <param name="workflow">The workflow.</param>
 public void Start(IWorkflow workflow)
 {
     Log.DebugFormat("Start({0})", workflow);
     //TODO: Block concurrent calls to Start/Process?
     Unloaded.Reset();
     Result      = new WorkflowResult();
     Application = CreateWorkflowApplication(workflow);
     Application.Run();
 }
 /// <summary>
 /// Starts the specified workflow.
 /// </summary>
 /// <param name="workflow">The workflow.</param>
 public void Start(Models.Domain.Workflow.WorkflowInstance workflow)
 {
     Log.Debug($"Start({workflow})");
     //TODO: Block concurrent calls to Start/Process?
     Unloaded.Reset();
     Result      = new WorkflowResult();
     Application = CreateWorkflowApplication(workflow);
     Application.Run();
 }
Example #8
0
        /// <summary>
        /// Called as part of the activity lifecycle when an activity is going into
        ///  the background, but has not (yet) been killed.
        /// </summary>
        protected override void OnPause()
        {
            base.OnPause();

            // Note: call *after* base so NavigationAdapter always gets called
            Unloaded.SafeInvoke(this);

            UninitializeBindingContext();
        }
Example #9
0
        public void Unload()
        {
            SoundBuilder.Unload();
            SoundBuilder = null;

            Unloaded?.Invoke(this, EventArgs.Empty);

            GameObject.Destroy(gameObject);
        }
Example #10
0
        public override void ViewDidDisappear(bool animated)
        {
            base.ViewDidDisappear(animated);

            // Note: call *after* base so NavigationAdapter always gets called
            Unloaded?.Invoke(this);

            UninitializeBindingContext();
        }
 private UnhandledExceptionAction OnException(WorkflowApplicationUnhandledExceptionEventArgs arg)
 {
     Log.WarnFormat("Error: {0} - {1}", arg.ExceptionSource, arg.UnhandledException);
     lock (Result)
     {
         Result.Error = arg.UnhandledException;
     }
     Unloaded.Set();
     return(UnhandledExceptionAction.Abort);
 }
Example #12
0
        /// <summary>
        /// Called when the framework element is unloaded.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The <see cref="EventArgs"/> instance containing the event data.
        /// </param>
        public void OnUnloaded(object sender, EventArgs e)
        {
            if (!IsLoaded)
            {
                return;
            }

            IsLoaded = false;

            Unloaded.SafeInvoke(this);
        }
Example #13
0
 /// <summary>
 /// Called when Form's Closing event is raised.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Form_Closing(object sender, FormClosingEventArgs e)
 {
     if (!_closeable)
     {
         e.Cancel = true; // Do not allow to Close
         this.Hide();
     }
     else
     {
         Unloaded?.Invoke(this, null);
     }
 }
Example #14
0
 private void ObserveIndexChanges(IObservable <Unit> databaseChanged)
 {
     if (Database.Value != null)
     {
         Database.Value.IndexChanges
         .Where(n => n.Name.Equals(CollectionsIndex, StringComparison.InvariantCulture))
         .SampleResponsive(TimeSpan.FromSeconds(2))
         .TakeUntil(Unloaded.Merge(databaseChanged))
         .ObserveOnDispatcher()
         .Subscribe(__ => RefreshCollectionsList());
     }
 }
        /// <summary>
        /// Waits for the workflow to reach the unloaded state.
        /// </summary>
        /// <param name="timeout">The timeout.</param>
        /// <returns></returns>
        public bool WaitOne(TimeSpan timeout)
        {
            SynchronizationContext.ExecuteQueue(timeout);
            var ret = Unloaded.WaitOne(0);

            lock (Result)
            {
                if (Result != null && Result.Error != null)
                {
                    throw Result.Error;
                }
            }
            return(ret);
        }
Example #16
0
        private async void UpdateDb_Click(object sender, RoutedEventArgs e)
        {
            //MessageBox.Show(Unloaded.Value.ToString());
            if (Unloaded.Value != 0)
            {
                Double loaded   = double.Parse(loadedmilk1.Text);
                Double unloaded = double.Parse(Unloaded.Value.ToString());
                Double Deficit  = loaded - unloaded;

                if (Deficit < 3.0)
                {
                    Deficit = 0;
                }
                Connection cn = new Connection();
                try{
                    cn.connect();
                    cn.cmd.Connection = cn.cnn;
                    cn.cmd.Connection.Open();
                    cn.cmd.CommandText = "update MilkCreameryDelivery Set Litres_Unloaded='" + unloaded + "', Deficit='" + Deficit + "',Delivered='True' WHERE DATE='" + DateTime.Now.ToShortDateString() + "'";

                    cn.cmd.ExecuteScalar();
                    MessageDialogResult x = new MessageDialogResult();
                    MetroDialogSettings y = new MetroDialogSettings();
                    y.AffirmativeButtonText = "Quit";

                    await this.ShowMessageAsync("Delivery Confirmed", "You have updated the Delivery Successfuly.", MessageDialogStyle.Affirmative, y);

                    if (x.ToString() == "Negative")
                    {
                        this.Close();
                    }
                    //farmerDatagrid.ItemsSource = LoadCollectionData();
                    //ViewFarmersTab.BringIntoView();
                    // clearRegFields();
                }
                catch (Exception ex)
                {
                    displayMetroError(ex);
                    //ShowOverlay();
                    //MessageBox.Show("Registration has Failed! The following Message was generated to explain why \n \n"+ex.Message+"\n \n"+ex.InnerException,"Registration Failure",MessageBoxButton.OK,MessageBoxImage.Error);
                    //HideOverlay();
                }
            }
            else
            {
                Unloaded.Focus();
            }
        }
Example #17
0
        public void Unload()
        {
            if (Domain != null)
            {
                Unloaded?.Invoke(this, Domain);

                AppDomain.Unload(Domain);
                AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
                Domain = null;
            }

            Unloaded = null;

            Assemblies.Clear();
            Classes = new RemoteClass[0];
        }
Example #18
0
 private static void OnUnloadedCommandPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     if (d is FrameworkElement element && e.NewValue is ICommand command)
     {
         if (!Unloaded.Contains(element))
         {
             Unloaded.Add(element);
             element.Unloaded += (s, a) =>
             {
                 command.Execute(null);
                 Loaded.Remove(element);
                 Unloaded.Remove(element);
             };
         }
     }
 }
        /// <summary>
        /// Processes the specified workflow, executing the specified <paramref name="transition"/> with the given <paramref name="request"/>
        /// </summary>
        /// <param name="workflow">The workflow.</param>
        /// <param name="transition">The transition.</param>
        /// <param name="request">The request.</param>
        public void Process(IWorkflow workflow, WorkflowTransition transition, WorkflowRequest request)
        {
            Log.DebugFormat("Process({0}, {1}, {2})", workflow, transition, request);
            //TODO: Block concurrent calls to Start/Process?
            Unloaded.Reset();
            Result      = new WorkflowResult();
            Application = CreateWorkflowApplication(null);
            if (!CheckForRunnableInstance())
            {
                Application.Load(workflow.WorkflowInstanceId);
            }
            else
            {
                Application.LoadRunnableInstance();
            }

            Application.ResumeBookmark(transition.Name, request);
        }
        /// <summary>
        /// Processes the specified workflow, executing the specified <paramref name="transition"/> with the given <paramref name="request"/>
        /// </summary>
        /// <param name="workflow">The workflow.</param>
        /// <param name="transition">The transition.</param>
        /// <param name="request">The request.</param>
        public void Process(WorkflowInstance workflow, WorkflowTransition transition, WorkflowRequest request)
        {
            Log.Debug($"Process({workflow}, {transition}, {request})");
            //TODO: Block concurrent calls to Start/Process?
            Unloaded.Reset();
            Result      = new WorkflowResult();
            Application = CreateWorkflowApplication(workflow, false);
            //UnloadApplication(Application);
            if (!CheckForRunnableInstance())
            {
                Application.Load(workflow.InstanceId);
            }
            else
            {
                Application.LoadRunnableInstance();
            }

            Application.ResumeBookmark(transition.Name, request);
        }
Example #21
0
 /// <summary>
 /// Free up the memory in this block, writing out to disk if dirty
 /// </summary>
 public void Unload()
 {
     if (!loaded)
     {
         return;
     }
     if (dirty)
     {
         if (address0 > io.Length)
         {
             io.SetLength(address0);
         }
         if (address0 != io.Position)
         {
             io.Seek(address0, SeekOrigin.Begin);
         }
         io.Write(mem, 0, PAGESIZE);
     }
     mem       = null;
     loaded    = false;
     last_used = 0;
     Unloaded?.Invoke(this, null);
 }
Example #22
0
        public async Task UnloadAsync(string id, object asset, IAssetUnloadParameters parameters)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentException("Value cannot be null or empty.", nameof(id));
            }
            if (asset == null)
            {
                throw new ArgumentNullException(nameof(asset));
            }
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            Type type = asset.GetType();

            Unloading?.Invoke(id, asset, parameters);

            await OnUnloadAsync(id, asset, parameters);

            Unloaded?.Invoke(id, type, parameters);
        }
        public async Task UnloadAsync(string id, Scene scene, ISceneUnloadParameters parameters)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentException("Value cannot be null or empty.", nameof(id));
            }
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            LogSceneUnload(id, scene, parameters, true);

            Unloading?.Invoke(id, scene, parameters);

            OnRemoveScene(id, scene, parameters);
            await OnUnloadAsync(id, scene, parameters);

            Instances.Remove(scene);

            Unloaded?.Invoke(id, parameters);

            LogSceneUnloaded(id, parameters, true);
        }
Example #24
0
 public virtual void Unload()
 {
     Unloaded?.Invoke(this, EventArgs.Empty);
 }
Example #25
0
 protected virtual void OnUnloaded(EventArgs e)
 {
     Unloaded?.Invoke(this, e);
 }
Example #26
0
 private void Unload()
 {
     Unloaded?.Invoke();
 }
Example #27
0
 private void Form_Unloaded(object sender, EventArgs e)
 {
     Unloaded?.Invoke(this, e);
 }
Example #28
0
 /// <summary>
 /// Handle end of unloading.
 /// </summary>
 protected virtual void OnUnloaded()
 {
     _loadProgress = 0;
     Unloaded?.Invoke(this);
 }
Example #29
0
 /// <summary>
 /// Called from <see cref="Application.End(Application.RunState)"/> before the <see cref="Toplevel"/> is disposed.
 /// </summary>
 internal virtual void OnUnloaded()
 {
     Unloaded?.Invoke();
 }
Example #30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LogicBase"/> class.
        /// </summary>
        /// <param name="targetView">The target control.</param>
        /// <param name="viewModelType">Type of the view model.</param>
        /// <param name="viewModel">The view model.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="targetView"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="viewModelType"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="viewModelType"/> does not implement interface <see cref="IViewModel"/>.</exception>
        protected LogicBase(IView targetView, Type viewModelType = null, IViewModel viewModel = null)
        {
            if (CatelEnvironment.IsInDesignMode)
            {
                return;
            }

            Argument.IsNotNull("targetView", targetView);

            var targetViewType = targetView.GetType();

            if (viewModelType is null)
            {
                viewModelType = (viewModel != null) ? viewModel.GetType() : _viewModelLocator.ResolveViewModel(targetViewType);
                if (viewModelType is null)
                {
                    throw Log.ErrorAndCreateException <NotSupportedException>($"The view model of the view '{targetViewType.Name}' could not be resolved. Make sure to customize the IViewModelLocator or register the view and view model manually");
                }
            }

            UniqueIdentifier = UniqueIdentifierHelper.GetUniqueIdentifier <LogicBase>();

            Log.Debug($"Constructing behavior '{GetType().Name}' for '{targetView.GetType().Name}' with unique id '{UniqueIdentifier}'");

            TargetView    = targetView;
            ViewModelType = viewModelType;
            ViewModel     = viewModel;

            ViewModelBehavior = (viewModel != null) ? LogicViewModelBehavior.Injected : LogicViewModelBehavior.Dynamic;

            if (ViewModel != null)
            {
                SetDataContext(ViewModel);
            }

            Log.Debug("Subscribing to view events");

            ViewLoadManager.AddView(this);

            if (this.SubscribeToWeakGenericEvent <ViewLoadEventArgs>(ViewLoadManager, nameof(IViewLoadManager.ViewLoading), OnViewLoadedManagerLoadingInternal, false) is null)
            {
                Log.Debug("Failed to use weak events to subscribe to 'ViewLoadManager.ViewLoading', going to subscribe without weak events");

                ViewLoadManager.ViewLoading += OnViewLoadedManagerLoadingInternal;
            }

            if (this.SubscribeToWeakGenericEvent <ViewLoadEventArgs>(ViewLoadManager, nameof(IViewLoadManager.ViewLoaded), OnViewLoadedManagerLoadedInternal, false) is null)
            {
                Log.Debug("Failed to use weak events to subscribe to 'ViewLoadManager.ViewLoaded', going to subscribe without weak events");

                ViewLoadManager.ViewLoaded += OnViewLoadedManagerLoadedInternal;
            }

            if (this.SubscribeToWeakGenericEvent <ViewLoadEventArgs>(ViewLoadManager, nameof(IViewLoadManager.ViewUnloading), OnViewLoadedManagerUnloadingInternal, false) is null)
            {
                Log.Debug("Failed to use weak events to subscribe to 'ViewLoadManager.ViewUnloading', going to subscribe without weak events");

                ViewLoadManager.ViewUnloading += OnViewLoadedManagerUnloadingInternal;
            }

            if (this.SubscribeToWeakGenericEvent <ViewLoadEventArgs>(ViewLoadManager, nameof(IViewLoadManager.ViewUnloaded), OnViewLoadedManagerUnloadedInternal, false) is null)
            {
                Log.Debug("Failed to use weak events to subscribe to 'ViewLoadManager.ViewUnloaded', going to subscribe without weak events");

                ViewLoadManager.ViewUnloaded += OnViewLoadedManagerUnloadedInternal;
            }

            // Required so the ViewLoadManager can handle the rest
            targetView.Loaded   += (sender, e) => Loaded?.Invoke(this, EventArgs.Empty);
            targetView.Unloaded += (sender, e) => Unloaded?.Invoke(this, EventArgs.Empty);

            TargetView.DataContextChanged += OnTargetViewDataContextChanged;

            Log.Debug("Subscribing to view properties");

            // This also subscribes to DataContextChanged, don't double subscribe
            var viewPropertiesToSubscribe = DetermineInterestingViewProperties();

            foreach (var viewPropertyToSubscribe in viewPropertiesToSubscribe)
            {
                TargetView.SubscribeToPropertyChanged(viewPropertyToSubscribe, OnTargetViewPropertyChanged);
            }

            Log.Debug($"Constructed behavior '{GetType().Name}' for '{TargetViewType?.Name}'");
        }