Exemple #1
0
        /// <summary>
        /// Process the given <see cref="NavigationResponse"/> instance
        /// </summary>
        /// <param name="response"></param>
        void INavigationHandler.ProcessResponse(NavigationResponse response)
        {
            // basic check
            if (response == null)
            {
                throw new ArgumentNullException("response");
            }

            // we check if the navigation was successfull or not
            if (response.Status != ResponseStatus.Success)
            {
                this.PublishNavigationFailedInfo(response.Request);

                IShowMessageViewService showMessageService = ViewServiceLocator.GetViewService <IShowMessageViewService>();

                showMessageService.ButtonSetup = DialogButton.Ok;
                showMessageService.Caption     = "Chronos - Error en la navegación";
                showMessageService.Text        =
                    ((response.Error != null) ? response.Error.Message : String.Format("No ha sido posible resolver la navegación solicitada ({0})", response.Request.RequestUrl));

                showMessageService.ShowMessage();
            }
            else
            {
                Application.Current.Dispatcher.BeginInvoke
                (
                    DispatcherPriority.Background,
                    new ThreadStart
                    (
                        () =>
                {
                    WindowElement window = response.Content as WindowElement;

                    if (response.ResponseParameters != null &&
                        response.ResponseParameters.Count > 0)
                    {
                        ISupportNavigationLifecycle supporter = nRoute.Navigation.NavigationService.GetSupporter <ISupportNavigationLifecycle>(response.Content);

                        if (supporter != null)
                        {
                            supporter.Initialize(response.ResponseParameters);
                        }
                    }

                    this.PublishNavigatedInfo(window.Title, response);

                    if (response.Request.NavigationMode == NavigateMode.Modal)
                    {
                        ServiceLocator.GetService <IVirtualDesktopManager>().ShowDialog(window);
                    }
                    else
                    {
                        ServiceLocator.GetService <IVirtualDesktopManager>().Show(window);
                    }
                }
                    )
                );
            }
        }
 protected override void OnDetaching()
 {
     base.OnDetaching();
     if (!string.IsNullOrEmpty(ViewServiceName) && this.AssociatedObject != null)
     {
         ViewServiceLocator.UnregisterViewServiceInstance(typeof(TViewService), this.ViewServiceName, this.AssociatedObject);
         Resource.UnregisterResourceLocator(typeof(TViewService), this.ViewServiceName);
     }
 }
Exemple #3
0
        /// <summary>
        /// Performs the navigation to the given target
        /// </summary>
        /// <param name="target"></param>
        public void Navigate(NavigateMode mode, string target, params object[] args)
        {
            if (String.IsNullOrEmpty(target))
            {
                IShowMessageViewService showMessageService = ViewServiceLocator.GetViewService <IShowMessageViewService>();

                showMessageService.ButtonSetup = DialogButton.Ok;
                showMessageService.Caption     = "Warning";
                showMessageService.Text        = "Option not mapped to a view.";

                showMessageService.ShowMessage();

                return;
            }

            Application.Current.Dispatcher.BeginInvoke
            (
                DispatcherPriority.Background,
                new ThreadStart
                (
                    delegate
            {
                ParametersCollection navParams = null;
                string area = null;

                if (args != null && args.Length > 0)
                {
                    navParams = new ParametersCollection();
                    navParams.Add(NavigationParams.NavigationParamsKey, args);
                }

                var smnode = SiteMapService.SiteMap.RootNode.ChildNodes
                             .OfType <NavigationNode>()
                             .Traverse <NavigationNode>(node => ((node.ChildNodes) != null ? node.ChildNodes.OfType <NavigationNode>() : null))
                             .Where(n => n.Url == target).SingleOrDefault();

                if (smnode != null)
                {
                    area = smnode.SiteArea;
                }

                NavigationRequest request   = new NavigationRequest(target, navParams, area, mode);
                IDisposable navigationToken = nRoute.Navigation.NavigationService.Navigate(request);

                if (navigationToken != null)
                {
                    navigationToken.Dispose();
                    navigationToken = null;
                }
            }
                )
            );
        }
Exemple #4
0
        private static void SaveFile(string filename, XElement xElement)
        {
            try
            {
                xElement.Save(filename);
            }
            catch (Exception)
            {
                IShowMessageViewService showMessageService = ViewServiceLocator.GetViewService <IShowMessageViewService>();

                showMessageService.ButtonSetup = DialogButton.Ok;
                showMessageService.Caption     = "Chronos - Error al guardar el estado del escritorio";
                showMessageService.Text        = "No ha sido posible al guardar el estado del escritorio.";

                showMessageService.ShowMessage();
            }
        }
        protected override void OnAttached()
        {
            base.OnAttached();

            // we need to have a name, else we can't register it
            if (string.IsNullOrEmpty(ViewServiceName))
            {
                this.ViewServiceName = Guid.NewGuid().ToString();
            }
            if (this.AssociatedObject != null)
            {
                if (!Resource.IsResourceRegistered(typeof(TViewService), this.ViewServiceName))
                {
                    var _meta = new ViewServiceMeta(typeof(TViewService), this.AssociatedObject.GetType(),
                                                    this.ViewServiceName, InitializationMode.WhenAvailable, ViewServiceLifetime.SelfRegisteredInstance);
                    Resource.RegisterResourceLocator(typeof(TViewService), new DefaultViewServiceLocator(_meta), this.IsDefault);
                }
                ViewServiceLocator.RegisterViewServiceInstance(typeof(TViewService), this.ViewServiceName, this.AssociatedObject);
            }
        }
Exemple #6
0
        private static XElement LoadFromFile(string filename)
        {
            try
            {
                if (File.Exists(filename))
                {
                    return(XElement.Load(filename));
                }
            }
            catch (Exception)
            {
                IShowMessageViewService showMessageService = ViewServiceLocator.GetViewService <IShowMessageViewService>();

                showMessageService.ButtonSetup = DialogButton.Ok;
                showMessageService.Caption     = "Chronos - Error en la carga del escritorio";
                showMessageService.Text        = "No ha sido posible realizar la carga del escritorio.";

                showMessageService.ShowMessage();
            }

            return(null);
        }
Exemple #7
0
 /// <summary>
 /// Gets the requested view service.
 /// </summary>
 /// <typeparam name="TViewService">The type of the view service.</typeparam>
 /// <returns></returns>
 protected TViewService GetViewService <TViewService>() where TViewService : class
 {
     return(ViewServiceLocator.GetViewService <TViewService>());
 }