Mini Kabibi Habibi

Current Path : C:/Users/Public/Documents/DXperience 13.1 Demos/WinForms/CS/WinRTLiveTileManagerMainDemo/
Upload File :
Current File : C:/Users/Public/Documents/DXperience 13.1 Demos/WinForms/CS/WinRTLiveTileManagerMainDemo/frmMain.cs

using System;
using DevExpress.Utils;
using DevExpress.XtraNavBar;
using DevExpress.DXperience.Demos;
using System.Collections.Generic;
using System.Windows.Forms;
using WinRTLiveTiles = DevExpress.XtraBars.WinRTLiveTiles;

namespace DevExpress.WinRTLiveTileManager.Demos {
    public partial class frmMain : DevExpress.DXperience.Demos.RibbonMainForm {
        public static string startupModuleName;
        static bool firstStart = true;
        public frmMain()
            : base() {
            navBarControl1.SmallImages = null;
        }
        #region Properties
        protected override string DemoName { get { return "WinRTLiveTileManager Features Demo (C# code)"; } }
        #endregion
        protected override void SetFormParam() {
            this.MinimumSize = new System.Drawing.Size(600, 500);
            this.navBarControl1.Parent.Width = 176;
            this.navBarControl1.AllowDrop = false;
            this.Icon = ResourceImageHelper.CreateIconFromResources("DevExpress.WinRTLiveTileManager.Demos.WinRTLiveTileManagerMainDemo.ico", typeof(frmMain).Assembly);
        }
        protected override RibbonMenuManager CreateRibbonMenuManager() {
            return new WinRTLiveTileManagerMenuManager(this);
        }
        protected override void ShowModule(string name, DevExpress.XtraEditors.GroupControl group, DevExpress.LookAndFeel.DefaultLookAndFeel lookAndFeel, DevExpress.Utils.Frames.ApplicationCaption caption) {
            if(!String.IsNullOrEmpty(startupModuleName)) {
                DemosInfo.ShowModule(startupModuleName, group, caption, RibbonMenuManager as WinRTLiveTileManagerMenuManager);
                startupModuleName = null;
            }
            else
                DemosInfo.ShowModule(name, group, caption, RibbonMenuManager as WinRTLiveTileManagerMenuManager);
            if(firstStart) {
                List<WinRTLiveTiles.WinRTLiveTileManager> managerList = new List<WinRTLiveTiles.WinRTLiveTileManager>();
                managerList = ModuleCreator.CreateModules();
                firstStart = false;
            } 
        }
        protected override void FillNavBar() {
            DemosInfo.FillNavBar(navBarControl1, DevExpress.XtraNavBar.NavBarGroupStyle.LargeIconsText, true, NavBarImage.Small);
        }
        protected override void ShowAbout() {
            DevExpress.Utils.About.AboutForm.Show(typeof(WinRTLiveTiles.WinRTLiveTileManager), DevExpress.Utils.About.ProductKind.DXperienceWin, DevExpress.Utils.About.ProductInfoStage.Registered);
        }
        const string strHasPinnedTiles = "Do you want to unpin demo live tiles from the Start screen?";
        protected override void OnClosed(EventArgs e) {
            List<WinRTLiveTiles.WinRTLiveTileManager> managerList = new List<WinRTLiveTiles.WinRTLiveTileManager>();
            managerList = ModuleCreator.ManagerList;
            if(!ModuleCreator.CheckTilesUnpinned(managerList))
                if(MessageBox.Show(strHasPinnedTiles, "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) 
                    foreach(WinRTLiveTiles.WinRTLiveTileManager manager in managerList)
                        manager.RemoveTile();
            base.OnClosed(e);
        }
    }
    public class ModuleCreator {
        static List<WinRTLiveTiles.WinRTLiveTileManager> managerList = new List<WinRTLiveTiles.WinRTLiveTileManager>();
        public ModuleCreator() { }

        public static List<WinRTLiveTiles.WinRTLiveTileManager> ManagerList {
            get { return managerList; }
        }

        public static List<WinRTLiveTiles.WinRTLiveTileManager> CreateModules() {
            if(DemosInfo.Count <= 0) return null;
            for(int i = 0; i < DemosInfo.Count; i++) {
                ModuleInfo item = DemosInfo.GetItem(i);
                var v = item.TModule;
                ITileManagerContainer moduleInterface = v as ITileManagerContainer;
                if(moduleInterface != null)
                    managerList.AddRange(moduleInterface.GetModuleTileManagers());
            }
            return managerList;
        }
        public static bool CheckTilesUnpinned(List<WinRTLiveTiles.WinRTLiveTileManager> managersList) {
            if(managersList.Count == 0) return true;
            foreach(WinRTLiveTiles.WinRTLiveTileManager manager in managersList)
                if(manager.HasPinnedTile) return false;
            return true;
        }
        const string strTileNotPinned = "A Live Tile for the {0} has not been created within the Windows Start Screen. Click Yes to run the Live Tile Manager and click the Pin button for the {0} item. \n \nDo you want to run the Live Tile Manager and add a live tile to the Start Screen?";

        public static bool CheckTilePinnedBeforeUpdate(WinRTLiveTiles.WinRTLiveTileManager manager) {
            if(manager == null) return true;
            if(!manager.HasPinnedTile) {
                if(MessageBox.Show(String.Format(strTileNotPinned, manager.ApplicationName), "Add Live Tile", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.Yes)
                    if(WinRTLiveTiles.WinRTLiveTileManager.CheckWinRTAppInstalled()) manager.ShowLiveTileManager();
                    else { 
                        WinRTLiveTiles.WinRTAppInstallHelperWindow.Show(false);
                        return false;
                    }
                return false;
            }
            else return true;
        }
    }
}