Ejemplo n.º 1
0
        /// <summary>
        /// XMLファイルの内容をオブジェクトに復元(逆シリアル化)する
        /// </summary>
        /// <typeparam name="T">型</typeparam>
        /// <param name="fileName">保存元</param>
        /// <returns>指定した型に格納したデータ</returns>
        public static T SerializeBack <T>(string fileName)
        {
            // 宣言
            T value;

            // 読み込むファイルを開く
            System.IO.StreamReader sr = new System.IO.StreamReader(fileName, new System.Text.UTF8Encoding(false));

            try
            {
                // XmlSerializerオブジェクトを作成
                System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(T));

                // XMLファイルから読み込み、逆シリアル化する
                value = (T)serializer.Deserialize(sr);
            }
            catch (Exception e)
            {
                DebugOnFile.ExceptionWrite(e);
                throw;
            }
            finally
            {
                // ファイルを閉じる
                sr.Close();
            }

            return(value);
        }
Ejemplo n.º 2
0
        public static bool TryParthFromShotDate(string sourceFilePath, out string filePath)
        {
            bool result = false;

            filePath = null;

            // 読み込む
            try
            {
                using (Bitmap bmp = new Bitmap(sourceFilePath))
                {
                    foreach (PropertyItem item in bmp.PropertyItems)
                    {
                        // Exif情報から撮影時間を取得する
                        if (item.Id == 0x9003 && item.Type == 2)
                        {
                            // 文字列に変換する
                            string val = Encoding.ASCII.GetString(item.Value);
                            val = val.Trim(new char[] { '\0' });
                            // DateTimeに変換
                            DateTime dt = DateTime.ParseExact(val, "yyyy:MM:dd HH:mm:ss", null);

                            filePath = Path.Combine(dt.ToString("yyyyMM"), Path.GetFileNameWithoutExtension(sourceFilePath));
                            result   = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                DebugOnFile.ExceptionWrite(ex);
            }

            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// BackgroundWorker1のRunWorkerCompletedイベントハンドラ
        /// 処理が終わったときに呼び出される
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void renameBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            _pad.SetButtonEnubled(true);

            if (e.Error != null)
            {
                // エラーが発生したとき
                DebugOnFile.ExceptionWrite(e.Error);
                _pad.SetCompletedMsg("エラーが発生しました。");
            }
            else
            {
                // 正常に終了したとき
                _pad.SetCompletedMsg("正常に終了しました。");
                // int result = (int)e.Result;
            }

            // buttonConvertを有効に戻す
            buttonMove.Enabled = true;
        }
Ejemplo n.º 4
0
        private void buttonMove_Click(object sender, EventArgs e)
        {
            if (dataGridViewFile.RowCount == 0)
            {
                MessageBox.Show("移動前ファイルパスと移動先ファイルパスを指定してください。", "情報");
                return;
            }

            DialogResult result = MessageBox.Show("ファイルを移動してよろしいですか?", "確認", MessageBoxButtons.OKCancel);

            if (result == DialogResult.OK)
            {
                bool isException = false;
                foreach (DataGridViewRow item in dataGridViewFile.Rows)
                {
                    string befor         = null;
                    string after         = null;
                    int    completeIndex = 1;
                    int    beforIndex    = 2;
                    int    afterIndex    = 3;

                    if (item.Cells[beforIndex].Value == null || item.Cells[afterIndex].Value == null ||
                        string.IsNullOrWhiteSpace(item.Cells[beforIndex].Value.ToString()) || string.IsNullOrWhiteSpace(item.Cells[afterIndex].Value.ToString()))
                    {
                        continue;
                    }

                    if (item.Cells[completeIndex].Value != null && item.Cells[completeIndex].Value.ToString() == COMPLETE)
                    {
                        continue;
                    }

                    befor = item.Cells[beforIndex].Value.ToString();
                    after = item.Cells[afterIndex].Value.ToString();

                    try
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(after));
                        File.Move(befor, after);
                        DebugOnFile.LogWrite(string.Format(@"【移動】{0}""{1}""{2}""{3}""", "\t", befor, "\t", after));
                    }
                    catch (Exception ex)
                    {
                        isException = true;
                        DebugOnFile.ExceptionWrite(ex);
                    }

                    item.Cells[completeIndex].Value = COMPLETE;
                    item.Cells[afterIndex].ReadOnly = true;

                    item.Cells[0].Style.BackColor             = Color.Gray;
                    item.Cells[completeIndex].Style.BackColor = Color.Gray;
                    item.Cells[beforIndex].Style.BackColor    = Color.Gray;
                    item.Cells[afterIndex].Style.BackColor    = Color.Gray;
                }

                if (isException)
                {
                    MessageBox.Show("移動に失敗したファイルがあります。ログファイルを確認してください。", "情報");
                }
            }
        }