private void BatchPostThreadMethod(object state)
        {
            if (ShowMessage != null)
            {
                ShowMessage(I18n.L.T("NewPostManager.DragDropHere"));
            }

            Thread.Sleep(10000);

            StartUpload = true;

            while (true)
            {
                NewPostItem _newPost;

                if (!Main.Current.RT.REST.IsNetworkAvailable)
                {
                    if (ShowMessage != null)
                    {
                        ShowMessage("");
                    }

                    UpdateUI(0, "");

                    continue;
                }

                lock (this)
                {
                    if (Items.Count > 0)
                    {
                        _newPost = Items[0];
                    }
                    else
                    {
                        _newPost = null;

                        if (ShowMessage != null)
                        {
                            ShowMessage(I18n.L.T("NewPostManager.DragDropHere"));
                        }
                    }
                }

                if (_newPost != null)
                {
                    if (ShowMessage != null)
                    {
                        ShowMessage("");
                    }

                    if (StartUpload)
                    {
                        NewPostItem _retItem = BatchPhotoPost(_newPost);

                        if (_retItem.PostOK)
                        {
                            lock (this)
                            {
                                Remove(_newPost);

                                if (UploadDone != null)
                                {
                                    UploadDone(I18n.L.T("PostForm.PostSuccess"));
                                }
                            }
                        }
                        else
                        {
                            if (_retItem.ErrorAndDeletePost)
                            {
                                Remove(_newPost);

                                UpdateUI(int.MinValue, "");

                                if (UploadDone != null)
                                {
                                    UploadDone(I18n.L.T("PostForm.PostError"));
                                }

                                s_logger.Error("Remove New Post");

                                continue;
                            }

                            lock (this)
                            {
                                Save();
                            }
                        }
                    }
                }

                Thread.Sleep(5000);
            }
        }
        public void Add(NewPostItem item)
        {
            Items.Add(item);

            Save();
        }
        public void Remove(NewPostItem item)
        {
            Items.Remove(item);

            Save();
        }
        private NewPostItem BatchPhotoPost(NewPostItem newPost)
        {
            int    _count    = 0;
            string _tmpStamp = DateTime.Now.Ticks.ToString();

            s_logger.Trace("[" + _tmpStamp + "]" + "BatchPhotoPost:" + newPost.Text + ", Files=" + newPost.Files.Count);

            string _ids = "[";

            while (true)
            {
                if (StartUpload)
                {
                    string _file = newPost.Files[_count];

                    if (newPost.UploadedFiles.Keys.Contains(_file))
                    {
                        _ids += "\"" + newPost.UploadedFiles[_file] + "\"" + ",";

                        s_logger.Trace("[" + _tmpStamp + "]" + "Batch Sended Photo [" + _count + "]" + _file);
                    }
                    else
                    {
                        try
                        {
                            Downloading = true;

                            if (!File.Exists(_file))
                            {
                                // 原始檔案不存在. 作錯誤處裡
                                s_logger.Error("Image File does not exist: [" + _file + "]");

                                if (ShowFileMissDialog != null)
                                {
                                    ShowFileMissDialog(_file);
                                }

                                while (Main.Current.NewPostThreadErrorDialogResult == DialogResult.None)
                                {
                                    Thread.Sleep(500);
                                }

                                switch (Main.Current.NewPostThreadErrorDialogResult)
                                {
                                case DialogResult.Cancel:      // Delete Post
                                    newPost.ErrorAndDeletePost = true;
                                    newPost.PostOK             = false;
                                    return(newPost);

                                case DialogResult.Yes:     // Remove Picture
                                    s_logger.Error("Remove: [" + _file + "]");

                                    newPost.Files.Remove(_file);
                                    newPost.PostOK = false;

                                    UpdateUI(int.MinValue, "");

                                    return(newPost);

                                case DialogResult.Retry:      // DoNothing
                                    s_logger.Error("Ignore & Retry Miss File: [" + _file + "]");

                                    newPost.PostOK = false;
                                    return(newPost);
                                }
                            }

                            if (CheckStoragesUsage() <= 0)
                            {
                                if (CheckStoragesUsage() <= 0) //Hack
                                {
                                    // 雲端個人儲存空間不足. 作錯誤處裡
                                    s_logger.Error("(CheckStoragesUsage() <= 0)");

                                    if (OverQuotaMissDialog != null)
                                    {
                                        OverQuotaMissDialog("");
                                    }

                                    while (Main.Current.NewPostThreadErrorDialogResult == DialogResult.None)
                                    {
                                        Thread.Sleep(500);
                                    }

                                    switch (Main.Current.NewPostThreadErrorDialogResult)
                                    {
                                    case DialogResult.Cancel:     // Delete Post
                                        newPost.ErrorAndDeletePost = true;
                                        newPost.PostOK             = false;
                                        return(newPost);

                                    case DialogResult.Retry:     // DoNothing

                                        newPost.PostOK = false;
                                        return(newPost);
                                    }
                                }
                            }

                            string _text         = new FileName(_file).Name;
                            string _resizedImage = ImageUtility.ResizeImage(_file, _text, newPost.ResizeRatio, 100);

                            MR_attachments_upload _uf = Main.Current.RT.REST.File_UploadFile(_text, _resizedImage, "",
                                                                                             true);
                            if (_uf == null)
                            {
                                newPost.PostOK = false;
                                return(newPost);
                            }

                            _ids += "\"" + _uf.object_id + "\"" + ",";

                            newPost.UploadedFiles.Add(_file, _uf.object_id);

                            s_logger.Trace("[" + _tmpStamp + "]" + "Batch Upload Photo [" + _count + "]" + _file);

                            string _localFile = Main.GCONST.CachePath + _uf.object_id + "_origin_" + _text;
                            File.Copy(_file, _localFile);

                            Downloading = false;
                        }
                        catch (Exception _e)
                        {
                            Downloading = false;

                            NLogUtility.Exception(s_logger, _e, "BatchPhotoPost:File_UploadFile");
                            newPost.PostOK = false;
                            return(newPost);
                        }
                    }

                    _count++;

                    int _counts = newPost.Files.Count;

                    if (UpdateUI != null)
                    {
                        string _msg;

                        if (Items.Count == 1)
                        {
                            _msg = string.Format(I18n.L.T("OnePostUpload"), _count, _counts - _count);
                        }
                        else
                        {
                            _msg = string.Format(I18n.L.T("MultiplePostUpload"), _count, _counts - _count, Items.Count - 1);
                        }

                        UpdateUI(_count * 100 / _counts, _msg);
                    }

                    if (_count == _counts)
                    {
                        break;
                    }
                }
                else
                {
                    newPost.PostOK = false;
                    return(newPost);
                }
            }

            _ids  = _ids.Substring(0, _ids.Length - 1); // 去掉最後一個","
            _ids += "]";

            try
            {
                MR_posts_new _np = Main.Current.RT.REST.Posts_New(newPost.Text, _ids, "", "image");

                if (_np == null)
                {
                    newPost.PostOK = false;
                    return(newPost);
                }

                s_logger.Trace("[" + _tmpStamp + "]" + "Batch Post:" + newPost.Text + ", Files=" + newPost.Files.Count);
            }
            catch (Exception _e)
            {
                NLogUtility.Exception(s_logger, _e, "BatchPhotoPost:File_UploadFile");

                newPost.PostOK = false;
                return(newPost);
            }

            newPost.PostOK = true;
            return(newPost);
        }