Beispiel #1
0
        protected override void Execute(CodeActivityContext context)
        {
            var useHeaderRow = false;

            if (UseHeaderRow != null)
            {
                useHeaderRow = UseHeaderRow.Get(context);
            }
            string[] delimeters = null;
            if (Delimeter != null)
            {
                var d = Delimeter.Get(context);
                if (!string.IsNullOrEmpty(d))
                {
                    delimeters = new string[] { d };
                }
            }
            if (delimeters == null || delimeters.Length == 0)
            {
                delimeters = new string[] { ",", ";" }
            }
            ;
            System.Data.DataTable result = null;
            var filename = Filename.Get(context);

            filename = Environment.ExpandEnvironmentVariables(filename);
            result   = GetDataTabletFromCSVFile(filename, useHeaderRow, delimeters);
            if (DataTable != null)
            {
                context.SetValue(DataTable, result);
            }
        }
    }
Beispiel #2
0
        internal static string[] ConsolidateQuotedValues(string[] values, Delimeter delimeter)
        {
            List <string> newValues = new List <string>();

            for (int i = 0; i < values.Length; i++)
            {
                if (ValueHasEvenNumberOfQuotes(values[i]))
                {
                    newValues.Add(values[i]);
                }
                else
                {
                    string newValue = $"{values[i++]}";

                    while (i < values.Length && !ValueHasEvenNumberOfQuotes(newValue))
                    {
                        newValue += $"{(char)delimeter}{values[i++]}";
                    }

                    if (i > values.Length && newValue.StartsWith("\""))
                    {
                        newValue += "\"";
                    }
                    else
                    {
                        i--;
                    }

                    newValues.Add(newValue);
                }
            }

            return(newValues.ToArray());
        }
Beispiel #3
0
 /// <summary>
 /// Save the CSV to a file.
 /// This method will delete an existing file with this name.
 /// </summary>
 /// <param name="fileName"></param>
 /// <param name="delimeter"></param>
 public void Save(string fileName, Delimeter delimeter = Delimeter.Comma)
 {
     if (File.Exists(fileName))
     {
         File.Delete(fileName);
     }
     using (FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate))
         this.Save(fs, delimeter);
 }
Beispiel #4
0
        protected override void Execute(CodeActivityContext context)
        {
            var                     csvPath    = CSVPath.Get(context);
            var                     isHeader   = IsHeader.Get(context);
            char                    delimeter  = Delimeter.Get(context);
            List <string>           headerList = HeaderList.Get(context);
            CSVToDataTableConverter converter  = new CSVToDataTableConverter(csvPath, isHeader, headerList, delimeter);

            ResultListItems.Set(context, converter.getDataTableCSVFile());
        }
Beispiel #5
0
        public DelimeterSeparatedValueExporter(Delimeter delimeter)
        {
            switch (delimeter)
            {
            case Delimeter.Comma:
                _delimeter = ",";
                break;

            case Delimeter.Tab:
                _delimeter = "\t";
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #6
0
        public void Save()
        {
            Xml settings = new Xml(AppDomain.CurrentDomain.BaseDirectory + "settings.xml");

            settings.RootName = "FTPFileSystemCleanup";

            settings.RemoveSection("Server"); settings.SetValue("Server", ServerName, String.Empty);
            settings.RemoveSection("Database"); settings.SetValue("Database", Database, String.Empty);
            settings.RemoveSection("User"); settings.SetValue("User", User, String.Empty);
            settings.RemoveSection("Password"); settings.SetValue("Password", Password, String.Empty);
            settings.RemoveSection("DirectoryToScan"); settings.SetValue("DirectoryToScan", DirectoryToScan, String.Empty);
            settings.RemoveSection("FileAgeLimit"); settings.SetValue("FileAgeLimit", FileAgeLimit.ToString(), String.Empty);
            settings.RemoveSection("ServiceExecuteEvery"); settings.SetValue("ServiceExecuteEvery", ServiceExecuteEvery.ToString(), String.Empty);
            settings.RemoveSection("FileDeleteCSVFile"); settings.SetValue("FileDeleteCSVFile", FileDeleteCSVFile.ToString(), String.Empty);
            settings.RemoveSection("DatabaseType"); settings.SetValue("DatabaseType", DatabaseType.GetHashCode().ToString(), String.Empty);
            settings.RemoveSection("Delimeter"); settings.SetValue("Delimeter", Delimeter.ToString(), String.Empty);
        }
Beispiel #7
0
        /// <summary>
        /// Open a CSV from a stream.
        /// </summary>
        /// <param name="inputStream"></param>
        /// <param name="delimeter"></param>
        public CSV(Stream inputStream, Delimeter delimeter = Delimeter.Comma)
        {
            Heading = "";
            _data   = new List <Row>();
            StreamReader reader  = new StreamReader(inputStream);
            string       content = reader.ReadToEnd();

            string[] lines = content.Replace("\r", "").Split('\n');

            lines = ConsolidateQuotedCsvLines(lines);

            string[] headers = lines[0].Split((char)delimeter);

            headers = Row.ConsolidateQuotedValues(headers, delimeter);

            for (int i = 0; i < headers.Length; i++)
            {
                if (headers[i].StartsWith("\"") && headers[i].EndsWith("\""))
                {
                    headers[i] = headers[i].Substring(1, headers[i].Length - 2);
                }
            }

            for (int l = 1; l < lines.Length; l++)
            {
                Row row = new Row(lines[l], headers, delimeter);

                /*string line = lines[l];
                 * string[] values = line.Split((char) delimeter);
                 * for (int i = 0; i < headers.Length && i < values.Length; i++)
                 * {
                 *  if (values[i].StartsWith("\"") && values[i].EndsWith("\""))
                 *  {
                 *      values[i] = values[i].Substring(1, values[i].Length - 2);
                 *  }
                 *
                 *  while (row.ContainsKey(headers[i])) headers[i] = $"{headers[i]} ";
                 *
                 *  row.Add(headers[i], values[i]);
                 * }*/

                _data.Add(row);
            }
        }
Beispiel #8
0
        public Row(string csvText, string[] headers, Delimeter delimeter = Delimeter.Comma)
        {
            string[] values = csvText.Split((char)delimeter);
            values = ConsolidateQuotedValues(values, delimeter);

            for (int i = 0; i < headers.Length && i < values.Length; i++)
            {
                if (values[i].StartsWith("\"") && values[i].EndsWith("\""))
                {
                    values[i] = values[i].Substring(1, values[i].Length - 2);
                }

                while (this.ContainsKey(headers[i]))
                {
                    headers[i] = $"{headers[i]} ";
                }

                this.Add(headers[i], values[i]);
            }
        }
Beispiel #9
0
        /// <summary>
        /// Save the CSV to a stream.
        /// </summary>
        /// <param name="output"></param>
        /// <param name="delimeter"></param>
        public void Save(Stream output, Delimeter delimeter = Delimeter.Comma)
        {
            using (StreamWriter writer = new StreamWriter(output, Encoding.UTF8))
            {
                writer.AutoFlush = true;

                if (AllKeys.Count <= 0)
                {
                    return;
                }

                writer.Write(ValueNeedsQuoting(AllKeys[0]) ? $"\"{AllKeys[0]}\"" : AllKeys[0]);
                for (int i = 1; i < AllKeys.Count; i++)
                {
                    writer.Write("{0}{1}", (char)delimeter, ValueNeedsQuoting(AllKeys[i]) ? $"\"{AllKeys[i]}\"" : AllKeys[i]);
                }

                writer.WriteLine();

                foreach (Row row in _data)
                {
                    if (row.ContainsKey(AllKeys[0]))
                    {
                        writer.Write(ValueNeedsQuoting(row[AllKeys[0]]) ? $"\"{row[AllKeys[0]]}\"" : row[AllKeys[0]]);
                    }
                    for (int i = 1; i < AllKeys.Count; i++)
                    {
                        writer.Write((char)delimeter);
                        if (row.ContainsKey(AllKeys[i]))
                        {
                            writer.Write(ValueNeedsQuoting(row[AllKeys[i]]) ? $"\"{row[AllKeys[i]]}\"" : row[AllKeys[i]]);
                        }
                    }

                    writer.WriteLine();
                }
            }
        }
Beispiel #10
0
        public async Task DiscoverMovieSmokeTest(string language, string region,
                                                 DiscoverMovieSortBy sortBy, string certificationCountry, string certification,
                                                 string certificationLessThanOrEqualTo, string certificationGreaterThanOrEqualTo,
                                                 bool?includeAdult, bool?includeVideo, int page, int?primaryReleaseYear,
                                                 string primaryReleaseDateGreaterThanOrEqualTo, string primaryReleaseDateLessThanOrEqualTo,
                                                 string releaseDateGreaterThanOrEqualTo, string releaseDateLessThanOrEqualTo,
                                                 IEnumerable <MovieReleaseType> withReleaseTypes, Delimeter withReleaseTypesDelimeter,
                                                 int?year, int?voteCountGreaterThanOrEqualTo, int?voteCountLessThanOrEqualTo,
                                                 int?voteAverageGreaterThanOrEqualTo, int?voteAverageLessThanOrEqualTo,
                                                 IEnumerable <int> withCastIds, IEnumerable <int> withCrewIds, IEnumerable <int> withPeopleIds,
                                                 IEnumerable <int> withCompanyIds, IEnumerable <int> withGenreIds, Delimeter withGenreIdsDelimeter,
                                                 IEnumerable <int> withoutGenreIds, Delimeter withoutGenreIdsDelimeter, IEnumerable <int> withKeywordIds,
                                                 Delimeter withKeywordIdsDelimeter, IEnumerable <int> withoutKeywordIds, Delimeter withoutKeywordIdsDelimeter,
                                                 int?withRuntimeGreaterThanOrEqualTo, int?withRuntimeLessThanOrEqualTo, string withOriginalLanguageAbbreviation,
                                                 IEnumerable <int> withWatchProviderIds, Delimeter withWatchProviderIdsDelimeter, string withWatchProviderRegionCountryCode)
        {
            var response = await Client.Discover.GetAsync(new DiscoverMovieRequest
            {
                LanguageAbbreviation = language,
                RegionCountryCode    = region,
                SortBy = sortBy,
                CertificationCountry              = certificationCountry,
                Certification                     = certification,
                CertificationLessThanOrEqualTo    = certificationLessThanOrEqualTo,
                CertificationGreaterThanOrEqualTo = certificationGreaterThanOrEqualTo,
                IncludeAdult       = includeAdult,
                IncludeVideo       = includeVideo,
                Page               = page,
                PrimaryReleaseYear = primaryReleaseYear.HasValue ? Convert.ToInt16(primaryReleaseYear) : null,
                PrimaryReleaseDateGreaterThanOrEqualTo = !string.IsNullOrEmpty(primaryReleaseDateGreaterThanOrEqualTo) ? DateTime.Parse(primaryReleaseDateGreaterThanOrEqualTo) : null,
                PrimaryReleaseDateLessThanOrEqualTo    = !string.IsNullOrEmpty(primaryReleaseDateLessThanOrEqualTo) ? DateTime.Parse(primaryReleaseDateLessThanOrEqualTo) : null,
                ReleaseDateGreaterThanOrEqualTo        = !string.IsNullOrEmpty(releaseDateGreaterThanOrEqualTo) ? DateTime.Parse(releaseDateGreaterThanOrEqualTo) : null,
                ReleaseDateLessThanOrEqualTo           = !string.IsNullOrEmpty(releaseDateLessThanOrEqualTo) ? DateTime.Parse(releaseDateLessThanOrEqualTo) : null,
                WithReleaseTypes          = withReleaseTypes,
                WithReleaseTypesDelimeter = withReleaseTypesDelimeter,
                Year = year.HasValue ? Convert.ToInt16(year) : null,
                VoteCountGreaterThanOrEqualTo   = voteCountGreaterThanOrEqualTo,
                VoteCountLessThanOrEqualTo      = voteCountLessThanOrEqualTo,
                VoteAverageGreaterThanOrEqualTo = voteAverageGreaterThanOrEqualTo,
                VoteAverageLessThanOrEqualTo    = voteAverageLessThanOrEqualTo,
                WithCastIds                        = withCastIds,
                WithCrewIds                        = withCrewIds,
                WithPeopleIds                      = withPeopleIds,
                WithCompanyIds                     = withCompanyIds,
                WithGenreIds                       = withGenreIds,
                WithGenreIdsDelimeter              = withGenreIdsDelimeter,
                WithoutGenreIds                    = withoutGenreIds,
                WithoutGenreIdsDelimeter           = withoutGenreIdsDelimeter,
                WithKeywordIds                     = withKeywordIds,
                WithKeywordIdsDelimeter            = withKeywordIdsDelimeter,
                WithoutKeywordIds                  = withoutKeywordIds,
                WithoutKeywordIdsDelimeter         = withoutKeywordIdsDelimeter,
                WithRuntimeGreaterThanOrEqualTo    = withRuntimeGreaterThanOrEqualTo,
                WithRuntimeLessThanOrEqualTo       = withRuntimeLessThanOrEqualTo,
                WithOriginalLanguageAbbreviation   = withOriginalLanguageAbbreviation,
                WithWatchProviderIds               = withWatchProviderIds,
                WithWatchProviderIdsDelimeter      = withWatchProviderIdsDelimeter,
                WithWatchProviderRegionCountryCode = withWatchProviderRegionCountryCode,
            });

            Assert.IsType <DiscoverMovieResponse>(response);
            Assert.True(response.Results.Any());
        }