示例#1
0
        // Конструкторы
        #region Конструкторы

        public MainWindow()
        {
            InitializeComponent();
            this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            m_Tasks = new ObservableCollection<MyTask>();
            m_TasksCounter = 0;
            m_CurrentTask = null;
            m_OutputStringBuilder = new MyStringBuilder();
            m_StatusBarMessage = String.Empty;
            //m_CurrentTaskId = 0;
            //m_NumOfTasksToComplete = 0;

            Properties.Settings.Default.TempDirectory = System.IO.Path.Combine(System.IO.Path.GetTempPath(),
                "GDAL_GUI_TEMP_THUMBNAILS");
            System.IO.Directory.CreateDirectory(Properties.Settings.Default.TempDirectory);

            TaskManager.InitializeProcessManager(this);
            TaskManager.SetDataReceivedHandler = OutputDataRecieved;

            // Привязка StringBuilder к TextBlock
            Binding myBinding = new Binding();
            myBinding.Path = new PropertyPath("Text");
            myBinding.Mode = BindingMode.OneWay;
            myBinding.Source = m_OutputStringBuilder;
            myBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            TextBox_OutputData.SetBinding(TextBox.TextProperty, myBinding);

            Binding myBindingStatusBar = new Binding();
            myBindingStatusBar.Path = new PropertyPath("StatusBarMessage");
            myBindingStatusBar.Mode = BindingMode.TwoWay;
            myBindingStatusBar.Source = this;
            myBindingStatusBar.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            //StatusBar_Label.SetBinding(Label.ContentProperty, myBindingStatusBar);
            StatusBar_TextBlock.SetBinding(TextBlock.TextProperty, myBindingStatusBar);

            Binding myBindingProgressBar = new Binding();
            myBindingProgressBar.Path = new PropertyPath("ProgressBarValue");
            myBindingProgressBar.Mode = BindingMode.TwoWay;
            myBindingProgressBar.Source = this;
            myBindingProgressBar.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            StatusBar_ProgressBar.SetBinding(ProgressBar.ValueProperty, myBindingProgressBar);

            Binding myBindingCurrentTaskIdTextBlock = new Binding();
            myBindingCurrentTaskIdTextBlock.Path = new PropertyPath("StatusBarCurrentTaskId");
            myBindingCurrentTaskIdTextBlock.Mode = BindingMode.TwoWay;
            myBindingCurrentTaskIdTextBlock.Source = this;
            myBindingCurrentTaskIdTextBlock.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            StatusBar_TextBlock_CurrentTaskId.SetBinding(TextBlock.TextProperty, myBindingCurrentTaskIdTextBlock);

            Binding myBindingNumOfTasksToComplete = new Binding();
            myBindingNumOfTasksToComplete.Path = new PropertyPath("StatusBarNumOfTasksToComplete");
            myBindingNumOfTasksToComplete.Mode = BindingMode.TwoWay;
            myBindingNumOfTasksToComplete.Source = this;
            myBindingNumOfTasksToComplete.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            StatusBar_TextBlock_NumOfTasksToComplete.SetBinding(TextBlock.TextProperty, myBindingNumOfTasksToComplete);

            EventAndPropertiesInitialization();
        }
示例#2
0
        // Методы
        #region Методы

        public static void InitializeProcessManager(MainWindow mainWindow)
        {
            m_MainWindow = mainWindow;
            m_TaskCounter = 0;
            m_Tasks = null;
            m_CurrentTask = null;
            m_DataReceivedHandler = null;
            m_RunMode = RunMode.All;
            m_IsCurrentlySomeTaskRunning = false;
        }
示例#3
0
 public TaskElement(MainWindow mainWindow, MyTask task, int processId)
 {
     InitializeComponent();
     m_MainWindow = mainWindow;
     m_ParentTask = task;
     m_TaskID = processId;
     m_IsCurrent = false;
     m_TaskElementState = TaskElementState.Normal;
     m_PreviousTaskElementState = m_TaskElementState;
     SetBackgroundBrush = TaskElement.m_NormalStateBrush;
     EventsAndOtherSettings();
 }
示例#4
0
        public TaskElement(TaskElement copy, SelectTaskDialogWindow selectTaskDialogWindow)
        {
            InitializeComponent();
            this.m_MainWindow = null;
            this.m_SelectTaskDialogWindow = selectTaskDialogWindow;
            this.m_ParentTask = copy.m_ParentTask;
            this.m_TaskID = copy.m_TaskID;
            this.m_IsCurrent = false;
            this.m_TaskElementState = TaskElementState.Normal;
            this.m_PreviousTaskElementState = m_TaskElementState;
            this.SetBackgroundBrush = TaskElement.m_NormalStateBrush;

            this.SetImageToImagePreviewElement(this.m_ParentTask.ThumbnailPath);
            this.SetTaskIDToLabel(this.m_TaskID);
            this.SetUtilityNameToLabel(this.m_ParentTask.UtilityName);
            this.SetFileNameToLabelAndToolTip(this.m_ParentTask.SrcFileName);
            this.SetTaskElementState(TaskElementState.Normal);

            this.MouseEnter += new MouseEventHandler(taskElement_MouseEnter);
            this.MouseLeave += new MouseEventHandler(taskElement_MouseLeave);
            this.MouseLeftButtonDown += new MouseButtonEventHandler(taskElement_MouseLeftButtonDown_SelectTaskDialog);
            this.image_SrcImagePreview.MouseEnter += new MouseEventHandler(Image_SrcImagePreview_MouseEnter);
            this.image_SrcImagePreview.MouseLeave += new MouseEventHandler(Image_SrcImagePreview_MouseLeave);

            Binding myBinding = new Binding();
            myBinding.Path = new PropertyPath("SetBackgroundBrush");
            myBinding.Mode = BindingMode.TwoWay;
            myBinding.Source = this;
            myBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            this.SetBinding(UserControl.BackgroundProperty, myBinding);
        }
示例#5
0
 public static void RunAll()
 {
     if (m_IsCurrentlySomeTaskRunning)
     {
         MessageBox.Show("В данный момент выполняется задача №" + m_CurrentTask.GetTaskID +
                         Environment.NewLine + "Запуск задач отменён.");
         return;
     }
     if (m_Tasks == null || m_Tasks.Count == 0)
     {
         System.Windows.MessageBox.Show("Отсутствуют задачи!", "Ошибка!",
             System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
         return;
     }
     //m_Tasks[0].StartProcess();
     m_RunMode = RunMode.All;
     m_CurrentTask = m_Tasks[0];
     m_CurrentTask.SubscribeOutputDataAndErrorReceivedHandler(m_DataReceivedHandler);
     m_MainWindow.StatusBarNumOfTasksToComplete = m_Tasks.Count;
     m_MainWindow.StatusBarCurrentTaskId = m_TaskCounter;
     m_TaskCounter++;
     m_IsCurrentlySomeTaskRunning = true;
     m_MainWindow.SetBordersForProgressBar(m_Tasks.Count);
     m_MainWindow.ProgressBarValue = 0;
     Execution(m_CurrentTask);
 }
示例#6
0
        public static void GetExitedTask(MyTask task, int exitCode)
        {
            m_CurrentTask = task;
            if (exitCode == 0)
            {
                m_CurrentTask.SetStateOfTask(MyTask.TaskState.Completed);
                m_CurrentTask.UnubscribeOutputDataAndErrorReceivedHandler(m_DataReceivedHandler);
                m_MainWindow.SendMessageToTextBox("Задача № " + task.GetTaskID.ToString() +
                    " выполнена!");
            }
            else
            {
                m_CurrentTask.SetStateOfTask(MyTask.TaskState.Error);
                m_CurrentTask.UnubscribeOutputDataAndErrorReceivedHandler(m_DataReceivedHandler);
                m_MainWindow.SendMessageToTextBox("Задача № " + task.GetTaskID.ToString() +
                    " завершилась с ошибкой!");
            }

            if (m_RunMode == RunMode.All)
            {
                if (m_TaskCounter < m_Tasks.Count)
                {
                    m_CurrentTask = m_Tasks[m_Tasks.IndexOf(m_CurrentTask) + 1];
                    m_CurrentTask.SubscribeOutputDataAndErrorReceivedHandler(m_DataReceivedHandler);
                    m_MainWindow.ProgressBarValue = m_TaskCounter;
                    m_MainWindow.StatusBarCurrentTaskId = m_TaskCounter;
                    m_TaskCounter++;
                    m_IsCurrentlySomeTaskRunning = true;
                    
                    Execution(m_CurrentTask);
                }
                else
                {
                    m_TaskCounter = 0;
                    m_IsCurrentlySomeTaskRunning = false;
                    m_MainWindow.SendMessageToTextBox(Environment.NewLine + 
                        "Все задачи выполнены!" + Environment.NewLine + 
                        "Время завершения: " + DateTime.Now.ToString());
                    m_MainWindow.StatusBarMessage = "Все задачи завершены";
                    m_MainWindow.ProgressBarValue = m_Tasks.Count;
                    m_MainWindow.StatusBarCurrentTaskId = m_Tasks.Count;
                }
            }
            else if (m_RunMode == RunMode.Selected)
            {
                m_IsCurrentlySomeTaskRunning = false;
                m_MainWindow.SendMessageToTextBox(Environment.NewLine +
                        "Выбранная задача выполнена!" + Environment.NewLine +
                        "Время завершения: " + DateTime.Now.ToString());
                m_MainWindow.StatusBarMessage = "Все задачи завершены";
                m_MainWindow.ProgressBarValue = 1.0d;
                m_MainWindow.StatusBarCurrentTaskId = 1;
            }
        }
示例#7
0
        private static void Execution(MyTask task)
        {
            if (task == null)
            {
                m_IsCurrentlySomeTaskRunning = false;
                return;
            }
            m_MainWindow.SendMessageToTextBox(Environment.NewLine + 
                "\t\tЗапуск задачи № " + task.GetTaskID.ToString() + 
                Environment.NewLine + "\tВремя запуска: " + DateTime.Now.ToString() +
                Environment.NewLine + "\tСформированная строка с аргументами:" + Environment.NewLine + 
                m_CurrentTask.ParametersString + Environment.NewLine +
                "\tВывод утилиты:");
            m_MainWindow.StatusBarMessage = "Выполняется задача № " + task.GetTaskID;

            task.StartProcess();
        }
示例#8
0
 // Удаление всех задач
 private void Menu_Edit_RemoveAllTasks_Click(object sender, RoutedEventArgs e)
 {
     //MessageBox.Show("Заглушка. Menu_Edit_RemoveAllTasks_Click");
     if (m_Tasks != null && m_Tasks.Count > 0 )
     {
         m_Tasks.Clear();
         m_CurrentTask = null;
         StackPanel_TaskElements.Children.Clear();
         MessageBox.Show("Все задачи удалены.", "Успех!",
             MessageBoxButton.OK, MessageBoxImage.Information);
     }
     else
     {
         MessageBox.Show("Нечего удалять.");
     }
 }
示例#9
0
 // Запуск одного выбранного задания
 private void Menu_Run_RunSelected_Click(object sender, RoutedEventArgs e)
 {
     RunSelectedTask(m_CurrentTask);
     m_CurrentTask = null;
     /*
     if (m_CurrentTask == null)
     {
         MessageBox.Show("Не выбрана задача!", "Ошибка!", MessageBoxButton.OK, MessageBoxImage.Error);
         return;
     }
     TaskManager.TasksCollection = m_Tasks;
     TaskManager.RunSelected(m_CurrentTask);
     */
 }
示例#10
0
 public void RemoveTask(MyTask task)
 {
     if (m_Tasks != null && m_Tasks.Count > 0 && task != null)
     {
         if (m_CurrentTask == task)
         {
             m_Tasks.Remove(m_CurrentTask);
             m_CurrentTask = null;
             MessageBox.Show("Выбранная задача удалена.", "Успех!",
                 MessageBoxButton.OK, MessageBoxImage.Information);
         }
         else
         {
             m_Tasks.Remove(task);
             MessageBox.Show("Задача удалена.", "Успех!",
                 MessageBoxButton.OK, MessageBoxImage.Information);
         }
     }
     else
     {
         MessageBox.Show("Нечего удалять.");
     }
 }
示例#11
0
 public void RunSelectedTask(MyTask task)
 {
     if (task == null)
     {
         MessageBox.Show("Не выбрана задача!", "Ошибка!", MessageBoxButton.OK, MessageBoxImage.Error);
         return;
     }
     TaskManager.TasksCollection = m_Tasks;
     TaskManager.RunSelected(task);
 }
示例#12
0
        public void ReplaceEditedTask(MyTask task)
        {
            if (task == null)
            {
                return;
            }
            if (m_CurrentTask == task)
            {
                m_CurrentTask = null;
                task.GetTaskElement.IsCurrent = false;
            }
            int index = m_Tasks.IndexOf(m_Tasks.FirstOrDefault(x => x.GetTaskID == task.GetTaskID));
            task.GetTaskElement.SetTaskElementState(TaskElement.TaskElementState.Normal);
            task.GetTaskElement.SetPreviousState();
            
            //m_Tasks.Insert(index, task);
            //m_Tasks.Remove(m_Tasks.Where(x => x.GetTaskID == task.GetTaskID).First());
            //m_Tasks.Add(task);

            m_Tasks.RemoveAt(index);
            m_Tasks.Insert(index, task);
        }
示例#13
0
 public void EditSelectedTask(MyTask task)
 {
     if (m_Tasks != null && m_Tasks.Count > 0 && task != null)
     {
         TaskEditWindow taskEditWindow = new TaskEditWindow(this, task);
         taskEditWindow.ShowDialog();
     }
     else
     {
         MessageBox.Show("Нечего редактировать.");
     }
 }
示例#14
0
 // Добавляет переданную задачу и инкремирует счётчик
 public void AddNewTask(MyTask task)
 {
     if (task == null)
     {
         return;
     }
     m_Tasks.Add(task);
     m_TasksCounter++;
 }
示例#15
0
        // Конструкторы
        #region Конструкторы
        public TaskEditWindow(MainWindow mainWindow)
        {
            InitializeComponent();
            this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            
            m_MainWindow = mainWindow;
            m_Task = new MyTask(m_MainWindow);
            m_IsThisTaskAdded = false;
            m_UtilitiesNames = new List<string>();
            m_UtilityParameters = new List<MyDataRow>();
            m_CurrentMode = InputMode.OneFile;
            m_FormedParametersArgument = String.Empty;
            m_AdditionalParametersInputs = new List<DataTable>();
            m_TaskEditWindowMode = TaskEditWindowMode.NewTask;
            m_InputModeChoices = new Dictionary<InputMode, string>();
            m_InputFiles = new List<string>();

            // Инициализируем экземпляр процесса, чтобы узнавать версии утилит
            m_ProcessForVersion = new Process();
            m_ProcessForVersion.StartInfo.UseShellExecute = false;
            m_ProcessForVersion.StartInfo.CreateNoWindow = true;
            m_ProcessForVersion.StartInfo.RedirectStandardOutput = true;
            m_ProcessForVersion.StartInfo.Arguments = "--version";
            m_ProcessForVersion.OutputDataReceived += new DataReceivedEventHandler(ProcessForVerion_DataReceived);

            EventAndPropertiesInitialization();
            ConnectToDbAndGetNecessaryData();
        }
示例#16
0
 private void MakeTask(int index)
 {
     if (m_TaskEditWindowMode == TaskEditWindowMode.NewTask)
     {
         m_Task = new MyTask(m_MainWindow);
     }
     m_Task.BeginEdit();
     m_Task.ParametersString = m_FormedParametersArgument;
     m_Task.UtilityName = ComboBox_UtilitiesNames.SelectedItem.ToString();
     m_Task.SrcFileName = m_InputFiles[index];
     if (m_ThumbnailsPaths != null)
     {
         m_Task.ThumbnailPath = m_ThumbnailsPaths[index];
     }
     else
     {
         m_Task.ThumbnailPath = String.Empty;
     }
     m_Task.IsThereOutput = (bool)m_UtilityInfo["IsThereOutput"];
     if (m_Task.IsThereOutput == true)
     {
         int dst_Position =
             (int)m_UtilityParameters.First(
                 x => x.GetDataRow["NameOfTheParameter"].ToString() == "dst_dataset").GetDataRow["PositionIndex"];
         m_Task.OutputPath = m_AllParameters[dst_Position];
     }
     else
     {
         m_Task.OutputPath = String.Empty;
     }
     m_Task.EndEdit();
 }