Exemple #1
0
        public void RefreshWndList(IList <Client.Model.WindowsModel> wndsList)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new DelegateWndChange(RefreshWndList), wndsList);
                return;
            }

            // do not handle if in minimized mode
            if (this.WindowState == FormWindowState.Minimized)
            {
                return;
            }

            // find difference with current list and updated list

            List <Client.Model.WindowsModel> tempList = new List <Client.Model.WindowsModel>(wndsList);

            // 1. find the windows that newly added
            List <Client.Model.WindowsModel> addedQuery = tempList.Except(applicationList, new WndObjComparer()).ToList();

            // 2. find the windows that removed
            List <Client.Model.WindowsModel> removedQuery = applicationList.Except(tempList, new WndObjComparer()).ToList();

            // 3. find the windows with attributes changed
            foreach (Client.Model.WindowsModel windows in addedQuery)
            {
                // remove the additional objects in list
                wndsList.Remove(windows);
            }

            foreach (Client.Model.WindowsModel windows in removedQuery)
            {
                // remove the additional objects in list
                wndsList.Remove(windows);
            }

            // compare the remaining list, these lists should contain the same object's id and count
            List <Client.Model.WindowsModel> modifiedNameQuery  = wndsList.Except(applicationList, new WndNameComparer()).ToList();
            List <Client.Model.WindowsModel> modifiedPosQuery   = wndsList.Except(applicationList, new WndPosComparer()).ToList();
            List <Client.Model.WindowsModel> modifiedSizeQuery  = wndsList.Except(applicationList, new WndSizeComparer()).ToList();
            List <Client.Model.WindowsModel> modifiedStyleQuery = wndsList.Except(applicationList, new WndStyleComparer()).ToList();

            // save the updated list
            applicationList.Clear();
            applicationList.AddRange(tempList);

            // Trace.WriteLine(String.Format("add:{0}, remove:{1}, modified:{2}, totalNow:{3}", addedQuery.Count.ToString(), removedQuery.Count.ToString(), modifiedQuery.Count.ToString(), applicationList.Count.ToString()));

            try
            {
                bool refreshAppList = false;
                foreach (Client.Model.WindowsModel windows in addedQuery)
                {
                    Trace.WriteLine("Added window processId: " + windows.ProcessId + ":" + windows.DisplayName);

                    refreshAppList |= true;
                    AddWindow(windows);

                    // preset
                    presetHelper.AddWindow(windows.WindowsId);
                }

                foreach (Client.Model.WindowsModel windows in removedQuery)
                {
                    refreshAppList |= true;
                    RemoveWindow(windows);

                    // preset
                    presetHelper.RemoveWindow(windows.WindowsId);
                }

                foreach (Client.Model.WindowsModel windows in modifiedNameQuery)
                {
                    refreshAppList |= true;
                    ChangeWindowName(windows);
                }

                foreach (Client.Model.WindowsModel windows in modifiedPosQuery)
                {
                    ChangeWindowPos(windows);
                }

                foreach (Client.Model.WindowsModel windows in modifiedStyleQuery)
                {
                    ChangeWindowStyle(windows);
                }

                foreach (Client.Model.WindowsModel windows in modifiedSizeQuery)
                {
                    ChangeWindowSize(windows);
                }

                // update entire list z-order
                foreach (Client.Model.WindowsModel windows in applicationList)
                {
                    ChangeWindowZOrder(windows);
                }

                if (refreshAppList)
                {
                    refreshAppListing();
                }
            }
            catch (Exception e)
            {
                if (Properties.Settings.Default.Debug)
                {
                    MessageBox.Show(e.Message);
                }
            }
        }