Пример #1
0
        public void TestRepository()
        {
            var connectionString = ConfigurationManager.ConnectionStrings["PelorusTraceConnection"];
            var repository = new ApplicationLogRepository(connectionString.ConnectionString);
            var log = repository.GetById(18);

            Assert.IsNotNull(log);
        }
        /// <summary>
        /// Return a specific application log by Id.
        /// </summary>
        /// <param name="context">
        /// An System.Web.HttpContext object that provides references to the intrinsic server objects (for example, Request, Response, Session, and 
        /// Server) used to service HTTP requests.
        /// </param>
        /// <param name="itemId">Id of the application log to return.</param>
        private void ReturnApplicationLogItem(HttpContext context, int itemId)
        {
            var config = CoreWebConfiguration.Configuration.ApplicationLogRssFeed;
            var connectionStringName = config.ConnectionString.Name;

            if (string.IsNullOrWhiteSpace(connectionStringName))
            {
                connectionStringName = DefaultConnectionStringName;
            }

            var connectionString = ConfigurationManager.ConnectionStrings[connectionStringName];
            var applicationLogRepository = new ApplicationLogRepository(connectionString.ConnectionString);
            var log = applicationLogRepository.GetById(itemId);

            var xmlDocument = new System.Xml.XmlDocument();
            var xmlNavigator = xmlDocument.CreateNavigator();

            using (var writer = xmlNavigator.AppendChild())
            {
                var serializer = new DataContractSerializer(typeof(ApplicationLogDao));
                serializer.WriteObject(writer, log);
            }

            if (null != log.Data.FirstChild)
            {
                var dataElement = xmlDocument.CreateElement("Data", xmlDocument.FirstChild.NamespaceURI);
                var importedElement = xmlDocument.ImportNode(log.Data.FirstChild, true);
                dataElement.AppendChild(importedElement);
                xmlDocument.FirstChild.AppendChild(dataElement);
            }

            context.Response.ContentType = "text/xml";
            context.Response.Output.Write(xmlDocument.InnerXml);
            context.Response.StatusCode = (int) HttpStatusCode.OK;
            context.Response.Flush();
        }