protected override void AddPlugins(ItemModel source, Endpoint endpoint)
        {
            //
            //create the plugin
            var settings = new FileSystemSettings();

            //
            //populate the plugin using values from the item
            settings.ColumnHeadersInFirstLine =
                base.GetBoolValue(source, FileSystemEndpointItemModel.ColumnHeadersInFirstLine);
            settings.ColumnSeparator =
                base.GetStringValue(source, FileSystemEndpointItemModel.ColumnSeparator);
            settings.Path =
                base.GetStringValue(source, FileSystemEndpointItemModel.Path);
            //
            //add the plugin to the endpoint
            endpoint.Plugins.Add(settings);
        }
Ejemplo n.º 2
0
        private IEnumerable <Dictionary <string, string> > GetEnumerable(FileSystemSettings settings, Sitecore.Services.Core.Diagnostics.ILogger logger)
        {
            if (Directory.Exists(settings.Path))
            {
                foreach (string filePath in Directory.EnumerateFiles(settings.Path))
                {
                    foreach (Dictionary <string, string> line in GetFileContents(filePath, settings))
                    {
                        yield return(line);
                    }

                    logger.Info("file: {0} was processed.", filePath);
                }
            }
            else
            {
                foreach (Dictionary <string, string> line in GetFileContents(settings.Path, settings))
                {
                    yield return(line);
                }
            }
        }
Ejemplo n.º 3
0
        private IEnumerable <Dictionary <string, string> > GetFileContents(string filePath, FileSystemSettings settings)
        {
            //read the file, one line at a time
            var separator = new string[] { settings.ColumnSeparator };

            string[] keys = null;

            using (var reader = new StreamReader(System.IO.File.OpenRead(filePath)))
            {
                var firstLine = true;
                while (!reader.EndOfStream)
                {
                    var line = reader.ReadLine();
                    if (firstLine && settings.ColumnHeadersInFirstLine)
                    {
                        firstLine = false;
                        keys      = line.Split(separator, StringSplitOptions.None);
                        continue;
                    }

                    if (string.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }

                    var values   = line.Split(separator, StringSplitOptions.None);
                    var record   = new Dictionary <string, string>();
                    int colIndex = 1;
                    foreach (string value in values)
                    {
                        if (keys != null)
                        {
                            record.Add(keys[colIndex - 1].Trim(), value.Trim());
                        }
                        else
                        {
                            record.Add(colIndex.ToString(), value.Trim());
                        }
                        colIndex++;
                    }
                    yield return(record);
                }
            }
        }