Пример #1
0
        /// <summary>
        /// Create a new dialog instance and then calls the show method of the instance.
        /// </summary>
        /// <param name="dialogs">The dialog service</param>
        /// <param name="presentable">The content of the dialog.</param>
        /// <param name="options">Dialog options.</param>
        public static IDialog ShowDialog(this IDialogService dialogs, IPresentable presentable, DialogOptions options)
        {
            var dialog = dialogs.CreateDialog(presentable, options);

            dialog.Show();
            return(dialog);
        }
Пример #2
0
        /// <summary>
        /// Register a new presentable object.
        /// </summary>
        /// <param name="obj">The object to register.</param>
        /// <returns>True if the object was successfully registered, false if the object was already registered.</returns>
        public static bool RegisterService(IPresentable obj)
        {
            lock (lockObj)
            {
                if (!feeds.Contains(obj))
                {
                    obj.PropertyChanged += OnFeedPropertyChanged;

                    feeds.Add(obj);
                }
                else
                {
                    return(false);
                }

                UpdateTriggerGroups();

                if (IntervalThread == null)
                {
                    cts = new CancellationTokenSource();

                    IntervalThread = new Thread(IntervalMethod);
                    IntervalThread.IsBackground = true;
                    IntervalThread.Start();
                }

                return(true);
            }
        }
Пример #3
0
		private void AddPresentable(IPresentable presentable)
		{
			Debug.Assert(presentable != null);
			Debug.Assert(!_disposed);

			var parent = presentable.Parent;

			if (parent != null)
			{
				// Insert the presentable right after the last one with the same parent.
				var node = _presentables.Last;

				while (node != null)
				{
					if (node.Value.IsChildOf(parent))
					{
						break;
					}

					node = node.Previous;
				}

				_presentables.AddAfter(node, presentable);
			}
			else
			{
				_presentables.AddLast(presentable);
			}
		}
Пример #4
0
		void IPresenterInternal.PresentCompleted(IPresentable presentable, Exception e, bool cancelled)
		{
			if (!_disposed)
			{
				PresentCompleted?.Invoke(this, new PresentCompletedEventArgs(presentable, e, cancelled));
			}
		}
Пример #5
0
        /// <summary>
        /// Create a new dialog instance and then calls the show method of the instance.
        /// </summary>
        /// <param name="dialogs">The dialog service</param>
        /// <param name="title">The title of the dialog.</param>
        /// <param name="presentable">The content of the dialog.</param>
        /// <param name="options">Dialog options.</param>
        /// <param name="actions">The actions of the dialog.</param>
        public static IDialog ShowDialog(this IDialogService dialogs, string title, IPresentable presentable, DialogOptions options, params ActionCommandBase[] actions)
        {
            var dialog = dialogs.CreateDialog(title, presentable, options, actions);

            dialog.Show();
            return(dialog);
        }
Пример #6
0
        /* ----------------------------------------------------------------- */
        ///
        /// OnBind
        ///
        /// <summary>
        /// Initializes for the About page.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        protected override void OnBind(IPresentable src)
        {
            base.OnBind(src);
            if (!(src is MainViewModel vm))
            {
                return;
            }

            FileListView.DataSource = vm.Files;

            MergeButton.Click  += (s, e) => vm.Merge();
            SplitButton.Click  += (s, e) => vm.Split();
            FileButton.Click   += (s, e) => vm.Add();
            UpButton.Click     += (s, e) => vm.Move(SelectedIndices, -1);
            DownButton.Click   += (s, e) => vm.Move(SelectedIndices, 1);
            RemoveButton.Click += (s, e) => vm.Remove(SelectedIndices);
            ClearButton.Click  += (s, e) => vm.Clear();

            Behaviors.Add(new CloseBehavior(src, this));
            Behaviors.Add(new DialogBehavior(src));
            Behaviors.Add(new OpenFileBehavior(src));
            Behaviors.Add(new OpenDirectoryBehavior(src));
            Behaviors.Add(new SaveFileBehavior(src));
            Behaviors.Add(vm.Subscribe <CollectionMessage>(e => vm.Files.ResetBindings(false)));
        }
Пример #7
0
        /// <summary>
        /// Create a new dialog instance and then calls the show method of the instance.
        /// </summary>
        /// <param name="dialogs">The dialog service</param>
        /// <param name="title">The title of the dialog.</param>
        /// <param name="presentable">The content of the dialog.</param>
        public static IDialog ShowDialog(this IDialogService dialogs, string title, IPresentable presentable)
        {
            var dialog = dialogs.CreateDialog(title, presentable);

            dialog.Show();
            return(dialog);
        }
Пример #8
0
 public static async Task Test(IPresentable presenter)
 {
     await MeasureTime(watch, presenter.ClearTable);
     await MeasureTime(watch, presenter.Add20Entities);
     await MeasureTime(watch, presenter.UpdateEntity);
     await MeasureTime(watch, presenter.DeleteEntity);
     await MeasureTime(watch, presenter.WhereExample);
 }
Пример #9
0
		private IPresentable CreatePresentable(IPresentable parent, Type controllerType, PresentOptions presentOptions, PresentArgs args)
		{
			Debug.Assert(controllerType != null);
			Debug.Assert(!_disposed);

			var resultType = typeof(int);
			var attrs = (ViewControllerAttribute[])controllerType.GetCustomAttributes(typeof(ViewControllerAttribute), false);
			var presentContext = new PresentResultArgs()
			{
				Id = ++_idCounter,
				ServiceProvider = _serviceProvider,
				ControllerFactory = _controllerFactory,
				ViewFactory = _viewFactory,
				ControllerType = controllerType,
				Parent = parent,
				PresentOptions = presentOptions,
				PresentArgs = args ?? PresentArgs.Default
			};

			if (attrs != null && attrs.Length > 0)
			{
				var controllerAttr = attrs[0];

				presentContext.PresentOptions |= controllerAttr.PresentOptions;
				presentContext.Layer = controllerAttr.Layer;
				presentContext.Tag = controllerAttr.Tag;
				presentContext.PrefabPath = controllerAttr.PrefabPath;
			}

			// Types inherited from IViewControllerResult<> use specific result values.
			if (IsAssignableToGenericType(controllerType, typeof(IViewControllerResult<>), out var t))
			{
				resultType = t.GenericTypeArguments[0];
			}

			// If parent is going to be dismissed, use its parent instead.
			if ((presentOptions & PresentOptions.Child) == 0)
			{
				presentContext.Parent = null;
			}
			else if ((presentOptions & PresentOptions.DismissAll) != 0)
			{
				presentContext.Parent = null;
			}
			else if ((presentOptions & PresentOptions.DismissCurrent) != 0)
			{
				presentContext.Parent = parent?.Parent;
			}

			// Instantiate the presentable.
			// https://docs.microsoft.com/en-us/dotnet/framework/reflection-and-codedom/how-to-examine-and-instantiate-generic-types-with-reflection
			var presentResultType = typeof(PresentResult<,>).MakeGenericType(controllerType, resultType);
			var c = (IPresentable)Activator.CreateInstance(presentResultType, this, presentContext);

			AddPresentable(c);

			return c;
		}
Пример #10
0
		private IPresentResult PresentInternal(IPresentable presentable, Type controllerType, PresentOptions presentOptions, Transform transform, PresentArgs args)
		{
			ThrowIfDisposed();
			ThrowIfInvalidControllerType(controllerType);

			var result = CreatePresentable(presentable, controllerType, presentOptions, args);
			PresentInternal(result, presentable, transform);
			return result;
		}
        public override void Present(IExperiment exp, IPresentable mean, IPresentable std)
        {
            _experimentName = exp.Name;
            _exp            = exp;

            for (int c = 0; c < exp.theBlauSpace.Dimension; c++)
            {
                Present((IBlauSpaceEvaluation)mean, (IBlauSpaceEvaluation)std, c);
            }
        }
Пример #12
0
        /* ----------------------------------------------------------------- */
        ///
        /// OnBind
        ///
        /// <summary>
        /// Invokes the binding to the specified object.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        protected override void OnBind(IPresentable src)
        {
            base.OnBind(src);
            if (!(src is VersionViewModel vm))
            {
                return;
            }

            VersionBindingSource.DataSource = vm;
            ExecButton.Click += (s, e) => vm.Apply();
        }
Пример #13
0
        /* ----------------------------------------------------------------- */
        ///
        /// OnBind
        ///
        /// <summary>
        /// Invokes the binding to the specified object.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        protected override void OnBind(IPresentable src)
        {
            base.OnBind(src);
            if (src is not MainViewModel vm)
            {
                return;
            }

            MainBindingSource.DataSource = vm;

            var ctx = new FileContextMenu(() => SelectedIndices.Count() > 0);

            ctx.PreviewMenu.Click += (s, e) => vm.Preview(SelectedIndices);
            ctx.UpMenu.Click      += (s, e) => vm.Move(SelectedIndices, -1);
            ctx.DownMenu.Click    += (s, e) => vm.Move(SelectedIndices, 1);
            ctx.RemoveMenu.Click  += (s, e) => vm.Remove(SelectedIndices);

            FileListView.ContextMenuStrip = ctx;
            FileListView.DataSource       = vm.Files;

            Shown                    += (s, e) => vm.Setup();
            MergeButton.Click        += (s, e) => vm.Merge();
            SplitButton.Click        += (s, e) => vm.Split();
            FileButton.Click         += (s, e) => vm.Add();
            UpButton.Click           += (s, e) => vm.Move(SelectedIndices, -1);
            DownButton.Click         += (s, e) => vm.Move(SelectedIndices, 1);
            RemoveButton.Click       += (s, e) => vm.Remove(SelectedIndices);
            ClearButton.Click        += (s, e) => vm.Clear();
            TitleButton.Click        += (s, e) => vm.About();
            FileListView.DoubleClick += (s, e) => vm.Preview(SelectedIndices);

            ShortcutKeys.Clear();
            ShortcutKeys.Add(Keys.Control | Keys.Shift | Keys.D, vm.Clear);
            ShortcutKeys.Add(Keys.Control | Keys.O, vm.Add);
            ShortcutKeys.Add(Keys.Control | Keys.H, vm.About);
            ShortcutKeys.Add(Keys.Control | Keys.K, () => vm.Move(SelectedIndices, -1));
            ShortcutKeys.Add(Keys.Control | Keys.J, () => vm.Move(SelectedIndices, 1));
            ShortcutKeys.Add(Keys.Control | Keys.M, () => vm.Invokable.Then(vm.Merge));
            ShortcutKeys.Add(Keys.Control | Keys.S, () => vm.Invokable.Then(vm.Split));

            Behaviors.Add(new CloseBehavior(vm, this));
            Behaviors.Add(new DialogBehavior(vm));
            Behaviors.Add(new OpenFileBehavior(vm));
            Behaviors.Add(new OpenDirectoryBehavior(vm));
            Behaviors.Add(new SaveFileBehavior(vm));
            Behaviors.Add(new FileDropBehavior(vm, this));
            Behaviors.Add(new ShowDialogBehavior <PasswordWindow, PasswordViewModel>(vm));
            Behaviors.Add(new ShowDialogBehavior <VersionWindow, VersionViewModel>(vm));
            Behaviors.Add(vm.Subscribe <CollectionMessage>(e => vm.Files.ResetBindings(false)));
            Behaviors.Add(vm.Subscribe <SelectMessage>(e => Select(e.Value)));
            Behaviors.Add(vm.Subscribe <PreviewMessage>(e => Process.Start(e.Value)));
        }
Пример #14
0
 /* ----------------------------------------------------------------- */
 ///
 /// Subscribe
 ///
 /// <summary>
 /// Sets some dummy callbacks to the specified Messenger.
 /// </summary>
 ///
 /* ----------------------------------------------------------------- */
 private IEnumerable <IDisposable> Subscribe(IPresentable src) => new[]
 {
     src.Subscribe <DialogMessage>(e => Select(e)),
     src.Subscribe <OpenFileMessage>(e => e.Value = new[] { Source }),
     src.Subscribe <SaveFileMessage>(e => e.Value = Destination),
     src.Subscribe <PasswordViewModel>(e =>
     {
         e.Password.Value = Password;
         var dest         = Password.HasValue() ? e.OK : e.Cancel;
         Assert.That(dest.Command.CanExecute(), Is.True, dest.Text);
         dest.Command.Execute();
     }),
 };
Пример #15
0
		IEnumerable<IPresentable> IPresenterInternal.GetChildren(IPresentable presentable)
		{
			var node = _presentables.Find(presentable)?.Next;

			while (node != null)
			{
				var p = node.Value;

				if (p.Parent == presentable)
				{
					yield return p;
				}

				node = node.Next;
			}
		}
Пример #16
0
        private void NavigationItem_NavigationRequested(object sender, IPresentable e)
        {
            var nav = sender as INavigationItem;

            foreach (var navigationItem in NavigationItems)
            {
                navigationItem.IsSelected = false;
            }
            Navigated?.Invoke(this, new NavigationEventArgs {
                OldLocation = _currentNavligationItem, NewLocation = nav
            });
            _navigationRegion.View(e);
            _currentNavligationItem = nav;
            ShowTitles     = false;
            nav.IsSelected = true;
        }
Пример #17
0
        public static bool IsChildOf(this IPresentable p, IPresentable other)
        {
            Debug.Assert(other != null);

            while (p != null)
            {
                if (p == other)
                {
                    return(true);
                }

                p = p.Parent;
            }

            return(false);
        }
Пример #18
0
        public PresentResult(IPresenterInternal presenter, PresentResultArgs context)
        {
            Debug.Assert(presenter != null);
            Debug.Assert(context != null);

            _presenter         = presenter;
            _id                = context.Id;
            _tag               = context.Tag;
            _layer             = context.Layer;
            _parent            = context.Parent;
            _serviceProvider   = context.ServiceProvider;
            _controllerFactory = context.ControllerFactory;
            _controllerType    = context.ControllerType;
            _presentArgs       = context.PresentArgs;
            _presentOptions    = context.PresentOptions;
            _deeplinkId        = GetDeeplinkId(_controllerType);
            _prefabPath        = string.IsNullOrEmpty(context.PrefabPath) ? GetDefaultPrefabName(_controllerType) : context.PrefabPath;
        }
Пример #19
0
 /// <inheritdoc />
 public NavigationItem(
     IPresentable destination,
     string title,
     string icon,
     NavItemPosition position = NavItemPosition.Top,
     bool localizedTitle      = false)
 {
     _destination = destination;
     Title        = title;
     if (!string.IsNullOrEmpty(icon))
     {
         Icon = Geometry.Parse(icon);
     }
     Position            = position;
     DestinationType     = _destination?.GetType();
     DestinationResolved = true;
     _localizedTitle     = localizedTitle;
 }
Пример #20
0
		private int GetZIndex(IPresentable presentable)
		{
			var zIndex = 0;

			foreach (var p in _presentables)
			{
				if (p == presentable)
				{
					break;
				}
				else if (p.Layer == presentable.Layer)
				{
					++zIndex;
				}
			}

			return zIndex;
		}
Пример #21
0
		public void Update()
		{
			var frameTime = Time.deltaTime;
			var node = _presentables.First;
			var newActive = default(IPresentable);

			// 1) Remove dismissed controllers & find active.
			while (node != null)
			{
				var p = node.Value;
				node = node.Next;

				if (p.IsDismissed)
				{
					if (p.Controller != null)
					{
						_controllerMap.Remove(p.Controller);
					}

					_presentables.Remove(p);
				}
				else
				{
					newActive = p;
				}
			}

			// 2) Activate/deactivate.
			if (newActive != _lastActive && newActive != null && newActive.TryActivate())
			{
				_lastActive?.Deactivate();
				_lastActive = newActive;
			}

			// 3) Update presentables.
			node = _presentables.First;

			while (node != null)
			{
				node.Value.Update(frameTime);
				node = node.Next;
			}
		}
Пример #22
0
        /* ----------------------------------------------------------------- */
        ///
        /// OnBind
        ///
        /// <summary>
        /// Initializes for the About page.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        protected override void OnBind(IPresentable src)
        {
            base.OnBind(src);
            if (!(src is MainViewModel vm))
            {
                return;
            }

            MainBindingSource.DataSource = vm;
            ClipListView.DataSource      = vm.Clips;

            OpenButton.Click   += (s, e) => vm.Open();
            AttachButton.Click += (s, e) => vm.Attach();
            DetachButton.Click += (s, e) => vm.Detach(SelectedIndices);
            SaveButton.Click   += (s, e) => vm.Save();
            ResetButton.Click  += (s, e) => vm.Reset();

            Behaviors.Add(new CloseBehavior(src, this));
            Behaviors.Add(new DialogBehavior(src));
            Behaviors.Add(new OpenFileBehavior(src));
            Behaviors.Add(new OpenDirectoryBehavior(src));
            Behaviors.Add(new SaveFileBehavior(src));
            Behaviors.Add(vm.Subscribe <CollectionMessage>(e => vm.Clips.ResetBindings(false)));
        }
Пример #23
0
        /// <summary>
        /// Unregister a presentable object.
        /// </summary>
        /// <param name="obj">The object to unregister.</param>
        /// <returns>True if the object was successfully unregistered, false if the object was not registered.</returns>
        public static bool UnregisterService(IPresentable obj)
        {
            lock (lockObj)
            {
                if (feeds.Contains(obj))
                {
                    feeds.Remove(obj);
                }
                else
                {
                    return(false);
                }

                if (feeds.Count == 0)
                {
                    CancelIntervalThread();
                }
                else
                {
                    UpdateTriggerGroups();
                }
                return(true);
            }
        }
Пример #24
0
 static void VerDatos(IPresentable p)
 {
     p.Presentar();
     Console.WriteLine("-----------------------------");
 }
Пример #25
0
		public abstract void Present(IExperiment exp, IPresentable obj);
Пример #26
0
		public abstract void Present(IExperiment exp, IPresentable mean, IPresentable std);
Пример #27
0
		IPresentResult IPresenterInternal.PresentAsync(IPresentable presentable, Type controllerType, PresentOptions presentOptions, Transform parent, PresentArgs args)
		{
			return PresentInternal(presentable, controllerType, presentOptions, parent, args);
		}
Пример #28
0
 public StandardConsoleOutputTests()
 {
     standardConsoleOutput = new StandardConsoleOutput();
 }
Пример #29
0
 /// <inheritdoc />
 public virtual void SetDestination(IPresentable destination)
 {
     _destination        = destination;
     DestinationResolved = true;
 }
Пример #30
0
		private async void PresentInternal(IPresentable presentable, IPresentable presentableParent, Transform transform)
		{
			var zIndex = GetZIndex(presentable);

			try
			{
				// 1) Execute the middleware chain. Order is important here.
				if (_presentDelegates != null)
				{
					foreach (var middleware in _presentDelegates)
					{
						await middleware(this, presentable);
					}
				}

				// 2) Load the controller view.
				var view = await _viewFactory.CreateViewAsync(presentable.PrefabPath, presentable.Layer, zIndex, presentable.PresentOptions, transform);

				if (view is null)
				{
					throw new PresentException(presentable, "View is null.");
				}

				// 3) Create the controller (or dispose view if the controller is dismissed at this point).
				if (presentable.IsDismissed)
				{
					view.Dispose();
					throw new OperationCanceledException();
				}
				else
				{
					presentable.CreateController(view);
				}

				_controllerMap.Add(presentable.Controller, presentable);

				// 4) Dismiss the specified controllers if requested.
				if ((presentable.PresentOptions & PresentOptions.DismissAll) != 0)
				{
					foreach (var p in _presentables)
					{
						if (p != presentable)
						{
							p.DismissCancel();
						}
					}
				}
				else if ((presentable.PresentOptions & PresentOptions.DismissCurrent) != 0)
				{
					presentableParent?.DismissCancel();
				}

				// 5) Dismiss controllers of the same type if requested (for singleton controllers only).
				if ((presentable.PresentOptions & PresentOptions.Singleton) != 0)
				{
					foreach (var p in _presentables)
					{
						if (p != presentable && p.ControllerType == presentable.ControllerType)
						{
							p.DismissCancel();
						}
					}
				}
			}
			catch (Exception e)
			{
				presentable.Dismiss(e);
			}
		}