public SessionImplObject GetLayout() { try { ISdmxObjects structure = GetKeyFamily(); IDataflowObject df = structure.Dataflows.First(); IDataStructureObject kf = structure.DataStructures.First(); if (kf == null || df == null) throw new InvalidOperationException("DataStructure is not set"); if (this.SessionObj.DafaultLayout == null) this.SessionObj.DafaultLayout = new Dictionary<string, LayoutObj>(); if (!this.SessionObj.DafaultLayout.ContainsKey(Utils.MakeKey(df))) { LayoutObj deflay = GetDefaultLayout(df, kf); this.SessionObj.DafaultLayout[Utils.MakeKey(df)] = deflay; } DefaultLayoutResponseObject defaultLayoutResponseObject = new DefaultLayoutResponseObject(); defaultLayoutResponseObject.DefaultLayout = this.SessionObj.DafaultLayout[Utils.MakeKey(df)]; this.SessionObj.SavedDefaultLayout = new JavaScriptSerializer().Serialize(defaultLayoutResponseObject); return this.SessionObj; } catch (InvalidOperationException ex) { Logger.Warn(Resources.ErrorMaxJsonLength); Logger.Warn(ex.Message, ex); throw new Exception(ErrorOccured); } catch (ArgumentException ex) { Logger.Warn(Resources.ErrorRecursionLimit); Logger.Warn(ex.Message, ex); throw new Exception(ErrorOccured); } catch (Exception ex) { Logger.Warn(ex.Message, ex); throw new Exception(ErrorOccured); } }
public SessionImplObject GetLayout(ConnectionStringSettings connectionStringSetting) { try { ISdmxObjects structure = GetKeyFamily(); IDataflowObject df = structure.Dataflows.First(); IDataStructureObject kf = structure.DataStructures.First(); if (kf == null || df == null) throw new InvalidOperationException("DataStructure is not set"); //if (this.SessionObj.DafaultLayout == null) this.SessionObj.DafaultLayout = new Dictionary<string, LayoutObj>(); //if (connectionStringSetting.ConnectionString!=null && connectionStringSetting.ConnectionString.ToLower() != "file") if (connectionStringSetting.ConnectionString != null ) { // Get automatic timeserie layout System.Data.SqlClient.SqlConnection Sqlconn = new System.Data.SqlClient.SqlConnection(connectionStringSetting.ConnectionString); Sqlconn.Open(); string sqlquery = string.Format("Select * from Template where [tmplKey]='{0}'", new System.Web.Script.Serialization.JavaScriptSerializer().Serialize( LayObj.Dataflow.id + "+" + LayObj.Dataflow.agency + "+" + LayObj.Dataflow.version + "+" + LayObj.Configuration.EndPoint).Replace("'", "''")); using (System.Data.SqlClient.SqlCommand comm = new System.Data.SqlClient.SqlCommand(sqlquery, Sqlconn)) { var reader = comm.ExecuteReader(); if (reader.Read()) { string layout = reader.GetString(reader.GetOrdinal("Layout")); this.SessionObj.DafaultLayout[Utils.MakeKey(df)] = (LayoutObj)new JavaScriptSerializer().Deserialize(layout, typeof(LayoutObj)); this.SessionObj.DafaultLayout[Utils.MakeKey(df)].block_axis_x = reader.GetBoolean(reader.GetOrdinal("BlockXAxe")); this.SessionObj.DafaultLayout[Utils.MakeKey(df)].block_axis_y = reader.GetBoolean(reader.GetOrdinal("BlockYAxe")); this.SessionObj.DafaultLayout[Utils.MakeKey(df)].block_axis_z = reader.GetBoolean(reader.GetOrdinal("BlockZAxe")); } } Sqlconn.Close(); } DefaultLayoutResponseObject defaultLayoutResponseObject = new DefaultLayoutResponseObject(); defaultLayoutResponseObject.DefaultLayout = (this.SessionObj.DafaultLayout.ContainsKey(Utils.MakeKey(df))) ? this.SessionObj.DafaultLayout[Utils.MakeKey(df)] : null; //if (defaultLayoutResponseObject.DefaultLayout == null){ return GetLayout(); } this.SessionObj.SavedDefaultLayout = new JavaScriptSerializer().Serialize(defaultLayoutResponseObject); return this.SessionObj; } catch (InvalidOperationException ex) { Logger.Warn(Resources.ErrorMaxJsonLength); Logger.Warn(ex.Message, ex); throw new Exception(ErrorOccured); } catch (ArgumentException ex) { Logger.Warn(Resources.ErrorRecursionLimit); Logger.Warn(ex.Message, ex); throw new Exception(ErrorOccured); } catch (Exception ex) { Logger.Warn(ex.Message, ex); throw new Exception(ErrorOccured); } }