Пример #1
0
        /// <summary>
        /// Creates an PlaylistGenerator from a list property values
        /// </summary>
        /// <param name="propValues">The list of property values</param>
        /// <param name="valuesAsText">Flag indicating if the values have been provided as text and must be parsed</param>
        /// <returns>An PlaylistGenerator</returns>
        private static PlaylistGenerator Create(Dictionary <string, object> propValues, bool valuesAsText)
        {
            // create variables to hold data from xml
            PlaylistGenerator playlistCreator = new PlaylistGenerator();

            foreach (string propName in propValues.Keys)
            {
                PropertyInfo prop = typeof(PlaylistGenerator).GetProperty(propName);
                if (prop != null)
                {
                    object propValue = propValues[propName];
                    bool   setValue  = true;
                    if (valuesAsText)
                    {
                        setValue = StringParser.TryParse(prop.PropertyType, (string)propValue, out propValue);
                    }

                    if (setValue)
                    {
                        prop.SetValue(playlistCreator, propValue, null);
                    }
                }
            }

            // check that directory exists
            if (!Directory.Exists(playlistCreator.MediaFolder))
            {
                throw new DirectoryNotFoundException(playlistCreator.MediaFolder);
            }

            // set output folder
            if (!Directory.Exists(playlistCreator.OutputFolder))
            {
                Directory.CreateDirectory(playlistCreator.OutputFolder);
            }

            return(playlistCreator);
        }
Пример #2
0
        /// <summary>
        /// Creates an PlaylistGenerator from a list property values
        /// </summary>
        /// <param name="propValues">The list of property values</param>
        /// <param name="valuesAsText">Flag indicating if the values have been provided as text and must be parsed</param>
        /// <returns>An PlaylistGenerator</returns>
        private static PlaylistGenerator Create(Dictionary<string, object> propValues, bool valuesAsText)
        {
            // create variables to hold data from xml
            PlaylistGenerator playlistCreator = new PlaylistGenerator();

            foreach (string propName in propValues.Keys)
            {
                PropertyInfo prop = typeof(PlaylistGenerator).GetProperty(propName);
                if (prop != null)
                {
                    object propValue = propValues[propName];
                    bool setValue = true;
                    if (valuesAsText)
                        setValue = StringParser.TryParse(prop.PropertyType, (string)propValue, out propValue);

                    if (setValue)
                        prop.SetValue(playlistCreator, propValue, null);
                }
            }

            // check that directory exists
            if (!Directory.Exists(playlistCreator.MediaFolder))
                throw new DirectoryNotFoundException(playlistCreator.MediaFolder);

            // set output folder
            if (!Directory.Exists(playlistCreator.OutputFolder))
                Directory.CreateDirectory(playlistCreator.OutputFolder);

            return playlistCreator;
        }