Esempio n. 1
0
 private void backgroundWorkerFormat_DoWork(object sender, DoWorkEventArgs e)
 {
     try
     {
         ExceptionMessage = "";
         GeneratedHtml = "";
         PNavigationInfo navInfo = new PNavigationInfo();
         e.Result = PTemplates.FormatObject(_formatObject, _template, _host, _overloads, backgroundWorkerFormat, navInfo);
         this.parsedNavLevels = navInfo.levels;
         this.parsedNavCaptions = navInfo.captions;
     }
     catch (Exception ex)
     {
         e.Result = "exception:" + ex.Message;
         this.ExceptionMessage = ex.Message;
     }
 }
Esempio n. 2
0
        public static string FormatObject(IPObject obj, string template, IMHost host, IMValueGetter overloads, BackgroundWorker worker, PNavigationInfo navInfo)
        {
            List<PTemplateAttr> attrs;
            List<PTemplateCollection> fcollects;

            _parse(template, out attrs, out fcollects);

            template = template.Replace("%id%", obj.Id.ToString());
            foreach (var attr in attrs)
            {
                string val = "";
                string moduleName = attr.Module.Trim().ToLower();
                string attrName = attr.Name;

                bool valFound = false;

                if (moduleName == "")
                {
                    if (overloads != null)
                        valFound = overloads.QueryValue(attrName, false, out val);
                    if (!valFound)
                        valFound = obj.GetAttr(attr.Name, true, out val);
                }
                else if (moduleName == "host")
                {
                    if (host != null)
                        valFound = host.QueryValue(attr.Name, false, out val);
                }
                else
                {
                    valFound = _queryToModule(moduleName, attrName, out val);
                }
                if (!valFound)
                    val = "<" + attr.ToString() + ">";

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

            foreach (var fcollect in fcollects)
            {
                IPCollection coll = obj.GetCollection(fcollect.collectionName);
                if (coll != null)
                {
                    string val = "";
                    int cnt = coll.Count;
                    for (int i = 0; i < cnt; i++)
                    {
                        IPObject cobj = coll.GetObject(i);

                        string tmp = "";
                        if (cobj.GetAttr(fcollect.templateName, true, out tmp))
                        {
                            if (worker != null && worker.CancellationPending)
                                return "";

                            bool navAdded = false;
                            if (fcollect.navigatorLevelCaption != "")
                            {
                                if (navInfo != null)
                                {
                                    navInfo.captions.Add(fcollect.navigatorLevelCaption);
                                    navInfo.levels.Add(fcollect.collectionName);
                                    navAdded = true;
                                }
                            }
                            val += FormatObject(cobj, tmp, host, overloads, worker, navInfo);

                            // теперь, если уровень навигации добавлялся - нужно сбросить переменную, чтоб в этом цикле не добавить соседние подходящие коллекции
                            if (navAdded)
                                navInfo = null;
                        }
                        else
                            val += "<!" + fcollect.templateName + "!>";
                        val += (fcollect.endsWithNewLine ? "\n" : "");
                    }
                    template = template.Replace(fcollect.OperatorText, val);
                }
            } // ToDo: может надо else что-нибудь вывести? Коллекция не найдена

            return template;
        }