private string TryGetValue(string propertyName)
        {
            XmlNodeList elemList = UserXml.GetElementsByTagName(propertyName);

            if (elemList != null)
            {
                if (elemList[0] != null)
                {
                    return(elemList[0].InnerText.Trim());
                }
            }

            return(String.Empty);
        }
        /// <summary>
        /// 再帰的にファイル一覧を取得
        /// System.Windows.Controls.TreeViewItemが無いから逆にすっきり
        /// </summary>
        /// <returns>The directory node.</returns>
        /// <param name="directoryInfo">Directory info.</param>
        public static TreeViewItem CreateDirectoryNode(DirectoryInfo directoryInfo)
        {
            Console.WriteLine(directoryInfo.FullName);
            if (!Directory.Exists(directoryInfo.FullName))
            {
                Directory.CreateDirectory(directoryInfo.FullName);
            }

            var directoryNode = new TreeViewItem(directoryInfo.Name,
                                                 directoryInfo.FullName,
                                                 UserXml.GetUserDataFromXml(directoryInfo.FullName)
                                                 );

            if (directoryInfo.GetDirectories().Length > 0 || directoryInfo.GetFiles().Length > 0)
            {
                directoryNode.isDir = true;
            }

            // ディレクトリ
            foreach (var directory in directoryInfo.GetDirectories())
            {
                TreeViewItem item = CreateDirectoryNode(directory);
                item.isDir    = true;
                item.fileName = directory.Name;
                item.FullPath = directory.FullName;
                directoryNode.Items.Add(item);
            }

            // ファイル(2階層はサポートしない)
            foreach (var file in directoryInfo.GetFiles())
            {
                if (Directory.Exists(file.FullName))
                {
                    continue;
                }
                if (!file.Name.EndsWith(".csm", StringComparison.CurrentCulture) &&
                    !file.Name.EndsWith(".mcsm", StringComparison.CurrentCulture)
                    )
                {
                    continue;
                }

                TreeViewItem item = new TreeViewItem(file.Name,
                                                     file.FullName,
                                                     UserXml.GetUserDataFromXml(file.FullName));
                directoryNode.Items.Add(item);
            }

            return(directoryNode);
        }
Example #3
0
        /// <summary>
        /// TreeView Click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void UserDirTree_ItemClick(object sender, ItemClickEventArgs e)
        {
            TreeViewItem2 item = (TreeViewItem2)e.ClickedItem;

            if (item.IsDir)
            {
                ReSet(item);
            }
            else
            {
                if (!File.Exists(item.FullPath))
                {
                    return;
                }
                StorageFile file = await AwaitGetStorageFile(item.FullPath);

                UserData udata = await UserXml.GetUserDataFromXml(file);

                SetEventTable(udata);
            }
        }
Example #4
0
        /// <summary>
        /// ユーザー追加
        /// </summary>
        /// <param name="sender">Sender.</param>
        partial void SubmitClick(NSObject sender)
        {
            DateTime date;

            if (UserBirth.DateValue == null)
            {
                return;
            }
            try
            {
                NSDate nsd = UserBirth.DateValue;
                date = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(2001, 1, 1, 0, 0, 0));
                date = date.AddSeconds(nsd.SecondsSinceReferenceDate);
            }
            catch (FormatException)
            {
                var alert = new NSAlert();
                alert.MessageText     = "エラー";
                alert.InformativeText = "正しい日付を入れてください";
                alert.RunModal();
                return;
            }
            catch (InvalidCastException)
            {
                Console.WriteLine("ERROR: invalid cast.");
                return;
            }

            double lat = 35.685175, lng = 139.7528;

            try {
                lat = double.Parse(UserLat.StringValue);
                lng = double.Parse(UserLng.StringValue);
            } catch (InvalidCastException)
            {
                var alert = new NSAlert();
                alert.MessageText     = "エラー";
                alert.InformativeText = "正しい緯度経度を入力してください";
                alert.RunModal();
                return;
            }

            if (FileName.StringValue == "")
            {
                var alert = new NSAlert();
                alert.MessageText     = "エラー";
                alert.InformativeText = "ファイル名を入れてください";
                alert.RunModal();
                return;
            }

            if (UserName.StringValue == "")
            {
                var alert = new NSAlert();
                alert.MessageText     = "エラー";
                alert.InformativeText = "名前を入れてください";
                alert.RunModal();
                return;
            }

            string selectedPath = CommonInstance.getInstance().SelectedDirectoryFullPath;

            if (File.Exists(selectedPath))
            {
                selectedPath = Path.GetDirectoryName(selectedPath);
            }
            string FilePath = selectedPath + "/" + FileName.StringValue + ".csm";

            UserXml.SaveUserData(FilePath, new UserData(
                                     UserName.StringValue,
                                     UserFurigana.StringValue,
                                     date,
                                     lat,
                                     lng,
                                     UserPlace.StringValue,
                                     UserMemo.TextStorage.MutableString.ToString(),
                                     "JST"
                                     ));
            UserDbViewController dbvc = this.PresentingViewController as UserDbViewController;

            dbvc.ReSetDbTree();

            DismissViewController(this);
        }
        partial void SubmitClicked(NSObject sender)
        {
            DateTime date;

            if (birthDay.DateValue == null)
            {
                return;
            }
            try
            {
                NSDate nsd = birthDay.DateValue;
                date = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(2001, 1, 1, 0, 0, 0));
                date = date.AddSeconds(nsd.SecondsSinceReferenceDate);
            }
            catch (FormatException)
            {
                var alert = new NSAlert();
                alert.MessageText     = "エラー";
                alert.InformativeText = "正しい日付を入れてください";
                alert.RunModal();
                return;
            }
            catch (InvalidCastException)
            {
                Console.WriteLine("ERROR: invalid cast.");
                return;
            }

            /*
             * double lat = 35.685175, lng = 139.7528;
             * try
             * {
             *  lat = double.Parse(UserLat.StringValue);
             *  lng = double.Parse(UserLng.StringValue);
             * }
             * catch (InvalidCastException)
             * {
             *  var alert = new NSAlert();
             *  alert.MessageText = "エラー";
             *  alert.InformativeText = "正しい緯度経度を入力してください";
             *  alert.RunModal();
             *  return;
             * }
             */

            if (fileName.StringValue == "")
            {
                var alert = new NSAlert();
                alert.MessageText     = "エラー";
                alert.InformativeText = "ファイル名を入れてください";
                alert.RunModal();
                return;
            }

            if (userName.StringValue == "")
            {
                var alert = new NSAlert();
                alert.MessageText     = "エラー";
                alert.InformativeText = "名前を入れてください";
                alert.RunModal();
                return;
            }

            // ファイル名が変わっていたら移動
            // 元のファイル名を保持が必要
            if (fileName.StringValue + ".csm" != CommonInstance.getInstance().SelectedFileName)
            {
                string fName    = fileName.StringValue;
                string fullPath = CommonInstance.getInstance().SelectedDirectoryFullPath;
                string FilePath = CommonInstance.getInstance().SelectedDirectoryFullPath + "/" + fName + ".csm";
                UserXml.SaveUserData(FilePath, new UserData(
                                         userName.StringValue,
                                         furigana.StringValue,
                                         date,
                                         double.Parse(userLat.StringValue),
                                         double.Parse(userLng.StringValue),
                                         userPlace.StringValue,
                                         memo.StringValue,
                                         "JST"
                                         ));
            }
            else
            {
                string fName        = fileName.StringValue;
                string selectedPath = CommonInstance.getInstance().SelectedDirectoryFullPath;
                if (File.Exists(selectedPath))
                {
                    selectedPath = Path.GetDirectoryName(selectedPath);
                }
                string FilePath = selectedPath + "/" + fName + ".csm";
                UserXml.SaveUserData(FilePath, new UserData(
                                         userName.StringValue,
                                         furigana.StringValue,
                                         date,
                                         double.Parse(userLat.StringValue),
                                         double.Parse(userLng.StringValue),
                                         userPlace.StringValue,
                                         memo.StringValue,
                                         "JST"
                                         ));
            }

            UserDbViewController dbvc = this.PresentingViewController as UserDbViewController;

            dbvc.ReSetDbTree();

            DismissViewController(this);
        }