Exemple #1
0
        private void SetLastReadPos()
        {
            try
            {
                if (RT.CurrentGroupPosts.Count == 0)
                {
                    s_logger.Trace("SetLastReadPos RT.CurrentGroupPosts.Count = 0");

                    return;
                }

                string _id = RT.CurrentGroupPosts[0].post_id;

                if (_id != string.Empty)
                {
                    string _ret = RT.REST.Footprints_setLastScan(_id);

                    if (_ret == null)
                    {
                        s_logger.Trace("SetLastReadPos.Footprints_setLastScan: null");
                    }
                    else
                    {
                        s_logger.Info("SetLastReadPos.Footprints_setLastScan: " + _ret);
                    }
                }
            }
            catch (Exception _e)
            {
                NLogUtility.Exception(s_logger, _e, "SetLastReadPos");
            }
        }
        private long CheckStoragesUsage()
        {
            try
            {
                MR_storages_usage _storagesUsage = Main.Current.RT.REST.Storages_Usage();

                if (_storagesUsage != null)
                {
                    long m_avail_month_total_objects = _storagesUsage.storages.waveface.available.avail_month_total_objects;
                    long m_month_total_objects       = _storagesUsage.storages.waveface.quota.month_total_objects;

                    //Hack
                    if (m_month_total_objects == -1)
                    {
                        return(long.MaxValue);
                    }

                    return(m_avail_month_total_objects);
                }
            }
            catch (Exception _e)
            {
                NLogUtility.Exception(s_logger, _e, "CheckStoragesUsage");
            }

            return(long.MinValue);
        }
        public void SetPosts(List <Post> posts, int lastRead, bool manualRefresh)
        {
            try
            {
                m_manualRefresh = manualRefresh;

                dataGridView.Enabled = false;

                m_posts             = posts;
                m_postBS.DataSource = posts;

                try
                {
                    dataGridView.DataSource = null;
                    dataGridView.DataSource = m_postBS;
                    dataGridView.Refresh();
                }
                catch (Exception _e)
                {
                    NLogUtility.Exception(s_logger, _e, "SetPosts-1");
                }

                dataGridView.Enabled = true;

                DoDisplayedScrolling(lastRead);

                NotifyDetailView();
            }
            catch (Exception _e)
            {
                NLogUtility.Exception(s_logger, _e, "SetPosts-2");
            }
        }
        public bool Save()
        {
            try
            {
                string _json = JsonConvert.SerializeObject(this);

                if (!GCONST.DEBUG)
                {
                    _json = StringUtility.Compress(_json);
                }

                string _filePath = Main.GCONST.CachePath + Main.Current.RT.Login.user.user_id + "_NP.dat";

                using (StreamWriter _outfile = new StreamWriter(_filePath))
                {
                    _outfile.Write(_json);
                }
            }
            catch (Exception _e)
            {
                NLogUtility.Exception(s_logger, _e, "Save");

                return(false);
            }

            s_logger.Trace("Save: OK");

            return(true);
        }
Exemple #5
0
        public void LoadGroupLocalRead()
        {
            try
            {
                string _json     = string.Empty;
                string _filePath = Main.GCONST.CachePath + Login.user.user_id + "_LR.dat";

                StreamReader _sr = File.OpenText(_filePath);
                _json = _sr.ReadToEnd();
                _sr.Close();

                if (!GCONST.DEBUG)
                {
                    _json = StringUtility.Decompress(_json);
                }

                LocalReadRT _lr = JsonConvert.DeserializeObject <LocalReadRT>(_json);

                m_groupLocalLastReadID = _lr.GroupLocalLastReadID;
                m_groupHaveReadPosts   = _lr.GroupHaveReadPosts;

                s_logger.Trace("LoadGroupLocalRead:OK");
            }
            catch (Exception _e)
            {
                NLogUtility.Exception(s_logger, _e, "LoadGroupLocalRead");
            }
        }
Exemple #6
0
        public bool SaveGroupLocalRead()
        {
            LocalReadRT _lr = new LocalReadRT();

            _lr.GroupLocalLastReadID = m_groupLocalLastReadID;
            _lr.GroupHaveReadPosts   = m_groupHaveReadPosts;

            try
            {
                string _json = JsonConvert.SerializeObject(_lr);

                if (!GCONST.DEBUG)
                {
                    _json = StringUtility.Compress(_json);
                }

                string _filePath = Main.GCONST.CachePath + Login.user.user_id + "_LR.dat";

                using (StreamWriter _outfile = new StreamWriter(_filePath))
                {
                    _outfile.Write(_json);
                }
            }
            catch (Exception _e)
            {
                NLogUtility.Exception(s_logger, _e, "SaveGroupLocalRead");

                return(false);
            }

            s_logger.Trace("SaveGroupLocalRead: OK");

            return(true);
        }
Exemple #7
0
        public RunTime LoadJSON()
        {
            try
            {
                string _json     = string.Empty;
                string _filePath = Main.GCONST.CachePath + Login.user.user_id + "_RT.dat";

                StreamReader _sr = File.OpenText(_filePath);
                _json = _sr.ReadToEnd();
                _sr.Close();

                if (!GCONST.DEBUG)
                {
                    _json = StringUtility.Decompress(_json);
                }

                RunTime _rt = JsonConvert.DeserializeObject <RunTime>(_json);

                s_logger.Trace("LoadJSON: OK");

                return(_rt);
            }
            catch (Exception _e)
            {
                NLogUtility.Exception(s_logger, _e, "LoadJSON");

                return(null);
            }
        }
        public static NewPostManager Load()
        {
            try
            {
                string _json     = string.Empty;
                string _filePath = Main.GCONST.CachePath + Main.Current.RT.Login.user.user_id + "_NP.dat";

                StreamReader _sr = File.OpenText(_filePath);
                _json = _sr.ReadToEnd();
                _sr.Close();

                if (!GCONST.DEBUG)
                {
                    _json = StringUtility.Decompress(_json);
                }

                NewPostManager _npm = JsonConvert.DeserializeObject <NewPostManager>(_json);

                s_logger.Trace("Load:OK");

                return(_npm);
            }
            catch (Exception _e)
            {
                NLogUtility.Exception(s_logger, _e, "Load");
            }

            return(null);
        }
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            NLogUtility.Exception(s_logger, (Exception)e.ExceptionObject, "CurrentDomain_UnhandledException");

            if (ShowCrashReporter)
            {
                CrashReporter _errorDlg = new CrashReporter((Exception)e.ExceptionObject);
                _errorDlg.ShowDialog();
            }
        }
Exemple #10
0
 private void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
 {
     try
     {
         if (IsHandleCreated)
         {
             Invoke(new MethodInvoker(UpdateNetworkStatus));
         }
     }
     catch (Exception _e)
     {
         NLogUtility.Exception(s_logger, _e, "NetworkChange_NetworkAvailabilityChanged");
     }
 }
Exemple #11
0
 private void CreateLoadingImage()
 {
     try
     {
         Bitmap   _img = new Bitmap(256, 256);
         Graphics _g   = Graphics.FromImage(_img);
         _g.FillRectangle(new SolidBrush(Color.WhiteSmoke), new Rectangle(0, 0, 256, 256));
         _img.Save(LoadingImagePath);
     }
     catch (Exception _e)
     {
         NLogUtility.Exception(s_logger, _e, "CreateLoadingImage");
     }
 }
Exemple #12
0
        private void doLogin(string email, string password)
        {
            Cursor = Cursors.WaitCursor;

            Program.ShowCrashReporter = true;

            try
            {
                QuitOption quit = _doLogin(email, password);
                if (quit == QuitOption.QuitProgram)
                {
                    Close();
                }
                else if (quit == QuitOption.Logout)
                {
                    Environment.Exit(-2);
                }
                else
                {
                    Environment.Exit(-1);
                }
            }
            catch (StationServiceDownException _e)
            {
                NLogUtility.Exception(s_logger, _e, "doLogin");

                MessageBox.Show(I18n.L.T("StationServiceDown"), "Waveface");
                Environment.Exit(-1);
            }
            catch (ServiceUnavailableException _e)
            {
                NLogUtility.Exception(s_logger, _e, "doLogin");

                // user should re-register station if receive service unavailable exception
                // so we close the login page here
                MessageBox.Show(I18n.L.T("RegisteredRequired", txtUserName.Text), "Waveface");
                Environment.Exit(-1);
            }
            catch (Exception _e)
            {
                NLogUtility.Exception(s_logger, _e, "doLogin");

                MessageBox.Show(I18n.L.T("LoginForm.LogInError") + " : " + _e.Message, "Waveface");
                Environment.Exit(-1);
            }
        }
        private void timerDisplayedScrolling_Tick(object sender, EventArgs e)
        {
            timerDisplayedScrolling.Enabled = false;

            try
            {
                dataGridView.FirstDisplayedScrollingRowIndex = m_lastRead;

                if (m_manualRefresh)
                {
                    dataGridView.FirstDisplayedScrollingRowIndex = 0;
                }
            }
            catch (Exception _e)
            {
                NLogUtility.Exception(s_logger, _e, "timerDisplayedScrolling_Tick");
            }
        }
Exemple #14
0
        private void Main_SizeChanged(object sender, EventArgs e)
        {
            try
            {
                panelLeftInfo.Width = leftArea.MyWidth + 8;

                if (WindowState == FormWindowState.Minimized)
                {
                    SetLastReadPos();

                    s_logger.Trace("Main_SizeChanged: FormWindowState.Minimized");
                }
            }
            catch (Exception _e)
            {
                NLogUtility.Exception(s_logger, _e, "Main_SizeChanged");
            }
        }
Exemple #15
0
        private void DoRealPostForm(List <string> pics, PostType postType)
        {
            if (!RT.LoginOK)
            {
                MessageBox.Show("Please Login first.", "Waveface");
                return;
            }

            m_canAutoFetchNewestPosts = false;

            try
            {
                m_postForm = new PostForm(pics, postType, null, false);
                DialogResult _dr = m_postForm.ShowDialog();

                switch (_dr)
                {
                case DialogResult.Yes:
                    break;

                case DialogResult.OK:
                    NewPostManager.Add(m_postForm.NewPostItem);
                    break;
                }
            }
            catch (Exception _e)
            {
                MessageBox.Show(I18n.L.T("PostError") + " : " + _e.Message, "Waveface");

                NLogUtility.Exception(s_logger, _e, "Post");
            }

            m_postForm = null;

            m_canAutoFetchNewestPosts = true;
        }
        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);
                }
            }
        }
        public bool doPost(string sUrl, string data, string referer)
        {
            bool           _dosuccess = false;
            HttpWebRequest _urlConn   = null;

            try
            {
                _urlConn = (HttpWebRequest)WebRequest.Create(sUrl);

                //連線最大等待時間
                //_urlConn.Timeout = 10000;
                _urlConn.Method = "POST";
                //_urlConn.ServicePoint.Expect100Continue = false;

                _urlConn.Headers.Set("Content-Encoding", "UTF-8");
                _urlConn.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
                _urlConn.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

                //設定referer
                if (referer != null)
                {
                    _urlConn.Referer = referer;
                }

                _urlConn.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";

                //自動從導
                // _urlConn.AllowAutoRedirect = true;

                if (data == null)
                {
                    data = "";
                }

                //把要傳送的資料變成binary
                byte[] _bytes = Encoding.UTF8.GetBytes(data);
                _urlConn.ContentLength = _bytes.Length;

                //設定Cookie,Session
                _urlConn.CookieContainer = s_cookie;

                //送出post資料
                if (data.Length > 0)
                {
                    Stream _oStreamOut = _urlConn.GetRequestStream();
                    _oStreamOut.Write(_bytes, 0, _bytes.Length);
                    _oStreamOut.Close();
                }

                //取回回傳內容
                m_buff = (new StreamReader(_urlConn.GetResponse().GetResponseStream())).ReadToEnd();

                _dosuccess = true;
            }
            catch (Exception _e)
            {
                NLogUtility.Exception(s_logger, _e, "doPost");
            }
            finally
            {
                try
                {
                    if (_urlConn != null)
                    {
                        _urlConn.GetResponse().Close();
                        _urlConn.GetRequestStream().Close();
                    }
                }
                catch
                {
                }
            }

            return(_dosuccess);
        }
        private void dataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
            try
            {
                //@ dataGridView.Rows[e.RowIndex].Height = 120 + (e.RowIndex % 10) * 20;

                bool _isDrawThumbnail;

                Graphics _g = e.Graphics;

                Post _post = m_postBS[e.RowIndex] as Post;

                bool _selected = ((e.State & DataGridViewElementStates.Selected) == DataGridViewElementStates.Selected);

                //Color _fcolor = (_selected ? e.CellStyle.SelectionForeColor : e.CellStyle.ForeColor);
                //Color _bcolor = (_selected ? e.CellStyle.SelectionBackColor : e.CellStyle.BackColor);

                int _X = e.CellBounds.Left + e.CellStyle.Padding.Left;
                int _Y = e.CellBounds.Top + e.CellStyle.Padding.Top;
                int _W = e.CellBounds.Width - (e.CellStyle.Padding.Left + e.CellStyle.Padding.Right);
                int _H = e.CellBounds.Height - (e.CellStyle.Padding.Top + e.CellStyle.Padding.Bottom);

                Rectangle _cellRect = new Rectangle(_X, _Y, _W, _H);

                // Draw background

                if (_selected)
                {
                    _g.FillRectangle(m_bgSelectedBrush, e.CellBounds);
                }
                else
                {
                    if (Main.Current.RT.CurrentGroupHaveReadPosts.Contains(_post.post_id))
                    {
                        _g.FillRectangle(m_bgReadBrush, e.CellBounds);
                    }
                    else
                    {
                        _g.FillRectangle(m_bgUnReadBrush, e.CellBounds);
                    }
                }

                _g.DrawRectangle(Pens.White, e.CellBounds.X + 1, e.CellBounds.Y + 1, e.CellBounds.Width - 2, e.CellBounds.Height - 2);

                Rectangle _timeRect = DrawPostTime(_g, m_fontPostTime, _cellRect, _post);

                DrawFavoriteIcon(_g, _post, e.CellBounds);

                Rectangle _thumbnailRect = new Rectangle(_X + 4, _Y + 8, PicWidth, PicHeight);

                _isDrawThumbnail = DrawThumbnail(_g, _thumbnailRect, _post);

                int _offsetThumbnail_W = (_isDrawThumbnail ? _thumbnailRect.Width : 0);

                switch (_post.type)
                {
                case "text":
                    Draw_Text_Post(_g, _post, _cellRect, _timeRect.Height, m_fontText);
                    break;

                case "rtf":
                    Draw_RichText_Post(_g, _post, _cellRect, _timeRect.Height, m_fontText, _thumbnailRect.Width);
                    break;

                case "image":
                case "doc":
                    Draw_Photo_Doc_Post(_g, _post, _cellRect, _timeRect.Height, m_fontPhotoInfo, m_fontText, _thumbnailRect.Width, _selected);
                    break;

                case "link":
                    Draw_Link(_g, _post, _cellRect, _timeRect.Height, m_fontPhotoInfo, _thumbnailRect.Width, _selected);
                    break;
                }
            }
            catch (Exception _e)
            {
                NLogUtility.Exception(s_logger, _e, "dataGridView_CellPainting");

                e.Handled = false;

                return;
            }

            // Let them know we handled it
            e.Handled = true;
        }