public bool Create(CategoryViewModel vm, Category e) { using (var DbTransaction = _unitOfWork.BeginTransaction()) { try { var contentDefinition = new ContentDefinition { Name = Contanst.TableName.Category }; e.ContentDefinition = contentDefinition; foreach (var item in vm.LanguageVms) { var contentEntry = new ContentEntry { LanguageId = item.LanguageId, Token = item.Token, Value = item.Value ?? string.Empty, ContentDefinitionId = contentDefinition.ContentDefinitionId }; e.ContentDefinition.ContentEntries.Add(contentEntry); } _categoryRepository.Insert(e); _unitOfWork.Complete(); DbTransaction.Commit(); return(true); } catch (Exception exception) { Console.WriteLine(exception); return(false); } } }
/// <summary> /// Write container header information for given data to stream /// </summary> /// <param name="stream">Stream to write to</param> /// <param name="contentDefinition">Content definition to serialize (can be null)</param> /// <param name="entries">Entry information to serialize (can be null)</param> /// <exception cref="ArgumentNullException"><paramref name="stream"/> is null</exception> public static void WriteHead(Stream stream, ContentDefinition contentDefinition, List <MutableKeyValuePair <string, int> > entries) { if (stream == null) { throw new ArgumentNullException(nameof(stream)); } var cpEntries = new List <MutableKeyValuePair <string, int> >(entries); for (var i = 0; i < cpEntries.Count; i++) { var kvp = cpEntries[i]; kvp.Item1 = kvp.Item1.Trim('/', '\\'); cpEntries[i] = kvp; } using (var ms = new MemoryStream()) { using (var ds = new DeflateStream(ms, CompressionLevel.Optimal, true)) { Serializer.Serialize(ds, contentDefinition); Serializer.Serialize(ds, entries); } stream.Write7S64(ms.Length); ms.Position = 0; ms.CopyTo(stream); } }
private CzBox(Stream stream, ContentDefinition contentDefinition, Dictionary <string, Tuple <int, int> > entries, long bOfs, bool leaveOpen) { _stream = stream; _contentDefinition = contentDefinition; _entries = entries; _bOfs = bOfs; _closable = !leaveOpen; }
public static T?HandleEmptyElementOfValueType <T>(this XRoadMessage message, ContentDefinition content, Func <T?> getStrictValue) where T : struct { switch (content.EmptyTagHandlingMode ?? message.ServiceManager.ProtocolDefinition.EmptyTagHandlingMode) { case EmptyTagHandlingMode.DefaultValue: return(default(T)); case EmptyTagHandlingMode.Null: return(null); default: return(getStrictValue()); } }
private ContentDefinition GetContentDefinition() { if (this._contentDefinition == null) { try { ContentDefinition definition = (ContentDefinition)this.ContentResolutionService.ContentDefinitions[((Content)base.Component).ContentPlaceHolderID]; this._contentDefinition = new ContentDefinition(definition.ContentPlaceHolderID, definition.DefaultContent, definition.DefaultDesignTimeHtml); } catch { } } return(this._contentDefinition); }
protected override void PostFilterProperties(IDictionary properties) { base.PostFilterProperties(properties); PropertyDescriptor oldPropertyDescriptor = (PropertyDescriptor)properties["ID"]; PropertyDescriptor descriptor2 = (PropertyDescriptor)properties["ContentPlaceHolderID"]; properties.Clear(); ContentDesignerState showDefaultContent = ContentDesignerState.ShowDefaultContent; ContentDefinition contentDefinition = this.GetContentDefinition(); if ((this.ContentResolutionService != null) && (contentDefinition != null)) { showDefaultContent = this.ContentResolutionService.GetContentDesignerState(contentDefinition.ContentPlaceHolderID); } oldPropertyDescriptor = TypeDescriptor.CreateProperty(oldPropertyDescriptor.ComponentType, oldPropertyDescriptor, new Attribute[] { (showDefaultContent == ContentDesignerState.ShowDefaultContent) ? ReadOnlyAttribute.Yes : ReadOnlyAttribute.No }); properties.Add("ID", oldPropertyDescriptor); descriptor2 = TypeDescriptor.CreateProperty(descriptor2.ComponentType, descriptor2, new Attribute[] { ReadOnlyAttribute.Yes }); properties.Add("ContentPlaceHolderID", descriptor2); }
public object Deserialize(XmlReader reader, IXmlTemplateNode templateNode, ContentDefinition content, XRoadMessage message) { if (!reader.ReadToDescendant("Include", NamespaceConstants.XOP)) { throw XRoadException.InvalidQuery("Missing `xop:Include` reference to multipart content."); } var contentID = reader.GetAttribute("href"); if (string.IsNullOrWhiteSpace(contentID)) { throw XRoadException.InvalidQuery("Missing `href` attribute to multipart content."); } var attachment = message.GetAttachment(contentID.Substring(4)); if (attachment == null) { throw XRoadException.PäringusPuudubAttachment(contentID); } return(attachment.ContentStream); }
private static int RunPack(PackOptions options) { ContentDefinition def = null; if (options.ContentDefinition != null) { using (var defFs = new FileStream(options.ContentDefinition, FileMode.Open, FileAccess.Read)) def = AuthoringUtil.JsonDeserialize <ContentDefinition>(defFs); } var bList = new List <FileInfo>(); if (options.Resources != null) { foreach (var res in options.Resources) { bList.Add(new FileInfo(res)); } } var metaList = new List <MutableKeyValuePair <string, int> >(); foreach (var ent in bList) { metaList.Add(new MutableKeyValuePair <string, int>(ent.Name, (int)ent.Length)); } using (var ofs = new FileStream(options.TargetFile, FileMode.Create, FileAccess.Write)) { CzBox.WriteHead(ofs, def, metaList); foreach (var ent in bList) { using (var eStream = ent.OpenRead()) eStream.CopyTo(ofs); } } return(0); }
public abstract object Deserialize(XmlReader reader, IXmlTemplateNode templateNode, ContentDefinition content, XRoadMessage message);
/// <summary> /// There are no comments for ContentDefinitionSet in the schema. /// </summary> public void AddToContentDefinitionSet(ContentDefinition contentDefinition) { base.AddObject("ContentDefinitionSet", contentDefinition); }
public override object Deserialize(XmlReader reader, IXmlTemplateNode templateNode, ContentDefinition content, XRoadMessage message) { var isEmptyElement = reader.IsEmptyElement; var stringValue = isEmptyElement ? "" : reader.ReadElementContentAsString(); if (!deserializationMapping.TryGetValue(stringValue, out var enumerationValue)) { throw new MissingFieldException($"Unexpected value `{stringValue}` for enumeration type `{Definition.Name}`."); } var result = Enum.ToObject(Definition.Type, enumerationValue); return(isEmptyElement ? MoveNextAndReturn(reader, result) : result); }
private void ValidateRemainingProperties(IEnumerator <IPropertyMap> properties, ContentDefinition content) { while (properties.MoveNext()) { if (!properties.Current.Definition.Content.IsOptional) { var typeName = Definition?.Name ?? ((content.Particle as ArrayItemDefinition)?.Array as PropertyDefinition)?.DeclaringTypeDefinition?.Name; throw XRoadException.InvalidQuery($"Element `{properties.Current.Definition.Content.SerializedName.LocalName}` is required by type `{typeName}` definition."); } } }
public override object Deserialize(XmlReader reader, IXmlTemplateNode templateNode, ContentDefinition content, XRoadMessage message) { if (reader.IsEmptyElement) { return(MoveNextAndReturn(reader, 0M)); } var value = reader.ReadElementContentAsString(); return(string.IsNullOrEmpty(value) ? 0M : XmlConvert.ToDecimal(value)); }
public override object Deserialize(XmlReader reader, IXmlTemplateNode templateNode, ContentDefinition content, XRoadMessage message) { throw new NotImplementedException(); }
public override void Serialize(XmlWriter writer, IXmlTemplateNode templateNode, object value, ContentDefinition content, XRoadMessage message) { var typeMap = serializer.GetTypeMap(value.GetType()); if (typeMap == null) { throw new NotImplementedException($"No type definition provided for runtime type: {value.GetType().FullName}"); } typeMap.Serialize(writer, templateNode, value, content, message); }
public override void Serialize(XmlWriter writer, IXmlTemplateNode templateNode, object value, ContentDefinition content, XRoadMessage message) { message.Style.WriteType(writer, Definition, content); writer.WriteValue(XmlConvert.ToString((DateTime)value, "yyyy-MM-dd")); }
/// <summary> /// Writes element type attribute according to style preferences. /// </summary> public virtual void WriteType(XmlWriter writer, TypeDefinition typeDefinition, ContentDefinition contentDefinition) { if (typeDefinition.IsAnonymous) { return; } if (typeDefinition.Type != contentDefinition.RuntimeType) { writer.WriteTypeAttribute(typeDefinition.Name); return; } if (!(contentDefinition.Particle is RequestDefinition)) { WriteExplicitType(writer, typeDefinition.Name); } }
public override void Serialize(XmlWriter writer, IXmlTemplateNode templateNode, object value, ContentDefinition content, XRoadMessage message) { if (!(content.Particle is RequestDefinition)) { message.Style.WriteExplicitType(writer, Definition.Name); } if (!serializationMapping.TryGetValue((int)value, out var enumerationValue)) { throw new MissingFieldException($"Cannot map value `{value}` to enumeration type `{Definition.Name}`."); } writer.WriteValue(enumerationValue); }
public abstract void Serialize(XmlWriter writer, IXmlTemplateNode templateNode, object value, ContentDefinition content, XRoadMessage message);
public void Serialize(XmlWriter writer, IXmlTemplateNode templateNode, object value, ContentDefinition content, XRoadMessage message) { var attachment = new XRoadAttachment((Stream)value); message.AllAttachments.Add(attachment); message.Style.WriteType(writer, Definition, content); writer.WriteStartElement(PrefixConstants.XOP, "Include", NamespaceConstants.XOP); writer.WriteAttributeString("href", $"cid:{attachment.ContentID}"); writer.WriteEndElement(); }
public override object Deserialize(XmlReader reader, IXmlTemplateNode templateNode, ContentDefinition content, XRoadMessage message) { if (reader.IsEmptyElement) { return(MoveNextAndReturn(reader, new DateTime())); } var value = reader.ReadElementContentAsString(); if (string.IsNullOrEmpty(value)) { return(null); } var date = DateTime.ParseExact(value, dateFormats, CultureInfo.InvariantCulture, DateTimeStyles.None); if (value[value.Length - 1] == 'Z') { date = date.ToLocalTime(); } return(date); }
public override void Serialize(XmlWriter writer, IXmlTemplateNode templateNode, object value, ContentDefinition content, XRoadMessage message) { message.Style.WriteType(writer, Definition, content); writer.WriteValue(value); }
public override object Deserialize(XmlReader reader, IXmlTemplateNode templateNode, ContentDefinition content, XRoadMessage message) { var entity = new T(); entity.SetTemplateMembers(templateNode.ChildNames); var validateRequired = content.Particle is RequestDefinition; if (contentPropertyMap != null) { ReadPropertyValue(reader, contentPropertyMap, templateNode[contentPropertyMap.Definition.TemplateName, message.Version], message, validateRequired, entity); return(entity); } var properties = propertyMaps.GetEnumerator(); if (reader.IsEmptyElement) { ValidateRemainingProperties(properties, content); return(MoveNextAndReturn(reader, entity)); } var parentDepth = reader.Depth; var itemDepth = parentDepth + 1; reader.Read(); while (parentDepth < reader.Depth) { if (reader.NodeType != XmlNodeType.Element || reader.Depth != itemDepth) { reader.Read(); continue; } var propertyNode = MoveToProperty(reader, properties, templateNode, message, validateRequired); ReadPropertyValue(reader, properties.Current, propertyNode, message, validateRequired, entity); } ValidateRemainingProperties(properties, content); return(entity); }
protected override void Seed(NeuCMS.Repositories.EntityFramework.ContentRepository context) { var nameSpace = new NameSpace() { Id = 1, Description = "Sample NeuCMS Content Data", NameSpaceName = "NeuCMS.Samples" }; context.NameSpaces.AddOrUpdate( n => n.Id, nameSpace); var contentDef1 = new ContentDefinition() { Id = 1, Name = "Message", NameSpace = nameSpace, AvailableOnAllViews = false }; var contentDef2 = new ContentDefinition() { Id = 2, Name = "Image", NameSpace = nameSpace, AvailableOnAllViews = false }; var view = new View() { Id = 1, NameSpace = nameSpace, ViewName = "Home", ContentDefinitions = new List <ContentDefinition>() { contentDef1, contentDef2 } }; var dimDef = new DimensionDefinition() { Id = 1, DimensionName = "Language", NameSpace = nameSpace }; var elementContent = new ElementContent() { Id = 1, Content = "Hello World!", ContentElementDefinition = view.ContentDefinitions[0], Dimensions = new List <DimensionValue>() { new DimensionValue() { Id = 1, DimensionDefinition = dimDef, Value = "English" } } }; var converter = new ImageConverter(); var imgBytes = (byte[])converter.ConvertTo(TestData.Test, typeof(byte[])); var mediaContent = new MediaContent() { Id = 2, ContentElementDefinition = view.ContentDefinitions[1], Dimensions = new List <DimensionValue>() { new DimensionValue() { Id = 1, DimensionDefinition = dimDef, Value = "English" } }, DigitalAsset = new DigitalAsset() { Id = 1, ContentType = "image/jpeg", Data = imgBytes } }; context.Views.AddOrUpdate(v => v.Id, view); context.ContentDefinitions.AddOrUpdate(c => c.Name, contentDef1); context.DimensionDefinitions.AddOrUpdate(d => d.DimensionName, dimDef); context.Contents.AddOrUpdate(c => c.Id, elementContent); context.Contents.AddOrUpdate(c => c.Id, mediaContent); }
public override void Serialize(XmlWriter writer, IXmlTemplateNode templateNode, object value, ContentDefinition content, XRoadMessage message) { if (!(content.Particle is RequestDefinition)) { message.Style.WriteExplicitType(writer, Definition.Name); } writer.WriteValue(value); }
public void Refresh() { _tempDef = null; Controls.Clear(); CreateChildControls(); }
public override object Deserialize(XmlReader reader, IXmlTemplateNode templateNode, ContentDefinition content, XRoadMessage message) { if (reader.IsEmptyElement) { return(MoveNextAndReturn(reader, HandleEmptyElement(content, message))); } var value = reader.ReadElementContentAsString(); if (string.IsNullOrEmpty(value)) { return(HandleEmptyElement(content, message)); } return(XmlConvert.ToBoolean(value)); }
void btnChange_WorkflowMethodCompleted(object sender, WorkflowMethodArgs e) { if (!e.UnsecureOutput.ContainsKey("NewLCID")) return; int newLCID = int.Parse(e.UnsecureOutput["NewLCID"].ToString()); MemDefCulture cu = tempDef.Culture[LCID]; tempDef.Culture.Remove(LCID); cu.LCID = newLCID; if (cu.OldLCID == 0) cu.OldLCID = LCID; tempDef.Culture.Add(cu.LCID, cu); LCID = newLCID; cu.Name = CultureInfo.GetCultureInfo(LCID).NativeName; tempDef.RegisterChange(cu.Guid); WAFContext.FlagChangeInTemporaryDefinition(); WAFContext.UpdateTemporaryLocalDefinitionFile(); _tempDef = null; this.Refresh(); if (NewLCID != null) NewLCID(this, EventArgs.Empty); }
private static bool?HandleEmptyElement(ContentDefinition content, XRoadMessage message) { return(message.HandleEmptyElementOfValueType <bool>(content, () => throw new InvalidQueryException("'' is not a valid value for 'boolean'"))); }
void btnNew_WorkflowMethodCompleted(object sender, WorkflowMethodArgs e) { if (!e.UnsecureOutput.ContainsKey("NewLCID")) return; int newLCID = int.Parse(e.UnsecureOutput["NewLCID"].ToString()); MemDefCulture cu = new MemDefCulture(); cu.LCID = newLCID; cu.Name = CultureInfo.GetCultureInfo(newLCID).NativeName; tempDef.Culture.Add(cu.LCID, cu); tempDef.RegisterChange(cu.Guid); WAFContext.FlagChangeInTemporaryDefinition(); WAFContext.UpdateTemporaryLocalDefinitionFile(); _editForm.LCID = newLCID; _editForm.Refresh(); _tempDef = null; list.SetSelected(_editForm.LCID.ToString()); setQuery(); }
private static int RunTemplate(TemplateOptions options) { switch (options.Type.ToLowerInvariant()) { case "definition": var def = new ContentDefinition(); def.MeshConfigs.Add("yourConfigName", new MeshConfig { Mesh = "yourMeshName", Materials = new List <Material> { new Material { Textures = new Dictionary <string, string> { { "yourShaderParameterName", "yourTextureName" } } } }, CustomAttachPoints = new List <AttachPoint> { new AttachPoint { BoneName = "yourBoneName" } } }); def.MeshPaths.Add("yourMeshName", "yourPath"); def.ResourcePaths.Add("yourResourceName", "yourPath"); def.TexturePaths.Add("yourTextureName", "yourPath"); def.TranslationPaths.Add("yourTranslationName", "yourPath"); def.CoTextures.Add("yourCoTextureName", new CoTextureDefinition { Height = 1024, Width = 1024, Textures = new List <SubTextureDefinition> { new SubTextureDefinition { Mask = "yourTextureName", Texture = "yourTextureName" } } }); using (var ofs = new FileStream(options.TargetFile, FileMode.Create, FileAccess.Write)) AuthoringUtil.JsonSerialize(def, ofs); break; case "matchfile": var matchFile = new MatchRules(); foreach (var t in (BoneType[])Enum.GetValues(typeof(BoneType))) { matchFile.Bones.Add($"boneRegex{t.ToString()}", t); } foreach (var t in (AttachPointType[])Enum.GetValues(typeof(AttachPointType))) { matchFile.AttachPoints.Add($"boneRegex{t.ToString()}", t); } using (var ofs = new FileStream(options.TargetFile, FileMode.Create, FileAccess.Write)) AuthoringUtil.JsonSerialize(matchFile, ofs); break; default: Console.Error.WriteLine("Template type not recognized"); return(0x10103040); } return(0); }
void _editForm_NewLCID(object sender, EventArgs e) { _tempDef = null; setQuery(); list.SetSelected(_editForm.LCID.ToString()); }
public void Serialize(XmlWriter writer, IXmlTemplateNode templateNode, object value, ContentDefinition content, XRoadMessage message) { var attachment = new XRoadAttachment((Stream)value); message.AllAttachments.Add(attachment); if (!(content.Particle is RequestDefinition)) { message.Style.WriteExplicitType(writer, Definition.Name); } writer.WriteStartElement(PrefixConstants.XOP, "Include", NamespaceConstants.XOP); //writer.WriteAttributeString(PrefixConstants.XMIME, "contentType", NamespaceConstants.XMIME, "application/octet-stream"); writer.WriteAttributeString("href", $"cid:{attachment.ContentID}"); writer.WriteEndElement(); }
public override object Deserialize(XmlReader reader, IXmlTemplateNode templateNode, ContentDefinition content, XRoadMessage message) { var contentID = reader.GetAttribute("href"); if (string.IsNullOrWhiteSpace(contentID)) { if (message.IsMultipartContainer) { throw new InvalidQueryException("Missing `href` attribute to multipart content."); } var tempAttachment = new XRoadAttachment(new MemoryStream()) { IsMultipartContent = false }; message.AllAttachments.Add(tempAttachment); if (reader.IsEmptyElement) { return(MoveNextAndReturn(reader, tempAttachment.ContentStream)); } reader.Read(); const int bufferSize = 1000; int bytesRead; var buffer = new byte[bufferSize]; while ((bytesRead = reader.ReadContentAsBase64(buffer, 0, bufferSize)) > 0) { tempAttachment.ContentStream.Write(buffer, 0, bytesRead); } return(tempAttachment.ContentStream); } var attachment = message.GetAttachment(contentID.Substring(4)); if (attachment == null) { throw new InvalidQueryException($"MIME multipart message does not contain message part with ID `{contentID}`."); } if (reader.IsEmptyElement) { return(MoveNextAndReturn(reader, attachment.ContentStream)); } reader.ReadToEndElement(); return(attachment.ContentStream); }
/// <summary> /// Create a new ContentDefinition object. /// </summary> /// <param name="contentId">Initial value of ContentId.</param> /// <param name="definitionId">Initial value of DefinitionId.</param> /// <param name="positionInContent">Initial value of PositionInContent.</param> public static ContentDefinition CreateContentDefinition(int contentId, int definitionId, int positionInContent) { ContentDefinition contentDefinition = new ContentDefinition(); contentDefinition.ContentId = contentId; contentDefinition.DefinitionId = definitionId; contentDefinition.PositionInContent = positionInContent; return contentDefinition; }
public override void Serialize(XmlWriter writer, IXmlTemplateNode templateNode, object value, ContentDefinition content, XRoadMessage message) { var attachment = new XRoadAttachment((Stream)value); message.AllAttachments.Add(attachment); if (message.BinaryMode == BinaryMode.Attachment) { if (!(content.Particle is RequestDefinition)) { message.Style.WriteExplicitType(writer, encodedTypeName); } writer.WriteAttributeString("href", $"cid:{attachment.ContentID}"); return; } message.Style.WriteType(writer, Definition, content); attachment.IsMultipartContent = false; attachment.WriteAsBase64(writer); }