Ejemplo n.º 1
0
        private void LoadInformationFile()
        {
            List <string> additionalComments = new List <string>();
            var           rawData            = MMEInformationFileHelper.ReadInformationFile(MovieInformationFilePath);

            Comments = rawData.AdditionalComments;

            MMEAttribute numberOfMoviesAttribute = rawData.Attributes.First(
                a => a.Name.Equals(MME_NUMBER_OF_MOVIES_KEY, StringComparison.InvariantCultureIgnoreCase)
                );

            int numberOfMovies = int.Parse(numberOfMoviesAttribute.Value);

            for (int i = 0; i < numberOfMovies; i++)
            {
                Dictionary <string, MMEAttribute> photoAttributes;

                photoAttributes = rawData.Attributes
                                  .Where(a => a.Name.EndsWith(" " + (i + 1)))
                                  .ToDictionary(a => a.Name);

                MMEMovie mmeMovie = new MMEMovie(this, photoAttributes);
                Add(mmeMovie);
            }
        }
Ejemplo n.º 2
0
        private void AssureAttribute(string key)
        {
            if (!Attributes.ContainsKey(key))
            {
                MMEAttribute newAttribute = new MMEAttribute();

                newAttribute.Name              = key;
                newAttribute.Value             = "";
                newAttribute.IsCustomAttribute = false;

                Attributes[key] = newAttribute;
            }
        }
Ejemplo n.º 3
0
        internal static void RemoveNumberFromAttributes(Dictionary <string, MMEAttribute> attributes)
        {
            // TODO: refactor this function
            List <string> oldKeys = new List <string>();

            foreach (var attr in attributes)
            {
                oldKeys.Add(attr.Key);

                attr.Value.Name = RemoveLastWordIfInt(attr.Value.Name);
            }

            foreach (string oldEntry in oldKeys)
            {
                MMEAttribute element = attributes[oldEntry];
                attributes.Add(element.Name, element);
                attributes.Remove(oldEntry);
            }
        }
Ejemplo n.º 4
0
        private MMEChannelMeta ParseToMMEMeta(MMEAttribute newAttribute)
        {
            string[] splittedValue = newAttribute.Value.Split(new[] { MME_CODE_NAME_SPLITTER }, 2);

            MMEChannelMeta mmeMeta = new MMEChannelMeta();

            if (splittedValue.Length > 0)
            {
                mmeMeta.Code = splittedValue[0].Trim();
            }

            if (splittedValue.Length > 1)
            {
                mmeMeta.Name = splittedValue[1].Trim();
            }

            mmeMeta.Number = int.Parse(newAttribute.Name.Substring(MME_NAME_OF_CHANNEL_KEY_PREFIX.Length).Trim());

            return(mmeMeta);
        }
Ejemplo n.º 5
0
        private void LoadChannelsMetaData()
        {
            using (StreamReader reader = new StreamReader(ChannelInformationFilePath,
                                                          Encoding.GetEncoding(MMEInformationFileHelper.DEFAULT_MME_ENCODING), true))
            {
                while (!reader.EndOfStream)
                {
                    MMEAttribute newAttribute = null;

                    MMEAttribute.ParseFromStream(reader, out newAttribute);

                    if (newAttribute == null)
                    {
                        continue;
                    }

                    if (newAttribute.Name == "" && newAttribute.Value == "")
                    {
                        Comments.AddRange(newAttribute.Comments);
                    }
                    else
                    {
                        if (newAttribute.Name.Equals(MME_NUMBER_OF_CHANNELS_KEY, StringComparison.InvariantCultureIgnoreCase))
                        {
                            // do not add Number of channels to the attributes list
                        }
                        else if (newAttribute.Name.StartsWith(MME_NAME_OF_CHANNEL_KEY_PREFIX, StringComparison.InvariantCultureIgnoreCase))
                        {
                            MMEChannelMeta metaInf         = ParseToMMEMeta(newAttribute);
                            string         channelFilePath = Path.Combine(ChannelDirectoryPath, DataSet.Name + "." + metaInf.Number.ToString("D3"));

                            this.Add(new MMEChannel(channelFilePath, metaInf));
                        }
                        else
                        {
                            Attributes.Add(newAttribute.Name, newAttribute);
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private static string ReadAttribute(RawMMEFile rawMMEData, StreamReader reader)
        {
            // TODO: refactor this function
            MMEAttribute newAttribute = null;

            string uninterpratedLine = MMEAttribute.ParseFromStream(reader, out newAttribute);

            if (newAttribute.Name == "" && newAttribute.Value == "")
            {
                if (newAttribute.Comments.Count > 0)
                {
                    rawMMEData.AdditionalComments.AddRange(newAttribute.Comments);
                }
            }
            else
            {
                rawMMEData.Attributes.Add(newAttribute);
            }

            return(uninterpratedLine);
        }
Ejemplo n.º 7
0
        public static string ParseFromStream(StreamReader reader, out MMEAttribute newAttribute)
        {
            newAttribute = new MMEAttribute();

            while (!reader.EndOfStream)
            {
                string line = reader.ReadLine();

                if (line.Trim() == "")
                {
                    continue;
                }

                string[] splittedLine = null;

                try
                {
                    splittedLine = SplitMMEAttributeLine(line);
                }
                catch (ArgumentOutOfRangeException)
                {
                    // we can no longer split the line
                    // and so we return the line we were not able to split
                    return(line);
                }

                if (!line.StartsWith("Comments"))
                {
                    newAttribute.Name  = splittedLine[0];
                    newAttribute.Value = splittedLine[1];
                    break;
                }
                else
                {
                    newAttribute.Comments.Add(splittedLine[1]);
                }
            }

            return("");
        }