/// <summary> /// Send the SalesOrderList to the data onboarding web service. This method accepts a SalesOrderList rather than a DataTable /// </summary> /// <param name="salesOrders">Sales Order Data List</param> /// <param name="primaryKey">Primary key field in the data</param> /// <param name="dateController">DateController field in the data</param> /// <param name="measureFields">List of measure fields in the data</param> /// <param name="longTextFields">List of long text fields in the data</param> /// <param name="commaAnalyzerFields">List of comma analyzer (CSV) fields in the data</param> /// <returns></returns> public bcl.DTO.DTO_Result SendData(DTO.SalesOrder.DTO_SalesOrderList salesOrders, string primaryKey, string dateController, List <string> measureFields = null, List <string> longTextFields = null, List <string> commaAnalyzerFields = null) { bcl.DTO.DTO_Result Results = new Framework.Bcl.DTO.DTO_Result(false); //Add the data to the Sales order datatable helper. SalesOrderDataTableHelper.AddSalesOrders(salesOrders); //check if the datatable is not empty if (SalesOrderDataTableHelper.SalesOrderTable != null) { if (SalesOrderDataTableHelper.SalesOrderTable.Rows.Count > 0) { //send the datatable for onboarding via the eMite data onboarding web service. Results = SendData(SalesOrderDataTableHelper.SalesOrderTable, primaryKey, dateController, measureFields, longTextFields, commaAnalyzerFields); SalesOrderDataTableHelper.Dispose(); } else { Results = new bcl.DTO.DTO_Result(false, "No records to index"); } } else { Results = new bcl.DTO.DTO_Result(false, "No records to index"); } return(Results); }
/// <summary> /// Sends a single SalesOrder object for onboarding into eMite. /// </summary> /// <param name="data"></param> /// <returns></returns> public override DTO_Result Onboard(DTO_Base data) { bcl.DTO.DTO_Result Results = new DTO_Result(); //Create a sales order list object DTO.SalesOrder.DTO_SalesOrderList SalesOrders = new DTO.SalesOrder.DTO_SalesOrderList(); //check if the DTO passed is of type DTO_SalesOrder if (data.GetType() == typeof(DTO.SalesOrder.DTO_SalesOrder)) { //cast the dto to DTO_SalesOrder object DTO.SalesOrder.DTO_SalesOrder salesOrder = (DTO.SalesOrder.DTO_SalesOrder)data; //add the sales order to the list SalesOrders.Add(salesOrder); //onboard the sales order. Results = Onboard(SalesOrders); } else { //Log DTO not of type DTO_SalesOrder Log.Error("Record not of type: DTO_SalesOrder"); } return(Results); }
/// <summary> /// Sends data for onboarding into eMite /// </summary> /// <param name="salesOrders"></param> /// <returns></returns> public override DTO_Result Onboard(DTO.SalesOrder.DTO_SalesOrderList salesOrders) { bcl.DTO.DTO_Result Results = new DTO_Result(); //We'll use the onboarding helper to onbaord a list of sales order data Results = OnboardingHelper.SendData(salesOrders, BM.Helpers.BM_SalesOrderDataTableHelper.SalesOrderIndexerConfig.PrimaryKey, BM.Helpers.BM_SalesOrderDataTableHelper.SalesOrderIndexerConfig.DateController, measureFields: BM.Helpers.BM_SalesOrderDataTableHelper.SalesOrderIndexerConfig.MeasureFields); return(Results); }
/// <summary> /// Adds a list of Sales Orders to the SalesOrder DataTable /// </summary> /// <param name="salesOrders"></param> public void AddSalesOrders(DTO.SalesOrder.DTO_SalesOrderList salesOrders) { lock (SalesOrderTableLock) { //Generate table if it does not exist. if (SalesOrderTable == null) { GenerateSalesOrderDatatable(SalesOrderIndexerConfig.IndexName); } //check and add all sales orders to the datatable. if (salesOrders != null) { foreach (var salesOrder in salesOrders) { AddSalesOrder(salesOrder); } } } }
public abstract DTO_Result Onboard(DTO.SalesOrder.DTO_SalesOrderList salesOrders);
/// <summary> /// Sends data for onboarding into eMite /// </summary> /// <param name="salesOrders"></param> /// <returns></returns> public override DTO_Result Onboard(DTO.SalesOrder.DTO_SalesOrderList salesOrders) { return(Dal.Onboard(salesOrders)); }
/// <summary> /// Entry point of the Adventure works adapter. /// </summary> public void Start() { bool ExitLoop = true; //authenticated token is globaly available via the BM_Authentication business module Log.Info("Authenticated Token: " + BM.Helpers.BM_Authentication.AuthenticatedToken); //only proceed if the authentication token is valid i.e. the code successfully authenticated with the source api. In this sample this will always be true. if (BM.Helpers.BM_Authentication.IsAuthenticated) { //get sales order filter criteria var SalesOrderFilter = GetQueryRange(); //loop until EndDate < DateTime.UTCNow do { bcl.DTO.DTO_Result OnboardResults = null; Log.Info("StartDate: " + SalesOrderFilter.StartDate.ToString("yyyy-MM-ddHH:mm:ss") + " | EndDate: " + SalesOrderFilter.EndDate.ToString("yyyy-MM-ddHH:mm:ss")); //load sales orders using the sale order filter var Data = BmSalesOrder.Get(SalesOrderFilter); //check if call was successful if (Data.Successful) { //check if there were results returned for the poll. if (Data.Results != null) { //cast the data into the SalesOrderList Object DTO.SalesOrder.DTO_SalesOrderList SalesOrders = (DTO.SalesOrder.DTO_SalesOrderList)Data.Results; //Send data for onboarding. OnboardResults = BmSalesOrder.Onboard(SalesOrders); //check if data onboarding was successful. if (OnboardResults.Errors != null) { //output error logs if any. if (OnboardResults.Errors.Count > 0) { Log.Warn(OnboardResults.Errors[0]); } } } } //check if the current poll EndDate is less than UtcNow. So that we can prepare a new filter criteria for the next data poll if (SalesOrderFilter.EndDate < DateTime.UtcNow) { //set filter criteia for next poll. SalesOrderFilter.StartDate = SalesOrderFilter.EndDate; //add the configured QueryInterval set by the user for each poll. SalesOrderFilter.EndDate = SalesOrderFilter.StartDate.AddMinutes(Config.QueryInterval); ExitLoop = false; } else { ExitLoop = true; } } while (ExitLoop == false); } }
/// <summary> /// Gets sales orders using the filter criteria supplied. /// </summary> /// <param name="filterCriteria"></param> /// <returns></returns> public override DTO_Result Get(FC_Base filterCriteria) { bcl.DTO.DTO_Result Results = new DTO_Result(); //defines SalesOrderList object to hold all sales orders returned by the poll. DTO.SalesOrder.DTO_SalesOrderList SalesOrders = new DTO.SalesOrder.DTO_SalesOrderList(); //filter criteria object should be of type FC_SalesOrder if (filterCriteria.GetType() == typeof(FC.SalesOrder.FC_SalesOrder)) { //cast the filter criteria to the FC_SalesOrder type. FC.SalesOrder.FC_SalesOrder cSalesOrder = (FC.SalesOrder.FC_SalesOrder)filterCriteria; #region "Sql" string query = @" SELECT h.[SalesOrderID] ,h.[RevisionNumber] ,h.[OrderDate] ,h.[DueDate] ,h.[ShipDate] ,h.[Status] ,h.[OnlineOrderFlag] ,h.[SalesOrderNumber] ,h.[PurchaseOrderNumber] ,h.[AccountNumber] ,h.[CustomerID] ,h.[SalesPersonID] ,h.[TerritoryID] ,h.[BillToAddressID] ,h.[ShipToAddressID] ,h.[ShipMethodID] ,h.[CreditCardID] ,h.[CreditCardApprovalCode] ,h.[CurrencyRateID] ,h.[SubTotal] ,h.[TaxAmt] ,h.[Freight] ,h.[TotalDue] ,h.[Comment] ,CONVERT(varchar(50), h.[rowguid],120) HeaderRowGuid ,h.[ModifiedDate] ,ISNULL(e.FirstName,'') + ' ' + ISNULL(e.MiddleName,'') + ' ' + ISNULL(e.LastName,'') SalesPerson ,ISNULL(p.FirstName,'') + ' ' + ISNULL(p.MiddleName,'') + ' ' + ISNULL(p.LastName,'') CustomerName ,t.CountryRegionCode + '-' + t.Name Territory ,sh.Name ShipMethod FROM Sales.SalesOrderHeader h --INNER JOIN Sales.SalesOrderDetail d ON h.SalesOrderID = d.SalesOrderID LEFT OUTER JOIN Sales.Customer c ON h.CustomerID = c.CustomerID LEFT OUTER JOIN Person.Person p ON c.PersonID = p.BusinessEntityID LEFT OUTER JOIN Person.Person e ON h.SalesPersonID = e.BusinessEntityID LEFT OUTER JOIN Purchasing.ShipMethod sh ON h.ShipMethodID = sh.ShipMethodID LEFT OUTER JOIN Sales.SalesTerritory t ON h.TerritoryID = t.TerritoryID WHERE h.ModifiedDate > @StartDate AND h.ModifiedDate <= @EndDate "; #endregion IEnumerable <dynamic> results = null; //run the query (via dapper) on the Adventure Works Database and fetch the results. using (var conn = new System.Data.SqlClient.SqlConnection(Config.AdventureWorksConnection)) { results = conn.Query <dynamic>(query, new { StartDate = cSalesOrder.StartDate, EndDate = cSalesOrder.EndDate }); } //we'll use the Slapper.AutoMapper to map results into the SalesOrder Object. The automapper can map data into a complex DTO hierarchy Slapper.AutoMapper.Cache.ClearInstanceCache(); //specify the primary key columns Slapper.AutoMapper.Configuration.AddIdentifiers(typeof(DTO.SalesOrder.DTO_SalesOrder), new List <string> { "SalesOrderID" }); //map the results into the SalesOrders List object. SalesOrders = new DTO.SalesOrder.DTO_SalesOrderList(Slapper.AutoMapper.MapDynamic <DTO.SalesOrder.DTO_SalesOrder>(results)); //fill in the results object for returning Results = new DTO_Result(true, SalesOrders); } else { //Filter criteria supplied was not of type FC_SalesOrder Results = new DTO_Result(false, "Filter criteria not of type: FC_SalesOrder"); Log.Error("Filter criteria not of type: FC_SalesOrder"); } return(Results); }