public void Load()
            {
                Configuration storedProceduresConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

                StoredProceduresSection storedProceduresSection = (StoredProceduresSection)storedProceduresConfig.GetSection("storedProcedures");

                StoredProceduresElementCollection storedProcedures = storedProceduresSection.StoredProcedures;

                Loaded = false;

                foreach (StoredProcedureConfigElement storedProcedure in storedProcedures)
                {
                    if (Name.CompareTo(storedProcedure.Name) != 0)
                    {
                        continue;
                    }

                    foreach (StoredProcedureParameterConfigElement param in storedProcedure.Parameters)
                    {
                        SqlParameter sqlParam = new SqlParameter("@" + param.Name, MsSqlDataProvider.TranslateToDbType(param.Type));

                        if (param.Direction == "in")
                        {
                            sqlParam.Direction = ParameterDirection.Input;
                        }
                        else if (param.Direction == "out")
                        {
                            sqlParam.Direction = ParameterDirection.Output; // not in use!!!
                        }
                        else if (param.Direction == "inout")
                        {
                            sqlParam.Direction = ParameterDirection.InputOutput; // not in use!!!
                        }

                        if (param.Size > 0)
                        {
                            sqlParam.Size = param.Size;
                        }

                        sqlParam.IsNullable = param.Nullable;

                        if (!string.IsNullOrEmpty(param.Column))
                        {
                            sqlParam.SourceColumn = param.Column;
                        }

                        Assert.Condition(!myParameters.ContainsKey(param.Name), string.Format("Duplicate param name in stored procedure: {0}", Name));

                        myParameters.Add(param.Name, sqlParam);
                    }

                    Loaded = true;

                    break;
                }

                Assert.Condition(Loaded, string.Format("Unable to load stored procedure {0}.", Name));
            }
Esempio n. 2
0
        public bool TryGetData(DateTime xiStartTime, DateTime xiEndTime, out List <string> xoData)
        {
            xoData = new List <string>();

            bool result = true;

            try
            {
                MsSqlDataProvider msSqlDataProvider = (MsSqlDataProvider)DataProviders.Instance[MsSqlDataProvider.kId];

                Dictionary <string, object> args = new Dictionary <string, object>();

                args.Add("StartTime", xiStartTime);
                args.Add("EndTime", xiEndTime);

                Dictionary <string, object> resultDataset = msSqlDataProvider.ExecuteStoredProcedure("GET_HISTORY", args);

                foreach (Dictionary <string, object> row in resultDataset.Values)
                {
                    foreach (KeyValuePair <string, object> kvp in row)
                    {
                        switch (kvp.Key)
                        {
                        case "Data":
                        {
                            string message = ((!Convert.IsDBNull(kvp.Value) && kvp.Value is string) ? (string)kvp.Value : string.Empty);

                            message = message.Replace("#", ",historic#");

                            xoData.Add(message);

                            break;
                        }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //?? log error
                string m = ex.Message;

                result = false;
            }

            return(result);
        }
Esempio n. 3
0
        private void SaveData(string xiData)
        {
            Assert.Condition(!string.IsNullOrEmpty(xiData), "Invalid data while saving history.");

            if (xiData.IndexOf("historic") < 0) // avoid recursion
            {
                MsSqlDataProvider msSqlDataProvider = (MsSqlDataProvider)DataProviders.Instance[MsSqlDataProvider.kId];

                if (msSqlDataProvider != null)
                {
                    Dictionary <string, object> args = new Dictionary <string, object>();

                    args.Add("Timestamp", DateTime.Now);
                    args.Add("Data", xiData);

                    msSqlDataProvider.ExecuteStoredProcedure("ADD_HISTORY", args);
                }
            }
        }