| | |
| | | using AutoUpdaterDotNET; |
| | | using DevExpress.XtraEditors; |
| | | using Gs.DevApp.ToolBox; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Configuration; |
| | | using System; |
| | | using System.Data; |
| | | using System.Drawing; |
| | | using System.Linq; |
| | | using System.Diagnostics; |
| | | using System.IO; |
| | | using System.Net; |
| | | using System.Text; |
| | | using System.Threading; |
| | | using System.Text.RegularExpressions; |
| | | using System.Threading.Tasks; |
| | | using System.Windows.Forms; |
| | | using System.Windows.Media.Animation; |
| | | using DevExpress.Internal.WinApi.Windows.UI.Notifications; |
| | | using DevExpress.XtraEditors; |
| | | using DevExpress.XtraRichEdit.Import.OpenXml; |
| | | using DevExpress.XtraTreeList.Data; |
| | | using Gs.DevApp.Entity; |
| | | using Gs.DevApp.ToolBox; |
| | | using Gs.DevApp.UserControl; |
| | | using Newtonsoft.Json; |
| | | |
| | | namespace Gs.DevApp.TestForm |
| | | { |
| | | public partial class XtraForm1 : DevExpress.XtraEditors.XtraForm |
| | | public partial class XtraForm1 : XtraForm |
| | | { |
| | | |
| | | //https://www.cnblogs.com/China3S/p/3452008.html |
| | | public XtraForm1() |
| | | { |
| | | InitializeComponent(); |
| | | string _version = ConfigurationManager.AppSettings["Version"]; |
| | | AutoUpdater.InstalledVersion = new Version(_version); |
| | | AutoUpdater.Start("https://dianbei.top/AutoUpdaterTest.xml"); |
| | | AutoUpdater.CheckForUpdateEvent += AutoUpdater_CheckForUpdateEvent; |
| | | //dddddddd(); |
| | | |
| | | //await Task.Run(() => |
| | | //{ |
| | | |
| | | //}); |
| | | } |
| | | |
| | | private void AutoUpdater_CheckForUpdateEvent(UpdateInfoEventArgs args) |
| | | { |
| | | if (args != null) |
| | | private async void dddddddd() { |
| | | |
| | | |
| | | UcLoading _loading = new UcLoading(); |
| | | var pgq = new PageQueryModel(1, 999999, "item_name", "asc", "", |
| | | " and fforbidstatus='A'"); |
| | | var json = JsonConvert.SerializeObject(pgq); |
| | | try |
| | | { |
| | | if (args.IsUpdateAvailable) |
| | | //var strReturn = await UtilityHelper.HttpPostAsync("", |
| | | // "MesItemsManager/GetListPageByLook", json); |
| | | //var rtn = UtilityHelper.ReturnToList(strReturn); |
| | | //var dt = rtn.rtnData; |
| | | |
| | | await csd(); |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MsgHelper.Warning("提示:" + ex.Message); |
| | | } |
| | | _loading.Stop(); |
| | | } |
| | | |
| | | private async Task<int> csd() |
| | | { |
| | | int c = 0; |
| | | //await Task.Delay(1000); |
| | | await Task.Run(() => |
| | | { |
| | | for (int i = 0; i < 10000; i++) |
| | | { |
| | | string _strMsg = string.Format($@"There is new version {args.CurrentVersion} available. You are using version {args.InstalledVersion}. This is required update. Press Ok to begin updating the application.", @"Update Available"); |
| | | if (!MsgHelper.AskQuestion(_strMsg)) |
| | | Application.Exit(); |
| | | try |
| | | c = c + i; |
| | | if (richTextBox1.InvokeRequired) |
| | | { |
| | | if (AutoUpdater.DownloadUpdate(args)) |
| | | richTextBox1.BeginInvoke(new Action(() => |
| | | { |
| | | Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); |
| | | if (config != null) |
| | | { |
| | | AppSettingsSection appSettings = (AppSettingsSection)config.GetSection("appSettings"); |
| | | if (appSettings.Settings.AllKeys.Contains("Version")) |
| | | { |
| | | appSettings.Settings["Version"].Value = args.CurrentVersion; |
| | | } |
| | | else |
| | | { |
| | | appSettings.Settings.Add("Version", args.CurrentVersion); |
| | | } |
| | | config.Save(ConfigurationSaveMode.Modified); |
| | | ConfigurationManager.RefreshSection("appSettings"); |
| | | } |
| | | Application.Exit(); |
| | | } |
| | | richTextBox1.Text = c.ToString(); |
| | | })); |
| | | } |
| | | catch (Exception exception) |
| | | else |
| | | { |
| | | MessageBox.Show(exception.Message, exception.GetType().ToString(), MessageBoxButtons.OK, |
| | | MessageBoxIcon.Error); |
| | | richTextBox1.Text = c.ToString(); |
| | | } |
| | | } |
| | | } |
| | | else |
| | | |
| | | }); |
| | | return c; |
| | | |
| | | } |
| | | private void simpleButton1_Click_1(object sender, EventArgs e) |
| | | { |
| | | dddddddd(); |
| | | } |
| | | |
| | | |
| | | private async void simpleButton2_Click(object sender, EventArgs e) |
| | | { |
| | | UcLoading _loading = new UcLoading(); |
| | | string url = "http://localhost:5263/"; |
| | | try |
| | | { |
| | | MessageBox.Show( |
| | | @"There is a problem reaching update server please check your internet connection and try again later.", |
| | | @"Update check failed", MessageBoxButtons.OK, MessageBoxIcon.Error); |
| | | string result = await GetHttpResponseAsync(url); |
| | | Console.WriteLine(result); |
| | | richTextBox1.Text = result; |
| | | } |
| | | catch (WebException ex) |
| | | { |
| | | richTextBox1.Text = ex.Message; |
| | | } |
| | | _loading.Stop(); |
| | | } |
| | | |
| | | private static async Task<string> GetHttpResponseAsync(string url) |
| | | { |
| | | string param = "{}"; |
| | | HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); |
| | | |
| | | request.Method = "POST"; |
| | | request.ContentType = "application/json"; |
| | | //request.Headers.Add("token", GetBasicAuthTicket()); |
| | | request.Accept = "*/*"; |
| | | request.Timeout = 15000; |
| | | request.AllowAutoRedirect = false; |
| | | |
| | | |
| | | //StreamWriter requestStream = null; |
| | | //requestStream = new StreamWriter(request.GetRequestStream()); |
| | | //requestStream.Write(param); |
| | | //requestStream.Close(); |
| | | |
| | | using (Stream requestStream = await request.GetRequestStreamAsync()) |
| | | { |
| | | byte[] dataBytes = Encoding.UTF8.GetBytes(param); |
| | | await requestStream.WriteAsync(dataBytes, 0, dataBytes.Length); |
| | | } |
| | | |
| | | |
| | | using (WebResponse response = await request.GetResponseAsync()) |
| | | using (Stream responseStream = response.GetResponseStream()) |
| | | using (StreamReader reader = new StreamReader(responseStream, Encoding.UTF8)) |
| | | { |
| | | return await reader.ReadToEndAsync(); |
| | | } |
| | | } |
| | | } |