Beispiel #1
0
        internal static void SendErrorReport(Exception exception, bool exit = true)
        {
            try
            {
                if (!Approved.HasValue)
                {
                    Approved = MessageBox.Show(string.Format("Во время выполнения приложения произошла непредвиденная ошибка. {0}Отправить отчёт разработчику?", exit ? "Приложение будет завершено. " : ""), Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes;
                }

                if (Approved.Value)
                {
                    var errorText = new StringBuilder();
                    while (exception != null)
                    {
                        errorText.AppendLine(exception.ToString()).AppendLine();
                        exception = exception.InnerException;
                    }

                    var service = new UpdateService.UpdateServiceClient();
                    service.SendErrorReport("CIRCe", Assembly.GetExecutingAssembly().GetName().Version, DateTime.Now, errorText.ToString());
                }
            }
            catch
            {
            }
            finally
            {
                if (exit)
                {
                    Application.Exit();
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Произвести поиск обновлений
        /// </summary>
        /// <returns>Нужно ли завершить приложение для выполнения обновления</returns>
        private static bool SearchForUpdatesNew()
        {
            var updateService = new UpdateService.UpdateServiceClient();

            try
            {
                updateService.Open();

                var currentVersion = Assembly.GetExecutingAssembly().GetName().Version;
                var actualVersion  = updateService.GetProductVersionByOS("CIRCe", Environment.OSVersion.Version);

                if (actualVersion > currentVersion)
                {
                    if (MessageBox.Show(string.Format(Resources.FullUpdates, actualVersion.ToString(3)), Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        var updateUri = updateService.GetProductUpdate("CIRCe");
                        if (!updateUri.IsAbsoluteUri)
                        {
                            updateUri = new Uri("http://vladimirkhil.com/" + updateUri.OriginalString);
                        }

                        var localFile = Path.Combine(Path.GetTempPath(), "setup.exe");

                        using (var webClient = new WebClient())
                        {
                            webClient.Headers.Add(HttpRequestHeader.UserAgent, Program.UserAgentHeader);
                            webClient.DownloadFile(updateUri, localFile);
                        }

                        Process.Start(localFile);
                        return(true);
                    }
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(string.Format(Resources.UpdateException, exc.Message), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                updateService.Close();
            }

            return(false);
        }