本文整理汇总了C#中System.Xml.Serialization.XmlSerializer.DeserializeXElement方法的典型用法代码示例。如果您正苦于以下问题:C# XmlSerializer.DeserializeXElement方法的具体用法?C# XmlSerializer.DeserializeXElement怎么用?C# XmlSerializer.DeserializeXElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Serialization.XmlSerializer
的用法示例。
在下文中一共展示了XmlSerializer.DeserializeXElement方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyPattern
public JsonResult ApplyPattern(int id, SequencingPattern pattern, int data)
{
var node = _Storage.GetNode(id);
var xml = new XmlSerializer(typeof(Sequencing));
var xelement = id == 0 ? _CurrentCourse.Sequencing : node.Sequencing;
var sequencing = xelement == null ? new Sequencing() : (Sequencing)xml.DeserializeXElement(xelement);
switch (pattern)
{
case SequencingPattern.ControlChapterSequencingPattern:
sequencing = SequencingPatternManager.ApplyControlChapterSequencing(sequencing);
break;
case SequencingPattern.RandomSetSequencingPattern:
sequencing = SequencingPatternManager.ApplyRandomSetSequencingPattern(sequencing, data);
break;
case SequencingPattern.OrganizationDefaultSequencingPattern:
sequencing = SequencingPatternManager.ApplyDefaultChapterSequencing(sequencing);
break;
}
if (id == 0)
{
_CurrentCourse.Sequencing = xml.SerializeToXElemet(sequencing);
_Storage.UpdateCourse(_CurrentCourse.Id, _CurrentCourse);
}
else
{
node.Sequencing = xml.SerializeToXElemet(sequencing);
_Storage.UpdateNode(id, node);
}
return Json(new { status = true });
}
示例2: SaveProperties
public JsonResult SaveProperties(int nodeId, string type)
{
var node = _Storage.GetNode(nodeId);
var xml = new XmlSerializer(typeof(Sequencing));
var xelement = nodeId == 0 ? _CurrentCourse.Sequencing : node.Sequencing;
var sequencing = xelement == null ? new Sequencing() : (Sequencing)xml.DeserializeXElement(xelement);
object model;
if (type == "ControlMode")
{
model = new ControlMode();
TryUpdateModel(model as ControlMode);
sequencing.ControlMode = model as ControlMode;
}
else if (type == "LimitConditions")
{
model = new LimitConditions();
TryUpdateModel(model as LimitConditions);
sequencing.LimitConditions = model as LimitConditions;
}
else if (type == "ConstrainedChoiceConsiderations")
{
model = new ConstrainedChoiceConsiderations();
TryUpdateModel(model as ConstrainedChoiceConsiderations);
sequencing.ConstrainedChoiceConsiderations = model as ConstrainedChoiceConsiderations;
}
else if (type == "RandomizationControls")
{
model = new RandomizationControls();
TryUpdateModel(model as RandomizationControls);
sequencing.RandomizationControls = model as RandomizationControls;
}
else if (type == "DeliveryControls")
{
model = new DeliveryControls();
TryUpdateModel(model as DeliveryControls);
sequencing.DeliveryControls = model as DeliveryControls;
}
else if (type == "RollupRules")
{
model = new RollupRules();
TryUpdateModel(model as RollupRules);
sequencing.RollupRules = model as RollupRules;
}
else if (type == "RollupConsiderations")
{
model = new RollupConsiderations();
TryUpdateModel(model as RollupConsiderations);
sequencing.RollupConsiderations = model as RollupConsiderations;
}
else
{
throw new NotImplementedException();
}
if(nodeId == 0)
{
_CurrentCourse.Sequencing = xml.SerializeToXElemet(sequencing);
_Storage.UpdateCourse(_CurrentCourse.Id, _CurrentCourse);
}
else
{
node.Sequencing = xml.SerializeToXElemet(sequencing);
_Storage.UpdateNode(nodeId, node);
}
return Json(new { status = true });
}
示例3: Properties
public JsonResult Properties(int id, string type)
{
var xml = new XmlSerializer(typeof(Sequencing));
var xelement = id == 0 ? _CurrentCourse.Sequencing : _Storage.GetNode(id).Sequencing;
var sequencing = xelement == null ? new Sequencing() : (Sequencing) xml.DeserializeXElement(xelement);
NodeProperty model;
var partialView = "Properties";
if (type == "ControlMode")
{
model = sequencing.ControlMode ?? new ControlMode();
}
else if (type == "LimitConditions")
{
model = sequencing.LimitConditions ?? new LimitConditions();
}
else if (type == "ConstrainedChoiceConsiderations")
{
model = sequencing.ConstrainedChoiceConsiderations ?? new ConstrainedChoiceConsiderations();
}
else if (type == "RandomizationControls")
{
model = sequencing.RandomizationControls ?? new RandomizationControls();
}
else if (type == "DeliveryControls")
{
model = sequencing.DeliveryControls ?? new DeliveryControls();
}
else if (type == "RollupRules")
{
model = sequencing.RollupRules ?? new RollupRules();
}
else if (type == "RollupConsiderations")
{
model = sequencing.RollupConsiderations ?? new RollupConsiderations();
}
else
{
throw new NotImplementedException();
}
model.CourseId = _CurrentCourse.Id;
model.NodeId = id;
model.Type = type;
return Json(new { status = true, type = type, data = PartialViewHtml(partialView, model, ViewData) });
}
示例4: EditPropertiesTest
public void EditPropertiesTest([Values("ControlMode",
"LimitConditions",
"ConstrainedChoiceConsiderations",
"RandomizationControls",
"DeliveryControls",
"RollupRules",
"RollupConsiderations")]
string type)
{
try
{
// create new node with name "SomeNode", id=ID, courseId=1, and add it to storage
this.createNode();
// create new xml serializer
var xml = new XmlSerializer(typeof(Sequencing));
// get Sequencing from node with id = ID
var xelement = this.Storage.GetNode(ID).Sequencing;
// deserialize sequencing from xelement
var sequencing = xelement == null ? new Sequencing() : (Sequencing)xml.DeserializeXElement(xelement);
// new model
object model;
// for different type initialise sequencing property
if (type == "ControlMode")
{
model = new ControlMode();
//TryUpdateModel(model as ControlMode);
sequencing.ControlMode = model as ControlMode;
}
else if (type == "LimitConditions")
{
model = new LimitConditions();
//TryUpdateModel(model as LimitConditions);
sequencing.LimitConditions = model as LimitConditions;
}
else if (type == "ConstrainedChoiceConsiderations")
{
model = new ConstrainedChoiceConsiderations();
//TryUpdateModel(model as ConstrainedChoiceConsiderations);
sequencing.ConstrainedChoiceConsiderations = model as ConstrainedChoiceConsiderations;
}
else if (type == "RandomizationControls")
{
model = new RandomizationControls();
//TryUpdateModel(model as RandomizationControls);
sequencing.RandomizationControls = model as RandomizationControls;
}
else if (type == "DeliveryControls")
{
model = new DeliveryControls();
//TryUpdateModel(model as DeliveryControls);
sequencing.DeliveryControls = model as DeliveryControls;
}
else if (type == "RollupRules")
{
model = new RollupRules();
//TryUpdateModel(model as RollupRules);
sequencing.RollupRules = model as RollupRules;
}
else if (type == "RollupConsiderations")
{
model = new RollupConsiderations();
//TryUpdateModel(model as RollupConsiderations);
sequencing.RollupConsiderations = model as RollupConsiderations;
}
else
{
throw new NotImplementedException();
}
// serialize sequencing
xelement = xml.SerializeToXElemet(sequencing);
// update node
this.Storage.UpdateNode(ID, this.Storage.GetNode(ID));
}
catch (Exception ex)
{
Assert.Fail(ex.Message);
}
}
示例5: ApplyPatternTest
public void ApplyPatternTest([Values(SequencingPattern.ControlChapterSequencingPattern,
SequencingPattern.RandomSetSequencingPattern,
SequencingPattern.OrganizationDefaultSequencingPattern)]
SequencingPattern pattern)
{
try
{
// create new node with name "SomeNode", id=ID, courseId=1, and add it to storage
this.createNode();
// get node with id = ID
var node = this.Storage.GetNode(ID);
// create new xml serializer
var xml = new XmlSerializer(typeof(Sequencing));
// get Sequencing from node with id = ID
var xelement = this.Storage.GetNode(ID).Sequencing;
// deserialize sequencing from xelement
var sequencing = xelement == null ? new Sequencing() : (Sequencing)xml.DeserializeXElement(xelement);
// for different patterns type apply different patterns
switch (pattern)
{
case SequencingPattern.ControlChapterSequencingPattern:
sequencing = SequencingPatternManager.ApplyControlChapterSequencing(sequencing);
break;
case SequencingPattern.RandomSetSequencingPattern:
sequencing = SequencingPatternManager.ApplyRandomSetSequencingPattern(sequencing, 1);
break;
case SequencingPattern.OrganizationDefaultSequencingPattern:
sequencing = SequencingPatternManager.ApplyDefaultChapterSequencing(sequencing);
break;
}
// serialize sequencing
node.Sequencing = xml.SerializeToXElemet(sequencing);
// try update node
this.Storage.UpdateNode(ID, node);
}
catch (Exception ex)
{
Assert.Fail(ex.Message);
}
}
示例6: ShowPropertiesTest
public void ShowPropertiesTest([Values("ControlMode",
"LimitConditions",
"ConstrainedChoiceConsiderations",
"RandomizationControls",
"DeliveryControls",
"RollupRules",
"RollupConsiderations")]
string type)
{
try
{
// create new node with name "SomeNode", id=ID, courseId=1, and add it to storage
this.createNode();
// create new xml serializer
var xml = new XmlSerializer(typeof(Sequencing));
// get Sequencing from node with id = ID
var xelement = this.Storage.GetNode(ID).Sequencing;
// deserialize sequencing from xelement
var sequencing = xelement == null ? new Sequencing() : (Sequencing)xml.DeserializeXElement(xelement);
// new model
NodeProperty model;
// for different types get node property and initialise model
if (type == "ControlMode")
{
model = sequencing.ControlMode ?? new ControlMode();
}
else if (type == "LimitConditions")
{
model = sequencing.LimitConditions ?? new LimitConditions();
}
else if (type == "ConstrainedChoiceConsiderations")
{
model = sequencing.ConstrainedChoiceConsiderations ?? new ConstrainedChoiceConsiderations();
}
else if (type == "RandomizationControls")
{
model = sequencing.RandomizationControls ?? new RandomizationControls();
}
else if (type == "DeliveryControls")
{
model = sequencing.DeliveryControls ?? new DeliveryControls();
}
else if (type == "RollupRules")
{
model = sequencing.RollupRules ?? new RollupRules();
}
else if (type == "RollupConsiderations")
{
model = sequencing.RollupConsiderations ?? new RollupConsiderations();
}
else
{
throw new NotImplementedException();
}
//model.CourseId = 1;
//model.NodeId = ID;
//model.Type = type;
}
catch (Exception ex)
{
Assert.Fail(ex.Message);
}
}
示例7: ApplyPattern
public JsonResult ApplyPattern(int id, SequencingPattern pattern, int data)
{
var node = this.storage.GetNode(id);
var xml = new XmlSerializer(typeof(Sequencing));
var xelement = id == 0 ? this.currentCourse.Sequencing : node.Sequencing;
var sequencing = xelement == null ? new Sequencing() : (Sequencing)xml.DeserializeXElement(xelement);
switch (pattern)
{
case SequencingPattern.ControlChapterSequencingPattern:
sequencing = SequencingPatternManager.ApplyControlChapterSequencing(sequencing);
break;
case SequencingPattern.RandomSetSequencingPattern:
sequencing = SequencingPatternManager.ApplyRandomSetSequencingPattern(sequencing, data);
break;
case SequencingPattern.OrganizationDefaultSequencingPattern:
sequencing = SequencingPatternManager.ApplyDefaultChapterSequencing(sequencing);
break;
}
if (id == 0)
{
this.currentCourse.Sequencing = xml.SerializeToXElemet(sequencing);
this.storage.UpdateCourse(this.currentCourse.Id, this.currentCourse);
// logic to update all nodes sequencing
var courseNodes = this.storage.GetAllNodes(this.currentCourse.Id);
foreach (var courseNode in courseNodes)
{
courseNode.Sequencing = xml.SerializeToXElemet(sequencing);
this.storage.UpdateNode(courseNode.Id, courseNode);
}
}
else
{
node.Sequencing = xml.SerializeToXElemet(sequencing);
this.storage.UpdateNode(id, node);
}
return Json(new { status = true });
}
示例8: ApplyDefaultPattern
private void ApplyDefaultPattern(Course course)
{
var xml = new XmlSerializer(typeof(Sequencing));
var xelement = course.Sequencing;
var sequencing = xelement == null ? new Sequencing() : (Sequencing)xml.DeserializeXElement(xelement);
sequencing = SequencingPatternManager.ApplyDefaultChapterSequencing(sequencing);
course.Sequencing = xml.SerializeToXElemet(sequencing);
this.storage.UpdateCourse(course.Id, course);
}