Exemple #1
0
        private void Delete()
        {
            var x = VisualFileList.IndexOf(SelectFile);

            VisualFileList.RemoveAt(x);
            FileList.RemoveAt(x);
            _mainViewmodel.ListData.RemoveAt(x);
        }
Exemple #2
0
        private void OpenFiles()
        {
            string FilePath = "";

            try
            {
                var dialog = new OpenFileDialog();
                dialog.ValidateNames   = false;
                dialog.CheckFileExists = false;
                dialog.CheckPathExists = true;
                dialog.FileName        = "default";
                dialog.Filter          = "All files|*.*|Xml files(*.xml)|*.xml|Text files(*.txt)|*.txt|Json files(*.json)|*.json";
                dialog.ShowDialog();

                string Path = System.IO.Path.GetFullPath(dialog.FileName);
                Path     = Path.Replace("default", "").Trim();
                FilePath = Path;

                string[] parser = Path.Split('.');
                Console.WriteLine(Path);

                if (parser.Length == 2)
                {
                    if (parser[1] == "xml")
                    {
                        XmlPath = Path;
                        FileList.Add(XmlPath);
                        string   temp      = XmlPath;
                        string[] fileparse = temp.Split('\\');
                        VisualFileList.Add(fileparse[fileparse.Length - 1]);
                        fileParsing(XmlPath);
                    }
                    else if (parser[1] == "txt")
                    {
                        TxtPath = Path;
                        FileList.Add(TxtPath);
                        string   temp      = TxtPath;
                        string[] fileparse = temp.Split('\\');
                        VisualFileList.Add(fileparse[fileparse.Length - 1]);
                        fileParsing(TxtPath);
                    }
                    else if (parser[1] == "json")
                    {
                        JsonPath = Path;
                        FileList.Add(JsonPath);
                        string   temp      = JsonPath;
                        string[] fileparse = temp.Split('\\');
                        VisualFileList.Add(fileparse[fileparse.Length - 1]);
                        fileParsing(JsonPath);
                    }
                }
                else
                {
                    string[] parse = Path.Split('.');
                    Console.WriteLine(parse[0]);
                    string[] files = Directory.GetFiles(parse[0]);

                    foreach (string x in files)
                    {
                        FileList.Add(x);
                        string   temp      = x;
                        string[] fileparse = temp.Split('\\');
                        VisualFileList.Add(fileparse[fileparse.Length - 1]);
                        fileParsing(x);
                    }
                }
                logViewModel.AddLog(GetType(), Path);
            }

            catch (Exception ex)
            {
                logViewModel.FailLog(GetType(), FilePath);
                Console.WriteLine($"An exception occurred from {MethodBase.GetCurrentMethod().Name}");
                Console.WriteLine(ex.ToString());
            }
        }