Exemplo n.º 1
0
        public Argument Extract(Cell cell, Parameter parameter, Command command)
        {
            if (!Regex.IsMatch(cell.Content, @"[@$=\(\)]"))
            {
                if (!Context.Arguments.Any(s => s.Name.Equals(cell.Content)
                    && s.Parameter.ParameterType.Equals(parameter.ParameterType)
                    && s.Command.Id == command.Id))
                {
                    var arg = new Argument
                    {
                        Name = cell.Content,
                        Parameter = parameter,
                        Command = command
                    };
                    return arg;
                }
                return (from a in Context.Arguments
                        where a.Name.Equals(cell.Content)
                              && a.Parameter.ParameterType.Equals(parameter.ParameterType)
                        select a).FirstOrDefault();
            }

            var pType = LatticeEnum.ParamterType.Call.ToString();
            return new Argument
            {
                Name = cell.Content,
                Parameter = (from p in Context.Parameters
                             where p.ParameterType.Equals(pType)
                             select p).FirstOrDefault(),
                Command = command,
                IsValid = false
            };
        }
Exemplo n.º 2
0
        private void FindValueInArray(Cell cell, Layout layout, string[] listOfLayoutNames)
        {
            string layoutName = ExtractLayoutNameFromCell(cell.Content);

            if (string.IsNullOrEmpty(layoutName))
            {
                return;
            }

            int pos = Array.IndexOf(listOfLayoutNames, layoutName.ToUpperInvariant());
            if (pos > -1)
            {
                BuildReferencedLayout(cell, layout, listOfLayoutNames[pos]);
            }
        }
Exemplo n.º 3
0
        private void BuildReferencedLayout(Cell cell, Layout layout, string layoutName)
        {
            var refLayout = Context.Layouts.Select(l => l).FirstOrDefault(l => l.Title == layoutName);

            if (refLayout == null)
            {
                return;
            }

            var referencedLayout = new ReferencedLayout()
            {
                LayoutContainingRef = layout,
                ReferenceToLayout = refLayout,
                CellContainingRef = cell,
                ReferencedToCell = cell.Content
            };

            Context.ReferencedLayouts.Add(referencedLayout);
            //Context.SaveChanges();
        }
Exemplo n.º 4
0
        public void Parse(string filename)
        {
            logger.Info("Parsing File - " + filename);

            using (var context = new LatticeContext())
            {
                var layout = new Layout
                {
                    Cells = new List<Cell>(),
                    Filename = filename,
                    Title = Path.GetFileNameWithoutExtension(filename)
                };

                context.Layouts.Add(layout);
                context.SaveChanges();

                //read the file
                var lines =
                    System.IO.File.ReadAllLines(filename);

                for (int i = 0; i < lines.Count(); i++)
                {
                    //regex to check for a white space, a number, 2 or more white spaces then words after.
                    if (Regex.IsMatch(lines[i], StartCell))
                    {
                        var cell = new Cell
                        {
                            Row = Convert.ToInt32(Regex.Match(lines[i], @":(.*),").Groups[1].Value),
                            Column = Convert.ToInt32(Regex.Match(lines[i], @",(.*)\]").Groups[1].Value)
                        };

                        for (i++; i < lines.Count(); i++)
                        {
                            //ensure this line is not a title, else break out of it.
                            if (Regex.IsMatch(lines[i], EndCell))
                            {
                                break;
                            }

                            //if number only found, this is the start of a verse
                            if (Regex.IsMatch(lines[i], FormulaCell1))
                            {

                                cell.Content = Regex.Match(lines[i], FormulaCell1).Value;
                                layout.Cells.Add(cell);

                                break;
                            }
                            else if (Regex.IsMatch(lines[i], FormulaCell2))
                            {

                                cell.Content = Regex.Match(lines[i], FormulaCell2).Value;
                                layout.Cells.Add(cell);

                                break;
                            }

                        }

                    }
                }

                context.SaveChanges();
            }

            // Console.WriteLine("number of populated cells are {0}", layout.Cells.Count);
        }
Exemplo n.º 5
0
        public int Extract(Cell mainCell)
        {
            Logger.Info("Extracting Command");

            var commandText = mainCell.Content;

            var signature = Regex.Match(commandText, CallRegex).Groups[1].Value;

            var call = (from c in Context.Calls
                        where c.Signature.Equals(signature, StringComparison.InvariantCultureIgnoreCase)
                        select c).FirstOrDefault();

            if (call == null)
                return 0;

            var command = new Command();

            command.Arguments = new List<Argument>();

            command.Call = call;

            //var arguments = Regex.Match(commandText, @"@.*\((.*)\)").Groups[1].Value.Split(',');

            //int count = 0;
            //var transformer = new CellReferenceTransformer();

            //var parameters = (from p in Context.Parameters
            //                  where p.Call.Id == command.Call.Id
            //                  orderby p.Position
            //                  select p).ToList();

            //foreach (var parameter in parameters)
            //{
            //    var transformedArgument = transformer.Tranform(arguments[count]);

            //    foreach (var cell in Layout.Cells)
            //    {
            //        if (cell.Row == transformedArgument.Item1 && cell.Column == transformedArgument.Item2)
            //        {
            //            var extractor = new ArgumentExtractor(Context);
            //            var argument = extractor.Extract(cell, parameter, command);

            //            if (argument == null)
            //            {
            //                return 0;
            //            }

            //            command.Arguments.Add(argument);

            //            break;
            //        }
            //    }
            //    count++;
            //}

            command.Layout = Layout;
            command.Cell = mainCell;

            Context.Commands.Add(command);
            Context.SaveChanges();

            return 1;
        }