public static bool ParseTemplateInfo(string path, out Template.TemplateInfo templateInfo, out ErrorCollector errorCollector)
 {
     errorCollector = new ErrorCollector(); templateInfo = new Template.TemplateInfo();
     try
     {
         using (XmlReader xmlReader = XmlReader.Create(path, new XmlReaderSettings()
         {
             ConformanceLevel = ConformanceLevel.Fragment
         }))
         {
             // first element must always be the TemplateInfo!
             while (xmlReader.NodeType != XmlNodeType.Element || xmlReader.Name != "TemplateInfo")
             {
                 if (!xmlReader.Read())
                 {
                     errorCollector.AddError("<TemplateInfo> not found!"); return(false);
                 }
             }
             XElement xeInfo = XElement.ReadFrom(xmlReader) as XElement;
             if (xeInfo == null || xeInfo.Name != "TemplateInfo")
             {
                 errorCollector.AddError("<TemplateInfo> not found!"); return(false);
             }
             templateInfo = ReadInfo(xeInfo, errorCollector);
             return(true); // the only error ReadInfo may produce (except an exception which is caught below) is unknown element, which does no harm
         }
     }
     catch (Exception exception) { errorCollector.AddError(exception.Message); return(false); }
 }
Пример #2
0
 internal PrettyInfoResources(Template.TemplateInfo _templateInfo,
                              SystemInfo _baseSystem, List <SystemInfo> _reformSystems,
                              string _packageKey, int _refNo)
 {
     templateInfo = _templateInfo;
     baseSystem   = _baseSystem; reformSystems = _reformSystems;
     packageKey   = _packageKey; refNo = _refNo;
 }
        private static Template.TemplateInfo ReadInfo(XElement xeInfo, ErrorCollector errorCollector)
        {
            Template.TemplateInfo info = new Template.TemplateInfo();

            if (xeInfo.Element("DebugMode") != null && errorCollector.XEleGetBool(xeInfo.Element("DebugMode"), xeInfo))
            {
                errorCollector.SetDebugMode();
            }

            foreach (XElement xe in xeInfo.Elements())
            {
                if (xe.Value == null)
                {
                    continue;
                }
                switch (GetXEleName(xe))
                {
                case "Name": info.name = xe.Value; break;

                case "Title": info.title = xe.Value; break;

                case "Subtitle": info.subtitle = xe.Value; break;

                case "Button": info.button = xe.Value; break;

                case "Description": info.description = xe.Value; break;

                case "GeneralDescription": info.generalDescription = xe.Value; break;

                case "MinFiles": info.minFiles = errorCollector.XEleGetInt(xe, xeInfo); break;

                case "MaxFiles": info.maxFiles = errorCollector.XEleGetInt(xe, xeInfo); break;

                case "HideMainSelectorForSingleFilePackage": info.HideMainSelectorForSingleFilePackage = errorCollector.XEleGetBool(xe, xeInfo); break;

                case "TemplateType": info.templateType = errorCollector.XEleGetEnum <HardDefinitions.TemplateType>(xe, xeInfo); break;

                case "AdditionalCalculationLevels": info.calculationLevels = ReadElementGroup(xe, ReadCalculationLevel, errorCollector); break;

                case "RequiredVariables": info.requiredVariables = ReadElementGroup(xe, ReadRequiredVariable, errorCollector); break;

                case "OptionalVariables": info.optionalVariables = ReadElementGroup(xe, ReadOptionalVariable, errorCollector); break;

                case "UserVariables": info.userVariables = ReadElementGroup(xe, ReadUserVariable, errorCollector); break;

                case "SDCDefinition": ReadTemplateInfoSDCDefinition(errorCollector, info, xe); break;

                case "ExportDescriptionMode": info.exportDescriptionMode = errorCollector.XEleGetEnum <HardDefinitions.ExportDescriptionMode>(xe, xeInfo); break;

                case "DebugMode": break;

                default: errorCollector.AddXmlUnkownEleError(xe, xeInfo); break;
                }
            }
            ;
            return(info);
        }
Пример #4
0
        internal static string GetPrettyHtml(Template.TemplateInfo templateInfo, string origText,
                                             SystemInfo baseSystem, List <SystemInfo> reformSystems = null,
                                             string packageKey = null, int refNo = -1)
        {
            throw new NotImplementedException();

            // is the HTML generated here and origText is really unformatted text or is it actually origHtml?

            //if (string.IsNullOrEmpty(origText)) return string.Empty;
            //PrettyInfoResources resources = new PrettyInfoResources(templateInfo, baseSystem, reformSystems, packageKey, refNo);
            //foreach (PrettyInfo pi in allPrettyInfos) origText = pi.ReplaceHtml(origText, resources);
            //return origText;
        }
Пример #5
0
        internal static string GetPrettyText(Template.TemplateInfo templateInfo, string origText,
                                             SystemInfo baseSystem, List <SystemInfo> reformSystems = null,
                                             string packageKey = null, int refNo = -1)
        {
            try
            {
                if (string.IsNullOrEmpty(origText))
                {
                    return(string.Empty);
                }

                PrettyInfoResources resources = new PrettyInfoResources(templateInfo, baseSystem, reformSystems, packageKey, refNo);

                string newText = origText;
                foreach (PrettyInfo pi in allPrettyInfos)
                {
                    newText = pi.ReplaceText(newText, resources);
                }
                return(newText);
            }
            catch { return(origText); }
        }
        private static void ReadTemplateInfoSDCDefinition(ErrorCollector errorCollector, Template.TemplateInfo info, XElement xe)
        {
            foreach (XElement xeg in xe.Elements())
            {
                if (xeg.Value == null)
                {
                    continue;
                }
                switch (GetXEleName(xeg))
                {
                case "HideZeroObs": info.sdcHideZeroObs = errorCollector.XEleGetBool(xeg, xe); break;

                case "MinObsDefault": info.sdcMinObsDefault = errorCollector.XEleGetInt(xeg, xe); break;

                case "MinObsAlternatives":
                    info.sdcMinObsAlternatives = new Dictionary <string, int>(StringComparer.OrdinalIgnoreCase);
                    foreach (var ele in ReadElementGroup(xeg, ReadSdcMinObsAlternative, errorCollector))
                    {
                        if (ele.Key == null)
                        {
                            continue;
                        }
                        if (info.sdcMinObsAlternatives.ContainsKey(ele.Key))
                        {
                            errorCollector.AddDebugOnlyError($"Double definition of SdcMinObsAlternative '{ele.Key}'.");
                        }
                        else
                        {
                            info.sdcMinObsAlternatives.Add(ele.Key, ele.Value);
                        }
                    }
                    break;

                default: errorCollector.AddXmlUnkownEleError(xeg, xe); break;
                }
            }
        }