コード例 #1
0
        public async static Task getSystemVersions(cServer ShareServer)
        {
            if (XMLSystemState == null)
            {
                using (var ftp = new cFTP(ShareServer, "APPS_CS"))
                {
                    var Item = new DirectoryItem()
                    {
                        Server      = ShareServer,
                        IsDirectory = false,
                        Name        = "systems.xml",
                        BaseUri     = new UriBuilder("ftp://" + ShareServer.IP.ToString() + "/APPS_CS").Uri
                    };
                    try
                    {
                        await ftp.DownloadItemAsync(Item, LOCAL_PATH + "systems.xml");
                    } catch (Exception ex)
                    {
                        //debugBox.AppendText(ex.Message);
                    }

                    XMLSystemState = XDocument.Load(LOCAL_PATH + "systems.xml");
                }
            }
        }
コード例 #2
0
        public async Task Run()
        {
            Updater.RunningTasks++;
            try
            {
                using (var ftp = new cFTP(Values.ShareServerList[Values.COD3], ""))
                {
                    await ftp.DownloadItemAsync(UpdateItem.Item, UpdateItem.LocalPath.Replace("\\", "/"));
                }
                UpdateItem.Status = LogonItemUpdateStatus.UPDATED;
                Updater.SendMessage("PROGRESS", false, UpdateItem.AppBotCode);

                /*
                 * item.Parent.ChangeProgress(item.Parent.ProgressValue + 1);
                 *
                 * if (item.Parent.UpdatedItems.Count == item.Parent.Items.Count())
                 * {
                 *  item.Parent.SetStatus(AppBotStatus.UPDATED);
                 * }
                 */
                if (UpdateItem.zipFile) //if its special unzip it
                {
                    try
                    {
                        var _localPath = Path.GetDirectoryName(UpdateItem.AppPath);
                        if (Directory.Exists(_localPath))
                        {
                            Directory.Delete(_localPath, true);
                        }
                        //await (Task.Run(() => ZipFile.ExtractToDirectory(item.LocalPath, Values.LOCAL_PATH)));
                        using (ZipArchive archive = ZipFile.OpenRead(UpdateItem.LocalPath))
                        {
                            foreach (ZipArchiveEntry entry in archive.Entries)
                            {
                                if (entry.FullName.Substring(entry.FullName.Length - 1, 1) == "/")
                                {
                                    Directory.CreateDirectory(Path.Combine(Values.LOCAL_PATH, entry.FullName));
                                }
                                else
                                {
                                    entry.ExtractToFile(Path.Combine(Values.LOCAL_PATH, entry.FullName));
                                }
                            }
                        }
                        File.Delete(UpdateItem.LocalPath);
                    }
                    catch (Exception ex)
                    {
                        Updater.SendError(string.Format("Error {0}\n", ex.Message), true, UpdateItem.AppBotCode);
                        UpdateItem.Status = LogonItemUpdateStatus.ERROR;
                    }
                }
                Updater.SendMessage("UPDATED", false, UpdateItem.AppBotCode);
            }
            catch (WebException ex)
            {
                Updater.SendError(string.Format("Error {0}\n", ex.InnerException.Message), true, UpdateItem.AppBotCode);
                UpdateItem.Status = LogonItemUpdateStatus.ERROR;

                /*
                 * CTWin.MsgError(ex.Message + "\n" + ex.InnerException.Message);
                 * if (null != item)
                 * {
                 *  item.Status = LogonItemUpdateStatus.ERROR;
                 *  item.Parent.SetStatus(AppBotStatus.ERROR);
                 * }
                 */
            }
            catch (InvalidOperationException ex)
            {
                Updater.SendError(string.Format("Error {0}\n", ex.InnerException.Message ?? ex.Message), true, UpdateItem.AppBotCode);
                UpdateItem.Status = LogonItemUpdateStatus.ERROR;

                /*
                 * CTWin.MsgError(ex.InnerException.Message ?? ex.Message);
                 * if (debug != null)
                 * {
                 *  AppendDebugText(string.Format("Thread {0} Done.\n", NumThread));
                 *  Values.ActiveThreads--;
                 *  if (Values.ActiveThreads == 1)
                 *      break;
                 *  this.Dispose();
                 * }
                 */
                System.Threading.Thread.Sleep(500);
            }
            catch (Exception ex)
            {
                Updater.SendError(string.Format("Error {0}\n", ex.InnerException.Message ?? ex.Message), true, UpdateItem.AppBotCode);
                UpdateItem.Status = LogonItemUpdateStatus.ERROR;

                /*
                 * CTWin.MsgError(ex.InnerException.Message ?? ex.Message);
                 * if (debug != null)
                 * {
                 *  AppendDebugText(string.Format("Thread {0} Waiting {1}\n", NumThread, ex.Message));
                 * }
                 */
                System.Threading.Thread.Sleep(500);
            }
            Updater.RunningTasks--;
        }