/// <summary> /// The deserialize. /// </summary> /// <returns> /// The <see cref="BaseAnswerMessageTemplate" />. /// </returns> internal BaseAnswerMessageTemplate Deserialize() { try { if (FileSystemPhysical.FileExists(filePath)) { switch (Path.GetExtension(filePath).ToLower()) { case ".rsp_zk1": return(XmlStreamer.Deserialize <RSP_ZK1>(filePath)); case ".rsp_zk2": return(XmlStreamer.Deserialize <RSP_ZK2>(filePath)); case ".rsp_zk4": return(XmlStreamer.Deserialize <RSP_ZK4>(filePath)); case ".rsp_zk5": return(XmlStreamer.Deserialize <RSP_ZK5>(filePath)); } return(XmlStreamer.Deserialize <Ack>(filePath)); } } catch (Exception exception) { FomsLogger.WriteError(exception, null); } return(null); }
/// <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); } }
/// <summary> /// The serialize with hash. /// </summary> /// <param name="person"> /// The person. /// </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(object person, string filePath, IXmlNamespaceResolver xmlNamespaceResolver) { try { FileSystemPhysical.RemoveFile(filePath); using (var stream = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite, FileShare.Read)) { using (var writer = new XmlTextWriter(stream, Encoding.Default)) { // XmlHelper.SerializeObject(writer, person, xmlNamespaceResolver); if (!CalculateAndSaveHash(stream, true)) { throw new InvalidOperationException(string.Format("Не удалось прописать контрольную сумму: ", filePath)); } } } return(true); } catch (Exception exception) { FomsLogger.WriteError(exception, null); return(false); } }
/// <summary> /// The load. /// </summary> /// <returns> /// The <see cref="XElement" />. /// </returns> internal XElement Load() { if (FileSystemPhysical.FileExists(filePath)) { return(XElement.Load(filePath)); } return(null); }
/// <summary> /// The calculate and save hash. /// </summary> /// <param name="filePath"> /// The file path. /// </param> /// <param name="hash"> /// The hash. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public static bool CalculateAndSaveHash(string filePath, out string hash) { FileSystemPhysical.FileMakeWritable(filePath); using (var stream = File.Open(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.Read)) { var flag = DoCalculateAndSaveHash(stream, out hash); hash = TStringHelper.StringToEmpty(hash).ToUpper(); return(flag); } }
/// <summary> /// The serialize. /// </summary> /// <param name="obj"> /// The obj. /// </param> /// <param name="filePath"> /// The file path. /// </param> /// <param name="xmlNamespaceResolver"> /// The xml namespace resolver. /// </param> public static void Serialize(object obj, string filePath, IXmlNamespaceResolver xmlNamespaceResolver) { try { if ((obj != null) && !string.IsNullOrEmpty(filePath)) { FileSystemPhysical.RemoveFile(filePath); using (var stream = new FileStream(filePath, FileMode.Create)) { using (var writer = new XmlTextWriter(stream, Encoding.Default)) { //// XmlHelper.SerializeObject(writer, obj, xmlNamespaceResolver); } } } } catch (Exception exception) { FomsLogger.WriteError(exception, null); } }