private void publishManage_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            UpdateManage w = new UpdateManage();

            w.Owner = this;
            w.ShowDialog();
        }
Esempio n. 2
0
        private void btnReceiveEmail_Click(object sender, RoutedEventArgs e)
        {
            var    executablePathRoot = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            string targetFolder       = "Update";
            var    targetPath         = System.IO.Path.Combine(executablePathRoot, targetFolder);

            DeleteDir(targetPath);

            var assembliesWithServices = new Assembly[1];

            assembliesWithServices[0] = typeof(AppHost).Assembly;
            var appHost    = new AppHost("AppHost", assembliesWithServices);
            var unzipToDir = appSettings.Get <string>("UnzipToDir");

            bool hasReceived = false;

            Task.Run(() =>
            {
                while (true)
                {
                    if (hasReceived)
                    {
                        break;
                    }

                    //每分钟,检查邮件
                    Thread.Sleep(1000);
                    string host = "pop.qq.com";
                    string user = "******";
                    string pass = "******";   //qclhpkrldvdzbfib
                    int port    = 995;

                    //解压到Update文件夹下


                    EmailHelper email = new EmailHelper(user, pass, host, port, true, null);
                    string error      = "";
                    var isSuccess     = email.ValidateAccount(ref error);

                    if (isSuccess)
                    {
                        var count = email.GetEmailCount();

                        if (count > 0)
                        {
                            var zipFilePath = "";
                            bool isPartZip  = false;

                            for (int i = count; i >= 1; i--)
                            {
                                //收取附件
                                var result = email.DownAttachmentsById(targetPath, i);

                                if (result.Item1)
                                {
                                    if (result.Item2 != "")
                                    {
                                        zipFilePath = result.Item2;
                                    }
                                    else
                                    {
                                        if (isPartZip == false)
                                        {
                                            isPartZip = true;
                                        }
                                    }
                                    if (zipFilePath != "" && i == 1)
                                    {
                                        //解压到同名目录下
                                        if (isPartZip)
                                        {
                                            var sourceDir     = targetPath;
                                            var desPath       = System.IO.Path.Combine(targetFolder, "release");
                                            var zipfileName   = System.IO.Path.GetFileName(zipFilePath);
                                            var searchPattern = System.IO.Path.GetFileNameWithoutExtension(zipFilePath) + "*";
                                            ZipPackage.ZIPDecompress(sourceDir, desPath, zipfileName, searchPattern);

                                            hasReceived = true;
                                        }
                                        else
                                        {
                                            ZipPackage.Unzip(zipFilePath, System.IO.Path.Combine(targetPath, unzipToDir));
                                            hasReceived = true;

                                            if (isDeploy)
                                            {
                                                //auto copy
                                                this.Dispatcher.Invoke(DispatcherPriority.Normal, (ThreadStart) delegate()
                                                {
                                                    UpdateManage w = new UpdateManage();
                                                    w.UpdateAll();
                                                });
                                                isDeploy = false;
                                            }
                                        }
                                    }
                                    this.Dispatcher.Invoke(DispatcherPriority.Normal, (ThreadStart) delegate()
                                    {
                                        ShowMessage($"收取文件成功,当前MessageId:{i}");
                                    });
                                }
                            }
                        }
                    }
                }
            });
        }