예제 #1
0
        /// <summary>
        /// Parse xml of previous path.
        /// </summary>
        private static void ParsePreviousPathXml(XDocument xdoc, AppConfigData configData)
        {
            XElement dataElement  = xdoc.Root.Element(PreviousFolderElemName);
            XElement previousPath = dataElement.Element(PreviousPathElemName);

            configData.PreviousFolderPath = previousPath.Value;
        }
예제 #2
0
        /// <summary>
        /// Parse xml of window size and position.
        /// </summary>
        private static void ParseWindowPlacementXml(XDocument xdoc, AppConfigData configData)
        {
            XElement dataElement              = xdoc.Root.Element(WindowPlacementElemName);
            XElement windowPlaceTopElement    = dataElement.Element(WindowPlacementTopElemName);
            XElement windowPlaceLeftElement   = dataElement.Element(WindowPlacementLeftElemName);
            XElement windowPlaceRightElement  = dataElement.Element(WindowPlacementRightElemName);
            XElement windowPlaceButtomElement = dataElement.Element(WindowsPlacementButtomElemName);
            XElement windowMaxPositionX       = dataElement.Element(WindowPlacementMaxPosXElemName);
            XElement windowMaxPositionY       = dataElement.Element(WindowPlacementMaxPosYElemName);
            XElement windowMinPositionX       = dataElement.Element(WindowPlacementMinPosXElemName);
            XElement windowMinPositionY       = dataElement.Element(WindowPlacementMinPosYElemName);
            XElement windowFlag      = dataElement.Element(WindowPlacementFlagElemName);
            XElement windowSwElement = dataElement.Element(WindowPlacementSwElemName);

            configData.WindowPlaceData.normalPosition.Top    = Convert.ToInt32(windowPlaceTopElement.Value);
            configData.WindowPlaceData.normalPosition.Left   = Convert.ToInt32(windowPlaceLeftElement.Value);
            configData.WindowPlaceData.normalPosition.Right  = Convert.ToInt32(windowPlaceRightElement.Value);
            configData.WindowPlaceData.normalPosition.Bottom = Convert.ToInt32(windowPlaceButtomElement.Value);
            configData.WindowPlaceData.maxPosition.X         = Convert.ToInt32(windowMaxPositionX.Value);
            configData.WindowPlaceData.maxPosition.Y         = Convert.ToInt32(windowMaxPositionY.Value);
            configData.WindowPlaceData.minPosition.X         = Convert.ToInt32(windowMinPositionX.Value);
            configData.WindowPlaceData.minPosition.Y         = Convert.ToInt32(windowMinPositionY.Value);
            configData.WindowPlaceData.length  = Marshal.SizeOf(typeof(MainWindow.WINDOWPLACEMENT));
            configData.WindowPlaceData.flags   = Convert.ToInt32(windowFlag.Value);
            configData.WindowPlaceData.showCmd = (MainWindow.SW)Enum.Parse(typeof(MainWindow.SW), windowSwElement.Value);
        }
예제 #3
0
        /// <summary>
        /// ウィンドウサイズ、位置などの情報をXMLデータから取得する
        /// </summary>
        /// <param name="doc">XMLデータ</param>
        /// <param name="configData">アプリケーション設定データ</param>
        private static void ParseWindowPlacementXml(XDocument doc, AppConfigData configData)
        {
            var dataElement              = doc.Root?.Element(PlacementElemName);
            var windowPlaceTopElement    = dataElement?.Element(PlacementTopElemName);
            var windowPlaceLeftElement   = dataElement?.Element(PlacementLeftElemName);
            var windowPlaceRightElement  = dataElement?.Element(PlacementRightElemName);
            var windowPlaceButtomElement = dataElement?.Element(PlacementBottomElemName);
            var windowMaxPositionX       = dataElement?.Element(PlacementMaxPosXElemName);
            var windowMaxPositionY       = dataElement?.Element(PlacementMaxPosYElemName);
            var windowMinPositionX       = dataElement?.Element(PlacementMinPosXElemName);
            var windowMinPositionY       = dataElement?.Element(PlacementMinPosYElemName);
            var windowFlag      = dataElement?.Element(PlacementFlagElemName);
            var windowSwElement = dataElement?.Element(PlacementSwElemName);

            configData.PlaceData.normalPosition.Top    = Convert.ToInt32(windowPlaceTopElement?.Value);
            configData.PlaceData.normalPosition.Left   = Convert.ToInt32(windowPlaceLeftElement?.Value);
            configData.PlaceData.normalPosition.Right  = Convert.ToInt32(windowPlaceRightElement?.Value);
            configData.PlaceData.normalPosition.Bottom = Convert.ToInt32(windowPlaceButtomElement?.Value);
            configData.PlaceData.maxPosition.X         = Convert.ToInt32(windowMaxPositionX?.Value);
            configData.PlaceData.maxPosition.Y         = Convert.ToInt32(windowMaxPositionY?.Value);
            configData.PlaceData.minPosition.X         = Convert.ToInt32(windowMinPositionX?.Value);
            configData.PlaceData.minPosition.Y         = Convert.ToInt32(windowMinPositionY?.Value);
            configData.PlaceData.length = Marshal.SizeOf(typeof(MainWindow.NativeMethods.Placement));
            configData.PlaceData.flags  = Convert.ToInt32(windowFlag?.Value);
            if (windowSwElement == null)
            {
                configData.PlaceData.showCmd = MainWindow.NativeMethods.Sw.ShowNormal;
            }
            else
            {
                configData.PlaceData.showCmd = Enum.Parse <MainWindow.NativeMethods.Sw>(windowSwElement.Value);
            }
        }
예제 #4
0
        /// <summary>
        /// Generate XML of Window size and position.
        /// </summary>
        private static XElement CreateWindowPlacementXml(AppConfigData configData)
        {
            var dataElement              = new XElement(WindowPlacementElemName);
            var windowPlaceTopElement    = new XElement(WindowPlacementTopElemName, new XText(configData.WindowPlaceData.normalPosition.Top.ToString()));
            var windowPlaceLeftElement   = new XElement(WindowPlacementLeftElemName, new XText(configData.WindowPlaceData.normalPosition.Left.ToString()));
            var windowPlaceRightElement  = new XElement(WindowPlacementRightElemName, new XText(configData.WindowPlaceData.normalPosition.Right.ToString()));
            var windowPlaceButtonElement = new XElement(WindowsPlacementButtomElemName, new XText(configData.WindowPlaceData.normalPosition.Bottom.ToString()));
            var windowMaxPositionX       = new XElement(WindowPlacementMaxPosXElemName, new XText(configData.WindowPlaceData.maxPosition.X.ToString()));
            var windowMaxPositionY       = new XElement(WindowPlacementMaxPosYElemName, new XText(configData.WindowPlaceData.maxPosition.Y.ToString()));
            var windowMinPositionX       = new XElement(WindowPlacementMinPosXElemName, new XText(configData.WindowPlaceData.minPosition.X.ToString()));
            var windowMinPositionY       = new XElement(WindowPlacementMinPosYElemName, new XText(configData.WindowPlaceData.minPosition.Y.ToString()));
            var windowFlag      = new XElement(WindowPlacementFlagElemName, new XText(configData.WindowPlaceData.flags.ToString()));
            var windowSwElement = new XElement(WindowPlacementSwElemName, new XText(configData.WindowPlaceData.showCmd.ToString()));

            dataElement.Add(windowPlaceTopElement);
            dataElement.Add(windowPlaceLeftElement);
            dataElement.Add(windowPlaceRightElement);
            dataElement.Add(windowPlaceButtonElement);
            dataElement.Add(windowMaxPositionX);
            dataElement.Add(windowMaxPositionY);
            dataElement.Add(windowMinPositionX);
            dataElement.Add(windowMinPositionY);
            dataElement.Add(windowFlag);
            dataElement.Add(windowSwElement);

            return(dataElement);
        }
예제 #5
0
        /// <summary>
        /// 登録アプリリストをXMLデータから取得する
        /// </summary>
        /// <param name="doc">XMLデータ</param>
        /// <param name="configData">アプリケーション設定データ</param>
        private static void ParseLinkageAppXml(XDocument doc, AppConfigData configData)
        {
            var linkageElement = doc.Root?.Element(LinkAppElemName);
            var dataElements   = linkageElement?.Elements(LinkAppDataName);

            if (dataElements == null)
            {
                return;
            }

            foreach (var dataElement in dataElements)
            {
                var appNameElement = dataElement.Element(LinkAppNameElemName);
                var appPathElement = dataElement.Element(LinkAppPathElemName);

                if (appPathElement != null && appNameElement != null &&
                    (string.IsNullOrEmpty(appNameElement.Value) || string.IsNullOrEmpty(appPathElement.Value)))
                {
                    continue;
                }

                var linkageApp = new ExtraAppSetting {
                    AppName = appNameElement?.Value, AppPath = appPathElement?.Value
                };
                configData.LinkageAppList.Add(linkageApp);
            }
        }
예제 #6
0
        /// <summary>
        /// Generate xml of previous folder path.
        /// </summary>
        private static XElement CreatePreviousPathXml(AppConfigData configData)
        {
            var dataElement  = new XElement(PreviousFolderElemName);
            var previousPath = new XElement(PreviousPathElemName, configData.PreviousFolderPath == null ? new XText("") : new XText(configData.PreviousFolderPath));

            dataElement.Add(previousPath);
            return(dataElement);
        }
예제 #7
0
        public void Import(AppConfigData configData)
        {
            var xdoc = XDocument.Load(appConfigFilePath);

            ParsePreviousPathXml(xdoc, configData);
            ParseLinkageAppXml(xdoc, configData);
            ParseWindowPlacementXml(xdoc, configData);
        }
예제 #8
0
        /// <summary>
        /// アプリケーション設定情報をXMLファイルからインポートする
        /// </summary>
        /// <param name="filePath">XMLファイルパス</param>
        /// <param name="configData">アプリケーション設定データ</param>
        public static void Import(string filePath, AppConfigData configData)
        {
            var doc = XDocument.Load(filePath);

            ParsePreviousPathXml(doc, configData);
            ParseLinkageAppXml(doc, configData);
            ParseWindowPlacementXml(doc, configData);
        }
예제 #9
0
        /// <summary>
        /// 前回のフォルダパスをXMLから読み込む
        /// </summary>
        /// <param name="doc">XMLデータ</param>
        /// <param name="configData">アプリケーション設定データ</param>
        private static void ParsePreviousPathXml(XDocument doc, AppConfigData configData)
        {
            var dataElement  = doc.Root?.Element(PreviousFolderElemName);
            var previousPath = dataElement?.Element(PreviousPathElemName);

            if (previousPath == null)
            {
                return;
            }
            configData.PreviousFolderPath = previousPath.Value;
        }
예제 #10
0
        public void Export(AppConfigData configData)
        {
            var xdoc  = new XDocument(new XDeclaration("1.0", "utf-8", null));
            var xdata = new XElement("data");

            xdata.Add(CreatePreviousPathXml(configData));
            xdata.Add(CreateLinkageAppXml(configData));
            xdata.Add(CreateWindowPlacementXml(configData));
            xdoc.Add(xdata);

            xdoc.Save(appConfigFilePath);
        }
예제 #11
0
        /// <summary>
        /// アプリケーション設定情報を既定XMLファイルに出力する
        /// </summary>
        /// <param name="filePath">XMLファイルパス</param>
        /// <param name="configData">アプリケーション設定データ</param>
        public static void Export(string filePath, AppConfigData configData)
        {
            var doc  = new XDocument(new XDeclaration("1.0", "utf-8", null));
            var data = new XElement("data");

            data.Add(CreatePreviousPathXml(configData));
            data.Add(CreateLinkageAppXml(configData));
            data.Add(CreateWindowPlacementXml(configData));
            doc.Add(data);

            doc.Save(filePath);
        }
예제 #12
0
        /// <summary>
        /// Parse the XML of the linked application.
        /// </summary>
        private static void ParseLinkageAppXml(XDocument xdoc, AppConfigData configData)
        {
            XElement linkageElement             = xdoc.Root.Element(LinkAppElemName);
            IEnumerable <XElement> dataElements = linkageElement.Elements(LinkAppDataName);

            foreach (XElement dataElement in dataElements)
            {
                XElement appNameElement = dataElement.Element(LinkAppNameElemName);
                XElement appPathElement = dataElement.Element(LinkAppPathElemName);

                if (!string.IsNullOrEmpty(appNameElement.Value) && !string.IsNullOrEmpty(appPathElement.Value))
                {
                    var linkageApp = new ExtraAppSetting {
                        AppName = appNameElement.Value, AppPath = appPathElement.Value
                    };
                    configData.LinkageAppList.Add(linkageApp);
                }
            }
        }
예제 #13
0
        /// <summary>
        /// Generate XML for linked application.
        /// </summary>
        private static XElement CreateLinkageAppXml(AppConfigData configData)
        {
            var linkageElement = new XElement(LinkAppElemName);

            List <ExtraAppSetting> linkageAppList = configData.LinkageAppList;

            foreach (ExtraAppSetting linkageApp in linkageAppList)
            {
                var dataElement    = new XElement(LinkAppDataName);
                var appNameElement = new XElement(LinkAppNameElemName, linkageApp == null ? new XText("") : new XText(linkageApp.AppName));
                var appPathElement = new XElement(LinkAppPathElemName, linkageApp == null ? new XText("") : new XText(linkageApp.AppPath));

                dataElement.Add(appNameElement);
                dataElement.Add(appPathElement);

                linkageElement.Add(dataElement);
            }

            return(linkageElement);
        }