示例#1
0
        private void ExecuteAction(string urlTbText, string dbName, string selectedFolderText, string fileName, ActionList action)
        {
            Check(urlTbText, dbName, selectedFolderText, fileName, action);
            ExecuteBtn.IsEnabled = false;
            CheckBtn.IsEnabled   = false;
            GetLastBtn.IsEnabled = false;
            ClearBtn.IsEnabled   = false;
            GetAllBtn.IsEnabled  = false;

            Logger.Log.InfoFormat("--- Выполняется операция {0} ---", action);

            if (!string.IsNullOrEmpty(urlTbText) && !string.IsNullOrEmpty(dbName))
            {
                var thread = new Thread(() =>
                {
                    string path;
                    switch (action)
                    {
                    case ActionList.CreateNewBackup:
                        path = Path.Combine(selectedFolderText, fileName);
                        _requestSender.InvokeAction(urlTbText, dbName, path, action);
                        break;

                    case ActionList.CheckExistFile:
                        _requestSender.InvokeAction(urlTbText, dbName, null, action);
                        break;

                    case ActionList.GetLastBackUp:
                        path = Path.Combine(selectedFolderText, fileName);
                        _requestSender.InvokeAction(urlTbText, dbName, path, action);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(action), action, null);
                    }

                    //if (data != null)
                    //{
                    //    FileUtils.SaveFile(data, selectedFolderText, fileName);
                    //    AddTextToConsole("Saved to " + selectedFolderText);
                    //}

                    ExecuteBtn?.Dispatcher?.Invoke(() => { ExecuteBtn.IsEnabled = true; });
                    CheckBtn?.Dispatcher?.Invoke(() => { CheckBtn.IsEnabled = true; });
                    GetLastBtn?.Dispatcher?.Invoke(() => { GetLastBtn.IsEnabled = true; });
                    ClearBtn?.Dispatcher?.Invoke(() => { ClearBtn.IsEnabled = true; });
                    GetAllBtn?.Dispatcher?.Invoke(() => { GetAllBtn.IsEnabled = true; });
                });
                thread.Start();
            }
        }
示例#2
0
 public async Task Execute(IJobExecutionContext context)
 {
     Logger.Log.Info("Выполнение задачи для планировщика.");
     Parallel.ForEach <ListItem>(_settings.List, listItem =>
     {
         if (!listItem.UseSchedule)
         {
             return;
         }
         var path = Path.Combine(_settings.DefaultPath, listItem.DbName);
         Logger.Log.InfoFormat("БД: {0}", listItem.DbName);
         Logger.Log.InfoFormat("URL: {0}", listItem.Url);
         Logger.Log.InfoFormat("Путь для сохранения: {0}", path);
         _requestSender.InvokeAction(listItem.Url, listItem.DbName, path, ActionList.CreateNewBackup);
     });
     Logger.Log.Info("Задача выполнена.");
 }