private string doPostDocs(List <string> docs)
        {
            string _ids = "[";

            foreach (string _path in docs)
            {
                try
                {
                    MR_attachments_upload _uf = File_UploadFile(new FileInfo(_path).Name, _path, "", false);

                    if (_uf == null)
                    {
                        return("");
                    }

                    _ids += "\"" + _uf.object_id + "\"" + ",";
                }
                catch
                {
                    return("");
                }
            }

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

            return(_ids);
        }
        private string postImages(List <string> images)
        {
            string _ids = "[";

            foreach (string _file in images)
            {
                try
                {
                    MR_attachments_upload _uf = File_UploadFile(new FileInfo(_file).Name, _file, "", true);

                    if (_uf == null)
                    {
                        return("");
                    }

                    _ids += "\"" + _uf.object_id + "\"" + ",";
                }
                catch
                {
                    return("");
                }
            }

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

            return(_ids);
        }
        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);
        }
        private void ThreadMethod(object state)
        {
            UploadOriginPhotosToStationItem _item = null;

            while (!m_exit)
            {
                Thread.Sleep(2500);

                while (true)
                {
                    lock (this)
                    {
                        if (m_items.Count == 0)
                        {
                            break;
                        }
                        else
                        {
                            _item = m_items[0];
                        }
                    }

                    if (!Main.Current.RT.StationMode)
                    {
                        break;
                    }

                    try
                    {
                        File.Copy(_item.FilePath_OID, _item.FilePath_REAL, true);

                        FileName _fileName = new FileName(_item.FilePath_REAL);

                        MR_attachments_upload _uf = Main.Current.RT.REST.File_UploadFile(_fileName.Name, _item.FilePath_REAL,
                                                                                         _item.ObjectID, true);

                        if (_uf == null)
                        {
                            break;
                        }


                        lock (this)
                        {
                            m_items.Remove(_item);
                        }

                        File.Delete(_item.FilePath_REAL);
                        File.Delete(_item.FilePath_OID);

                        s_logger.Trace("UploadOriginPhotosToStation:" + _item.FilePath_REAL);
                    }
                    catch (Exception _e)
                    {
                        NLogUtility.Exception(s_logger, _e, "ThreadMethod");
                        break;
                    }

                    Thread.Sleep(1);
                }
            }
        }
Example #5
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            if (!Main.Current.CheckNetworkStatus())
            {
                return;
            }

            m_progressDialog = new ProgressDialog("Upload ..."
                                                  , delegate
            {
                string _ids = "[";

                //Upload Image
                if (imageListView.SelectedItems.Count == 0)
                {
                    return("*ERROR*");
                }

                ImageListViewItem _imgItem = imageListView.SelectedItems[0];

                string _imageFile = _imgItem.FileName;
                string _imageURL  = _imgItem.Tag.ToString();

                try
                {
                    MR_attachments_upload _uf = Main.Current.RT.REST.File_UploadFile(_imageURL, _imageFile, "", true);

                    if (_uf == null)
                    {
                        return("*ERROR*");
                    }

                    _ids += "\"" + _uf.object_id + "\"" + ",";
                }
                catch
                {
                    return("*ERROR*");
                }

                m_progressDialog.RaiseUpdateProgress(50);

                if (m_progressDialog.WasCancelled)
                {
                    return("*ERROR*");
                }

                try
                {
                    MR_attachments_upload _uf = Main.Current.RT.REST.File_UploadFile("_RichText_", MyParent.GetHtmlFile(), "", false);

                    if (_uf == null)
                    {
                        return("*ERROR*");
                    }

                    _ids += "\"" + _uf.object_id + "\"" + ",";
                }
                catch
                {
                    return("*ERROR*");
                }

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

                return(_ids);
            });          // This value will be passed to the method

            // Then all you need to do is
            m_progressDialog.ShowDialog();

            if (!m_progressDialog.WasCancelled && ((string)m_progressDialog.Result) != "*ERROR*")
            {
                try
                {
                    if (DoRealPost((string)m_progressDialog.Result))
                    {
                        DialogResult = DialogResult.Yes;
                        Close();
                    }

                    return;
                }
                catch (Exception _e)
                {
                    MessageBox.Show(_e.Message);
                    return;
                }
            }
            else
            {
                MessageBox.Show("Action canceled");
            }
        }
Example #6
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            if (!Main.Current.CheckNetworkStatus())
            {
                return;
            }

            if (listViewFiles.Items.Count > 0)
            {
                Dictionary <string, string> _uploadFiles = new Dictionary <string, string>();

                foreach (ListViewItem _item in listViewFiles.Items)
                {
                    _uploadFiles.Add(_item.Tag.ToString(), new FileInfo(_item.Tag.ToString()).Name); // Path, FileName
                }

                resetUI(true);

                m_progressDialog = new ProgressDialog("Upload Document ..."
                                                      , delegate
                {
                    string _ids = "[";

                    int i = 0;

                    foreach (string _path in _uploadFiles.Keys)
                    {
                        if (m_progressDialog.WasCancelled)
                        {
                            return("*ERROR*");
                        }

                        try
                        {
                            MR_attachments_upload _uf = Main.Current.RT.REST.File_UploadFile(_uploadFiles[_path], _path, "", false);

                            if (_uf == null)
                            {
                                return("*ERROR*");
                            }

                            _ids += "\"" + _uf.object_id + "\"" + ",";
                        }
                        catch
                        {
                            return("*ERROR*");
                        }

                        i++;

                        m_progressDialog.RaiseUpdateProgress(i * 100 / _uploadFiles.Keys.Count);
                    }

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

                    return(_ids);
                });                // This value will be passed to the method

                // Then all you need to do is
                m_progressDialog.ShowDialog();

                if (!m_progressDialog.WasCancelled && ((string)m_progressDialog.Result) != "*ERROR*")
                {
                    try
                    {
                        if (DoRealPost((string)m_progressDialog.Result))
                        {
                            MyParent.SetDialogResult_Yes_AndClose();
                        }

                        return;
                    }
                    catch (Exception _e)
                    {
                        MessageBox.Show(_e.Message);
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("Action canceled");

                    //Restore File List
                    foreach (string _filePath in _uploadFiles.Keys)
                    {
                        addNewFileToListView(_filePath, false);
                    }

                    selectLastestListViewItem();
                }

                return;
            }

            //單純文字
            if (MyParent.pureTextBox.Text.Trim().Equals(string.Empty))
            {
                MessageBox.Show("Text cannot be empty!");
            }
            else
            {
                if (DoRealPost(""))
                {
                    MyParent.SetDialogResult_Yes_AndClose();
                }
            }
        }