public void Run(params string[] args_in) { var args = args_in.Skip(1).ToArray(); var playlists_folder = PhoneSystem.Root.GetParameterValue("IVRPROMPTPATH") + "/Playlist"; using (var all_playlists = PhoneSystem.Root.GetAllAudioFeeds().GetDisposer()) { if (args.Length == 0 || args[0] == "list") //no parameters. display all playlists { var playlists = all_playlists.Value .Where(x => x.Type == AudioFeedType.FolderRandomFeed || x.Type == AudioFeedType.FolderSortedFeed) .ToDictionary(x => x.Source); var configured_folders = new HashSet <string>(playlists.Keys); var all_folders = new HashSet <string>(Directory.EnumerateDirectories(playlists_folder).Select(x => Path.GetFileName(x))); var playlists_with_folders = configured_folders.Intersect(all_folders).ToArray(); var folders_without_playlist = all_folders.Except(configured_folders).ToArray(); try { foreach (var a in playlists) { bool folder_exists = playlists_with_folders.Contains(a.Value.Source); if (folder_exists) { //properly configured playlists Console.ForegroundColor = ConsoleColor.Green; } else { Console.ForegroundColor = ConsoleColor.Red; //misconfigured } Console.WriteLine("Name={0}, Source={1}, Shuffle={2}, AutoGain={3}, MaxVolume={4}% NoNStop={5}:\n{{\n\t{6}\n}}", a.Value.Name, //{0] a.Value.Source, //{1} a.Value.Type == AudioFeedType.FolderRandomFeed, //{2} a.Value.AutoGain, //{3} a.Value.MaxVolume, //{4} a.Value.NoPauseIfEmpty, //{5} folder_exists ? string.Join("\n\t", Directory.EnumerateFiles(playlists_folder + "/" + a.Value.Source).ToArray()) : "" //{6} ); } Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Other folders:\n{0}", string.Join("\t\n", folders_without_playlist.ToArray()) ); } finally { Console.ResetColor(); } return; } //parsing parameters string name = null; string source = null; bool autogaincollected = false; bool autogain = false; bool volumecollected = false; int MaxVolume = 0; bool shufflecollected = false; bool nonstop = false; bool nonstopcollected = false; AudioFeedType shuffle = AudioFeedType.FolderSortedFeed; switch (args[0]) { case "create": case "update": case "delete": { foreach (var a in args.Skip(1).ToArray()) { if (a.StartsWith("name=")) { name = string.Join("=", a.Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries).Skip(1).ToArray()); continue; } if (a.StartsWith("source=")) { source = string.Join("=", a.Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries).Skip(1).ToArray()); continue; } if (a.StartsWith("volume=")) { volumecollected = true; MaxVolume = int.Parse(a.Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries)[1]); continue; } if (a == "autogain" || a == "no-autogain") { autogaincollected = true; autogain = a == "autogain"; continue; } if (a == "shuffle" || a == "sorted") { shufflecollected = true; shuffle = a == "shuffle" ? AudioFeedType.FolderRandomFeed : AudioFeedType.FolderSortedFeed; continue; } if (a == "no-stopempty" || a == "stopempty") { nonstopcollected = true; nonstop = a == "no-stopempty"; continue; } Console.WriteLine($"unrecognized parameter: {a}"); return; } } break; default: Console.WriteLine($"unknown option {args[0]}"); return; } //search for feed object or create new AudioFeed theFeed = null; switch (args[0]) { case "create": { if (source == null && name == null) { Console.WriteLine("Insufficiend parameters"); return; } if (source != null && PhoneSystem.Root.GetAllAudioFeeds().Any(x => x.Source.Equals(source))) { Console.WriteLine("Source already bound"); return; } if (name != null && PhoneSystem.Root.GetAllAudioFeeds().Any(x => x.Source.Equals(source))) { Console.WriteLine("Source already bound"); return; } string chars = "abcdefghijklmnopqrstuvwxyz0123456789"; if (name == null) { var a = new Random((int)DateTime.Now.Ticks); name = name + chars[a.Next(26)]; for (int i = 0; i < 8; i++) { name += chars[a.Next(chars.Length)]; } } if (!name.All(x => chars.Contains(x)) || Char.IsDigit(name[0])) { Console.WriteLine("Invalid name"); return; } if (source == null) { source = name; } theFeed = PhoneSystem.Root.CreateAudioFeed(); } break; case "update": case "delete": { if (name != null) { theFeed = all_playlists.FirstOrDefault(x => x.Name == name); } else { theFeed = all_playlists.First(x => x.Source == source); if (name != null && name != theFeed.Name) { theFeed = null; } else { name = theFeed.Name; } } } break; default: Console.WriteLine($"unknown option {args[0]}"); break; } if (theFeed == null) { Console.WriteLine("Not found"); } switch (args[0]) { case "create": { var folder_path = Path.Combine(playlists_folder, source); if (!Directory.Exists(folder_path)) { Console.WriteLine($"Creating new directory {folder_path}"); Directory.CreateDirectory(folder_path); } else { Console.WriteLine($"Directory {folder_path} already exists."); } theFeed.Source = source; theFeed.Name = name; theFeed.Type = shuffle; theFeed.MaxVolume = MaxVolume; theFeed.AutoGain = autogain; theFeed.NoPauseIfEmpty = nonstop; theFeed.Save(); } break; case "update": { //Name property cannot be updated if (theFeed.Source != source) { theFeed.Source = source; } if (autogaincollected && theFeed.AutoGain != autogain) { theFeed.AutoGain = autogain; } if (volumecollected && theFeed.MaxVolume != MaxVolume) { theFeed.AutoGain = autogain; } if (shufflecollected && theFeed.Type != shuffle) { theFeed.Type = shuffle; } if (nonstopcollected && theFeed.NoPauseIfEmpty != nonstop) { theFeed.NoPauseIfEmpty = nonstop; } theFeed.Save(); } break; case "delete": { //verification: //check all parameters and objects where references can exist var reference = @"\\.\pipe\" + name; var paramReferences = MOHParameters.Where(x => PhoneSystem.Root.GetParameterValue(x) == reference); using (var queues = PhoneSystem.Root.GetAll <Queue>().GetDisposer().Extract(y => y.OnHoldFile == reference)) { if (paramReferences.Any() || queues.Any()) { Console.WriteLine($"Cannot delete Playlist{theFeed.Source} because it is referenced by :"); foreach (var a in paramReferences) { Console.WriteLine($"\tPARAMETER: {a}"); } foreach (var a in queues) { Console.WriteLine($"\tQUEUE: {a.Number}"); } } else { //does not remove folder. theFeed.Delete(); } } } break; } } }
public void Run(params string[] args_in) { var args = args_in.Skip(1).ToArray(); if (args.Any()) { Console.ForegroundColor = ConsoleColor.Red; var allParams = args.Select(x => { var stringset = x.Split(new char[] { '=' }); var value = string.Join("=", stringset.Skip(1).ToArray()); value = (value != String.Empty || x.EndsWith("=")) ? value : null; if (value == null) { Console.WriteLine($"Malformed argument {x} should be <ENTITY>=<VALUE>"); } return(new KeyValuePair <string, string>(stringset.First().Trim(), value)); }).Where(y => y.Value != null); Console.ResetColor(); var FilesFolder = PhoneSystem.Root.GetParameterValue("IVRPROMPTPATH"); //base folder for files var PlaylistFolder = Path.Combine(FilesFolder, "Playlist"); //base folder for playlists foreach (var a in allParams) { var name = a.Key; var value = a.Value; //can be folder of configured playlist or the path to the file if (value != string.Empty) { if (!File.Exists(Path.Combine(FilesFolder, value))) { AudioFeed playlist = null; if (!Directory.Exists(Path.Combine(PlaylistFolder, value)) || (playlist = PhoneSystem.Root.GetAllAudioFeeds().GetDisposer(x => x.Source == value).FirstOrDefault()) == null) //not found even playlist { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"Source {value} is not found to update {name}"); Console.ResetColor(); continue; } //we need to set pipe reference Console.WriteLine($"Source for {name} is the playlist {value} ({playlist.Name})"); value = @"\\.\pipe\" + playlist.Name; } else { value = Path.Combine(FilesFolder, value); } } var q = PhoneSystem.Root.GetDNByNumber(name) as Queue; var p = PhoneSystem.Root.GetParameterValue(name); if (p != null && MOHParameters.Contains(name)) //parameter { PhoneSystem.Root.SetParameter(name, value); Console.WriteLine($"updated PARAM.{name}={value}"); } else if (q != null && p == null) { try { q.OnHoldFile = value; q.Save(); Console.WriteLine($"updated queue music on hold QUEUE.{name}={value}"); } catch { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"Failed to update music on hold on QUEUE.{name}"); Console.ResetColor(); } } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"Invalid entity {name}. Should be name of a custom parameter or queue number"); Console.ResetColor(); } } } Console.WriteLine("All MOH users:"); var allMOHSources = MOHParameters.Select(x => new KeyValuePair <string, string>("PARAM." + x, PhoneSystem.Root.GetParameterValue(x))).Where(z => z.Value != null) .Concat(PhoneSystem.Root.GetQueues().Select(y => new KeyValuePair <string, string>("QUEUE." + y.Number, y.OnHoldFile))); foreach (var a in allMOHSources) { if (a.Value.StartsWith(@"\\.\pipe\")) // it should be AudioFeed reference { var res = PhoneSystem.Root.GetAllAudioFeeds().FirstOrDefault(x => x.Name == a.Value.Substring(9)); if (res == null) //not found { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"{a.Key}={a.Value} UNDEFINED PLAYLIST REFERENCE"); } else { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"{a.Key}=PL[{res.Source}]({res.Name})"); } } else { bool exists = File.Exists(a.Value); if (!exists) { Console.ForegroundColor = ConsoleColor.Red; } else { Console.ForegroundColor = ConsoleColor.Green; } Console.WriteLine($"{a.Key}=FILE[{a.Value}]" + (exists?"":" NOT EXIST")); } Console.ResetColor(); } }
public async void LoadDataAsync() { var data = await _entertainmentService.GetAudioFeed(); AudioFeed = data; }