Ejemplo n.º 1
0
        /// <summary>
        /// The serialize with hash.
        /// </summary>
        /// <param name="person">
        /// The person.
        /// </param>
        /// <param name="messages">
        /// The messages.
        /// </param>
        /// <param name="filePath">
        /// The file path.
        /// </param>
        /// <param name="xmlNamespaceResolver">
        /// The xml namespace resolver.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public static bool SerializeWithHash(
            BasePersonTemplate person,
            IEnumerable messages,
            string filePath,
            IXmlNamespaceResolver xmlNamespaceResolver)
        {
            try
            {
                var fomsLogPrefix = Hl7Helper.FomsLogPrefix;
                FomsLogger.WriteLog(
                    LogType.Local,
                    "Сериализация пакета Hl7. " + person.BeginPacket.RetrieveShortInfo(),
                    fomsLogPrefix,
                    LogErrorType.None);
                FileSystemPhysical.RemoveFile(filePath);
                using (var writer = new Hl7Writer(filePath, person, xmlNamespaceResolver))
                {
                    writer.WriteMessages(messages);
                    writer.FinalizeWrite();
                }

                return(true);
            }
            catch (Exception exception)
            {
                FomsLogger.WriteError(exception, null);
                return(false);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// The serialize with hash.
 /// </summary>
 /// <param name="person">
 /// The person.
 /// </param>
 /// <param name="message">
 /// The message.
 /// </param>
 /// <param name="filePath">
 /// The file path.
 /// </param>
 /// <param name="xmlNamespaceResolver">
 /// The xml namespace resolver.
 /// </param>
 /// <returns>
 /// The <see cref="bool"/>.
 /// </returns>
 public static bool SerializeWithHash(
     BasePersonTemplate person,
     object message,
     string filePath,
     IXmlNamespaceResolver xmlNamespaceResolver)
 {
     return(SerializeWithHash(person, new[] { message }, filePath, xmlNamespaceResolver));
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Hl7Writer"/> class.
        /// </summary>
        /// <param name="targetFilePath">
        /// The target file path.
        /// </param>
        /// <param name="personObject">
        /// The person object.
        /// </param>
        /// <param name="resolver">
        /// The resolver.
        /// </param>
        public Hl7Writer(string targetFilePath, BasePersonTemplate personObject, IXmlNamespaceResolver resolver)
            : this(targetFilePath)
        {
            inputStream = new MemoryStream();

            // XmlHelper.SerializeObject(this.inputStream, personObject, resolver);
            inputStream.Position = 0L;
            var reader = new XmlTextReader(inputStream)
            {
                WhitespaceHandling = WhitespaceHandling.None
            };
            this.reader = reader;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Сериализация наследников BasePersonTemplate
        /// </summary>
        /// <param name="person">
        /// Объект пакета
        /// </param>
        /// <param name="fileName">
        /// Имя файла
        /// </param>
        /// <param name="tableName">
        /// Корневой тег
        /// </param>
        private static void SerializeBasePersonTemplate(BasePersonTemplate person, string fileName, string tableName)
        {
            var nt = new NameTable();

            nt.Add(tableName);
            var nameres = GetNamespaces(nt);

            var directoryName = new FileInfo(fileName).DirectoryName;

            if (directoryName != null && !Directory.Exists(directoryName))
            {
                Directory.CreateDirectory(directoryName);
            }

            using (var stream = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
            {
                using (var writer = new XmlTextWriter(stream, Encoding.GetEncoding(1251)))
                {
                    var serializer = GetSerializer(person);
                    var namespaces = XmlHelper.ResolveNamespacesForSerializer(nameres);
                    if (namespaces != null)
                    {
                        serializer.Serialize(writer, person, namespaces);
                    }
                    else
                    {
                        serializer.Serialize(writer, person);
                    }

                    if (!XmlStreamer.CalculateAndSaveHash(stream, out person.EndPacket.Hash))
                    {
                        throw new InvalidOperationException("Не удалось прописать контрольную сумму");
                    }
                }
            }
        }