Esempio n. 1
0
        public bool SetDataProviderList(Schemas.DataProviderType[] dataProviders)
        {
            using (var context = new DataProvidersDataContext())
            {
                #region Delete existing data
                var currentDataProviders =
                    from dataProvider in context.DataProviders
                    //where dataProvider.DataProviderType.IsExternal == true
                    select dataProvider;

                if (currentDataProviders.Count() > 0)
                {
                    context.DataProviders.DeleteAllOnSubmit(currentDataProviders);
                }
                #endregion
                // Add new data providers
                for (int iProv = 0; iProv < dataProviders.Length; iProv++)
                {
                    DataProviderType oio = dataProviders[iProv];
                    var provObj          = Reflection.CreateInstance <IExternalDataProvider>(oio.TypeName);
                    // TODO: Also pass IPerDataProvider properties here
                    var dbProv = DataProvider.FromXmlType(oio, iProv, provObj.ConfigurationKeys.Select(p => p.Name).ToArray());
                    context.DataProviders.InsertOnSubmit(dbProv);
                }
                context.SubmitChanges();
                return(true);
            }
        }
Esempio n. 2
0
        public static void CheckInterval(DataProvidersDataContext dataContext, BudgetInterval budgetInterval)
        {
            var checkTime = DateTime.Now;

            if (budgetInterval.CanRunAt(checkTime, IntervalAllowancePercentage))
            {
                using (var appDataContext = new ApplicationDataContext())
                {
                    var intervalEntries = appDataContext.DataProviderCalls
                                          .Where(dce => dce.CallTime >= budgetInterval.SuggestedStartTime(checkTime) && dce.CallTime < checkTime);

                    CheckInterval <decimal>(budgetInterval.Name, () => intervalEntries.Sum(dpe => dpe.Cost), budgetInterval.CostThreshold, "cost");
                    CheckInterval <int>(budgetInterval.Name, () => intervalEntries.Count(), budgetInterval.CallThreshold, "number of calls");

                    budgetInterval.LastChecked = checkTime;
                    dataContext.SubmitChanges();
                }
            }
        }
        protected void dataProvidersGridView_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Ping")
            {
                using (var dataContext = new DataProvidersDataContext())
                {
                    var           id     = new Guid(e.CommandArgument.ToString());
                    DataProvider  dbProv = dataContext.DataProviders.Where(p => p.DataProviderId == id).OrderBy(dp => dp.Ordinal).SingleOrDefault();
                    IDataProvider prov   = DataProviderManager.CreateDataProvider(dbProv);

                    if (prov.IsAlive())
                    {
                        Master.AlertMessages.Add("Ping succeeded");
                    }
                    else
                    {
                        Master.AlertMessages.Add("Ping failed");
                    }
                }
            }
            else if (e.CommandName == "Enable")
            {
                using (var dataContext = new DataProvidersDataContext())
                {
                    var          id     = new Guid(e.CommandArgument.ToString());
                    DataProvider dbProv = dataContext.DataProviders.Where(p => p.DataProviderId == id).SingleOrDefault();
                    dbProv.IsEnabled = !(dbProv.IsEnabled);
                    dataContext.SubmitChanges();
                    dataProvidersGridView.DataBind();
                }
            }
            else if (e.CommandName == "Up" || e.CommandName == "Down")
            {
                using (var dataContext = new DataProvidersDataContext())
                {
                    var          id            = new Guid(e.CommandArgument.ToString());
                    var          dataProviders = LoadDataProviders(dataContext);
                    DataProvider dbProv        = dataProviders.First(p => p.DataProviderId == id);

                    for (int index = 0; index < dataProviders.Length; index++)
                    {
                        dataProviders[index].Ordinal = index;
                    }

                    int providerIndex = Array.IndexOf <DataProvider>(dataProviders, dbProv);
                    if (providerIndex != -1)
                    {
                        if (e.CommandName == "Up" && providerIndex > 0)
                        {
                            dataProviders[providerIndex].Ordinal     = providerIndex - 1;
                            dataProviders[providerIndex - 1].Ordinal = providerIndex;
                        }
                        else if (e.CommandName == "Down" && providerIndex < dataProviders.Length - 1)
                        {
                            dataProviders[providerIndex].Ordinal     = providerIndex + 1;
                            dataProviders[providerIndex + 1].Ordinal = providerIndex;
                        }
                        dataContext.SubmitChanges();
                        dataProvidersGridView.DataBind();
                    }
                }
            }
        }