Example #1
0
        private void FillDoc(DocumentBuilder builder, string prefix, DynaDoc doc)
        {
            var pref = String.IsNullOrEmpty(prefix) ? "" : prefix + ".";

            //foreach (var attr in doc.Doc.Attributes)
            //{
            //    var fn = Logger.GetLogFileName("ReportManagerError");
            //    Logger.OutputLog(fn, "ERROR BLOB: " + attr.AttrDef.Name + " ----- " + attr.GetType() + " ----- " + attr.ObjectValue.ToString().Length + " ----- " + (attr is BlobAttribute));
            //}

            foreach (var attr in doc.Doc.Attributes)
            {
                var value = attr.ObjectValue;

                try
                {
                    if (attr is BlobAttribute)
                    {
                        //var fn = Logger.GetLogFileName("ReportManagerError");
                        //Logger.OutputLog(fn, "ERROR BLOB: " + attr.AttrDef.Name + " ----- " + attr.GetType());

                        IDocRepository _docRepo = Provider.Get <IDocRepository>();

                        BlobData img = _docRepo.GetBlobAttrData(doc.Doc.Id, attr.AttrDef);

                        //Logger.OutputLog(fn, "ERROR BLOB: " + img.FileName);

                        // We assume only Image types blobs are used in reports
                        builder.SetBlobField(pref + attr.AttrDef.Name, img.Data);

                        continue;
                    }
                }
                catch (Exception e)
                {
                    var fn = Logger.GetLogFileName("ReportManagerError");
                    Logger.OutputLog(fn, e, e.Message);
                }

                if (value == null)
                {
                    continue;
                }

                if (attr is DocAttribute)
                {
                    var attrDoc = doc.GetAttrDoc((DocAttribute)attr);

                    if (attrDoc != null)
                    {
                        using (var dynaDoc = new DynaDoc(attrDoc, UserId, Provider))
                            FillDoc(builder, pref + attr.AttrDef.Name, dynaDoc);
                    }
                }
                else if (attr is DocListAttribute)
                {
                    var index = 0;
                    foreach (var docItem in doc.GetAttrDocList((DocListAttribute)attr))
                    {
                        using (var dynaDoc = new DynaDoc(docItem, UserId, Provider))
                            FillDoc(builder, string.Format("{0}{1}.{2}", pref, attr.AttrDef.Name, index), dynaDoc);
                        index++;
                    }
                }
                else if (attr is EnumAttribute)
                {
                    var enumValue = doc.GetAttrEnum((EnumAttribute)attr);

                    if (enumValue != null)
                    {
                        builder.SetField(pref + attr.AttrDef.Name, enumValue.Value);
                    }
                }
                else if (attr is DateTimeAttribute)
                {
                    builder.SetField(pref + attr.AttrDef.Name, String.Format("{0:d}", value));
                }
                else if (attr is CurrencyAttribute || attr is FloatAttribute)
                {
                    builder.SetField(pref + attr.AttrDef.Name, String.Format("{0:F2}", value));
                }
                else
                {
                    builder.SetField(pref + attr.AttrDef.Name, value);
                }
            }
        }