public MetaFileStream(MetaObject mo, MetaFile mf, string metaFieldName, long contentLength) { _metaObject = mo; _metaFile = mf; _metaFieldName = metaFieldName; _stream = new MemoryStream(); _contentLength = contentLength; }
protected void Page_Load(object sender, System.EventArgs e) { int ObjectId = int.Parse(Request.QueryString["Id"]); string MetaClassName = Request.QueryString["Class"]; string FieldName = Request.QueryString["Field"]; MetaObject obj = MetaDataWrapper.LoadMetaObject(ObjectId, MetaClassName); Mediachase.MetaDataPlus.MetaFile mf = (Mediachase.MetaDataPlus.MetaFile)obj[FieldName]; Response.ContentType = "image/jpeg"; Response.BinaryWrite(mf.Buffer); Response.End(); }
private void GetFieldValue(MD45.MetaObject object45, MD47.Meta.Management.MetaField field47, ref bool fieldPresent, ref object value) { string field47Name = field47.Name; if (_fieldMap.ContainsKey(field47Name)) { fieldPresent = true; string field45Name = _fieldMap[field47Name]; if (field47.IsEnum || field47.IsMultivalueEnum) { if (object45[field45Name] != null) { Dictionary <int, string> enumValues; //Try find mapping id for this FieldType if (!_enumValuesByType.TryGetValue(field47.GetMetaType(), out enumValues)) { throw new ArgumentException("Not mapped enum item"); } if (field47.IsMultivalueEnum) { List <string> valueList = new List <string>(); foreach (MD45.Configurator.MetaDictionaryItem enumItem in (MD45.Configurator.MetaDictionaryItem[])object45[field45Name]) { valueList.Add(enumItem.Value); } if (valueList.Count > 0) { value = valueList.ToArray(); } } else { value = ((MD45.Configurator.MetaDictionaryItem)object45[field45Name]).Value; } } } else if (field47.GetMetaType().McDataType == MD47.Meta.Management.McDataType.File) { MD45.MetaFile metaFile45 = object45[field45Name] as MD45.MetaFile; if (metaFile45 != null) { //Begin copy file to 47 if (metaFile45.Buffer != null) { using (MemoryStream stream = new MemoryStream(metaFile45.Buffer)) { value = new MD47.Meta.FileInfo(metaFile45.Name, stream); } } else { value = new MD47.Meta.FileInfo(metaFile45.Name); } } } else { switch (field47Name) { case "Created": value = object45.Created; break; case "CreatorId": value = object45.CreatorId; break; case "Modified": value = object45.Modified; break; case "ModifierId": value = object45.ModifierId; break; default: value = object45[field45Name]; break; } } } else { fieldPresent = false; } }
private void BindCustomFields() { int ObjectId = GetObjectId(); string MetaClassName = GetMetaClassName(); MetaObject obj = MetaDataWrapper.LoadMetaObject(ObjectId, MetaClassName); if (obj != null) { int cur_weight = 0; for (int irow = 0; irow < _mflist.Count; irow++) { tblCustomFields.Rows.Add(new HtmlTableRow()); } foreach (MetaField field in obj.MetaClass.UserMetaFields) { if (ContainsMetaField(field.Name)) { cur_weight = _mflist.IndexOf(field.Name); HtmlTableRow row = new HtmlTableRow(); HtmlTableCell cellTitle = new HtmlTableCell(); HtmlTableCell cellValue = new HtmlTableCell(); cellTitle.NoWrap = true; cellTitle.VAlign = "Top"; cellTitle.InnerHtml = String.Format("<span class=ibn-label>{0}:</span>", field.FriendlyName); cellValue.Width = "90%"; object fieldValue = obj[field.Name]; if (fieldValue != null) { switch (field.DataType) { case MetaDataType.File: Mediachase.MetaDataPlus.MetaFile mf = (Mediachase.MetaDataPlus.MetaFile)fieldValue; int ContentTypeId = DSFile.GetContentTypeByFileName(mf.Name); string sInnerHTML = "<img src='../Common/ContentIcon.aspx?IconID=" + +ContentTypeId + "' border='0' align='middle' width='16px' height='16px' /> " + mf.Name; string metaFileUrl = WebDavUrlBuilder.GetMetaDataPlusWebDavUrl(ObjectId, MetaClassName, field.Name, true); string sNameLocked = Util.CommonHelper.GetLockerText(metaFileUrl); cellValue.InnerHtml = String.Format("<a href='{0}'>{1}</a> {2}", metaFileUrl, sInnerHTML, sNameLocked); //cellValue.InnerHtml = "<a href='../Modules/DownloadMetaFile.aspx?Id="+ObjectId.ToString()+ // "&Class="+MetaClassName+"&Field="+field.Name+"'>"+sInnerHTML+"</a>"; break; case MetaDataType.ImageFile: cellValue.InnerHtml = "<img align='middle' border='0' src='../Modules/GetMetaImageFile.aspx?Id=" + ObjectId.ToString() + "&Class=" + MetaClassName + "&Field=" + field.Name + "' />"; break; case MetaDataType.Binary: case MetaDataType.VarBinary: cellValue.InnerHtml = String.Format("<span class=ibn-value>{0}</span>", "[BinaryData]"); break; case MetaDataType.Bit: case MetaDataType.Boolean: if ((bool)fieldValue) { cellValue.InnerHtml = String.Format("<span class=ibn-value>{0}</span>", LocRM.GetString("BooleanYes")); } else { cellValue.InnerHtml = String.Format("<span class=ibn-value>{0}</span>", LocRM.GetString("BooleanNo")); } break; case MetaDataType.Date: cellValue.InnerHtml = String.Format("<span class=ibn-value>{0}</span>", ((DateTime)fieldValue).ToShortDateString()); break; case MetaDataType.Email: cellValue.InnerHtml = String.Format("<a href='mailto:{0}'>{0}</a>", fieldValue.ToString()); break; case MetaDataType.Image: cellValue.InnerHtml = String.Format("<span class=ibn-value>{0}</span>", "[Image]"); break; case MetaDataType.LongHtmlString: cellValue.InnerHtml = String.Format("<span class=ibn-description>{0}</span>", fieldValue.ToString()); break; case MetaDataType.DateTime: case MetaDataType.SmallDateTime: case MetaDataType.Timestamp: cellValue.InnerHtml = String.Format("<span class=ibn-value>{0} {1}</span>", ((DateTime)fieldValue).ToShortDateString(), ((DateTime)fieldValue).ToShortTimeString()); break; case MetaDataType.Url: cellValue.InnerHtml = String.Format("<a href='{0}' target='_blank'>{0}</a>", Server.UrlDecode(fieldValue.ToString())); break; case MetaDataType.Money: cellValue.InnerHtml = String.Format("<span class=ibn-value>{0}</span>", ((decimal)fieldValue).ToString("f")); break; case MetaDataType.Float: cellValue.InnerHtml = String.Format("<span class=ibn-value>{0}</span>", fieldValue.ToString()); break; case MetaDataType.EnumSingleValue: case MetaDataType.DictionarySingleValue: MetaDictionaryItem item = (MetaDictionaryItem)fieldValue; cellValue.InnerHtml = String.Format("<span class=ibn-value>{0}</span>", item.Value); break; case MetaDataType.EnumMultivalue: case MetaDataType.DictionaryMultivalue: MetaDictionaryItem[] items = (MetaDictionaryItem[])fieldValue; string sItems = String.Empty; foreach (MetaDictionaryItem mdItem in items) { if (sItems != "") { sItems += "<br>"; } sItems += mdItem.Value; } sItems = String.Format(CultureInfo.InvariantCulture, "<span class=ibn-value>{0}</span>", sItems); cellValue.InnerHtml = sItems; break; default: try { cellValue.InnerHtml = String.Format("<span class=ibn-value>{0}</span>", fieldValue.ToString()); } catch { cellValue.InnerHtml = ""; } break; } } cellTitle.Attributes.Add("class", "text"); cellValue.Attributes.Add("class", "text"); row.Cells.Add(cellTitle); row.Cells.Add(cellValue); //tblCustomFields.Rows.Add(row); tblCustomFields.Rows.Insert(cur_weight, row); tblCustomFields.Rows.RemoveAt(cur_weight + 1); } } } }
void LoadMetaFields2() { foreach (MetaField field in this.MetaClass.MetaFields) { if (field.IsSystem) continue; object FieldValue = this[field.Name]; if (FieldValue != null) { if (field.DataType == MetaDataType.DictionarySingleValue || field.DataType == MetaDataType.EnumSingleValue) { //bool bFound = false; //foreach (MetaDictionaryItem DicItem in field.Dictionary) //{ // if (DicItem.Id == (int)FieldValue) // { // bFound = true; // FieldValue = DicItem; // break; // } //} //if (!bFound) //{ // System.Diagnostics.Trace.WriteLine(string.Format("Couldn't find the MetaDictionaryItem (Id = {0}).", (int)FieldValue), "Mediachase.MetaDataPlus.MetaObject"); // FieldValue = null; //} } else if (field.DataType == MetaDataType.DictionaryMultivalue || field.DataType == MetaDataType.EnumMultivalue) { int MetaKey = (int)FieldValue; // TODO: Move it in to the current transaction [12/1/2004] using (SqlDataReader readerValue = SqlHelper.ExecuteReader(MetaDataContext.Current, CommandType.StoredProcedure, AsyncResources.GetConstantValue("SP_LoadMultivalueDictionary"), new SqlParameter("@MetaKey", MetaKey))) { ArrayList MultuValues = new ArrayList(); while (readerValue.Read()) { foreach (MetaDictionaryItem DicItem in field.Dictionary) { if (DicItem.Id == (int)readerValue["MetaDictionaryId"]) { MultuValues.Add(DicItem); break; } } } readerValue.Close(); FieldValue = (MetaDictionaryItem[])MultuValues.ToArray(typeof(MetaDictionaryItem)); } } else if (field.DataType == MetaDataType.File || field.DataType == MetaDataType.ImageFile) { int MetaKey = (int)FieldValue; // TODO: Move it in to the current transaction [12/1/2004] using (SqlDataReader readerValue = SqlHelper.ExecuteReader(MetaDataContext.Current, CommandType.StoredProcedure, AsyncResources.GetConstantValue("SP_LoadMetaFile"), new SqlParameter("@MetaKey", MetaKey))) { if (readerValue.Read()) { MetaFile file = new MetaFile(readerValue); FieldValue = file; } else FieldValue = null; readerValue.Close(); } } else if (field.DataType == MetaDataType.StringDictionary) { int MetaKey = (int)FieldValue; // TODO: Move it in to the current transaction [12/1/2004] using (SqlDataReader readerValue = SqlHelper.ExecuteReader(MetaDataContext.Current, CommandType.StoredProcedure, AsyncResources.GetConstantValue("SP_LoadMetaStringDictionary"), new SqlParameter("@MetaKey", MetaKey))) { if (readerValue.Read()) { MetaStringDictionary dic = new MetaStringDictionary(); dic.LoadDictionary(readerValue); FieldValue = dic; } else FieldValue = null; readerValue.Close(); } } else if (field.DataType == MetaDataType.MetaObject) { using (SqlDataReader readerValue = SqlHelper.ExecuteReader(MetaDataContext.Current, CommandType.StoredProcedure, AsyncResources.GetConstantValue("SP_LoadMetaObjectValue"), new SqlParameter("@MetaKey", (int)FieldValue))) { int MetaClassId = -1; int MetaObjectId = -1; if (readerValue.Read()) { MetaClassId = (int)readerValue["MetaClassId"]; MetaObjectId = (int)readerValue["MetaObjectId"]; readerValue.Close(); try { FieldValue = MetaObject.Load(MetaObjectId, MetaClassId); } catch (Exception ex) { FieldValue = null; System.Diagnostics.Trace.WriteLine(ex, "Load MetaDataType.MetaObject"); } } else { FieldValue = null; readerValue.Close(); } } } } _fieldStorage[field.Name] = FieldValue; } this._state = MetaObjectState.Unchanged; }