private void BroadcastExpenseKPI(ErpKPI kpi)
 {
     Clients.All.updateExpenseKPI(kpi);
 }
 public void UpdateKPI(ErpKPI kpi)
 {
     _erpTicker.UpdateKPI(kpi);
 }
 private void BroadcastCashFlowKPI(ErpKPI kpi)
 {
     Clients.All.updateCashFlowKPI(kpi);
 }
 private void BroadcastSalesKPI(ErpKPI kpi)
 {
     Clients.All.updateSalesKPI(kpi);
 }
        private void BroadcastNewKPI(ErpKPI kpi)
        {
            switch (kpi.Channel)
            {
                case "Sales":
                    Clients.All.addSalesKPI(kpi);
                    break;

                case "CashFlow":
                    Clients.All.addCashFlowKPI(kpi);
                    break;

                case "Expense":
                    Clients.All.addExpenseKPI(kpi);
                    break;

                default:
                    break;
            }
        }
        private void BroadcastKPI(ErpKPI kpi)
        {
            switch (kpi.Channel)
            {
                case "Sales":
                    BroadcastSalesKPI(kpi);
                    break;

                case "CashFlow":
                    BroadcastCashFlowKPI(kpi);
                    break;

                case "Expense":
                    BroadcastExpenseKPI(kpi);
                    break;

                default:
                    break;
            }
        }
/*
        public void UpdateSalesKPI(ErpKPI kpi)
        {
            lock (_updateKPIsLock)
            {
                if (!_updatingKPIs)
                {
                    ErpKPI newKPI;
                    _KPIs.TryGetValue(kpi.Type, out newKPI);
                    newKPI.Amount = kpi.Amount;


                    BroadcastSalesKPI(newKPI);
                }
                _updatingKPIs = false;
            }
        }

        public void UpdateCashFlowKPI(ErpKPI kpi)
        {
            lock (_updateKPIsLock)
            {
                if (!_updatingKPIs)
                {
                    ErpKPI newKPI;
                    _KPIs.TryGetValue(kpi.Type, out newKPI);
                    newKPI.Amount = kpi.Amount;


                    BroadcastCashFlowKPI(newKPI);
                }
                _updatingKPIs = false;
            }
        }
*/
        public void UpdateKPI(ErpKPI kpi)
        {
            lock (_updateKPIsLock)
            {
                if (!_updatingKPIs)
                {
                    ErpKPI newKPI;
                    if (_KPIs.TryGetValue(kpi.Type, out newKPI))
                    {
                        newKPI.Amount = kpi.Amount;
                        BroadcastKPI(newKPI);
                    }
                    else
                    {
                        //add new kpi type
                        newKPI = new ErpKPI { Channel = kpi.Channel, Type = kpi.Type, Amount = 0m };
                        newKPI.Amount = kpi.Amount; //perhaps need to broadcast to Add so javascript can append?
                        _KPIs.TryAdd(newKPI.Type, newKPI);
                        BroadcastNewKPI(newKPI);

                    }

                }
                _updatingKPIs = false;
            }
        }