Esempio n. 1
0
        private Collection <AliasInfo> GetAliasesFromFile(bool isLiteralPath)
        {
            Collection <AliasInfo> collection = new Collection <AliasInfo>();
            string filePath = null;

            using (StreamReader reader = this.OpenFile(out filePath, isLiteralPath))
            {
                CSVHelper helper = new CSVHelper(',');
                long      num    = 0L;
                string    line   = null;
                while ((line = reader.ReadLine()) != null)
                {
                    num += 1L;
                    if (((line.Length != 0) && !OnlyContainsWhitespace(line)) && (line[0] != '#'))
                    {
                        Collection <string> collection2 = helper.ParseCsv(line);
                        if (collection2.Count != 4)
                        {
                            string          message     = StringUtil.Format(AliasCommandStrings.ImportAliasFileInvalidFormat, filePath, num);
                            FormatException exception   = new FormatException(message);
                            ErrorRecord     errorRecord = new ErrorRecord(exception, "ImportAliasFileFormatError", ErrorCategory.ReadError, filePath)
                            {
                                ErrorDetails = new ErrorDetails(message)
                            };
                            base.ThrowTerminatingError(errorRecord);
                        }
                        ScopedItemOptions none = ScopedItemOptions.None;
                        try
                        {
                            none = (ScopedItemOptions)Enum.Parse(typeof(ScopedItemOptions), collection2[3], true);
                        }
                        catch (ArgumentException exception2)
                        {
                            string      str4    = StringUtil.Format(AliasCommandStrings.ImportAliasOptionsError, filePath, num);
                            ErrorRecord record2 = new ErrorRecord(exception2, "ImportAliasOptionsError", ErrorCategory.ReadError, filePath)
                            {
                                ErrorDetails = new ErrorDetails(str4)
                            };
                            base.WriteError(record2);
                            continue;
                        }
                        AliasInfo item = new AliasInfo(collection2[0], collection2[1], base.Context, none);
                        if (!string.IsNullOrEmpty(collection2[2]))
                        {
                            item.Description = collection2[2];
                        }
                        collection.Add(item);
                    }
                }
                reader.Close();
            }
            return(collection);
        }
Esempio n. 2
0
 private Collection<AliasInfo> GetAliasesFromFile(bool isLiteralPath)
 {
     Collection<AliasInfo> collection = new Collection<AliasInfo>();
     string filePath = null;
     using (StreamReader reader = this.OpenFile(out filePath, isLiteralPath))
     {
         CSVHelper helper = new CSVHelper(',');
         long num = 0L;
         string line = null;
         while ((line = reader.ReadLine()) != null)
         {
             num += 1L;
             if (((line.Length != 0) && !OnlyContainsWhitespace(line)) && (line[0] != '#'))
             {
                 Collection<string> collection2 = helper.ParseCsv(line);
                 if (collection2.Count != 4)
                 {
                     string message = StringUtil.Format(AliasCommandStrings.ImportAliasFileInvalidFormat, filePath, num);
                     FormatException exception = new FormatException(message);
                     ErrorRecord errorRecord = new ErrorRecord(exception, "ImportAliasFileFormatError", ErrorCategory.ReadError, filePath) {
                         ErrorDetails = new ErrorDetails(message)
                     };
                     base.ThrowTerminatingError(errorRecord);
                 }
                 ScopedItemOptions none = ScopedItemOptions.None;
                 try
                 {
                     none = (ScopedItemOptions) Enum.Parse(typeof(ScopedItemOptions), collection2[3], true);
                 }
                 catch (ArgumentException exception2)
                 {
                     string str4 = StringUtil.Format(AliasCommandStrings.ImportAliasOptionsError, filePath, num);
                     ErrorRecord record2 = new ErrorRecord(exception2, "ImportAliasOptionsError", ErrorCategory.ReadError, filePath) {
                         ErrorDetails = new ErrorDetails(str4)
                     };
                     base.WriteError(record2);
                     continue;
                 }
                 AliasInfo item = new AliasInfo(collection2[0], collection2[1], base.Context, none);
                 if (!string.IsNullOrEmpty(collection2[2]))
                 {
                     item.Description = collection2[2];
                 }
                 collection.Add(item);
             }
         }
         reader.Close();
     }
     return collection;
 }
Esempio n. 3
0
        private Collection <AliasInfo> GetAliasesFromFile(bool isLiteralPath)
        {
            Collection <AliasInfo> result = new Collection <AliasInfo>();

            string filePath = null;

            using (StreamReader reader = OpenFile(out filePath, isLiteralPath))
            {
                CSVHelper csvHelper = new CSVHelper(',');

                Int64  lineNumber = 0;
                string line       = null;
                while ((line = reader.ReadLine()) != null)
                {
                    ++lineNumber;

                    // Ignore blank lines
                    if (line.Length == 0)
                    {
                        continue;
                    }

                    // Ignore lines that only contain whitespace
                    if (OnlyContainsWhitespace(line))
                    {
                        continue;
                    }

                    // Ignore comment lines
                    if (line[0] == '#')
                    {
                        continue;
                    }

                    Collection <string> values = csvHelper.ParseCsv(line);

                    if (values.Count != 4)
                    {
                        string message = StringUtil.Format(AliasCommandStrings.ImportAliasFileInvalidFormat, filePath, lineNumber);

                        FormatException formatException =
                            new FormatException(message);

                        ErrorRecord errorRecord =
                            new ErrorRecord(
                                formatException,
                                "ImportAliasFileFormatError",
                                ErrorCategory.ReadError,
                                filePath);

                        errorRecord.ErrorDetails = new ErrorDetails(message);

                        ThrowTerminatingError(errorRecord);
                    }

                    ScopedItemOptions options = ScopedItemOptions.None;

                    try
                    {
                        options = (ScopedItemOptions)Enum.Parse(typeof(ScopedItemOptions), values[3], true);
                    }
                    catch (ArgumentException argException)
                    {
                        string message = StringUtil.Format(AliasCommandStrings.ImportAliasOptionsError, filePath, lineNumber);

                        ErrorRecord errorRecord =
                            new ErrorRecord(
                                argException,
                                "ImportAliasOptionsError",
                                ErrorCategory.ReadError,
                                filePath);

                        errorRecord.ErrorDetails = new ErrorDetails(message);
                        WriteError(errorRecord);
                        continue;
                    }

                    AliasInfo newAlias =
                        new AliasInfo(
                            values[0],
                            values[1],
                            Context,
                            options);

                    if (!String.IsNullOrEmpty(values[2]))
                    {
                        newAlias.Description = values[2];
                    }

                    result.Add(newAlias);
                }
                reader.Dispose();
            }
            return(result);
        }
Esempio n. 4
0
        private Collection<AliasInfo> GetAliasesFromFile(bool isLiteralPath)
        {
            Collection<AliasInfo> result = new Collection<AliasInfo>();

            string filePath = null;
            using (StreamReader reader = OpenFile(out filePath, isLiteralPath))
            {
                CSVHelper csvHelper = new CSVHelper(',');

                Int64 lineNumber = 0;
                string line = null;
                while ((line = reader.ReadLine()) != null)
                {
                    ++lineNumber;

                    // Ignore blank lines
                    if (line.Length == 0)
                    {
                        continue;
                    }

                    // Ignore lines that only contain whitespace
                    if (OnlyContainsWhitespace(line))
                    {
                        continue;
                    }

                    // Ignore comment lines
                    if (line[0] == '#')
                    {
                        continue;
                    }

                    Collection<string> values = csvHelper.ParseCsv(line);

                    if (values.Count != 4)
                    {
                        string message = StringUtil.Format(AliasCommandStrings.ImportAliasFileInvalidFormat, filePath, lineNumber);

                        FormatException formatException =
                            new FormatException(message);

                        ErrorRecord errorRecord =
                            new ErrorRecord(
                                formatException,
                                "ImportAliasFileFormatError",
                                ErrorCategory.ReadError,
                                filePath);

                        errorRecord.ErrorDetails = new ErrorDetails(message);

                        ThrowTerminatingError(errorRecord);
                    }

                    ScopedItemOptions options = ScopedItemOptions.None;

                    try
                    {
                        options = (ScopedItemOptions)Enum.Parse(typeof(ScopedItemOptions), values[3], true);
                    }
                    catch (ArgumentException argException)
                    {
                        string message = StringUtil.Format(AliasCommandStrings.ImportAliasOptionsError, filePath, lineNumber);

                        ErrorRecord errorRecord =
                            new ErrorRecord(
                                argException,
                                "ImportAliasOptionsError",
                                ErrorCategory.ReadError,
                                filePath);

                        errorRecord.ErrorDetails = new ErrorDetails(message);
                        WriteError(errorRecord);
                        continue;
                    }

                    AliasInfo newAlias =
                        new AliasInfo(
                            values[0],
                            values[1],
                            Context,
                            options);

                    if (!String.IsNullOrEmpty(values[2]))
                    {
                        newAlias.Description = values[2];
                    }

                    result.Add(newAlias);
                }
                reader.Dispose();
            }
            return result;
        }