Esempio n. 1
0
        private async void BuildTotalChart()
        {
            foreach (var path in PathChecker.GetAllPaths())
            {
                var places = path.Split('-');
                if (places[0] == "C")
                {
                    places[0] = "";
                }
                var checker = new PathChecker(Paths.Count + 1, new BlaBlaCarRequestModel
                {
                    ApiKey    = ApiKeyController.CurrentKey,
                    Locale    = "uk_UA",
                    PlaceFrom = places[0],
                    PlaceTo   = places[1]
                });
                checker.OnMessage         += OnPathCheckerMessage;
                checker.OnPathHandlingEnd += OnPathHandlingEnd;
                if (Paths.All(p => p.Request.ToString() != path.ToString()))
                {
                    Paths.Add(checker);
                }
            }

            await BuildChart(Paths);
        }
Esempio n. 2
0
        public void AddFile(object param)
        {
            IOpenFileDialogService fbg = GetService <IOpenFileDialogService>();

            if (fbg != null)
            {
                if (DialogResult.OK == fbg.Show("Please choose your awesome track", "Amazing Track", Helper.GetMultipleFilter("Supported Formats", musicFileFilters), true))
                {
                    string[] selectedPaths = fbg.SelectedPaths;
                    foreach (string selectedPath in selectedPaths)
                    {
                        // Check if such directory exists, and check if such directory wasn't already introduced
                        if (!string.IsNullOrEmpty(selectedPath) && Paths.All(folder => selectedPath != folder.Path))
                        {
                            if (Directory.Exists(selectedPath))
                            {
                                Paths.Add(new Item {
                                    Path = selectedPath, Count = -1, IsFolder = true
                                });
                            }
                            else if (File.Exists(selectedPath))
                            {
                                Paths.Add(new Item {
                                    Path = selectedPath, Count = 1, IsFolder = false
                                });
                            }
                        }
                    }
                }
            }

            if (param != null)
            {
                if (File.Exists(param as string))
                {
                    string extension = Path.GetExtension(param as string);
                    if (musicFileFilters.Where(filter => extension != null).Any(filter => filter.Contains(extension)))
                    {
                        Paths.Add(new Item {
                            Path = param as string, Count = 1, IsFolder = false
                        });
                    }
                }
            }
        }
Esempio n. 3
0
 static bool AllExist(params string[] Paths)
 {
     return(Paths.All(ServiceProvider.FileExists));
 }
Esempio n. 4
0
        public void AddMoreFolders(object param)
        {
            IFolderBrowserDialogService fbg = GetService <IFolderBrowserDialogService>();

            if (fbg != null)
            {
                if (DialogResult.OK == fbg.Show())
                {
                    string selectedPath = fbg.SelectedPath;

                    // Check if such directory exists, and check if such directory wasn't already introduced
                    if (!string.IsNullOrEmpty(selectedPath) && Paths.All(folder => selectedPath != folder.Path))
                    {
                        if (Directory.Exists(selectedPath))
                        {
                            Paths.Add(new Item {
                                Path = selectedPath, Count = -1, IsFolder = true
                            });
                        }
                        else if (File.Exists(selectedPath))
                        {
                            Paths.Add(new Item {
                                Path = selectedPath, Count = 1, IsFolder = false
                            });
                            return;
                        }
                        else
                        {
                            return;
                        }

                        // count the number of available music files asynchronously
                        Task.Factory.StartNew(
                            () =>
                        {
                            int count = Helper.CountNumberOfMusicFiles(selectedPath, musicFileFilters);

                            lock (LockObject)
                            {
                                int index = -1;
                                foreach (Item path in Paths)
                                {
                                    index++;
                                    if (path.Path == selectedPath)
                                    {
                                        break;
                                    }
                                }

                                if (Paths != null && Paths.Count >= index && index >= 0)
                                {
                                    totalMusicItems   += count;
                                    Paths[index].Count = count;
                                }
                            }
                        }).ContinueWith(
                            task => CommandManager.InvalidateRequerySuggested(), TaskScheduler);
                    }
                }
            }
        }