示例#1
0
 protected override void ProcessRecord()
 {
     if (!(this.specifiedPath ^ this.isLiteralPath))
     {
         InvalidOperationException exception = new InvalidOperationException(CsvCommandStrings.CannotSpecifyPathAndLiteralPath);
         ErrorRecord errorRecord = new ErrorRecord(exception, "CannotSpecifyPathAndLiteralPath", ErrorCategory.InvalidData, null);
         base.ThrowTerminatingError(errorRecord);
     }
     if (this._paths != null)
     {
         foreach (string str in this._paths)
         {
             using (StreamReader reader = PathUtils.OpenStreamReader(this, str, this.Encoding, this.isLiteralPath))
             {
                 ImportCsvHelper helper = new ImportCsvHelper(this, this._delimiter, this._header, null, reader);
                 try
                 {
                     helper.Import(ref this._alreadyWarnedUnspecifiedNames);
                 }
                 catch (ExtendedTypeSystemException exception2)
                 {
                     ErrorRecord record2 = new ErrorRecord(exception2, "AlreadyPresentPSMemberInfoInternalCollectionAdd", ErrorCategory.NotSpecified, null);
                     base.ThrowTerminatingError(record2);
                 }
             }
         }
     }
 }
示例#2
0
        private void CreateFileStream()
        {
            string path = PathUtils.ResolveFilePath(this.Path, this, this.isLiteralPath);
            bool   flag = true;

            if ((this.Append != 0) && File.Exists(path))
            {
                using (StreamReader reader = PathUtils.OpenStreamReader(this, this.Path, this._encodingParameter, this.isLiteralPath))
                {
                    flag = reader.Peek() == -1;
                }
            }
            this.isActuallyAppending = ((this.Append != 0) && File.Exists(path)) && !flag;
            if (this.isActuallyAppending)
            {
                System.Text.Encoding currentEncoding;
                using (StreamReader reader2 = PathUtils.OpenStreamReader(this, this.Path, this._encodingParameter, this.isLiteralPath))
                {
                    ImportCsvHelper helper = new ImportCsvHelper(this, base.Delimiter, null, null, reader2);
                    helper.ReadHeader();
                    this._preexistingPropertyNames = helper.Header;
                    currentEncoding = reader2.CurrentEncoding;
                }
                PathUtils.MasterStreamOpen(this, this.Path, currentEncoding, false, (bool)this.Append, (bool)this.Force, (bool)this.NoClobber, out this._fs, out this._sw, out this.readOnlyFileInfo, this.isLiteralPath);
            }
            else
            {
                PathUtils.MasterStreamOpen(this, this.Path, this._encodingParameter ?? "ASCII", false, (bool)this.Append, (bool)this.Force, (bool)this.NoClobber, out this._fs, out this._sw, out this.readOnlyFileInfo, this.isLiteralPath);
            }
        }
示例#3
0
 protected override void ProcessRecord()
 {
     foreach (PSObject obj2 in this._object)
     {
         using (MemoryStream stream = new MemoryStream(Encoding.Unicode.GetBytes(obj2.ToString())))
         {
             using (StreamReader reader = new StreamReader(stream, Encoding.Unicode))
             {
                 ImportCsvHelper helper = new ImportCsvHelper(this, this._delimiter, this._header, this._typeName, reader);
                 try
                 {
                     helper.Import(ref this._alreadyWarnedUnspecifiedNames);
                 }
                 catch (ExtendedTypeSystemException exception)
                 {
                     ErrorRecord errorRecord = new ErrorRecord(exception, "AlreadyPresentPSMemberInfoInternalCollectionAdd", ErrorCategory.NotSpecified, null);
                     base.ThrowTerminatingError(errorRecord);
                 }
                 if ((this._header == null) && (helper.Header != null))
                 {
                     this._header = helper.Header.ToArray<string>();
                 }
                 if ((this._typeName == null) && (helper.TypeName != null))
                 {
                     this._typeName = helper.TypeName;
                 }
             }
         }
     }
 }
 protected override void ProcessRecord()
 {
     foreach (PSObject obj2 in this._object)
     {
         using (MemoryStream stream = new MemoryStream(Encoding.Unicode.GetBytes(obj2.ToString())))
         {
             using (StreamReader reader = new StreamReader(stream, Encoding.Unicode))
             {
                 ImportCsvHelper helper = new ImportCsvHelper(this, this._delimiter, this._header, this._typeName, reader);
                 try
                 {
                     helper.Import(ref this._alreadyWarnedUnspecifiedNames);
                 }
                 catch (ExtendedTypeSystemException exception)
                 {
                     ErrorRecord errorRecord = new ErrorRecord(exception, "AlreadyPresentPSMemberInfoInternalCollectionAdd", ErrorCategory.NotSpecified, null);
                     base.ThrowTerminatingError(errorRecord);
                 }
                 if ((this._header == null) && (helper.Header != null))
                 {
                     this._header = helper.Header.ToArray <string>();
                 }
                 if ((this._typeName == null) && (helper.TypeName != null))
                 {
                     this._typeName = helper.TypeName;
                 }
             }
         }
     }
 }
示例#5
0
 protected override void ProcessRecord()
 {
     if (!(this.specifiedPath ^ this.isLiteralPath))
     {
         InvalidOperationException exception = new InvalidOperationException(CsvCommandStrings.CannotSpecifyPathAndLiteralPath);
         ErrorRecord errorRecord             = new ErrorRecord(exception, "CannotSpecifyPathAndLiteralPath", ErrorCategory.InvalidData, null);
         base.ThrowTerminatingError(errorRecord);
     }
     if (this._paths != null)
     {
         foreach (string str in this._paths)
         {
             using (StreamReader reader = PathUtils.OpenStreamReader(this, str, this.Encoding, this.isLiteralPath))
             {
                 ImportCsvHelper helper = new ImportCsvHelper(this, this._delimiter, this._header, null, reader);
                 try
                 {
                     helper.Import(ref this._alreadyWarnedUnspecifiedNames);
                 }
                 catch (ExtendedTypeSystemException exception2)
                 {
                     ErrorRecord record2 = new ErrorRecord(exception2, "AlreadyPresentPSMemberInfoInternalCollectionAdd", ErrorCategory.NotSpecified, null);
                     base.ThrowTerminatingError(record2);
                 }
             }
         }
     }
 }
示例#6
0
        ProcessRecord()
        {
            foreach (PSObject pObject in InputObject)
            {
                using (MemoryStream memoryStream = new MemoryStream(Encoding.Unicode.GetBytes(pObject.ToString())))
                using (StreamReader streamReader = new StreamReader(memoryStream, System.Text.Encoding.Unicode))
                {
                    ImportCsvHelper helper = new ImportCsvHelper(this, Delimiter, Header, _typeName, streamReader);

                    try
                    {
                        helper.Import(ref _alreadyWarnedUnspecifiedNames);
                    }
                    catch (ExtendedTypeSystemException exception)
                    {
                        ErrorRecord errorRecord = new ErrorRecord(exception, "AlreadyPresentPSMemberInfoInternalCollectionAdd", ErrorCategory.NotSpecified, null);
                        this.ThrowTerminatingError(errorRecord);
                    }

                    if ((Header == null) && (helper.Header != null))
                    {
                        Header = helper.Header.ToArray();
                    }
                    if ((_typeName == null) && (helper.TypeName != null))
                    {
                        _typeName = helper.TypeName;
                    }
                }
            }
        }
示例#7
0
        /// <summary>
        /// ProcessRecord overload
        /// </summary>
        protected override void ProcessRecord()
        {
            // Validate that they don't provide both Path and LiteralPath, but have provided at least one.
            if (!(_specifiedPath ^ _isLiteralPath))
            {
                InvalidOperationException exception = new InvalidOperationException(CsvCommandStrings.CannotSpecifyPathAndLiteralPath);
                ErrorRecord errorRecord = new ErrorRecord(exception, "CannotSpecifyPathAndLiteralPath", ErrorCategory.InvalidData, null);
                this.ThrowTerminatingError(errorRecord);
            }

            if (_paths != null)
            {
                foreach (string path in _paths)
                {
                    using (StreamReader streamReader = PathUtils.OpenStreamReader(this, path, this.Encoding, _isLiteralPath))
                    {
                        ImportCsvHelper helper = new ImportCsvHelper(this, Delimiter, Header, null /* typeName */, streamReader);

                        try
                        {
                            helper.Import(ref _alreadyWarnedUnspecifiedNames);
                        }
                        catch (ExtendedTypeSystemException exception)
                        {
                            ErrorRecord errorRecord = new ErrorRecord(exception, "AlreadyPresentPSMemberInfoInternalCollectionAdd", ErrorCategory.NotSpecified, null);
                            this.ThrowTerminatingError(errorRecord);
                        }
                    }
                }
            }//if
        }////ProcessRecord  
示例#8
0
        private void CreateFileStream()
        {
            Dbg.Assert(_path != null, "FileName is mandatory parameter");

            string resolvedFilePath = PathUtils.ResolveFilePath(this.Path, this, _isLiteralPath);

            bool isCsvFileEmpty = true;

            if (this.Append && File.Exists(resolvedFilePath))
            {
                using (StreamReader streamReader = PathUtils.OpenStreamReader(this, this.Path, Encoding, _isLiteralPath))
                {
                    isCsvFileEmpty = streamReader.Peek() == -1 ? true : false;
                }
            }

            // If the csv file is empty then even append is treated as regular export (i.e., both header & values are added to the CSV file).
            _isActuallyAppending = this.Append && File.Exists(resolvedFilePath) && !isCsvFileEmpty;

            if (_isActuallyAppending)
            {
                Encoding encodingObject;

                using (StreamReader streamReader = PathUtils.OpenStreamReader(this, this.Path, Encoding, _isLiteralPath))
                {
                    ImportCsvHelper readingHelper = new ImportCsvHelper(
                        this, this.Delimiter, null /* header */, null /* typeName */, streamReader);
                    readingHelper.ReadHeader();
                    _preexistingPropertyNames = readingHelper.Header;

                    encodingObject = streamReader.CurrentEncoding;
                }

                PathUtils.MasterStreamOpen(
                    this,
                    this.Path,
                    encodingObject,
                    false, // defaultEncoding
                    Append,
                    Force,
                    NoClobber,
                    out _fs,
                    out _sw,
                    out _readOnlyFileInfo,
                    _isLiteralPath);
            }
            else
            {
                PathUtils.MasterStreamOpen(
                    this,
                    this.Path,
                    Encoding ?? "ASCII",
                    false, // defaultEncoding
                    Append,
                    Force,
                    NoClobber,
                    out _fs,
                    out _sw,
                    out _readOnlyFileInfo,
                    _isLiteralPath);
            }
        }
示例#9
0
 private void CreateFileStream()
 {
     string path = PathUtils.ResolveFilePath(this.Path, this, this.isLiteralPath);
     bool flag = true;
     if ((this.Append != 0) && File.Exists(path))
     {
         using (StreamReader reader = PathUtils.OpenStreamReader(this, this.Path, this._encodingParameter, this.isLiteralPath))
         {
             flag = reader.Peek() == -1;
         }
     }
     this.isActuallyAppending = ((this.Append != 0) && File.Exists(path)) && !flag;
     if (this.isActuallyAppending)
     {
         System.Text.Encoding currentEncoding;
         using (StreamReader reader2 = PathUtils.OpenStreamReader(this, this.Path, this._encodingParameter, this.isLiteralPath))
         {
             ImportCsvHelper helper = new ImportCsvHelper(this, base.Delimiter, null, null, reader2);
             helper.ReadHeader();
             this._preexistingPropertyNames = helper.Header;
             currentEncoding = reader2.CurrentEncoding;
         }
         PathUtils.MasterStreamOpen(this, this.Path, currentEncoding, false, (bool) this.Append, (bool) this.Force, (bool) this.NoClobber, out this._fs, out this._sw, out this.readOnlyFileInfo, this.isLiteralPath);
     }
     else
     {
         PathUtils.MasterStreamOpen(this, this.Path, this._encodingParameter ?? "ASCII", false, (bool) this.Append, (bool) this.Force, (bool) this.NoClobber, out this._fs, out this._sw, out this.readOnlyFileInfo, this.isLiteralPath);
     }
 }