Esempio n. 1
0
 public static void AddValueKeyNotExist <T>(this IDictionary <string, T> dictionary, string key, T keyValue)
 {
     if (!dictionary.ContainsKeyIgnoreCase(key))
     {
         dictionary.Add(key, keyValue);
     }
 }
Esempio n. 2
0
        public static T GetValueIgnoreKeyCaseThrows <T>(this IDictionary <string, T> dictionary, string key)
        {
            if (!dictionary.ContainsKeyIgnoreCase(key))
            {
                throw new Exception(string.Format("Key {0} not found in Dictionary", key));
            }

            return(GetValueIgnoreKeyCase <T>(dictionary, key));
        }
        public static bool CompareMetadata(this MetadataCollection requirements, IDictionary <string, object> provided)
        {
            bool result =
                requirements.All(
                    i =>
                    provided.ContainsKeyIgnoreCase(i.Key) &&
                    CompareMetadataItems(i.Value, provided.GetEntryIgnoreCase(i.Key)));

            return(result);
        }
Esempio n. 4
0
        public static void AddUpdateIgnoreKeyCase <T>(this IDictionary <string, T> dictionary, string key, T keyValue)
        {
            var keyName = key;

            if (dictionary.ContainsKeyIgnoreCase(key))
            {
                var existingKey = dictionary.Keys.First(k => string.Equals(k, key, StringComparison.CurrentCultureIgnoreCase));
                dictionary.Remove(existingKey);
                keyName = existingKey;
            }
            dictionary.Add(keyName, keyValue);
        }
Esempio n. 5
0
 public static bool TryGetPlayerXamlThemeSource(IDictionary<string, string> initParams, out Uri xamlThemeSource)
 {
     if (initParams.ContainsKeyIgnoreCase("XamlThemeSource"))
     {
         if (Uri.TryCreate(initParams.GetEntryIgnoreCase("XamlThemeSource"), UriKind.RelativeOrAbsolute, out xamlThemeSource))
         {
             return true;
         }
     }
     xamlThemeSource = null;
     return false;
 }
Esempio n. 6
0
        private static bool TryGetPlayerSettings(IDictionary<string, string> initParams, out IPlayerSettings playerSettings)
        {
            if (initParams.ContainsKeyIgnoreCase("InitialSettings"))
            {
                string xmlSettings = initParams.GetEntryIgnoreCase("InitialSettings");
                if (!String.IsNullOrWhiteSpace(xmlSettings))
                {
                    var serializer = new XmlSerializer(typeof(PlayerSettings));
                    playerSettings = (IPlayerSettings)serializer.Deserialize(xmlSettings.AsStream());
                    return true;
                }

            }
            playerSettings = null;
            return false;
        }
        /// <summary>
        /// Load settings from init params
        /// </summary>
        /// <param name="initParams"></param>
        public void LoadInitParams(IDictionary<string, string> initParams)
        {
            bool autoPlay;
            FeatureVisibility playerGraphVisibility;

            if (initParams.ContainsKeyIgnoreCase(SupportedInitParams.Title))
            {
                MediaTitleContent = initParams.GetEntryIgnoreCase(SupportedInitParams.Title);
            }

            if (initParams.ContainsKeyIgnoreCase(SupportedInitParams.ScriptableName)
                && !initParams.GetEntryIgnoreCase(SupportedInitParams.ScriptableName).IsNullOrWhiteSpace())
            {
                ScriptableName = initParams.GetEntryIgnoreCase(SupportedInitParams.ScriptableName);
            }

            if (initParams.ContainsKeyIgnoreCase(SupportedInitParams.AutoPlay)
                && bool.TryParse(initParams.GetEntryIgnoreCase(SupportedInitParams.AutoPlay), out autoPlay))
            {
                AutoPlay = autoPlay;
            }

            if (initParams.ContainsKeyIgnoreCase(SupportedInitParams.PlayerGraphVisibility)
                && FeatureVisibility.TryParse(initParams.GetEntryIgnoreCase(SupportedInitParams.PlayerGraphVisibility), true, out playerGraphVisibility))
            {
                PlayerGraphVisibility = playerGraphVisibility;
            }

            bool isStartPositionOffset = true;
            if (initParams.ContainsKeyIgnoreCase(SupportedInitParams.IsStartPositionOffset) && bool.TryParse(initParams.GetEntryIgnoreCase(SupportedInitParams.IsStartPositionOffset), out isStartPositionOffset))
            {
                IsStartPositionOffset = isStartPositionOffset;
            }

            if (initParams.ContainsKeyIgnoreCase(SupportedInitParams.MediaUrl)
                && !initParams.GetEntryIgnoreCase(SupportedInitParams.MediaUrl).IsNullOrWhiteSpace())
            {
                var playlist = new ObservableCollection<PlaylistItem>();

                var playlistItem = new PlaylistItem
                {
                    MediaSource = new Uri(initParams.GetEntryIgnoreCase(SupportedInitParams.MediaUrl))
                };


                DeliveryMethods deliveryMethod;
                if (initParams.ContainsKeyIgnoreCase(SupportedInitParams.DeliveryMethod)
                    && initParams.GetEntryIgnoreCase(SupportedInitParams.DeliveryMethod).EnumTryParse(true, out deliveryMethod))
                {
                    playlistItem.DeliveryMethod = deliveryMethod;
                }


                if (initParams.ContainsKeyIgnoreCase(SupportedInitParams.SelectedCaptionStream)
                    && !initParams.GetEntryIgnoreCase(SupportedInitParams.SelectedCaptionStream).IsNullOrWhiteSpace())
                {
                    playlistItem.SelectedCaptionStreamName = initParams.GetEntryIgnoreCase(SupportedInitParams.SelectedCaptionStream);
                }

                if (initParams.ContainsKeyIgnoreCase(SupportedInitParams.ThumbnailUrl)
                    && !initParams.GetEntryIgnoreCase(SupportedInitParams.ThumbnailUrl).IsNullOrWhiteSpace())
                {
                    playlistItem.ThumbSource = new Uri(initParams.GetEntryIgnoreCase(SupportedInitParams.ThumbnailUrl));
                }

                playlist.Add(playlistItem);
                Playlist = playlist;
            }
            else if (initParams.ContainsKeyIgnoreCase(SupportedInitParams.PlayerSettings)
                && !initParams.GetEntryIgnoreCase(SupportedInitParams.PlayerSettings).IsNullOrWhiteSpace())
            {
                ImportPlayerSettings(initParams.GetEntryIgnoreCase(SupportedInitParams.PlayerSettings));
            }

            Uri pluginSource;
            if (initParams.ContainsKeyIgnoreCase(SupportedInitParams.PluginUrl)
                && !initParams.GetEntryIgnoreCase(SupportedInitParams.PluginUrl).IsNullOrWhiteSpace()
                && Uri.TryCreate(initParams.GetEntryIgnoreCase(SupportedInitParams.PluginUrl), UriKind.RelativeOrAbsolute, out pluginSource))
            {
                BeginAddExternalPlugins(pluginSource);
            }
        }
        /// <summary>
        /// Method supplied to the <see cref="VersatileIO.OnGetSelection"/> delegate.
        /// </summary>
        /// <param name="prompt">Dictionary of options and their respective keys</param>
        /// <param name="options">Text given as a prompt after selections are listed.</param>
        /// <returns>The key of the resulting item.</returns>
        public override string GetSelection(string prompt, IDictionary<string, object> options)
        {
            foreach (KeyValuePair<string, object> kvp in options)
            {
                Console.ForegroundColor = PromptColor;
                Console.WriteLine("  [{0}]: {1}", kvp.Key, kvp.Value);
            }

            while (true)
            {
                Console.ForegroundColor = PromptColor;
                Console.Write(prompt);
                string input = Console.ReadLine();

                if (options.ContainsKeyIgnoreCase(input))
                {
                    return input;
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("'{0}' is not one of the options above.", input);

                    if (!BePersistent)
                    {
                        Console.WriteLine("Defaulting to first option.");
                        return options.Keys.FirstOrDefault();
                    }
                }
            }
        }
        /// <summary>
        /// Method supplied to the <see cref="VersatileIO.OnGetIgnorableSelection"/> delegate.
        /// </summary>
        /// <param name="prompt">Dictionary of options and their respective keys</param>
        /// <param name="options">Text given as a prompt after selections are listed.</param>
        /// <returns>The key of the resulting item.</returns>
        public override string GetSelectionIgnorable(string prompt, IDictionary<string, object> options)
        {
            foreach (KeyValuePair<string, object> kvp in options)
            {
                Console.ForegroundColor = PromptColor;
                Console.WriteLine("  [{0}]: {1}", kvp.Key, kvp.Value);
            }

            Console.ForegroundColor = PromptColor;
            Console.Write(prompt);
            string input = Console.ReadLine();

            if (options.ContainsKeyIgnoreCase(input))
            {
                return input;
            }
            else
            {
                return null;
            }
        }
        public override string GetSelectionIgnorable(string prompt, IDictionary<string, object> options)
        {
            foreach (KeyValuePair<string, object> kvp in options)
            {
                LogLine("  [{0}]: {1}".Fmt(kvp.Key, kvp.Value), ConsoleColor.White);
            }

            string input = GetString(prompt);

            if (options.ContainsKeyIgnoreCase(input))
            {
                return input;
            }
            else
            {
                return null;
            }
        }
        public override string GetSelection(string prompt, IDictionary<string, object> options)
        {
            foreach (KeyValuePair<string, object> kvp in options)
            {
                LogLine("  [{0}]: {1}".Fmt(kvp.Key, kvp.Value), ConsoleColor.White);
            }

            while (true)
            {
                string input = GetString(prompt);

                if (options.ContainsKeyIgnoreCase(input))
                {
                    return input;
                }
                else
                {
                    VersatileIO.Error("'{0}' is not one of the options above.", input);

                    if (!BePersistent)
                    {
                        VersatileIO.Info("Defaulting to first option.");
                        return options.Keys.FirstOrDefault();
                    }
                }
            }
        }