コード例 #1
0
        public IContextInfo CreateContextInfo(ParagraphUnitContext context)
        {
            var contextInfo = PropertiesFactory.CreateContextInfo(context.ContextType);

            contextInfo.DisplayName = context.DisplayName;
            contextInfo.DisplayCode = context.DisplayCode;
            contextInfo.Description = context.Description;
            foreach (var metaData in context.MetaData)
            {
                contextInfo.SetMetaData(metaData.Key, metaData.Value);
            }

            return(contextInfo);
        }
コード例 #2
0
        private static void ReadProjectFile(XContainer file, ProjectFileInfo projectFileInfo, ref int segmentIdCounter)
        {
            foreach (var element in file.Elements())
            {
                if (string.Compare(element.Name.LocalName, "header", StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    foreach (var fileInfo in element.Elements())
                    {
                        if (string.Compare(fileInfo.Name.LocalName, "file-info", StringComparison.InvariantCultureIgnoreCase) == 0)
                        {
                            foreach (var value in fileInfo.Elements())
                            {
                                if (string.Compare(value.Name.LocalName, "value", StringComparison.InvariantCultureIgnoreCase) == 0)
                                {
                                    if (!value.HasAttributes)
                                    {
                                        continue;
                                    }

                                    SetFileInfoAttributes(projectFileInfo, value);
                                }
                            }
                        }

                        if (string.Compare(fileInfo.Name.LocalName, "filetype-info", StringComparison.InvariantCultureIgnoreCase) == 0)
                        {
                            var fileType = fileInfo.Elements().FirstOrDefault(a => string.Compare(a.Name.LocalName, "filetype-id", StringComparison.InvariantCultureIgnoreCase) == 0);
                            if (fileType != null)
                            {
                                projectFileInfo.FileTypeId = fileType.Value;
                            }
                        }

                        if (string.Compare(fileInfo.Name.LocalName, "cxt-defs", StringComparison.InvariantCultureIgnoreCase) == 0)
                        {
                            foreach (var cxtdef in fileInfo.Elements())
                            {
                                var contextDefinition = new ParagraphUnitContext();
                                foreach (var attribute in cxtdef.Attributes())
                                {
                                    if (string.Compare(attribute.Name.LocalName, "id", StringComparison.InvariantCultureIgnoreCase) == 0)
                                    {
                                        contextDefinition.Id = attribute.Value;
                                    }

                                    if (string.Compare(attribute.Name.LocalName, "type", StringComparison.InvariantCultureIgnoreCase) == 0)
                                    {
                                        contextDefinition.ContextType = attribute.Value;
                                    }

                                    if (string.Compare(attribute.Name.LocalName, "code", StringComparison.InvariantCultureIgnoreCase) == 0)
                                    {
                                        contextDefinition.DisplayCode = attribute.Value;
                                    }

                                    if (string.Compare(attribute.Name.LocalName, "descr", StringComparison.InvariantCultureIgnoreCase) == 0)
                                    {
                                        contextDefinition.Description = attribute.Value;
                                    }

                                    if (string.Compare(attribute.Name.LocalName, "color", StringComparison.InvariantCultureIgnoreCase) == 0)
                                    {
                                        contextDefinition.DisplayName = attribute.Value;
                                    }
                                }

                                var props = cxtdef.Elements().FirstOrDefault(a => string.Compare(a.Name.LocalName, "props", StringComparison.InvariantCultureIgnoreCase) == 0);
                                if (props != null)
                                {
                                    foreach (var value in props.Elements())
                                    {
                                        if (string.Compare(value.Name.LocalName, "value", StringComparison.InvariantCultureIgnoreCase) == 0)
                                        {
                                            if (!value.HasAttributes)
                                            {
                                                continue;
                                            }

                                            foreach (var attribute in value.Attributes())
                                            {
                                                if (!contextDefinition.MetaData.ContainsKey(attribute.Value))
                                                {
                                                    contextDefinition.MetaData.Add(attribute.Value, value.Value);
                                                }
                                            }
                                        }
                                    }

                                    projectFileInfo.ContextDefinitions.Add(contextDefinition);
                                }
                            }
                        }
                    }
                }

                if (string.Compare(element.Name.LocalName, "body", StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    foreach (var group in element.Elements())
                    {
                        if (string.Compare(group.Name.LocalName, "group", StringComparison.InvariantCultureIgnoreCase) == 0)
                        {
                            var contextDefinitions = new List <ParagraphUnitContext>();
                            var contexts           = group.Elements().FirstOrDefault(a => string.Compare(a.Name.LocalName, "cxts", StringComparison.InvariantCultureIgnoreCase) == 0);
                            if (contexts != null)
                            {
                                foreach (var value in contexts.Elements())
                                {
                                    if (string.Compare(value.Name.LocalName, "cxt", StringComparison.InvariantCultureIgnoreCase) == 0)
                                    {
                                        foreach (var attribute in value.Attributes())
                                        {
                                            if (string.Compare(attribute.Name.LocalName, "id", StringComparison.InvariantCultureIgnoreCase) == 0)
                                            {
                                                var contextDefinition = projectFileInfo.ContextDefinitions.FirstOrDefault(a => a.Id == attribute.Value);
                                                if (contextDefinition != null)
                                                {
                                                    contextDefinitions.Add(contextDefinition);
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            var transUnits = group.Elements().Where(a =>
                                                                    string.Compare(a.Name.LocalName, "trans-unit", StringComparison.InvariantCultureIgnoreCase) == 0);
                            foreach (var transUnit in transUnits)
                            {
                                var paragraphInfos = GetParagraphInfo(transUnit, ref segmentIdCounter);
                                paragraphInfos.ContextDefinitions = contextDefinitions;
                                projectFileInfo.ParagraphInfos.Add(paragraphInfos);
                            }
                        }
                        if (string.Compare(group.Name.LocalName, "trans-unit", StringComparison.InvariantCultureIgnoreCase) == 0)
                        {
                            var paragraphInfos = GetParagraphInfo(group, ref segmentIdCounter);
                            paragraphInfos.ContextDefinitions = new List <ParagraphUnitContext>();
                            projectFileInfo.ParagraphInfos.Add(paragraphInfos);
                        }
                    }
                }
            }
        }