当前位置: 首页>>代码示例>>C#>>正文


C# DataContractSerializer.WriteEndObject方法代码示例

本文整理汇总了C#中System.Runtime.Serialization.DataContractSerializer.WriteEndObject方法的典型用法代码示例。如果您正苦于以下问题:C# DataContractSerializer.WriteEndObject方法的具体用法?C# DataContractSerializer.WriteEndObject怎么用?C# DataContractSerializer.WriteEndObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Runtime.Serialization.DataContractSerializer的用法示例。


在下文中一共展示了DataContractSerializer.WriteEndObject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CompareXml

        public void CompareXml()
        {
            var auditConfiguration = AuditConfiguration.Default;

            auditConfiguration.IncludeRelationships = true;
            auditConfiguration.LoadRelationships = true;
            auditConfiguration.DefaultAuditable = true;

            // customize the audit for Task entity
            //auditConfiguration.IsAuditable<Task>()
            //  .NotAudited(t => t.TaskExtended)
            //  .FormatWith(t => t.Status, v => FormatStatus(v));

            // set name as the display member when status is a foreign key
            auditConfiguration.IsAuditable<Status>()
              .DisplayMember(t => t.Name);

            var db = new TrackerContext();
            var audit = db.BeginAudit();

            var user = db.Users.Find(1);
            user.Comment = "Testing: " + DateTime.Now.Ticks;

            var task = new Task()
            {
                AssignedId = 1,
                CreatedId = 1,
                StatusId = 1,
                PriorityId = 2,
                Summary = "Summary: " + DateTime.Now.Ticks
            };
            db.Tasks.Add(task);

            var task2 = db.Tasks.Find(1);
            task2.PriorityId = 2;
            task2.StatusId = 2;
            task2.Summary = "Summary: " + DateTime.Now.Ticks;

            var log = audit.CreateLog();
            Assert.IsNotNull(log);

            string xml = log.ToXml();
            Assert.IsNotNull(xml);
            File.WriteAllText(@"test.xml.xml", xml);

            foreach (var property in log.Entities.SelectMany(e => e.Properties))
            {
                Assert.AreNotEqual(property.Current, "{error}");
                Assert.AreNotEqual(property.Original, "{error}");
            }

            var builder = new StringBuilder();
            var settings = new XmlWriterSettings { Indent = true, OmitXmlDeclaration = true };
            var writer = XmlWriter.Create(builder, settings);

            var serializer = new DataContractSerializer(typeof(AuditLog));
            serializer.WriteStartObject(writer, log);
            writer.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema");
            serializer.WriteObjectContent(writer, log);
            serializer.WriteEndObject(writer);

            writer.Flush();

            string xml2 = builder.ToString();
            File.WriteAllText(@"test.data.xml", xml2);

            string json = JsonConvert.SerializeObject(log, Newtonsoft.Json.Formatting.Indented, new StringEnumConverter());
            File.WriteAllText(@"test.data.json", json);


        }
开发者ID:jwaala,项目名称:EntityFramework.Extended,代码行数:71,代码来源:AuditTest.cs

示例2: SaveVisit

        public bool SaveVisit()
        {
            if (_observations.Count != 0 && _currentVisit != null && _project != null)
            {
                // WRITING XML FILE
                var t = DateTime.UtcNow - new DateTime(1970, 1, 1);
                var secondsSinceEpoch = (int)t.TotalSeconds;

                var filename = [email protected]"project_{secondsSinceEpoch}.xml";
                using (var fw = new FileStream(path: filename, mode: FileMode.Create, access: FileAccess.Write))
                {
                    var dcsw = new DataContractSerializer(typeof (Xml));
                    var xmlWrite = new Xml(_currentVisit, _observations);

                    var writer = XmlDictionaryWriter.CreateTextWriter(fw);
                    writer.WriteStartDocument(true);
                    writer.WriteStartElement("Waarnemingen");
                    // Try to write and catch the exception if failed to write
                    try
                    {
                        dcsw.WriteObject(fw, xmlWrite);
                        dcsw.WriteEndObject(writer);
                        return true;
                    }
                    catch (Exception x)
                    {
                        //MessageBox.Show(x.ToString());
                        return false;
                    }
                }
            }
            else
            {
                return false;
            }
        }
开发者ID:djdino56,项目名称:PPS2_Fontys,代码行数:36,代码来源:VisitForm.cs


注:本文中的System.Runtime.Serialization.DataContractSerializer.WriteEndObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。