/// <summary> /// Get structured Data Message from Database /// </summary> /// <param name="idDataset">Dataset Code</param> /// <param name="whereStatement">Where condition</param> /// <param name="BuilderCallback">delegate to call for write data response</param> /// <param name="TimeStamp">LastUpdate parameter request only observation from this date onwards</param> /// <returns>Object for Write response in streaming <see cref="IFlyWriterBody"/></returns> public IFlyWriterBody GetTableMessage(string idDataset, IDataWhereStatment whereStatement, WriteResponseDelegate BuilderCallback, string TimeStamp) { try { string TimeWhere = ""; List <IParameterValue> parametri = new List <IParameterValue>() { new ParameterValue() { Item = "DataSetCode", Value = idDataset }, new ParameterValue() { Item = "WhereStatement", Value = ConvertIDataQueryToWhereStatement(whereStatement, out TimeWhere) }, new ParameterValue() { Item = "Time", Value = TimeWhere }, new ParameterValue() { Item = "UserName", Value = FlyConfiguration.UserName }, new ParameterValue() { Item = "Domain", Value = FlyConfiguration.Domain }, }; if (!string.IsNullOrEmpty(TimeStamp)) { parametri.Add(new ParameterValue() { Item = "TimeStamp", Value = TimeStamp, SqlType = SqlDbType.DateTime }); } FlyLog.WriteLog(this, FlyLog.LogTypeEnum.All, @"GetData parameter: {0}", string.Join("\n", parametri)); //EFFETTUO LA RICHIESTA AL DB return(this.DbAccess.ExecuteGetData(parametri, new GetDBResponseDelegate(GetDBResponse), BuilderCallback)); } catch (SdmxException) { throw; } catch (Exception ex) { throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.GetTableMessage, ex); } }
/// <summary> /// Converting in WhereStatment string to pass at database parameter the DataWhereStatment parsed from query /// </summary> /// <param name="DataWhereStatment">DataWhereStatment parsed from query</param> /// <param name="TimeWhere">return a string representing a TimeWhere to pass a database parameter</param> /// <returns>a string to pass at database WhereStatment parameter</returns> private string ConvertIDataQueryToWhereStatement(IDataWhereStatment DataWhereStatment, out string TimeWhere) { try { TimeWhere = ""; List <string> _TimeAndFreqWhere = new List <string>(); List <string> ParseGroupWhere = new List <string>(); foreach (IDataWhereStatmentSelectionGroup group in DataWhereStatment.SelectionGroups) { List <string> ParseWhere = new List <string>(); string _freqWhere, _TimeWhere = null; string _parseWhereGroup = parseWhereGroup(group, out _freqWhere); if (!string.IsNullOrEmpty(_parseWhereGroup)) { ParseWhere.Add(_parseWhereGroup); } //Controllo l'esistenza di una where per Time if (group.DateFrom != null || group.DateTo != null) { _TimeWhere = ParseTimeValueWhereStatment(group.DateFrom, group.DateTo); } if (!string.IsNullOrEmpty(_freqWhere) && !string.IsNullOrEmpty(_TimeWhere)) { _TimeAndFreqWhere.Add(string.Format("({0} AND {1})", _freqWhere, _TimeWhere)); } else if (!string.IsNullOrEmpty(_freqWhere)) { _TimeAndFreqWhere.Add(_freqWhere); } else if (!string.IsNullOrEmpty(_TimeWhere)) { _TimeAndFreqWhere.Add(_TimeWhere); } if (ParseWhere.Count > 0) { ParseGroupWhere.Add(string.Format("({0})", string.Join(" AND ", ParseWhere))); } } //Popolo il TimeWhere if (_TimeAndFreqWhere.Count > 0) { TimeWhere = string.Format("({0})", string.Join(" OR ", _TimeAndFreqWhere)); } if (ParseGroupWhere.Count == 0) { return("1=1");//per far tornare tutti i valori nel campo Where } return(string.Join(" OR ", ParseGroupWhere)); } catch (SdmxException) { throw; } catch (Exception ex) { throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.InternalError, ex); } }