Exemple #1
0
        /// <summary>
        /// 指定Id页面是否已经显示于指定的区域
        /// </summary>
        /// <param name="viewId"></param>
        /// <param name="regionName"></param>
        /// <returns></returns>
        public static bool RegionWetherHasThisIdView(int viewId, string regionName)
        {
            if (!RegionManagerInstances.Regions.ContainsRegionWithName(regionName))
            {
                return(false);
            }

            var view = ViewComponentHolding.GetViewById(viewId + "");

            if (view == null)
            {
                return(false);
            }
            if (RegionManagerInstances.Regions[regionName].Views.Contains(view))
            {
                return(true);
            }
            return(false);
        }
Exemple #2
0
        /// <summary>
        /// 通过页面Id获取页面实例; 页面必须继承自 ContentControl ;如果页面需要执行初始化则必须实现IINavOnLoad 接口 NavOnLoad方法实现参数初始化 ;
        /// </summary>
        /// <param name="viewId"></param>
        /// <param name="args"></param>
        /// <returns>无法查阅则返回 null</returns>
        public static object GetViewById(int viewId, params object[] args)
        {
            var obs = ViewComponentHolding.GetViewById(viewId + "");

            if (obs != null)
            {
                //View = obs;
                var userControlMvvm = obs as ContentControl; // UserControl; ContentControl
                if (userControlMvvm != null)
                {
                    var mvvm = userControlMvvm.DataContext as IINavOnLoad; //导航页面必须实现此接口方可使用此函数进行页面导航数据初始化,否则需要自设定导航初始化
                    if (mvvm != null)
                    {
                        mvvm.NavOnLoad(args);
                    }
                }
            }
            return(obs);
        }
Exemple #3
0
        ////定义委托
        //private delegate void DoTask();
        ///// <summary>
        ///// 提供外部使用
        ///// </summary>
        //public void OnImportsSatisfiedViewsForOutUse()
        //{
        //    try
        //    {
        //        Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
        //                                              new DoTask(OnImportsSatisfiedViews));
        //    }
        //    catch (Exception ex)
        //    {

        //    }
        //}


        private void OnImportsSatisfiedViews()
        {
            try
            {
                CheckSameViewId();
                //  Thread.Sleep(100);
                if (ViewComponentHolding.Count < RegisteredViews.Length)
                {
                    //增加部件
                    foreach (var t in RegisteredViews)
                    {
                        ViewComponentHold.AddViewItem(t.Metadata, t.Value, false);
                    }
                    AddRegisteredViews();
                }
                else if (ViewComponentHolding.Count > RegisteredViews.Length)
                {
                    var lstCollection = new List <string>();
                    foreach (var t in ViewComponentHolding.GetAllViewsID)
                    {
                        lstCollection.Add(t);
                    }
                    //删除部件
                    foreach (var t in lstCollection)
                    {
                        if (!RegisteredViewsContainsId(t))
                        {
                            DeleteRegisteredViews(ViewComponentHolding.GetViewMetadataById(t),
                                                  ViewComponentHolding.GetViewById(t));
                            ViewComponentHold.DeleteViewItem(t, false);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLog.WriteLogError("Core AutoPopulate happen an super error:" + ex.ToString());
            }
        }
Exemple #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="argu"></param>
        internal static void DoTaskB(params object[] argu)
        {
            // int viewId, string viewAttachRegionName, bool show


            try
            {
                if (argu.Length < 2)
                {
                    return;
                }
                if (argu[0] == null)
                {
                    return;
                }

                string viewId           = argu[0].ToString();
                string viewAttachRegion = ViewComponentHolding.GetViewAttachRegionById(viewId);
                //   string viewAttachRegion = argu[1].ToString();
                object[] arus = new object[argu.Length - 1];
                for (int i = 1; i < argu.Length; i++)
                {
                    arus[i - 1] = argu[i];
                }


                var view = ViewComponentHolding.GetViewById(viewId);
                if (view == null)
                {
                    WriteLog.WriteLogInfo(
                        "Core ShowViewByIdAttachRegion Can not find View IN ViewComponentHolding By id :" + viewId);
                    return;
                }


                try
                {
                    var userControlMvvm = view as ContentControl;
                    if (userControlMvvm != null)
                    {
                        var mvvm = userControlMvvm.DataContext as IINavInitBeforShow;
                        //导航页面必须实现此接口方可使用此函数进行页面导航数据初始化,否则需要自设定导航初始化
                        if (mvvm != null)
                        {
                            //  mvvm.NavInitBeforShow(arus);

                            var dt = DateTime.Now.Ticks;
                            mvvm.NavInitBeforShow(arus);
                            var ds = DateTime.Now.Ticks - dt;
                            CalInitTime(viewId, ds);
                        }
                    }
                }
                catch (Exception ex)
                {
                    WriteLog.WriteLogInfo(
                        "Core ShowViewByIdAttachRegion NavInitBeforShow Error IN ViewComponentHolding By id :" + viewId);
                }

                int vid = Convert.ToInt32(viewId);
                if (item.ContainsKey(vid))
                {
                    item[vid].Show();
                    item[vid].Focus();
                    item[vid].WindowState = WindowState.Normal;


                    var userControlMvvm = item[vid].Content as ContentControl;
                    if (userControlMvvm != null)
                    {
                        var mvvm = userControlMvvm.DataContext as IINavOnLoad;
                        //导航页面必须实现此接口方可使用此函数进行页面导航数据初始化,否则需要自设定导航初始化
                        if (mvvm != null)
                        {
                            //mvvm.NavOnLoad(arus);

                            var dt = DateTime.Now.Ticks;

                            mvvm.NavOnLoad(arus);
                            var ds = DateTime.Now.Ticks - dt;
                            CalInitTime(vid, ds);
                        }
                    }
                    return;
                }



                try
                {
                    bool   bolNavOnLoad    = false;
                    var    userControlMvvm = view as ContentControl;
                    string title           = string.Empty;
                    if (userControlMvvm != null)
                    {
                        var mvvm = userControlMvvm.DataContext as IINavOnLoad;
                        //导航页面必须实现此接口方可使用此函数进行页面导航数据初始化,否则需要自设定导航初始化
                        if (mvvm != null)
                        {
                            var dt = DateTime.Now.Ticks;

                            mvvm.NavOnLoad(arus);
                            bolNavOnLoad = true;
                            var ds = DateTime.Now.Ticks - dt;
                            CalInitTime(vid, ds);
                        }
                        var mv = userControlMvvm.DataContext as IITab;
                        if (mv != null)
                        {
                            title = mv.Title;
                        }
                    }
                    AddAndShowView(title, vid, userControlMvvm);
                }
                catch (Exception ex)
                {
                    WriteLog.WriteLogError("Core ShowViewByIdAttachRegion Error while NavOnLoad:" + ex);
                }
            }
            catch (Exception ex)
            {
                WriteLog.WriteLogError("Core ShowViewByIdAttachRegion Error:" + ex);
            }
        }
Exemple #5
0
        internal static void DoTaskA(Tuple <string, bool> tuple)
        {
            string viewId  = tuple.Item1;
            bool   show    = tuple.Item2;
            int    viewIdx = Convert.ToInt32(viewId);

            try
            {
                var attachRegion = ViewComponentHolding.GetViewAttachRegionById(viewId);


                var view = ViewComponentHolding.GetViewById(viewId);
                if (view == null)
                {
                    WriteLog.WriteLogInfo(
                        "Core ShowViewByIdAttachRegion Can not find View IN ViewComponentHolding By id :" + viewId);
                    return;
                }


                if (show)
                {
                    if (item.ContainsKey(viewIdx))
                    {
                        item[viewIdx].Show();
                        item[viewIdx].Focus();
                        item[viewIdx].WindowState = WindowState.Normal;
                        return;
                    }

                    try
                    {
                        var    userControlMvvm = view as ContentControl;
                        string title           = string.Empty;
                        if (userControlMvvm != null)
                        {
                            userControlMvvm.HorizontalAlignment = HorizontalAlignment.Center;
                            userControlMvvm.VerticalAlignment   = VerticalAlignment.Center;
                            //userControlMvvm.HorizontalContentAlignment = HorizontalAlignment.Center;
                            //userControlMvvm.VerticalContentAlignment  = VerticalAlignment.Center;
                            var mvvm = userControlMvvm.DataContext as IINavInitBeforShow;
                            //导航页面必须实现此接口方可使用此函数进行页面导航数据初始化,否则需要自设定导航初始化
                            if (mvvm != null)
                            {
                                var dt = DateTime.Now.Ticks;
                                mvvm.NavInitBeforShow();
                                var ds = DateTime.Now.Ticks - dt;
                                CalInitTime(viewIdx, ds);

                                // mvvm.NavInitBeforShow();
                            }

                            var mv = userControlMvvm.DataContext as IITab;
                            if (mv != null)
                            {
                                title = mv.Title;
                            }
                        }
                        AddAndShowView(title, viewIdx, userControlMvvm);

                        //Window win = new Window();
                        //win.Title = title;
                        //win.Closing += new System.ComponentModel.CancelEventHandler(win_Closing);

                        //win.Content = userControlMvvm;
                        //win.Show();
                        //if (item.ContainsKey(viewIdx) == false) item.Add(viewIdx, win);
                    }
                    catch (Exception ex)
                    {
                        WriteLog.WriteLogInfo(
                            "Core ShowViewByIdAttachRegion NavInitBeforShow Error IN ViewComponentHolding By id :" +
                            view);
                    }
                }
                //else
                //{
                //    if (RegionManagerInstances.Regions[attachRegion].Views.Contains(view))
                //    {
                //        RegionManagerInstances.Regions[attachRegion].Remove(view);
                //    }
                //}
            }
            catch (Exception ex)
            {
                WriteLog.WriteLogError("Core ShowViewByIdAttachRegion Error:" + ex);
            }
        }
Exemple #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="argu"></param>
        private static void DoTaskB(params object[] argu)
        {
            // int viewId, string viewAttachRegionName, bool show


            try
            {
                if (argu.Length < 2)
                {
                    return;
                }
                if (argu[0] == null)
                {
                    return;
                }

                string viewId           = argu[0].ToString();
                string viewAttachRegion = ViewComponentHolding.GetViewAttachRegionById(viewId);
                //   string viewAttachRegion = argu[1].ToString();
                object[] arus = new object[argu.Length - 1];
                for (int i = 1; i < argu.Length; i++)
                {
                    arus[i - 1] = argu[i];
                }

                if (viewAttachRegion.Equals("DocumentRegion") && IsNewViewInDocumentRegionPopup)
                {
                    RegionManageExtend.DoTaskB(argu);
                    return;
                }

                if (!RegionManagerInstances.Regions.ContainsRegionWithName(viewAttachRegion))
                {
                    WriteLog.WriteLogInfo(
                        "Core ShowViewByIdAttachRegion Can not find Region :" + viewAttachRegion);
                    return;
                }
                var view = ViewComponentHolding.GetViewById(viewId);
                if (view == null)
                {
                    WriteLog.WriteLogInfo(
                        "Core ShowViewByIdAttachRegion Can not find View IN ViewComponentHolding By id :" + viewId);
                    return;
                }


                try
                {
                    var userControlMvvm = view as ContentControl;
                    if (userControlMvvm != null)
                    {
                        var mvvm = userControlMvvm.DataContext as IINavInitBeforShow;
                        //导航页面必须实现此接口方可使用此函数进行页面导航数据初始化,否则需要自设定导航初始化
                        if (mvvm != null)
                        {
                            //mvvm.NavInitBeforShow(arus);

                            var dt = DateTime.Now.Ticks;
                            mvvm.NavInitBeforShow(arus);
                            var ds = DateTime.Now.Ticks - dt;
                            RegionManageExtend.CalInitTime(viewId, ds);
                        }
                    }
                }
                catch (Exception ex)
                {
                    WriteLog.WriteLogInfo(
                        "Core ShowViewByIdAttachRegion NavInitBeforShow Error IN ViewComponentHolding By id :" + viewId);
                }

                if (!RegionManagerInstances.Regions[viewAttachRegion].Views.Contains(view))
                {
                    RegionManagerInstances.Regions[viewAttachRegion].Add(view);
                }
                RegionManagerInstances.Regions[viewAttachRegion].Activate(view);


                //bool bolNavOnLoad = false;
                //var userControlMvvm = view as ContentControl;
                //if (userControlMvvm != null)
                //{
                //    var mvvm = userControlMvvm.DataContext as IINavOnLoad; //导航页面必须实现此接口方可使用此函数进行页面导航数据初始化,否则需要自设定导航初始化
                //    if (mvvm != null)
                //    {
                //        mvvm.NavOnLoad(arus);
                //        bolNavOnLoad = true;
                //    }
                //}

                //if (!bolNavOnLoad)
                //{
                //    WriteLog.WriteLogInfo("ShowViewByIdAttachRegion  viewId :" + viewId +
                //                          " Can not find Mvvm and can not be  NavOnLoaded");
                //}


                Task t = new Task(() =>
                {
                    Thread.Sleep(500);
                    try
                    {
                        Application.Current.Dispatcher.Invoke(
                            System.Windows.Threading.DispatcherPriority.Normal,
                            new DoTaskFuck(Fucksssss),
                            new Tuple <string, object, object[]>(viewId, view, arus));
                    }
                    catch (Exception e)
                    {
                        WriteLog.WriteLogError(
                            "Core ShowViewByIdAttachRegion Error in Invoke Task:" + e);
                    }
                });
                t.Start();
            }
            catch (Exception ex)
            {
                WriteLog.WriteLogError("Core ShowViewByIdAttachRegion Error:" + ex);
            }
        }
Exemple #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tuple"></param>
        private static void DoTaskA(Tuple <string, bool> tuple)
        {
            // int viewId, string viewAttachRegionName, bool show


            try
            {
                var attachRegion = ViewComponentHolding.GetViewAttachRegionById(tuple.Item1);

                if (attachRegion.Equals("DocumentRegion") && IsNewViewInDocumentRegionPopup)
                {
                    RegionManageExtend.DoTaskA(tuple);
                    return;
                }

                if (!RegionManagerInstances.Regions.ContainsRegionWithName(attachRegion))
                {
                    WriteLog.WriteLogInfo(
                        "Core ShowViewByIdAttachRegion Can not find Region :" + attachRegion);
                    return;
                }
                var view = ViewComponentHolding.GetViewById(tuple.Item1);
                if (view == null)
                {
                    WriteLog.WriteLogInfo(
                        "Core ShowViewByIdAttachRegion Can not find View IN ViewComponentHolding By id :" + tuple.Item1);
                    return;
                }


                if (tuple.Item2)
                {
                    if (!RegionManagerInstances.Regions[attachRegion].Views.Contains(view))
                    {
                        try
                        {
                            var userControlMvvm = view as ContentControl;
                            if (userControlMvvm != null)
                            {
                                var mvvm = userControlMvvm.DataContext as IINavInitBeforShow;
                                //导航页面必须实现此接口方可使用此函数进行页面导航数据初始化,否则需要自设定导航初始化
                                if (mvvm != null)
                                {
                                    // mvvm.NavInitBeforShow();

                                    var dt = DateTime.Now.Ticks;
                                    mvvm.NavInitBeforShow();
                                    var ds = DateTime.Now.Ticks - dt;
                                    RegionManageExtend.CalInitTime(tuple.Item1, ds);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            WriteLog.WriteLogInfo(
                                "Core ShowViewByIdAttachRegion NavInitBeforShow Error IN ViewComponentHolding By id :" + tuple.Item1);
                        }

                        RegionManagerInstances.Regions[attachRegion].
                        Add(view);
                    }
                    RegionManagerInstances.Regions[attachRegion].Activate(view);
                }
                else
                {
                    if (RegionManagerInstances.Regions[attachRegion].Views.Contains(view))
                    {
                        RegionManagerInstances.Regions[attachRegion].Remove(view);
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLog.WriteLogError("Core ShowViewByIdAttachRegion Error:" + ex);
            }
        }