コード例 #1
0
        protected override async Task Execute()
        {
            // if not modal
            if (!Workitem.IsModal)
            {
                // focus next workitem
                IWorkItem toFocus = null;

                if (Workitem.IsFocused && CurrentContextService.Collection.Count > 1)
                {
                    int index = CurrentContextService.Collection.IndexOf(Workitem);
                    if (index > 0)
                    {
                        toFocus = CurrentContextService.Collection[index - 1];
                    }
                    else if (index == 0)
                    {
                        toFocus = CurrentContextService.Collection[index + 1];
                    }
                }
                else if (Workitem.IsFocused && CurrentContextService.Collection.Count <= 1)
                {
                    await CurrentContextService.FocusWorkitem(null);
                }

                if (toFocus != null)
                {
                    await CurrentContextService.FocusWorkitem(toFocus);
                }
            }
        }
コード例 #2
0
 protected override async Task Execute()
 {
     // if not modal
     if (!(Workitem.IsModal))
     {
         await CurrentContextService.FocusWorkitem((IWorkItem)Workitem.Parent);
     }
 }
コード例 #3
0
        private void OpenBrandManagerWorkItem()
        {
            DateTime start = DateTime.Now;

            CurrentContextService.LaunchWorkItem <BrandManagerWorkItem>();
            TimeSpan took = DateTime.Now - start;

            Debug.WriteLine("Launch Workitem took: " + took.TotalSeconds);
        }
コード例 #4
0
        /// <summary>
        /// Internal Launch implementation
        /// </summary>
        /// <param name="modalMetadata">Modal metadata</param>
        /// <returns></returns>
        private async Task <IObservable <WorkitemEventArgs> > LaunchInternal(ModalOptions modalMetadata = null)
        {
            try
            {
                //Logger.LogWithWorkitemData(String.Format("Opening workitem {0}{1}.", Workitem.WorkItemName, ShouldOpenModal ? " in modal state" : ""), LogLevel.Informative, Workitem);

                // Trick to let ui have some time to update its state
                await TaskManager.Run(() => Thread.Sleep(50)).ConfigureAwait(false);

                // Get the workitem type
                Type type = Workitem.GetType();

                // If workitem is single instance and there is alredy a workitem
                // with the same type open focus the opened otherwise continue launching
                SingleInstanceWorkitemAttribute attribute = type.GetCustomAttributes(typeof(SingleInstanceWorkitemAttribute), false).FirstOrDefault() as SingleInstanceWorkitemAttribute;
                if (attribute != null)
                {
                    IWorkItem exists = CurrentContextService.Collection.Where(w => w.GetType().Equals(type)).FirstOrDefault();
                    if (exists != null)
                    {
                        await CurrentContextService.FocusWorkitem(exists).ConfigureAwait(false);

                        return(null);
                    }
                }
                var impl = Workitem.GetType().GetInterfaces().FirstOrDefault(x =>
                                                                             x.IsGenericType &&
                                                                             x.GetGenericTypeDefinition() == typeof(ISupportsInitialization <>));
                // If workitem supports initialization than do initialize it
                if (impl != null)
                {
                    //Logger.LogWithWorkitemData("Initializing workitem", LogLevel.Informative, Workitem);
                    try
                    {
                        var initType = impl.GetGenericArguments()[0];
                        // initialize
                        if (Data == null || initType.IsAssignableFrom(Data.GetType()))
                        {
                            var methodInfo = Workitem.GetType().GetMethod("Initialize", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
                            methodInfo.Invoke(Workitem, new object[] { Data });
                        }
                        else
                        {
                            throw new ArgumentException($"Workitem supports initialization only by {initType}");
                        }
                    }
                    catch (Exception e)
                    {
                        // Log error with workitem data
                        //Logger.LogWithWorkitemData("Workitem initialization failed", LogLevel.Exception, Workitem, e);
                        // Show error to the UI
                        UIManager.Error("Failed to Initialize Workitem");
                        return(null);
                    }
                }

                // Log
                //Logger.LogWithWorkitemData("Configuring Workitem", LogLevel.Informative, Workitem);

                // Configure Workitem
                Workitem.Configure();

                // if should open modal set the workitem window
                if (ShouldOpenModal)
                {
                    // if no custom modalMetadata is provided get the workitem default
                    if (modalMetadata == null)
                    {
                        ModalMetadata = Workitem.Configuration.GetOption <ModalOptions>();
                    }
                    else
                    {
                        ModalMetadata = modalMetadata;
                    }

                    // Set the workitem window in UI thread
                    Application.Current.Dispatcher.InvokeIfNeeded(() => Workitem.Window = CurrentContextService.InitModalWindow(Project.GetOption <RegionOptions>().CreateModalWindow(), Workitem, ModalMetadata));
                }

                // Execute isnatce specific launching
                await Execute().ConfigureAwait(false);

                // If Workitem is NullWorkitem set the WorkitemCollection.Null
                // otherwise add to the collection
                if (Workitem is NullWorkitem)
                {
                    CurrentContextService.Collection.Null = Workitem;
                }
                else if (!ShouldOpenModal || !ModalMetadata.IsDialog)
                {
                    CurrentContextService.Collection.Add(Workitem);
                }

                // If should open modal open the window
                if (ShouldOpenModal)
                {
                    //// Log
                    //Logger.LogWithWorkitemData("Showing modal window", LogLevel.Informative, Workitem);
                    // If should open in dialog mode call Workitem.Window.ShowDialog
                    if (ModalMetadata.IsDialog)
                    {
                        //// end loading now because after show dialog is execution will be blocked
                        //CurrentContextService.EndLoading();
                        // Show dialog
                        Application.Current.Dispatcher.InvokeIfNeeded(() => Workitem.Window.ShowDialog());
                    }
                    else
                    {
                        Application.Current.Dispatcher.InvokeIfNeeded(() => Workitem.Window.Show());
                    }
                }

                if (!ShouldOpenModal || !ModalMetadata.IsDialog)
                {
                    await CurrentContextService.FocusWorkitem(Workitem).ConfigureAwait(false);
                }
                // return the communication channel
                return(Channel);
            }
            catch (Exception e)
            {
                // Try and fix the broken parts
                CurrentContextService.Collection.Remove(Workitem);
                Workitem.Dispose();
                //// Log workitem exception
                //Logger.LogWithWorkitemData("Failed to open workitem", LogLevel.Exception, Workitem, e);
                // Show error in the UI
                UIManager.Error("Failed to open workitem");
                // return an empty channel
                return(Observable.Empty <WorkitemEventArgs>());
            }
            finally
            {
                //// finally end loding for modal
                //if (ShouldOpenModal)
                //    CurrentContextService.EndLoading();
            }
        }
コード例 #5
0
 private void OpenModalExampleModalWorkitem()
 {
     CurrentContextService.LaunchModalWorkItem <ModalExampleWorkitem>();
 }
コード例 #6
0
 private void OpenModalRuntimeExampleWorkitem()
 {
     CurrentContextService.LaunchWorkItem <ModalRuntimeExampleWorkitem>();
 }
コード例 #7
0
ファイル: Workitem.cs プロジェクト: vadrsa/eShop
 protected virtual void Close()
 {
     CurrentContextService.CloseCurrentWorkItem();
 }
コード例 #8
0
 private void OpenMesagesWorkItem()
 {
     CurrentContextService.LaunchWorkItem <MessageWorkItem>();
 }
コード例 #9
0
 private void OpenCategoriesWorkItem()
 {
     CurrentContextService.LaunchWorkItem <CategoriesWorkItem>();
 }
コード例 #10
0
 private void OpenBrandManagerWorkItem()
 {
     CurrentContextService.LaunchWorkItem <BrandManagerWorkItem>();
 }
コード例 #11
0
 private void OpenProductManagerWorkItem()
 {
     CurrentContextService.LaunchWorkItem <ProductManagerWorkItem>();
 }
コード例 #12
0
 private void OpenLocalStorageExampleWorkitem()
 {
     CurrentContextService.LaunchWorkItem <LocalStorageExampleWorkitem>();
 }
コード例 #13
0
ファイル: WorkitemBase.cs プロジェクト: vadrsa/Prism.Kernel
 /// <summary>
 /// Close the workitem
 /// </summary>
 /// <returns></returns>
 public Task <bool> Close()
 {
     return(CurrentContextService.CloseWorkitem(this));
 }