Esempio n. 1
0
        /// <summary>
        /// Save the hl7 message to a file
        /// </summary>
        /// <param name="Filename"></param>
        /// <param name="Hl7Message"></param>
        private void SaveFile(string Filename, string Hl7Message)
        {
            SplitHL7BatchFileResult result;

            // if the -WhatIf switch is supplied don't commit changes to file
            if (this.ShouldProcess(Filename, "Saving HL7 message to file"))
            {
                try {
                    // prompt the user to overwrite the file if it exists (and the -OverwriteFile switch is not set)
                    if (!this.overwriteFile && File.Exists(Filename))
                    {
                        if (this.ShouldContinue("File " + Filename + " exists.  Are you sure you want to overwrite the file?", "Overwrite file", ref this.yesToAll, ref this.noToAll))
                        {
                            System.IO.File.WriteAllText(Filename, Hl7Message);
                            result = new SplitHL7BatchFileResult(Filename);
                            WriteObject(result);
                        }
                    }
                    else
                    {
                        System.IO.File.WriteAllText(Filename, Hl7Message);
                        result = new SplitHL7BatchFileResult(Filename);
                        WriteObject(result);
                    }
                }
                // write error if any exceptions raised when saving the file
                catch {
                    IOException fileException     = new FileNotFoundException("File not found", Filename);
                    ErrorRecord fileNotFoundError = new ErrorRecord(fileException, "SaveFailed", ErrorCategory.WriteError, Filename);
                    WriteError(fileNotFoundError);
                }
            }
        }
        /// <summary>
        /// Save the hl7 message to a file
        /// </summary>
        /// <param name="Filename"></param>
        /// <param name="Hl7Message"></param>
        private void SaveFile(string Filename, string Hl7Message)
        {
            SplitHL7BatchFileResult result;

            // if the -WhatIf switch is supplied don't commit changes to file
            if (this.ShouldProcess(Filename, "Saving HL7 message to file"))
            {
                string cr      = ((char)0x0D).ToString();
                string newline = System.Environment.NewLine;

                try
                {
                    // prompt the user to overwrite the file if it exists (and the -OverwriteFile switch is not set)
                    if (!this.overwriteFile && File.Exists(Filename))
                    {
                        if (this.ShouldContinue("File " + Filename + " exists.  Are you sure you want to overwrite the file?", "Overwrite file", ref this.yesToAll, ref this.noToAll))
                        {
                            // replace <CR> segment delimeter with system newline char(s) since writing to file.
                            System.IO.File.WriteAllText(Filename, Hl7Message.Replace(cr, newline));
                            result = new SplitHL7BatchFileResult(Filename);
                            WriteObject(result);
                        }
                    }
                    else
                    {
                        // replace <CR> segment delimeter with system newline char(s) since writing to file.
                        System.IO.File.WriteAllText(Filename, Hl7Message.Replace(cr, newline));
                        result = new SplitHL7BatchFileResult(Filename);
                        WriteObject(result);
                    }
                }
                // write error if any exceptions raised when saving the file
                catch
                {
                    IOException fileException     = new FileNotFoundException("File not found", Filename);
                    ErrorRecord fileNotFoundError = new ErrorRecord(fileException, "SaveFailed", ErrorCategory.WriteError, Filename);
                    WriteError(fileNotFoundError);
                }
            }
        }