Example #1
0
        private void ConvertRow(Row row, string data)
        {
            //This method is responsible for initiating parsing of
            //row section. A new instance of row parser is created
            //by passing the current data and row information
            RowParser rowParser = new RowParser(dataReader, data, row);

            //invoke the writer band start method
            dataWriter.WriteStartRow(row, rowParser.Data);
            //invoke row parser
            if (rowParser.Parse() == false)
            {
                //if there is no matching data found based on row identifier
                //then bypass the column processing and invoke
                //the writer row end method
                dataWriter.WriteEndRow(row);
                return;
            }
            //initiate the column parsing
            ColumnParser colParser = new ColumnParser(dataReader);

            //iterate through individual columns
            //and process the column level information
            foreach (Column col in row.Columns)
            {
                colParser.Data           = data;
                colParser.CellsAttribute = col;
                ConvertCol(row, col, data, colParser);
            }
            //invoke the writer row end method
            dataWriter.WriteEndRow(row);
        }
 public ConstraintParser(TypeAccessor typeAccessor)
     : this()
 {
     this.typeAccessor = typeAccessor;
     columnParser      = new ColumnParser();
     parser            = this;
 }
Example #3
0
 private void ConvertCol(Row row, Column col, string data, ColumnParser colParser)
 {
     //This method is responsible for initiating parsing of
     //column section
     colParser.Parse();
     //invoke writer column start and end method
     dataWriter.WriteStartColumn(col, colParser.Data);
     dataWriter.WriteEndColumn(col);;
 }
        public Column ToColumn()
        {
            var regex     = new Regex(@"NOT\s+NULL", RegexOptions.IgnoreCase);
            var isNotNull = regex.IsMatch(Attributes);

            return(new Column(Identifier, ColumnParser.ParseType(Type), !isNotNull,
                              Attributes.ToUpper().Contains("AUTO_INCREMENT"),
                              Type.ToUpper() == "SERIAL" || Type.ToUpper() == "BIGSERIAL"));
        }
Example #5
0
        private void LoadFromTemplate(AsposeExcel template)
        {
            string sourcefullpath       = template.ReadCell(0, 1);
            string destinationfullpath  = template.ReadCell(1, 1);
            string sourceworksheet      = template.ReadCell(0, 2);
            string destinationworksheet = template.ReadCell(1, 2);

            if (File.Exists(sourcefullpath) && File.Exists(destinationfullpath))
            {
                _migrationContainer.Source = new AsposeExcel(sourcefullpath);
                InitSourceExcel();
                _migrationContainer.Destination = new AsposeExcel(destinationfullpath);
                InitDestinationExcel();

                if (_migrationContainer.Source.ChangeWorksheet(sourceworksheet) && _migrationContainer.Destination.ChangeWorksheet(destinationworksheet))
                {
                    _migrationContainer.TemplateAttached = true;

                    for (int crow = 3; crow < template.RowsCount; crow++)
                    {
                        ColumnParser col = new ColumnParser();
                        col.SourceColumnName       = template.ReadCell(crow, 0);
                        col.SourceColumnIndex      = Convert.ToInt16(template.ReadCell(crow, 1));
                        col.DestinationColumnName  = template.ReadCell(crow, 2);
                        col.DestinationColumnIndex = Convert.ToInt16(template.ReadCell(crow, 3));
                        col.IsKey       = Convert.ToBoolean(template.ReadCell(crow, 4));
                        col.LookupMatch = Convert.ToBoolean(template.ReadCell(crow, 5));

                        _migrationContainer.ColumnParsers.Add(col);
                    }
                    if (_migrationContainer.ColumnParsers.Count() > 0)
                    {
                        var msg = new MessageView("Template has been loaded");
                        msg.Show();
                    }
                    else
                    {
                        var msg = new MessageView("Cannot find any column relations");
                        msg.Show();
                    }
                }
                else
                {
                    var msg = new MessageView("Cannot find worksheets");
                    msg.Show();
                }
            }
            else
            {
                var msg = new MessageView("Cannot find files. Put them in the same directory as written in excel file");
                msg.Show();
            }
        }
Example #6
0
        private IEnumerable <Field> GetValuesFromCursor(ICommenceCursor cur)
        {
            IEnumerable <Field>      retval            = new List <Field>(); // a cursor cannot have no fields, so we should be safe.
            ColumnParser             cp                = new ColumnParser(cur);
            IList <ColumnDefinition> columnDefinitions = cp.ParseColumns();

            _db.ClarifyItemNames("true");
            _itemName = _db.GetActiveItemName(); // also marks the item for us

            IList <Field> fields = new List <Field> {
                new Field {
                    Name  = _nameField,
                    Value = _itemName,
                    Label = columnDefinitions
                            .Where(w => !w.IsConnection)
                            .SingleOrDefault(s => s.FieldName.Equals(_nameField))?.ColumnLabel
                }
            };

            // if the name field isn't in the view the view label will be empty,
            // in that casechange it to fieldname instead
            // note that this will actually return more information than is showing in Commence
            if (string.IsNullOrEmpty(fields[0].Label))
            {
                fields[0].Label = _nameField;
            }

            // get a list of all the direct fields except the name field
            IEnumerable <ColumnDefinition> directFields = columnDefinitions
                                                          .Where(w => !w.IsConnection && w.FieldName != _nameField)
                                                          .ToArray();
            // get the direct field values using DDE
            IEnumerable <Field> directFieldValues = GetDirectFieldValues(directFields);

            retval = fields.Concat(directFieldValues);

            // get the indirect values
            IEnumerable <RelatedColumn> relatedColumns = columnDefinitions
                                                         .Where(w => w.IsConnection)
                                                         .Select(s => new RelatedColumn(s.Connection,
                                                                                        s.Category,
                                                                                        s.FieldName,
                                                                                        RelatedColumnType.ConnectedField,
                                                                                        s.QualifiedConnection + ' ' + s.FieldName)) // very dirty trick!!!!!!
                                                         .ToArray();
            IEnumerable <Field> connectedFieldValues = GetConnectedFieldValues(relatedColumns);

            retval = retval.Concat(connectedFieldValues);
            _db.ClarifyItemNames(clarifyStatus); // restore original setting
            return(retval);
        } // method
Example #7
0
        public void FillSourceIfFoundDestination(ColumnParser parser, string caption)
        {
            if (_migration.Source.ColumnCaptionsWithIndexDictionary.ContainsKey(caption))
            {
                parser.SourceColumnName  = caption;
                parser.SourceColumnIndex = _migration.Source.ColumnCaptionsWithIndexDictionary[caption];
            }
            else
            {
                if (_migration.Source.ColumnCaptionsWithIndexDictionary.ContainsKey(caption))
                {
                    parser.SourceColumnName  = caption;
                    parser.SourceColumnIndex = _migration.Source.ColumnCaptionsWithIndexDictionary[caption.ToLower()];
                }
                else
                {
                    string highest = string.Empty;
                    int    memory  = 100;
                    foreach (var par in _migration.Source.ColumnCaptionList)
                    {
                        int distance = Levenstein.NettoDistance(par, caption);
                        if (distance < memory)
                        {
                            highest = par;
                            memory  = distance;
                        }
                    }

                    if (memory <= 3)
                    {
                        parser.SourceColumnName  = highest;
                        parser.SourceColumnIndex = _migration.Source.ColumnCaptionsWithIndexDictionary[highest];
                    }
                    else
                    {
                        var s = _migration.Source.ColumnCaptionsWithIndexDictionary.First();
                        parser.SourceColumnName  = s.Key;
                        parser.SourceColumnIndex = s.Value;
                    }
                }
            }
        }
Example #8
0
        public void ColumnParserTest()
        {
            StringReader reader = new StringReader(
                "\r\n" +
                "# comment\r\n" +
                "\r\n" +
                "1    2    3   4        5         6 7\r\n" +
                "---- -    --- -------- --------- - ----\r\n" +
                "a a  b  x c   d     d          e f g   \r\n" +
                "AAAAABBBBBCCCCDDDDDDDDDEEEEEEEEEEFFGGGGGGGG\r\n");

            var parsed = new ColumnParser(reader);

            CollectionAssert.AreEqual(new string[] { "1", "2", "3", "4", "5", "6", "7" }, parsed.Fields.ToList());

            var data = parsed.Data;

            Assert.AreEqual(data.Count, 2);

            var dict = data[0].dict;

            Assert.AreEqual("a a", dict["1"]);
            Assert.AreEqual("b", dict["2"]);
            Assert.AreEqual("c", dict["3"]);
            Assert.AreEqual("d     d", dict["4"]);
            Assert.AreEqual("        e", dict["5"]);
            Assert.AreEqual("f", dict["6"]);
            Assert.AreEqual("g", dict["7"]);

            dict = data[1].dict;
            Assert.AreEqual("AAAA", dict["1"]);
            Assert.AreEqual("B", dict["2"]);
            Assert.AreEqual("CCC", dict["3"]);
            Assert.AreEqual("DDDDDDDD", dict["4"]);
            Assert.AreEqual("EEEEEEEEE", dict["5"]);
            Assert.AreEqual("F", dict["6"]);
            Assert.AreEqual("GGGG", dict["7"]);
        }
Example #9
0
        private void LoadComparisonView()
        {
            if (!_migration.TemplateAttached)
            {
                if (_migration.Destination != null)
                {
                    var captionsWithIndex = _migration.Destination.ColumnCaptionsWithIndexDictionary;
                    foreach (var col in captionsWithIndex)
                    {
                        ColumnParser parser = new ColumnParser();
                        parser.DestinationColumnName        = col.Key;
                        parser.DestinationColumnIndex       = col.Value;
                        parser.DestinationColumnCaptionList = _migration.Destination.ColumnCaptionList;
                        parser.SourceColumnCaptionList      = _migration.Source.ColumnCaptionList;
                        FillSourceIfFoundDestination(parser, col.Key);

                        columnParsers.Add(parser);
                    }
                    itemsListColumnParsers.ItemsSource = columnParsers;
                }
            }
            else
            {
                if (_migration.Destination != null)
                {
                    foreach (var parser in _migration.ColumnParsers)
                    {
                        parser.DestinationColumnCaptionList = _migration.Destination.ColumnCaptionList;
                        parser.SourceColumnCaptionList      = _migration.Source.ColumnCaptionList;

                        columnParsers.Add(parser);
                    }
                    itemsListColumnParsers.ItemsSource = columnParsers;
                }
            }
        }
 public ConstraintParser()
 {
     parser       = this;
     columnParser = new ColumnParser();
 }
Example #11
0
 public void Setup()
 {
     _parser = new LoggerParser();
 }