Exemple #1
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);
        }
Exemple #2
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);
                }
            }
        }