本文整理汇总了C#中XmlSerializer.DeserializeXElement方法的典型用法代码示例。如果您正苦于以下问题:C# XmlSerializer.DeserializeXElement方法的具体用法?C# XmlSerializer.DeserializeXElement怎么用?C# XmlSerializer.DeserializeXElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlSerializer
的用法示例。
在下文中一共展示了XmlSerializer.DeserializeXElement方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Export
public string Export(int id)
{
var course = GetCourse(id);
var path = GetCoursePath(id);
if (course.Locked != null && course.Locked.Value)
{
return path + ".zip";
}
path = Path.Combine(path, Guid.NewGuid().ToString());
path = Path.Combine(path, course.Name);
Directory.CreateDirectory(path);
var nodes = GetNodes(id).ToList();
for (var i = 0; i < nodes.Count; i++)
{
if (nodes[i].IsFolder == false)
{
File.Copy(GetNodePath(nodes[i].Id) + ".html", Path.Combine(path, nodes[i].Id + ".html"));
}
else
{
var subNodes = GetNodes(id, nodes[i].Id);
nodes.AddRange(subNodes);
}
}
var coursePath = GetCoursePath(id);
FileHelper.DirectoryCopy(Path.Combine(coursePath, "Node"), Path.Combine(path, "Node"));
foreach (var file in _TemplateFiles)
{
File.Copy(Path.Combine(coursePath, file), Path.Combine(path, file));
}
var helper = new ManifestManager();
var manifest = new Manifest();
var sw = new StreamWriter(Path.Combine(path, SCORM.ImsManifset));
var parentItem = new Item();
parentItem = AddSubItems(parentItem, null, id, helper, ref manifest);
manifest.Organizations = ManifestManager.AddOrganization(manifest.Organizations, helper.CreateOrganization());
manifest.Organizations.Default = manifest.Organizations[0].Identifier;
manifest.Organizations[0].Items = parentItem.Items;
manifest.Organizations[0].Title = course.Name;
if (course.Sequencing != null)
{
var xml = new XmlSerializer(typeof(Sequencing));
manifest.Organizations[0].Sequencing = (Sequencing)xml.DeserializeXElement(course.Sequencing);
}
var resource = new Resource
{
Identifier = _ResourceIdForTemplateFiles,
Files = _TemplateFiles.Select(file => new ManifestModels.ResourceModels.File(file)).ToList(),
ScormType = ScormType.Asset
};
manifest.Resources = ManifestManager.AddResource(manifest.Resources, resource);
ManifestManager.Serialize(manifest, sw);
sw.Close();
Zipper.CreateZip(path + ".zip", path);
return path + ".zip";
}
示例2: AddSubItems
private Item AddSubItems(Item parentItem, Node parentNode, int courseId, ManifestManager helper, ref Manifest manifest)
{
var nodes = parentNode == null ? GetNodes(courseId) : GetNodes(courseId, parentNode.Id);
foreach (var node in nodes)
{
if (node.IsFolder)
{
var item = helper.CreateItem();
item.Title = node.Name;
if (node.Sequencing != null)
{
var xml = new XmlSerializer(typeof (Sequencing));
item.Sequencing = (Sequencing) xml.DeserializeXElement(node.Sequencing);
}
item = AddSubItems(item, node, courseId, helper, ref manifest);
parentItem = ManifestManager.AddItem(parentItem, item);
}
else
{
var files = new List<ManifestModels.ResourceModels.File>();
files.Add(new ManifestModels.ResourceModels.File(node.Id + ".html"));
var resource = helper.CreateResource(ScormType.SCO, files, new[] { _ResourceIdForTemplateFiles });
resource.Href = node.Id + ".html";
manifest.Resources = ManifestManager.AddResource(manifest.Resources, resource);
var item = helper.CreateItem(resource.Identifier);
item.Title = node.Name;
if (node.Sequencing != null)
{
var xml = new XmlSerializer(typeof(Sequencing));
item.Sequencing = (Sequencing)xml.DeserializeXElement(node.Sequencing);
}
parentItem = ManifestManager.AddItem(parentItem, item);
}
}
return parentItem;
}
示例3: Export
public virtual string Export(int id, bool exportForPlayCourse = false)
{
var course = this.GetCourse(id);
var path = this.GetCoursePath(id);
if (course.Locked != null && course.Locked.Value)
{
return path + ".zip";
}
path = Path.Combine(path, Guid.NewGuid().ToString());
path = Path.Combine(path, course.Name);
Directory.CreateDirectory(path);
var nodes = this.GetNodes(id).ToList();
for (var i = 0; i < nodes.Count; i++)
{
if (nodes[i].IsFolder == false)
{
File.Copy(this.GetNodePath(nodes[i].Id) + ".html", Path.Combine(path, nodes[i].Id + ".html"));
}
else
{
var subNodes = GetNodes(id, nodes[i].Id);
nodes.AddRange(subNodes);
}
}
var coursePath = this.GetCoursePath(id);
FileHelper.DirectoryCopy(Path.Combine(coursePath, "Node"), Path.Combine(path, "Node"));
foreach (var file in this.templateFiles)
{
try
{
File.Copy(Path.Combine(coursePath, file), Path.Combine(path, file), true);
}
catch (FileNotFoundException)
{
continue;
}
}
var helper = new ManifestManager();
var manifest = new Manifest();
var sw = new StreamWriter(Path.Combine(path, SCORM.ImsManifset));
var parentItem = new Item();
parentItem = this.AddSubItems(parentItem, null, id, helper, ref manifest);
manifest.Organizations = ManifestManager.AddOrganization(manifest.Organizations, helper.CreateOrganization());
manifest.Organizations.Default = manifest.Organizations[0].Identifier;
manifest.Organizations[0].Items = parentItem.Items;
manifest.Organizations[0].Title = course.Name;
if (course.Sequencing != null)
{
var xml = new XmlSerializer(typeof(Sequencing));
manifest.Organizations[0].Sequencing = (Sequencing)xml.DeserializeXElement(course.Sequencing);
}
var resource = new Resource
{
Identifier = ResourceIdForTemplateFiles,
Files = this.templateFiles.Select(file => new ManifestModels.ResourceModels.File(file)).ToList(),
ScormType = ScormType.Asset
};
manifest.Resources = ManifestManager.AddResource(manifest.Resources, resource);
ManifestManager.Serialize(manifest, sw);
sw.Close();
Zipper.CreateZip(path + ".zip", path);
if (exportForPlayCourse)
{
try
{
IudicoCourseInfo ci = CourseParser.Parse(course, this);
this.AddCourseInfo(ci);
}
catch (Exception ex)
{
log.Error(string.Format("Exception message: {0}\nData: {1}\nHelp Link: {2}\nInner exception: {3}\nSource: {4}\nStack trace: {5}\nTarget site: {6}", ex.Message, ex.Data, ex.HelpLink, ex.InnerException, ex.Source, ex.StackTrace, ex.TargetSite));
}
}
return path + ".zip";
}