Exemple #1
0
        private void SendProcess()
        {
            var sender = new PostSender(_report.ReportInfo);

            try
            {
                string dirName  = Guid.NewGuid().ToString();
                string tempPath = Path.GetTempPath();
                string usedPath = tempPath + dirName;
                Directory.CreateDirectory(usedPath);

                try
                {
                    if (this._report.ReportInfo.ScreenshotImage != null)
                    {
                        using (var stream = File.OpenWrite(usedPath + Path.DirectorySeparatorChar + "screenshot.jpg"))
                        {
                            this._report.ReportInfo.ScreenshotImage.Save(stream, ImageFormat.Jpeg);

                            stream.Close();
                        }
                    }
                }
                catch { }

                try
                {
                    File.Copy(
                        Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "callservice.settings.xml"),
                        usedPath + Path.DirectorySeparatorChar + "settings.xml");
                }
                catch { }

                try
                {
                    File.Copy("pjsip.log", usedPath + Path.DirectorySeparatorChar + "pjsip.log");
                }
                catch { }

                try
                {
                    this._report.SaveReportToFile(usedPath + Path.DirectorySeparatorChar + "report.txt");
                }
                catch { }

                try
                {
                    var sb = new StringBuilder();

                    foreach (var item in Logger.Log)
                    {
                        sb.AppendLine(item.ToString());
                    }

                    File.WriteAllText(usedPath + Path.DirectorySeparatorChar + "log.txt", sb.ToString());
                }
                catch { }

                ZipUtil.ZipFiles(usedPath, usedPath + ".zip", "");
                sender.AddFile("log_files", usedPath + ".zip");

                sender.Send();

                this.CrossThreadClose(DialogResult.OK);
            }
            catch (Exception e)
            {
                MessageBox.Show("Не удалось отправить отчет!\r\n" + e.Message, "Ошибка при отправке отчета", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                this.CrossThreadClose(DialogResult.Cancel);
            }
            finally
            {
                sender = null;
            }
        }
        protected override void OnViewStateChanged(string key)
        {
            #region SendMessage

            if (key == "SendMessage")
            {
                try
                {
                    using (new WaitWrapper(false))
                    {
                        Globals.BaseLogic.AddComments((string)ViewData["Message"],
                                                      (string)ViewData["UserID"] + "_" +
                                                      (string)ViewData["PhotoID"],
                                                      false);
                    }
                    view.UpdateView("SendCommentSuccess");

                    using (new WaitWrapper(false))
                    {
                        PhotosCommentsResponseHistory pchResponse = null;
                        PhotosCommentsResponse        pcResponse  = null;

                        try
                        {
                            //pchResponse = Cache.LoadFromCache<PhotosCommentsResponseHistory>(string.Empty, "PhotosCommentsResponseHistory");

                            pchResponse = DataModel.Data.PhotosCommentsResponseHistoryData;

                            if (pchResponse == null)
                            {
                                throw new Exception();
                            }
                        }
                        catch (Exception)
                        {
                            pchResponse = new PhotosCommentsResponseHistory();
                        }

                        pcResponse = pchResponse.GetItem(Convert.ToInt32((string)ViewData["PhotoID"]));

                        if (pcResponse == null)
                        {
                            pcResponse = new PhotosCommentsResponse();
                            pchResponse.AddItem(pcResponse);
                        }

                        var newPhotoData = new PhotoData
                        {
                            pdPhotoID       = Convert.ToInt32((string)ViewData["PhotoID"]),
                            pdUserID        = Convert.ToInt32((string)ViewData["UserID"]),
                            pdPhotoURL604px = (string)ViewData["LargePhotoUrl"]
                        };

                        var newPostReceiver = new PostReceiver
                        {
                            prUserID = Convert.ToInt32((string)ViewData["UserID"])
                        };

                        var newPostSender = new PostSender
                        {
                            psUserID =
                                Convert.ToInt32(Globals.BaseLogic.IDataLogic.GetUid()),
                            psUserName = Resources.MessageI
                        };

                        var newWallData = new WallData
                        {
                            wdWallDataType = WallDataType.PlainText,
                            wdText         = (string)ViewData["Message"]
                        };

                        pcResponse.pcrPhotoID = Convert.ToInt32((string)ViewData["PhotoID"]);
                        pcResponse.pcrComments.Insert(0, new CommentPost
                        {
                            cpID           = 0,
                            cpTime         = DateTime.Now,
                            cpPhotoData    = newPhotoData,
                            cpPostReceiver = newPostReceiver,
                            cpPostSender   = newPostSender,
                            cpWallData     = newWallData
                        }
                                                      );

                        //try
                        //{
                        //    bool result = Cache.SaveToCache(pchResponse, string.Empty,
                        //                                    "PhotosCommentsResponseHistory");
                        //    DebugHelper.WriteLogEntry(result
                        //                                  ? "Новый комментарий сохранен в кэш."
                        //                                  : "Новый комментарий не сохранены в кэш.");
                        //}
                        //catch (IOException newException)
                        //{
                        //    DebugHelper.WriteLogEntry("Ошибка сохранения комментария к фото в кэш: " +
                        //                              newException.Message);
                        //}

                        DataModel.Data.PhotosCommentsResponseHistoryData = pchResponse;

                        if ((string)ViewData["UserID"] == Globals.BaseLogic.IDataLogic.GetUid())
                        {
                            try
                            {
                                //pcResponse = Cache.LoadFromCache<PhotosCommentsResponse>(string.Empty,
                                //                                                         "PhotosCommentsResponse");

                                pcResponse = DataModel.Data.PhotosCommentsResponseData;

                                if (pcResponse == null)
                                {
                                    throw new Exception();
                                }
                            }
                            catch (Exception)
                            {
                                pcResponse = new PhotosCommentsResponse();
                            }

                            pcResponse.pcrPhotoID = Convert.ToInt32((string)ViewData["PhotoID"]);
                            pcResponse.pcrComments.Insert(0, new CommentPost
                            {
                                cpID           = 0,
                                cpTime         = DateTime.Now,
                                cpPhotoData    = newPhotoData,
                                cpPostReceiver = newPostReceiver,
                                cpPostSender   = newPostSender,
                                cpWallData     = newWallData
                            }
                                                          );

                            //try
                            //{
                            //    bool result = Cache.SaveToCache(pcResponse, string.Empty, "PhotosCommentsResponse");
                            //    DebugHelper.WriteLogEntry(result
                            //                                  ? "Новый комментарий сохранен в кэш комментариев к своим фото."
                            //                                  : "Новый комментарий не сохранен в кэш комментариев к своим фото.");
                            //}
                            //catch (IOException newException)
                            //{
                            //    DebugHelper.WriteLogEntry("Ошибка сохранения комментария к своему фото в кэш: " +
                            //                              newException.Message);
                            //}

                            DataModel.Data.PhotosCommentsResponseData = pcResponse;
                        }
                        NavigationService.GoBack();
                    }
                }
                catch (VKException ex)
                {
                    //timerKeepAwake.Enabled = false;
                    string err = ExceptionTranslation.TranslateException(ex);
                    if (!string.IsNullOrEmpty(err))
                    {
                        ViewData["SendCommentError"] = err;
                        view.UpdateView("SendCommentFail");

                        if (ex.LocalizedMessage == ExceptionMessage.IncorrectLoginOrPassword)
                        {
                            Globals.BaseLogic.IDataLogic.SetToken(string.Empty);

                            view.UpdateView("GoToLogin");
                        }
                    }
                }
                catch (OutOfMemoryException)
                {
                    ViewData["SendCommentError"] = Resources.OutOfMemory;
                    view.UpdateView("SendCommentFail");
                }
            }

            #endregion

            #region GoBack

            if (key == "GoBack")
            {
                using (new WaitWrapper(false))
                {
                    NavigationService.GoBack();
                }
            }

            #endregion

            if (key == "GoGoToLogin")
            {
                MasterForm.Navigate <LoginController>();
            }
        }