public AppContext()
        {
            _appProfile = AppProfile.FromConfig();

            _dataSourceConfig = new DataSourceConfig(
                _appProfile.DataSource,
                _appProfile.Database,
                _appProfile.Username,
                _appProfile.Password
                );

            _addressRepository     = new AddressRepository(_dataSourceConfig);
            _billingInfoRepository = new BillingInfoRepository(_dataSourceConfig, _addressRepository);
            _contactInfoRepository = new ContactInfoRepository(_dataSourceConfig);
            _supplierRepository    = new SupplierRepository(_dataSourceConfig, _billingInfoRepository, _contactInfoRepository);
            _receiverRepository    = new ReceiverRepository(_dataSourceConfig, _billingInfoRepository, _contactInfoRepository);
            _itemRepository        = new InvoiceItemRepository(_dataSourceConfig);
            _paymentRepository     = new InvoicePaymentRepository(_dataSourceConfig);
            _invoiceRepository     = new InvoiceRepository(_dataSourceConfig, _supplierRepository, _receiverRepository, _itemRepository, _paymentRepository
                                                           );

            _addressService     = new AddressService(_addressRepository);
            _billingInfoService = new BillingInfoService(_billingInfoRepository);
            _contactInfoService = new ContactInfoService(_contactInfoRepository);
            _supplierService    = new SupplierService(_supplierRepository);
            _receiverService    = new ReceiverService(_receiverRepository);
            _itemService        = new InvoiceItemService(_itemRepository);
            _paymentService     = new InvoicePaymentService(_paymentRepository);
            _invoiceService     = new InvoiceService(_invoiceRepository);
        }
Example #2
0
 public SupplierRepository(
     IDataSourceConfig dataSource,
     IBillingInfoRepository billingInfoRepository,
     IContactInfoRepository contactInfoRepository
     )
 {
     _dataSource            = dataSource;
     _billingInfoRepository = billingInfoRepository;
     _contactInfoRepository = contactInfoRepository;
 }
Example #3
0
 public InvoiceRepository(
     IDataSourceConfig dataSource,
     IEntitySupplierRepository supplierRepository,
     IEntityReceiverRepository receiverRepository,
     IInvoiceItemRepository itemRepository,
     IInvoicePaymentRepository paymentRepository
     )
 {
     _dataSource         = dataSource;
     _supplierRepository = supplierRepository;
     _receiverRepository = receiverRepository;
     _itemRepository     = itemRepository;
     _paymentRepository  = paymentRepository;
 }
Example #4
0
        public BaseDataSource(IDataSourceConfig config)
        {
            _lineParser = new LineParser
            {
                Delimiter = config.Delimiter,
                HasFieldsEnclosedInQuotes = config.HasFieldsEnclosedInQuotes
            };

            if (!string.IsNullOrWhiteSpace(config.CommentedOutIndicator))
            {
                IsLineCommentedOut = (line) =>
                {
                    return(line.StartsWith(config.CommentedOutIndicator));
                };
            }
        }
Example #5
0
        public IDataSource Load(IDataSourceConfig source)
        {
            if (source == null ||
                (source.All == null && source.Negative == null && source.Positive == null))
            {
                throw new ArgumentNullException("Data source was not specified");
            }

            if (source.All != null)
            {
                if (File.Exists(source.All))
                {
                    logger.LogInformation("Loading {0}", source.All);
                    if (source.All.EndsWith(".xml", StringComparison.OrdinalIgnoreCase))
                    {
                        return(new XmlDataLoader(loggerFactory.CreateLogger <XmlDataLoader>()).LoadOldXml(source.All));
                    }

                    if (source.All.EndsWith(".csv", StringComparison.OrdinalIgnoreCase))
                    {
                        return(new CsvDataSource(loggerFactory.CreateLogger <CsvDataSource>(), source.All));
                    }

                    logger.LogInformation("Loading {0} as JSON", source.All);
                    var data = new JsonDataSource(loggerFactory.CreateLogger <JsonDataSource>(), source.All);
                    return(data);
                }

                return(new SimpleDataSource(loggerFactory.CreateLogger <SimpleDataSource>(), source.All, null));
            }

            var loaders = new List <IDataSource>();

            if (!string.IsNullOrEmpty(source.Negative))
            {
                loaders.Add(new SimpleDataSource(loggerFactory.CreateLogger <SimpleDataSource>(), source.Negative, SentimentClass.Negative));
            }

            if (!string.IsNullOrEmpty(source.Positive))
            {
                loaders.Add(new SimpleDataSource(loggerFactory.CreateLogger <SimpleDataSource>(), source.Positive, SentimentClass.Positive));
            }

            return(new CombinedDataSource(loaders.ToArray()));
        }
        public string ToHtmlString()
        {
            StringBuilder js = new StringBuilder("upshot.dataSources = upshot.dataSources || {};\n");

            // First emit metadata for each referenced DataController
            IEnumerable <Type> dataControllerTypes = dataSources.Select(x => x.Value.DataControllerType).Distinct();

            foreach (Type dataControllerType in dataControllerTypes)
            {
                js.AppendFormat("upshot.metadata({0});\n", GetMetadata(dataControllerType));
            }

            // Let the first dataSource construct a dataContext, and all subsequent ones share it
            IEnumerable <IDataSourceConfig> allDataSources = dataSources.Values;
            IDataSourceConfig firstDataSource = allDataSources.FirstOrDefault();

            if (firstDataSource != null)
            {
                // All but the first data source share the DataContext implicitly instantiated by the first.
                foreach (IDataSourceConfig dataSource in allDataSources.Skip(1))
                {
                    dataSource.DataContextExpression = firstDataSource.SharedDataContextExpression;
                }

                // Let the first dataSource define the client mappings
                firstDataSource.ClientMappingsJson = GetClientMappingsObjectLiteral();
            }

            // Now emit initialization code for each dataSource
            foreach (IDataSourceConfig dataSource in allDataSources)
            {
                js.AppendLine("\n" + dataSource.GetInitializationScript());
            }

            // Also record the mapping functions in use
            foreach (var mapping in clientMappings)
            {
                js.AppendFormat("upshot.registerType(\"{0}\", function() {{ return {1} }});\n", EncodeServerTypeName(mapping.Key), mapping.Value);
            }

            return(string.Format(CultureInfo.InvariantCulture, "<script type='text/javascript'>\n{0}</script>", js));
        }
Example #7
0
        /// <summary>
        /// Add a Join to DataSource
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <param name="config"></param>
        /// <param name="key1"></param>
        /// <param name="key2"></param>
        /// <returns></returns>
        public static IDataSourceConfig WithJoin <T1, T2, T3>(this IDataSourceConfig config,
                                                              Expression <Func <T1, T3> > key1, Expression <Func <T2, T3> > key2)
            where T1 : class
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            var expression1 = key1.Body is MemberExpression
                ? (MemberExpression)key1.Body
                : ((MemberExpression)((UnaryExpression)key1.Body).Operand);

            var expression2 = key2.Body is MemberExpression
                ? (MemberExpression)key2.Body
                : ((MemberExpression)((UnaryExpression)key2.Body).Operand);

            config.Joins.Add(new DataSourceJoinConfig <T1, T2>(expression1.Member.Name, expression2.Member.Name));

            return(config);
        }
 public AddressFindAllCommand(IDataSourceConfig dataSource)
 {
     _rowMapper  = new AddressRowMapper();
     _dataSource = dataSource;
 }
Example #9
0
 public InvoiceSaveCommand(IDataSourceConfig dataSource, InvoiceEntity Invoice)
 {
     _rowMapper  = new InvoiceRowMapper();
     _dataSource = dataSource;
     _Invoice    = Invoice;
 }
 public InvoicePaymentFindByIdCommand(IDataSourceConfig dataSource, ulong id)
 {
     _rowMapper    = new InvoicePaymentRowMapper();
     _dataSource   = dataSource;
     _queryParamId = id;
 }
Example #11
0
 public ReceiverSaveCommand(IDataSourceConfig dataSource, ReceiverEntity receiver)
 {
     _rowMapper  = new ReceiverRowMapper();
     _dataSource = dataSource;
     _receiver   = receiver;
 }
 public SupplierFindAllCommand(IDataSourceConfig dataSource)
 {
     _rowMapper  = new SupplierRowMapper();
     _dataSource = dataSource;
 }
 public InvoiceItemRepository(IDataSourceConfig dataSource)
 {
     _dataSource = dataSource;
 }
Example #14
0
 public ContactInfoDeleteCommand(IDataSourceConfig dataSource, ulong id)
 {
     _rowMapper  = new ContactInfoRowMapper();
     _dataSource = dataSource;
     _id         = id;
 }
Example #15
0
 public BillingInfoSaveCommand(IDataSourceConfig dataSource, BillingInfoEntity billingInfo)
 {
     _rowMapper   = new BillingInfoRowMapper();
     _dataSource  = dataSource;
     _billingInfo = billingInfo;
 }
 public ContactInfoFindAllCommand(IDataSourceConfig dataSource)
 {
     _rowMapper  = new ContactInfoRowMapper();
     _dataSource = dataSource;
 }
Example #17
0
 public InvoicePaymentSaveCommand(IDataSourceConfig dataSource, InvoicePaymentEntity InvoicePayment)
 {
     _rowMapper      = new InvoicePaymentRowMapper();
     _dataSource     = dataSource;
     _InvoicePayment = InvoicePayment;
 }
 public InvoicePaymentRepository(IDataSourceConfig dataSource)
 {
     _dataSource = dataSource;
 }
 public AddressFindByIdCommand(IDataSourceConfig dataSource, ulong id)
 {
     _rowMapper    = new AddressRowMapper();
     _dataSource   = dataSource;
     _queryParamId = id;
 }
 public SupplierFIndByIdCommand(IDataSourceConfig dataSource, ulong id)
 {
     _rowMapper    = new SupplierRowMapper();
     _dataSource   = dataSource;
     _queryParamId = id;
 }
 public AddressRepository(IDataSourceConfig dataSource)
 {
     _dataSource = dataSource;
 }
Example #22
0
 public ContactInfoRepository(IDataSourceConfig dataSource)
 {
     _dataSource = dataSource;
 }
Example #23
0
 public ContactInfoSaveCommand(IDataSourceConfig dataSource, ContactInfoEntity contactInfo)
 {
     _rowMapper   = new ContactInfoRowMapper();
     _dataSource  = dataSource;
     _contactInfo = contactInfo;
 }
Example #24
0
 public InvoicePaymentFindAllCommand(IDataSourceConfig dataSource)
 {
     _rowMapper  = new InvoicePaymentRowMapper();
     _dataSource = dataSource;
 }
Example #25
0
 public SupplierDeleteCommand(IDataSourceConfig dataSource, ulong id)
 {
     _rowMapper  = new SupplierRowMapper();
     _dataSource = dataSource;
     _id         = id;
 }
Example #26
0
 public ReceiverFindAllCommand(IDataSourceConfig dataSource)
 {
     _rowMapper  = new ReceiverRowMapper();
     _dataSource = dataSource;
 }
 public BillingInfoFIndByIdCommand(IDataSourceConfig dataSource, ulong id)
 {
     _rowMapper    = new BillingInfoRowMapper();
     _dataSource   = dataSource;
     _queryParamId = id;
 }
 public InvoiceFindAllItemsCommand(IDataSourceConfig dataSource, ulong invoiceId)
 {
     _dataSource = dataSource;
     _invoiceId  = invoiceId;
 }
 public InvoicePaymentDeleteCommand(IDataSourceConfig dataSource, ulong id)
 {
     _rowMapper  = new InvoicePaymentRowMapper();
     _dataSource = dataSource;
     _id         = id;
 }
Example #30
0
 public InvoiceItemFindAllCommand(IDataSourceConfig dataSource)
 {
     _rowMapper  = new InvoiceItemRowMapper();
     _dataSource = dataSource;
 }