示例#1
0
        public void Drop(IDropInfo dropInfo)
        {
            ProgramToStart         sourceItem     = dropInfo.Data as ProgramToStart;       //dragged item
            ProgramToStart         targetItem     = dropInfo.TargetItem as ProgramToStart; //item on with user drops the sourceitem
            RelativeInsertPosition positionOfItem = dropInfo.InsertPosition;               //position (before or after targetItem)
            int insertIndex = dropInfo.InsertIndex;                                        //positon in ProgramsToStartList where item was dropped

            //Checking if item was dropped before or after targetItem and moving into correct position in ProgramsToStartList
            if (positionOfItem == (RelativeInsertPosition.BeforeTargetItem | RelativeInsertPosition.TargetItemCenter))
            {
                ProgramsToStartList.Move(sourceItem.StartingOrder - 1, insertIndex);
            }
            else
            {
                //Checking if new position is the last in the list - if it is last, put item in the last position
                //To prevent ArgumentOutOfRange Exception for ProgramsToStartList.Move()
                if (insertIndex == ProgramsToStartList.Count)
                {
                    ProgramsToStartList.Move(sourceItem.StartingOrder - 1, insertIndex - 1);
                }
                else
                {
                    ProgramsToStartList.Move(sourceItem.StartingOrder - 1, insertIndex);
                }
            }

            //After source Item was moved to the new position we need to update StartingOrder property of all ProgramsToStart
            UpdateStartingOrdersInProgramsToStartListView();

            //Then we need to refresh the ListView
            RefreshProgramsToStartListView();
        }
示例#2
0
 private void StartNowButtonClicked(object obj)
 {
     TimeToStart.Stop();
     if (ProgramsToStartList.Any())
     {
         ProgramsStartingProcedure();
     }
     else
     {
         ProgramsToStartListIsEmpty();
     }
 }
示例#3
0
 /// <summary>
 /// Timer_Tick event
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void GapCountTimer_Tick(object sender, EventArgs e)
 {
     //If there are still programs to start on the list then start the next one on the list
     if (CurrentProgramStartingOrder <= ProgramsToStartList.Count())
     {
         StartNextProgram();
     }
     //else stop the starting procedure
     else
     {
         IsStartupDone = true;
         GapCountTimer.Stop();
     }
 }
示例#4
0
        public StartProgramsViewModel()
        {
            //Assigning startup values for controls
            SecondsToStartTextBlockVisibility  = Visibility.Visible;
            StartAndDontStartButtonsVisibility = Visibility.Visible;
            ProgressBarVisibility                = Visibility.Collapsed;
            OptionsGridVisibility                = Visibility.Collapsed;
            FinalizeStartNoErrorsVisibility      = Visibility.Collapsed;
            FinalizeStartWithErrorsVisibility    = Visibility.Collapsed;
            ProgramsToStartListIsEmptyVisibility = Visibility.Collapsed;
            OptionsButtonContent          = "Options >>>";
            ProgramsToStartGridVisibility = Visibility.Collapsed;
            ProgramsToStartButtonContent  = "Programs to Start >>>";

            //Obtain configuration.xml path
            ObtainingConfigurationXMLPath();

            //Read all saved Programs from configuration file and assign them to ProgramsToStartList
            ReadingProgramsToStartCollection();

            //Read all options from configuration file and assign them to proper variables
            ReadingOptionsToVariables();


            //Binding for buttons
            StartNowButtonCommand                = new RelayCommand(StartNowButtonClicked);
            DontStartButtonCommand               = new RelayCommand(DontStartButtonClicked);
            CancelButtonCommand                  = new RelayCommand(CancelButtonClicked);
            OptionsButtonCommand                 = new RelayCommand(OptionsButtonClicked);
            ProgramsToStartButtonCommand         = new RelayCommand(ProgramsToStartButtonClicked);
            RemoveProgramFromProgramsToStartList = new RelayCommand(RemoveProgramContextMenuItemClicked);
            AddProgramToProgramsToStartList      = new RelayCommand(AddProgramContextMenuItemClicked);
            SaveButtonCommand     = new RelayCommand(SaveButtonClicked);
            TryAgainButtonCommand = new RelayCommand(TryAgainButtonClicked);
            ErrorLogButtonCommand = new RelayCommand(ErrorLogButtonClicked);
            ThankYouButtonCommand = new RelayCommand <Window>(ThankYouButtonClicked);

            //Check if ProgramsToStartList is not empty then start counting seconds to start
            if (ProgramsToStartList.Any())
            {
                //Start counting seconds to start and begin startin procedure of programs when countdown is done
                CountingSecondsToStart();
            }
            else
            {
                //Inform User that list is empty
                ProgramsToStartListIsEmpty();
            }
        }
示例#5
0
        private void TryAgainButtonClicked(object obj)
        {
            //Setting proper visibility
            FinalizeStartNoErrorsVisibility   = Visibility.Collapsed;
            FinalizeStartWithErrorsVisibility = Visibility.Collapsed;

            //Start programs again
            if (ProgramsToStartList.Any())
            {
                ProgramsStartingProcedure();
            }
            else
            {
                ProgramsToStartListIsEmpty();
            }
        }
示例#6
0
        /// <summary>
        /// This method is a starting procedure for all programs in the list
        /// </summary>
        private void ProgramsStartingProcedure()
        {
            //changing values of controls and assigning startup values
            SecondsToStartTextBlockVisibility    = Visibility.Collapsed;
            StartAndDontStartButtonsVisibility   = Visibility.Collapsed;
            ProgramsToStartListIsEmptyVisibility = Visibility.Collapsed;
            ProgressBarVisibility       = Visibility.Visible;
            PercentageOfStartedPrograms = "0";

            //Start of 1 sec timer for refreshing values for UI
            Refresh1sec.Interval = TimeSpan.FromSeconds(1);
            Refresh1sec.Tick    += Refresh1sec_Tick;
            Refresh1sec.Start();

            //Starting Procedure
            startingProcedure = new StartingProgramsHandler(ProgramsToStartList.ToList(), Gap_Between_Programs);
            Task.Run(() => startingProcedure.Start());
        }
示例#7
0
        /// <summary>
        /// Begining starting procedure for all programs in the list
        /// </summary>
        public void Start()
        {
            //if programs list is not empty then begin starting programs
            if (ProgramsToStartList.Any())
            {
                //Start first program in the list
                StartNextProgram();

                //Start GapCountTimer and every timer tick next program will be started
                GapCountTimer.Start();
            }
            //if list is empty then don't begin starting programs and update ErrorLog
            else
            {
                HasErrors     = true;
                IsStartupDone = true;
                ErrorLog log = new ErrorLog(DateTime.Now, LogNameProgramStarter, LogNameStartingProgramsHandler, "List of programs to start is empty!");
                ErrorsList.Add(log);
            }
        }
示例#8
0
        public void RefreshProgramsToStartListView()
        {
            //
            //TODO: This is a temporary solution, need to figure out how to refresh ListView without clearing whole list
            ObservableCollection <ProgramToStart> _temp = new ObservableCollection <ProgramToStart>();

            foreach (ProgramToStart item in ProgramsToStartList)
            {
                ProgramToStart insert = new ProgramToStart(item.ProgramName, item.Path);
                insert.StartingOrder = item.StartingOrder;
                _temp.Add(insert);
            }

            ProgramsToStartList.Clear();
            foreach (ProgramToStart item in _temp)
            {
                ProgramToStart insert = new ProgramToStart(item.ProgramName, item.Path);
                insert.StartingOrder = item.StartingOrder;
                ProgramsToStartList.Add(insert);
            }
        }
示例#9
0
        /// <summary>
        /// This method is starting next program in the list, calculating PercentOfStartedPrograms and incrementing CurrentProgramStartingOrder
        /// </summary>
        private void StartNextProgram()
        {
            //Start program
            ProgramToStart program = ProgramsToStartList.Where(p => p.StartingOrder == CurrentProgramStartingOrder).FirstOrDefault();
            string         path    = ProgramsToStartList.Where(p => p.StartingOrder == CurrentProgramStartingOrder).Select(x => x.Path).FirstOrDefault().ToString();

            try
            {
                StartProgram(path);
            }
            catch (Exception ex)
            {
                HasErrors = true;
                ErrorLog log = new ErrorLog(DateTime.Now, program.ProgramName, program.Path, ex.ToString());
                ErrorsList.Add(log);
            }

            //Calculate percentage of started programs
            PercentOfStartedPrograms = ((float)CurrentProgramStartingOrder / ProgramsToStartList.Count()) * 100;

            //Increment CurrentProgramStartingOrder
            CurrentProgramStartingOrder++;
        }
示例#10
0
        private void AddProgramContextMenuItemClicked(object obj)
        {
            //TODO: This is breaking the MVVM concept, need to figure out how to this in MVVM style
            OpenFileDialog openFileDialog = new OpenFileDialog();

            if (openFileDialog.ShowDialog() == true)
            {
                ProgramToStart program = new ProgramToStart(openFileDialog.SafeFileName, openFileDialog.FileName);

                //check if user clicked on program or on some empty field in ListView
                //if user clicked on program then insert new program before the selected item
                if (SelectedProgramOnProgramsToStartListView != null)
                {
                    ProgramsToStartList.Insert(SelectedProgramOnProgramsToStartListView.StartingOrder - 1, program);
                }
                else //if user clicked on some empty field then add new program at the end of the list
                {
                    ProgramsToStartList.Add(program);
                }

                UpdateStartingOrdersInProgramsToStartListView();
                RefreshProgramsToStartListView();
            }
        }
示例#11
0
 private void RemoveProgramContextMenuItemClicked(object obj)
 {
     ProgramsToStartList.Remove(SelectedProgramOnProgramsToStartListView);
     UpdateStartingOrdersInProgramsToStartListView();
     RefreshProgramsToStartListView();
 }