Пример #1
0
        private void button_save_Click(object sender, RoutedEventArgs e)
        {
            if (!Connection.CheckConnection())
            {
                indikacenetu();
                System.Windows.MessageBox.Show("No internet connection, please connect first");
            }
            else
            {
                if (dataGrid.Items.Count == 0)
                {
                    System.Windows.MessageBox.Show("No data available");
                }

                else
                {
                    using (var dialog = new System.Windows.Forms.FolderBrowserDialog())
                    {
                        dialog.SelectedPath = settingshandler.getStorageTB();
                        System.Windows.Forms.DialogResult result = dialog.ShowDialog();
                        if (result.ToString() == "OK")
                        {
                            settingshandler.setStorageTB(dialog.SelectedPath);
                            try
                            {
                                getter.SaveFile(settingshandler.getStorageTB(), GitFile.convertorToDict(dataGrid.SelectedItems.Cast <GitFile>().ToList(), getter.FilesChanges));
                                System.Windows.MessageBox.Show("Saved");
                            }
                            catch (ArgumentNullException ex)
                            {
                                System.Windows.MessageBox.Show("No data available");
                            }
                            catch (NullReferenceException ex)
                            {
                                System.Windows.MessageBox.Show("Error");
                            }
                        }
                    }
                }
            }


            //// Configure save file dialog box
            //Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            //dlg.FileName = "Document"; // Default file name
            //dlg.DefaultExt = ".text"; // Default file extension
            //dlg.Filter = "Text documents (.txt)|*.txt"; // Filter files by extension

            //// Show save file dialog box
            //Nullable<bool> result = dlg.ShowDialog();

            //// Process save file dialog box results
            //if (result == true)
            //{
            //    // Save document
            //    string filename = dlg.FileName;
            //}
        }
Пример #2
0
        //

        /**
         * convert dict to GitFile obj
         * return List<GitFile>
         */
        public static List <GitFile> convertorToList(IDictionary <string, List <string[]> > dict)
        {
            List <GitFile> result = new List <GitFile>();

            foreach (var dictItem in dict)
            {
                foreach (var item in dictItem.Value)
                {
                    GitFile gf = new GitFile(dictItem.Key, item[2], Int32.Parse(item[0]));
                    result.Add(gf);
                }
            }
            return(result);
        }
Пример #3
0
        private void OnTick(RepositoryGetter getter, DateTime currentDateTime)
        {
            //Task.Run(() => CheckingRepositoryPeriodicAsync(OnTick, dueTime, interval, cts.Token, getter).Wait());
            //CancellationToken.None
            //CheckingConnectionAsync(OnTick, dueTime, interval, CancellationToken.None);



            var k = "";

            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                MainWindow win = (MainWindow)Application.Current.MainWindow;
                win.lb_status_connect.Content    = (Connection.CheckConnection()) ? "Online" : "Offline";
                win.lb_status_connect.Foreground = win.lb_status_connect.Content.Equals("Online") ? Brushes.Green : Brushes.Red;
                if (win.lb_status_connect.Content.ToString() == "Offline")
                {
                    //Task.Run(() => CheckingRepositoryPeriodicAsync(OnTick, dueTime, interval, cts.Token, getter).Wait());
                    k = "Offline";
                    win.lb_status.Content    = "Failed";                                                                                           //CheckingConnectionAsync(OnTick, dueTime, interval, CancellationToken.None);
                    win.lb_status.Foreground = Brushes.Red;
                }
                else
                {
                    k = "Online";

                    win.lb_status.Content = "Searching...";
                }
            }));

            // load backup from file
            if (k == "Online")
            {
                if (getter.FilesChanges.Count() == 0)
                {
                    logger.Info("load backup from file");
                    getter.loadNewFilesChangesFromListString(Save.LoadBackupContentFromFile(getter.UserName + "_" + getter.RepoName + ".txt"));
                }
                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    MainWindow win = (MainWindow)Application.Current.MainWindow;
                    win.lb_status_connect.Content    = (Connection.CheckConnection()) ? "Online" : "Offline";
                    win.lb_status_connect.Foreground = win.lb_status_connect.Content.Equals("Online") ? Brushes.Green : Brushes.Red;
                    if (win.lb_status_connect.Content.ToString() == "Offline")
                    {
                        k = "Offline";
                        win.lb_status.Content    = "Failed";
                        win.lb_status.Foreground = Brushes.Red;
                    }

                    else
                    {
                        k = "Online";

                        win.lb_status.Content = "Searching...";
                    }
                }));
                if (k == "Online")
                {
                    logger.Info("searching files");
                    IDictionary <string, List <string[]> > filesExtensions = new Dictionary <string, List <string[]> >();
                    try
                    {
                        filesExtensions = getter.ChangedFiles(new DateTime(currentDateTime.Year, currentDateTime.Month,
                                                                           currentDateTime.Day, currentDateTime.Hour, currentDateTime.Minute, currentDateTime.Second)).Result;
                    }
                    catch (Exception ex)
                    {
                        Application.Current.Dispatcher.Invoke(new Action(() =>
                        {
                            MainWindow win                = (MainWindow)Application.Current.MainWindow;
                            win.lb_status.Content         = "Failed";
                            win.lb_status_connect.Content = (Connection.CheckConnection()) ? "Online" : "Offline";
                        }));
                    }


                    //var filesExtensions = getter.ChangedFiles(new DateTime(2016, 4, 19, 20, 22, 12)).Result;
                    //currentDateTime = new DateTime(2016, 4, 19, 20, 22, 12);

                    Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        MainWindow win = (MainWindow)Application.Current.MainWindow;
                        if (win.lb_status.Content != "Failed")
                        {
                            //win.dataGrid.ItemsSource = GitFile.convertor(filesExtensions);
                            win.dataGrid.ItemsSource = GitFile.convertorToList(filesExtensions).OrderByDescending(x => x.datetime);

                            foreach (GitFile item in win.dataGrid.ItemsSource)
                            {
                                var row = win.dataGrid.ItemContainerGenerator.ContainerFromItem(item) as DataGridRow;
                                if (row == null)
                                {
                                    win.dataGrid.UpdateLayout();
                                    row = win.dataGrid.ItemContainerGenerator.ContainerFromItem(item) as DataGridRow;
                                }
                                DateTime myDate = DateTime.ParseExact(item.datetime, "dd.MM.yyyy HH:mm:ss",
                                                                      System.Globalization.CultureInfo.InvariantCulture);
                                if (myDate >= currentDateTime)
                                {
                                    try
                                    {
                                        row.Background = Brushes.GreenYellow;
                                    }
                                    catch
                                    {
                                        //nevim proc je row nekdy null
                                    }
                                }
                            }

                            //save to file
                            logger.Info("save changes to file ");
                            Save.SaveDatagridContent(getter.UserName + "_" + getter.RepoName + ".txt", getter.FilesChanges);
                            win.lb_status.Content    = "Finished";
                            win.lb_status.Foreground = Brushes.Green;
                        }
                    }));
                }
            }
        }