Пример #1
0
        public string TransformText(string templateName, RBaseObject obj, ref string path, bool addPath)
        {
            string template = "";

            if (!_items.TryGetValue(templateName.ToLower(), out template))
            {
                template = NotFoundMarks.collections.Begin + templateName + NotFoundMarks.collections.End;
            }
            else
            {
                List<RTemplateAttr> attrs;
                List<RTemplateCollection> fcollects;

                _parse(template, out attrs, out fcollects);

                template = template.Replace("%id%", obj.Id.ToString());
                foreach (var attr in attrs)
                {
                    string val = "";
                    if (!obj.GetAttr(attr.Name, out val))
                        val = NotFoundMarks.attrs.Begin + attr.Name + NotFoundMarks.attrs.End;
                    template = template.Replace(attr.OperatorText, val);
                }

                foreach (var fcollect in fcollects)
                {
                    RCollection coll = obj.GetCollection(fcollect.collectionName, false);
                    if (coll != null)
                    {
                        string val = "";
                        for (int ii = 0; ii < coll.Count(); ii++)
                        {
                            //val += this.PreScript + TransformText(fcollect.templateName, coll.GetObject(ii)) + this.PostStript;

                            RBaseObject cobj =  coll.GetObject(ii);
                            bool addNext = (addPath && fcollect.navigatorLevelText != "");
                            if (addNext)
                            {
                                path += ((path != "")?"/":"") + fcollect.collectionName + ":" + fcollect.navigatorLevelText;
                                addPath = false;
                            }
                            val += this.TransformText(fcollect.templateName, cobj, ref path, addNext);

                        }
                        template = template.Replace(fcollect.OperatorText, val);
                    }
                }
            }

            return template;
        }