Esempio n. 1
0
 private CalcCell(string address, CalcChainContext context)
 {
     Require.That(context).Named("context").IsNotNull();
     Id = context.IdProvider.NewId();
     _context = context;
     Address = address;
 }
Esempio n. 2
0
 private CalcCell(string address, CalcChainContext context)
 {
     Require.That(context).Named("context").IsNotNull();
     Id       = context.IdProvider.NewId();
     _context = context;
     Address  = address;
 }
        public CalcChainContext Build(ParsingContext context, string worksheetName)
        {
            _parsingContext = context;
            var chainContext = CalcChainContext.Create(context.Configuration.IdProvider);
            var lexer        = context.Configuration.Lexer;
            var cells        = string.IsNullOrEmpty(worksheetName) ?
                               _parsingContext.ExcelDataProvider.GetWorkbookFormulas() :
                               _parsingContext.ExcelDataProvider.GetWorksheetFormulas(worksheetName);

            foreach (var cellInfo in cells)
            {
                var address     = cellInfo.Key;
                var cell        = chainContext.CalcCells.AddOrGet(address);
                var formula     = cellInfo.Value;
                var r           = lexer.Tokenize(formula);
                var toAddresses = r.Where(x => x.TokenType == TokenType.ExcelAddress);
                foreach (var toAddress in toAddresses)
                {
                    var rangeAddress = context.RangeAddressFactory.Create(toAddress.Value);
                    var rangeCells   = new List <string>();
                    if (rangeAddress.FromRow < rangeAddress.ToRow || rangeAddress.FromCol < rangeAddress.ToCol)
                    {
                        for (var col = rangeAddress.FromCol; col <= rangeAddress.ToCol; col++)
                        {
                            for (var row = rangeAddress.FromRow; row <= rangeAddress.ToRow; row++)
                            {
                                rangeCells.Add(context.RangeAddressFactory.Create(col + 1, row + 1).Address);
                            }
                        }
                    }
                    else
                    {
                        rangeCells.Add(toAddress.Value);
                    }
                    CalcChain chain;
                    foreach (var rangeCell in rangeCells)
                    {
                        var toCell  = chainContext.CalcCells.AddOrGet(rangeCell);
                        var chainId = cell.GetCalcChainId();
                        if (chainId == null)
                        {
                            chain = CalcChain.Create(context.Configuration.IdProvider);
                            chainContext.AddCalcChain(chain);
                        }
                        else
                        {
                            chain = chainContext.CalcChains.Where(x => x.Id == chainId).FirstOrDefault();
                        }
                        chain.Add(toCell);
                        cell.AddRelationTo(toCell, chain);
                        toCell.AddRelationFrom(cell, chain);
                    }
                }
            }

            return(chainContext);
        }
 public void Setup()
 {
     _idProvider = new IntegerIdProvider();
     _provider = MockRepository.GenerateStub<ExcelDataProvider>();
     SetupExcelProvider();
     _idProvider = new IntegerIdProvider();
     _chainContext = CalcChainContext.Create(_idProvider);
     _builder = new CalcChainContextBuilder();
     _parsingContext = ParsingContext.Create();
     _parsingContext.RangeAddressFactory = new RangeAddressFactory(_provider);
     _parsingContext.Configuration.SetIdProvider(_idProvider);
     _parsingContext.Configuration.SetLexer(new Lexer(_parsingContext.Configuration.FunctionRepository, _parsingContext.NameValueProvider));
     _parsingContext.ExcelDataProvider = _provider;
 }
Esempio n. 5
0
 public static CalcCellRepository Create(CalcChainContext context)
 {
     return(new CalcCellRepository(context));
 }
Esempio n. 6
0
 private CalcCellRepository(CalcChainContext context)
 {
     _context = context;
 }
Esempio n. 7
0
 public static CalcCell Create(string address, CalcChainContext context)
 {
     return new CalcCell(address, context);
 }
Esempio n. 8
0
 public void Setup()
 {
     _chainContext = CalcChainContext.Create(new IntegerIdProvider());
     _chain = CalcChain.Create(_chainContext.IdProvider);
 }
 public void Setup()
 {
     _chainContext = CalcChainContext.Create(_idProvider);
     _repository = CalcCellRepository.Create(_chainContext);
 }
Esempio n. 10
0
 public static CalcCell Create(string address, CalcChainContext context)
 {
     return(new CalcCell(address, context));
 }
 public static CalcCellRepository Create(CalcChainContext context)
 {
     return new CalcCellRepository(context);
 }
 private CalcCellRepository(CalcChainContext context)
 {
     _context = context;
 }