Example #1
0
        /// <summary>
        /// Given the id for document in SE4, it loads all of its attribute elements to further processing.
        /// </summary>
        /// <param name="p">id of document to retrieve</param>
        /// <param name="layout">Name of layout to check fields against</param>
        /// <returns>List of useful attributes for document</returns>
        private List<SE4Attribute> LoadSE4DocItems(long p, string layout) {
            if (log.IsDebugEnabled) log.Debug("LoadSE4DocItems start");
            string elementName = "";
            List<SE4Attribute> docAttrList = new List<SE4Attribute>();
            List<ValidMapField> documentValidFields = se4TemplateFieldMapping[layout];
            string sql = "select A.Orden, A.Elemento, A.OrdenAtributo, A.Atributo, A.Texto, A.CodContenidoLargo, B.ContenidoLargo " +
                         " from objetosecontenido A left join " +
                         "     contenidolargo    B on A.CodContenidoLargo = B.id_ContenidoLargo " +
                         " where Codobjetose = @idSE4 " +
                         "order by A.CodObjetoSE, A.orden, A.OrdenAtributo ";

            if (log.IsDebugEnabled) {
                log.Debug("Using sql=[" + sql + "]");
            }

            HandleDatabase hdb = new HandleDatabase(_connStr);
            SqlParameter param1 = new SqlParameter();
            param1.ParameterName = "@idSE4";
            param1.Value = p;
            param1.SqlDbType = SqlDbType.BigInt;

            hdb.Open();
            SqlTransaction transaction = hdb.BeginTransaction("LoadSE4DocItems");
            SqlDataReader rdr = hdb.ExecSelectSQLStmtAsReader(transaction, sql, param1);
            while (rdr.Read()) {
                elementName = rdr["Elemento"].ToString();
                if (documentValidFields.Exists(e => e.Source == elementName && e.Use)) {
                    int order = Convert.ToInt32(rdr["Orden"]);
                    int attributeOrder = Convert.ToInt32(rdr["OrdenAtributo"]);
                    string attributeName = rdr["Atributo"].ToString();
                    string text = rdr["Texto"].ToString();
                    long hugeContentCode = -1;
                    string hugeText = null;
                    SE4Attribute attr = null;

                    if (rdr["CodContenidoLargo"] != DBNull.Value) {
                        hugeContentCode = Convert.ToInt64(rdr["CodContenidoLargo"]);
                    }
                    if (rdr["ContenidoLargo"] != DBNull.Value) {
                        hugeText = rdr["ContenidoLargo"].ToString();
                    }

                    text = ReplaceHTMLCharacters(text);
                    hugeText = ReplaceHTMLCharacters(hugeText);

                    ValidMapField vmf = documentValidFields.Find(e => e.Source == elementName && e.Use);
                    if (vmf.Attributes != null) {
                        ValidMapFieldAttributes vmfa = vmf.Attributes.Find(e => e.Source == elementName && e.SourceAttribute == attributeName && e.Use);
                        if (vmfa == null) {
                            continue;
                        }
                    }
                    attr = new SE4Attribute(order, elementName, attributeOrder, attributeName, text, hugeContentCode, hugeText);
                    docAttrList.Add(attr);
                }
            }
            rdr.Close();
            transaction.Commit();
            hdb.Close();
            if (log.IsDebugEnabled) log.Debug("LoadSE4DocItems end");
            return docAttrList;
        }
Example #2
0
 /// <summary>
 /// Inspects if there is an image in attr.
 /// </summary>
 /// <param name="attr">Data to work with</param>
 /// <param name="info">Info of document being processed</param>
 /// <param name="documentPath">Target resource directory</param>
 /// <returns>Filenane part</returns>
 private string ExtractMediaName(SE4Attribute attr, IterwebMapInfo info, string documentPath) {
     string s = "";
     if (log.IsDebugEnabled) log.Debug("Extracting mediaName Start ATTR");
     if (attr.Text != "") {
         s = attr.Text;
         var isJpg = s.Contains(".jpg") || s.Contains(".JPG");
         if (!isJpg) {
             s += ".jpg";
         }
         s = ExtractImageNamePart(s);
         attr.Text = s = s.Supress('/').Supress('\\');
         s = CopyImageToZip(_se4MediaSourceFolder, documentPath, s, info);
         if (s != "") {
             s = attr.Text = DocumentImageDir + s;
             if (log.IsDebugEnabled) log.Debug("Media name found, set to [" + attr.Text + "]");
         }
     }
     if (log.IsDebugEnabled) log.Debug("Extracting mediaName End ATTR");
     return s;
 }