public QvDataContractResponse getFields(string username, string password, QvxConnection connection, string database, string owner, string table) { if (verifyCredentials(username, password)) { var currentTable = connection.FindTable(table, connection.MTables); return new QvDataContractFieldListResponse { qFields = (currentTable != null) ? currentTable.Fields : new QvxField[0] }; } return new Info { qMessage = "Credentials WRONG!" }; }
public static string GetUsername(QvxConnection connection, string authHostname, string accessToken, string refreshToken, string hostname, string idURL) { Dictionary <string, string> connectionValues = new Dictionary <string, string>(); connectionValues.Add(QvxSalesforceConnectionInfo.CONNECTION_HOST, hostname); connectionValues.Add(QvxSalesforceConnectionInfo.CONNECTION_AUTHHOST, authHostname); connectionValues.Add(QvxSalesforceConnectionInfo.CONNECTION_ACCESS_TOKEN, accessToken); connectionValues.Add(QvxSalesforceConnectionInfo.CONNECTION_REFRESH_TOKEN, refreshToken); return(ValidateAccessTokenAndPerformRequest(connection, connectionValues, token => { Uri idURI = new Uri(idURL); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(idURI); request.Method = "GET"; WebHeaderCollection headers = new WebHeaderCollection(); headers.Add("Authorization", "Bearer " + token); request.Headers = headers; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (Stream stream = response.GetResponseStream()) { StreamReader reader = new StreamReader(stream, Encoding.UTF8); string responseString = reader.ReadToEnd(); JObject jsonResponse = JObject.Parse(responseString); return jsonResponse["username"].Value <string>(); } } })); }
public QvDataContractResponse getDictionaryDef(String id, String source, QvxConnection connection) { //Debugger.Launch(); String dictionary = getDictionary(id, source, connection); if (!String.IsNullOrEmpty(dictionary)) { dynamic dic = JsonConvert.DeserializeObject(dictionary); String factory_oauth_authorize_url; if (dic.auth_options.auth_version != null && dic.auth_options.auth_version.ToString() == "1.0") { factory_oauth_authorize_url = String.Concat(ConfigurationManager.AppSettings["PublicDictionaryHost"], "/api/oauth1_authorize"); } else { factory_oauth_authorize_url = String.Concat(ConfigurationManager.AppSettings["PublicDictionaryHost"], "/api/oauth2_authorize"); } dic.factory_oauth_authorize_url = factory_oauth_authorize_url; return(new Info { qMessage = JsonConvert.SerializeObject(dic) }); } else { return(new Info { qMessage = errorHelper.ErrorDownloadingData }); } }
public string getDictionary(string id, String source, QvxConnection connection) { QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "Getting dictionary"); QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, DateTime.Now.ToLongTimeString()); string d = ""; if (source == "online") { WebClient client = new WebClient(); client.Headers.Add("Accept", "application/json"); String dictionaryUrl = ConfigurationManager.AppSettings["PublicDictionaryHost"]; if (String.IsNullOrEmpty(dictionaryUrl)) { return(null); } dictionaryUrl += "/api/public/dictionary/"; dictionaryUrl += id; String dictionary = client.DownloadString(dictionaryUrl); if (!String.IsNullOrEmpty(dictionary)) { // connection.MParameters["fulldictionary"] = dictionary; QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "Got dictionary"); QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, DateTime.Now.ToLongTimeString()); return(dictionary); } } else { string configDirectory = @"C:\Program Files\Common Files\Qlik\Custom Data\GenericRestConnector\configs\"; return(new StreamReader(configDirectory + id + "\\dictionary.json").ReadToEnd()); } return(d); }
// Helper Functions public static Dictionary <string, string> GetParamsFromConnection(QvxConnection connection) { string host, authHost, username, access_token, refresh_token; connection.MParameters.TryGetValue(QvxSalesforceConnectionInfo.CONNECTION_USERID, out username); // Set when creating new connection or from inside the QlikView Management Console (QMC) connection.MParameters.TryGetValue(QvxSalesforceConnectionInfo.CONNECTION_HOST, out host); connection.MParameters.TryGetValue(QvxSalesforceConnectionInfo.CONNECTION_AUTHHOST, out authHost); connection.MParameters.TryGetValue(QvxSalesforceConnectionInfo.CONNECTION_ACCESS_TOKEN, out access_token); connection.MParameters.TryGetValue(QvxSalesforceConnectionInfo.CONNECTION_REFRESH_TOKEN, out refresh_token); if (string.IsNullOrEmpty(host) || string.IsNullOrEmpty(authHost) || string.IsNullOrEmpty(access_token) || string.IsNullOrEmpty(refresh_token)) { return(null); } Dictionary <string, string> connectionValues = new Dictionary <string, string>(); connectionValues.Add(QvxSalesforceConnectionInfo.CONNECTION_USERID, username); connectionValues.Add(QvxSalesforceConnectionInfo.CONNECTION_HOST, host); connectionValues.Add(QvxSalesforceConnectionInfo.CONNECTION_AUTHHOST, authHost); connectionValues.Add(QvxSalesforceConnectionInfo.CONNECTION_ACCESS_TOKEN, access_token); connectionValues.Add(QvxSalesforceConnectionInfo.CONNECTION_REFRESH_TOKEN, refresh_token); return(connectionValues); }
private string HandleRequest(string method, string[] userParameters, QvxConnection connection) { QvDataContractResponse response; switch (method) { case "getDatabases": response = getDatabases(connection); break; case "getOwner": string username = ""; connection.MParameters.TryGetValue("userid", out username); // Set when creating new connection or from inside the QlikView Management Console (QMC) response = new Info { qMessage = username }; break; case "getTables": response = getTables(connection, userParameters[0]); break; case "getFields": response = getFields(connection, userParameters[0], userParameters[1]); break; default: response = new Info { qMessage = "Unknown command" }; break; } return(ToJson(response)); // serializes response into JSON string }
public QvDataContractResponse getTables(string username, string password, QvxConnection connection, string database, string owner) { return(new QvDataContractTableListResponse { qTables = connection.MTables }); }
public QvDataContractResponse GetFields(QvxConnection io_connection, string io_database, string io_owner, string io_table) { var lo_currentTable = io_connection.FindTable(io_table, io_connection.MTables); return(new QvDataContractFieldListResponse { qFields = (lo_currentTable != null) ? lo_currentTable.Fields : new QvxField[0] }); }
public QvDataContractResponse getFields(string username, string password, QvxConnection connection, string database, string owner, string table) { var currentTable = connection.FindTable(table, connection.MTables); return(new QvDataContractFieldListResponse { qFields = (currentTable != null) ? currentTable.Fields : new QvxField[0] }); }
public QvDataContractResponse getDatabases(String id, String source, QvxConnection connection) { currentDictionary = getDictionary(id, source, connection); String response = "{\"qDatabases\":[{\"qName\": \"Not Applicable\"}]"; response += ", \"dictionary\":" + currentDictionary + "}"; return new Info { qMessage = response }; }
private IEnumerable <QvxDataRow> GetData(QvxConnection connection, QvxFieldsWrapper fields, string reportID) { IEnumerable <QvxDataRow> rows = EndpointCalls.GetReportData(connection, fields, reportID); if (rows.Count() == 0) { QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "No rows were returned for report ID: '" + reportID + "'."); } return(rows); }
public QvDataContractResponse getTables(string username, string password, QvxConnection connection, string database, string owner) { if (verifyCredentials(username, password)) { return new QvDataContractTableListResponse { qTables = connection.MTables }; } return new Info { qMessage = "Credentials WRONG!" }; }
public QvDataContractResponse getDatabases(String id, String source, QvxConnection connection) { currentDictionary = getDictionary(id, source, connection); String response = "{\"qDatabases\":[{\"qName\": \"Not Applicable\"}]"; response += ", \"dictionary\":" + currentDictionary + "}"; return(new Info { qMessage = response }); }
public QvDataContractResponse getDatabases(QvxConnection connection) { IEnumerable <string> databases = EndpointCalls.GetReportFoldersList(connection); return(new QvDataContractDatabaseListResponse { qDatabases = databases.Select(name => new Database() { qName = name }).ToArray() }); }
public QvDataContractResponse getTables(string username, string password, QvxConnection connection, string database, string owner) { if (verifyCredentials(username, password)) { return(new QvDataContractTableListResponse { qTables = connection.MTables }); } return(new Info { qMessage = "Credentials WRONG!" }); }
public static T ValidateAccessTokenAndPerformRequest <T>(QvxConnection connection, IDictionary <string, string> connectionParams, Func <string, T> endpointCall) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; try { return(endpointCall(connectionParams[QvxSalesforceConnectionInfo.CONNECTION_ACCESS_TOKEN])); } catch (WebException e) { if (((HttpWebResponse)e.Response).StatusCode == HttpStatusCode.Unauthorized || ((HttpWebResponse)e.Response).StatusCode == HttpStatusCode.Forbidden) { Uri authHostnameUri = new Uri(connectionParams[QvxSalesforceConnectionInfo.CONNECTION_AUTHHOST]); string newTokenPath = string.Format("/services/oauth2/token?grant_type=refresh_token&client_id={0}&refresh_token={1}", QvxSalesforceConnectionInfo.CLIENT_ID, connectionParams[QvxSalesforceConnectionInfo.CONNECTION_REFRESH_TOKEN]); HttpWebRequest newTokenRequest = (HttpWebRequest)WebRequest.Create(new Uri(authHostnameUri, newTokenPath)); newTokenRequest.Method = "POST"; string newAccessToken = connectionParams[QvxSalesforceConnectionInfo.CONNECTION_ACCESS_TOKEN]; using (HttpWebResponse newTokenResponse = (HttpWebResponse)newTokenRequest.GetResponse()) { using (Stream stream = newTokenResponse.GetResponseStream()) { StreamReader reader = new StreamReader(stream, Encoding.UTF8); string responseString = reader.ReadToEnd(); JObject response = JObject.Parse(responseString); newAccessToken = response["access_token"].Value <string>(); } } connection.MParameters[QvxSalesforceConnectionInfo.CONNECTION_ACCESS_TOKEN] = newAccessToken; try { return(endpointCall(newAccessToken)); } catch (Exception ex) { QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Error, "Call to Salesforce API failed with exception: " + ex.Message); return(default(T)); } } QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Error, "Failed trying to get new access token. Refresh token is: " + connectionParams[QvxSalesforceConnectionInfo.CONNECTION_REFRESH_TOKEN]); QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Error, string.Format("Status code: '{0}' Exception: {1}", ((HttpWebResponse)e.Response).StatusCode, e.Message)); throw new Exception("Invalid Web Response"); } catch (Exception exception) { QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Error, "Call to Salesforce API failed with exception: " + exception.Message); return(default(T)); } }
public QvDataContractResponse getFields(string username, string password, QvxConnection connection, string database, string owner, string table) { if (verifyCredentials(username, password)) { var currentTable = connection.FindTable(table, connection.MTables); return(new QvDataContractFieldListResponse { qFields = (currentTable != null) ? currentTable.Fields : new QvxField[0] }); } return(new Info { qMessage = "Credentials WRONG!" }); }
private QvxTable BuildSingleTable(QvxConnection connection, string tableID, string tableName) { QvxFieldsWrapper fields = GetFields(connection, tableID); if (fields.GetLength() == 0) { QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "No fields were found for table '" + tableName + "'."); return(null); } QvxTable.GetRowsHandler handler = () => { return(GetData(connection, fields, tableID)); }; return(new QvxTable() { TableName = tableName, Fields = fields.Fields, GetRows = handler }); }
public QvDataContractResponse getTables(QvxConnection connection, string folderName) { if (connection.MParameters.ContainsKey("folder_name")) { connection.MParameters["folder_name"] = folderName; } else { connection.MParameters.Add("folder_name", folderName); } connection.Init(); return(new QvDataContractTableListResponse { qTables = connection.MTables }); }
/** * QlikView 12 classes */ public override string HandleJsonRequest(string method, string[] userParameters, QvxConnection connection) { QvDataContractResponse response; /** * -- How to get hold of connection details? -- * * Provider, username and password are always available in * connection.MParameters if they exist in the connection * stored in the QlikView Repository Service (QRS). * * If there are any other user/connector defined parameters in the * connection string they can be retrieved in the same way as seen * below */ string provider, host, username, password; connection.MParameters.TryGetValue("provider", out provider); // Set to the name of the connector by QlikView Engine connection.MParameters.TryGetValue("userid", out username); // Set when creating new connection or from inside the QlikView Management Console (QMC) connection.MParameters.TryGetValue("password", out password); // Same as for username connection.MParameters.TryGetValue("host", out host); // Defined when calling createNewConnection in connectdialog.js switch (method) { case "getInfo": response = getInfo(); break; case "getDatabases": response = getDatabases(username, password); break; case "getTables": response = getTables(username, password, connection, userParameters[0], userParameters[1]); break; case "getFields": response = getFields(username, password, connection, userParameters[0], userParameters[1], userParameters[2]); break; case "testConnection": response = testConnection(userParameters[0], userParameters[1]); break; default: response = new Info { qMessage = "Unknown command" }; break; } return ToJson(response); // serializes response into JSON string }
private string HandleAPIRequests(string method, string[] userParameters, QvxConnection connection) { QvDataContractResponse response; switch (method) { case "API-getSalesforcePath": Uri baseUri = new Uri(userParameters[0]); string url = new Uri(baseUri, string.Format("services/oauth2/authorize?response_type=token&client_id={0}&redirect_uri=https%3A%2F%2Flogin.salesforce.com%2Fservices%2Foauth2%2Fsuccess", QvxSalesforceConnectionInfo.CLIENT_ID)).AbsoluteUri; response = new Info { qMessage = url }; break; case "API-BuildConnectionString": string connectionString = String.Format("{0}={1};{2}={3};{4}={5};{6}={7};", QvxSalesforceConnectionInfo.CONNECTION_HOST, userParameters[0], QvxSalesforceConnectionInfo.CONNECTION_AUTHHOST, userParameters[1], QvxSalesforceConnectionInfo.CONNECTION_ACCESS_TOKEN, userParameters[2], QvxSalesforceConnectionInfo.CONNECTION_REFRESH_TOKEN, userParameters[3]); response = new Info { qMessage = connectionString }; break; case "API-getUsername": string username = EndpointCalls.GetUsername(connection, userParameters[0], userParameters[1], userParameters[2], Uri.UnescapeDataString(userParameters[3]), Uri.UnescapeDataString(userParameters[4])); response = new Info { qMessage = string.Format("{{\"username\": \"{0}\", \"host\": \"{1}\" }}", username, Uri.UnescapeDataString(userParameters[3])) }; break; default: response = new Info { qMessage = "Unknown command" }; break; } return(ToJson(response)); }
public QvDataContractResponse getFields(QvxConnection connection, string folderName, string table) { if (connection.MParameters.ContainsKey("folder_name")) { connection.MParameters["folder_name"] = folderName; } else { connection.MParameters.Add("folder_name", folderName); } connection.Init(); QvxTable currentTable = connection.FindTable(table, connection.MTables); return(new QvDataContractFieldListResponse { qFields = (currentTable != null) ? currentTable.Fields : new QvxField[0] }); }
private List <QvxTable> BuildTablesAsync(QvxConnection connection, IDictionary <string, string> tableDictionary) { int index = 0; int concurrentTables = 20; if (tableDictionary.Count < concurrentTables) { concurrentTables = tableDictionary.Count; } List <QvxTable> newTables = new List <QvxTable>(); Task <QvxTable>[] taskArray = new Task <QvxTable> [concurrentTables]; for (int i = 0; i < concurrentTables; i++) { string key = tableDictionary.ElementAt(index).Key; string value = tableDictionary.ElementAt(index).Value; taskArray[i] = Task <QvxTable> .Factory.StartNew(() => BuildSingleTable(connection, key, value)); index++; } while (index < (tableDictionary.Count)) { int taskIndex = Task.WaitAny(taskArray); newTables.Add(taskArray[taskIndex].Result); string key = tableDictionary.ElementAt(index).Key; string value = tableDictionary.ElementAt(index).Value; taskArray[taskIndex] = Task <QvxTable> .Factory.StartNew(() => BuildSingleTable(connection, key, value)); index++; } foreach (Task <QvxTable> t in taskArray) { if (!t.IsCompleted) { t.Wait(); } newTables.Add(t.Result); } return(newTables.Where(t => t != null && t.Fields.Length != 0).ToList()); }
private QvxFieldsWrapper GetFields(QvxConnection connection, string tableID) { IDictionary <string, SalesforceDataType> fields = EndpointCalls.GetFieldsFromReport(connection, tableID); if (fields == default(IDictionary <string, Type>)) { return(new QvxFieldsWrapper(0)); } QvxFieldsWrapper qvxFields = new QvxFieldsWrapper(fields.Count); for (int i = 0; i < fields.Count; i++) { if (fields.ElementAt(i).Value == SalesforceDataType.String) { qvxFields.SetFieldValue(i, new QvxField(fields.ElementAt(i).Key, QvxFieldType.QVX_TEXT, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII), fields.ElementAt(i).Value); } else if (fields.ElementAt(i).Value == SalesforceDataType.Integer || fields.ElementAt(i).Value == SalesforceDataType.Boolean) { qvxFields.SetFieldValue(i, new QvxField(fields.ElementAt(i).Key, QvxFieldType.QVX_SIGNED_INTEGER, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.INTEGER), fields.ElementAt(i).Value); } else if (fields.ElementAt(i).Value == SalesforceDataType.Double || fields.ElementAt(i).Value == SalesforceDataType.Currency || fields.ElementAt(i).Value == SalesforceDataType.Percent) { qvxFields.SetFieldValue(i, new QvxField(fields.ElementAt(i).Key, QvxFieldType.QVX_IEEE_REAL, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.REAL), fields.ElementAt(i).Value); } else if (fields.ElementAt(i).Value == SalesforceDataType.Date) { qvxFields.SetFieldValue(i, new QvxField(fields.ElementAt(i).Key, QvxFieldType.QVX_IEEE_REAL, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.DATE), fields.ElementAt(i).Value); } else if (fields.ElementAt(i).Value == SalesforceDataType.DateTime) { qvxFields.SetFieldValue(i, new QvxField(fields.ElementAt(i).Key, QvxFieldType.QVX_IEEE_REAL, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.TIMESTAMP), fields.ElementAt(i).Value); } else { qvxFields.SetFieldValue(i, new QvxField(fields.ElementAt(i).Key, QvxFieldType.QVX_TEXT, QvxNullRepresentation.QVX_NULL_FLAG_WITH_UNDEFINED_DATA, FieldAttrType.ASCII), fields.ElementAt(i).Value); } } return(qvxFields); }
private List <QvxTable> BuildTablesSync(QvxConnection connection, IDictionary <string, string> tableDictionary) { List <QvxTable> newTables = new List <QvxTable>(tableDictionary.Select(table => { QvxFieldsWrapper fields = GetFields(connection, table.Key); if (fields.GetLength() == 0) { return(null); } QvxTable.GetRowsHandler handler = () => { return(GetData(connection, fields, table.Key)); }; return(new QvxTable() { TableName = table.Value, Fields = fields.Fields, GetRows = handler }); }).Where(t => t != null && t.Fields.Length != 0) ); return(newTables); }
public static IEnumerable <string> GetReportFoldersList(QvxConnection connection) { IDictionary <string, string> connectionParams = GetParamsFromConnection(connection); if (connectionParams == null) { return(new List <string>()); } return(ValidateAccessTokenAndPerformRequest <IEnumerable <string> >(connection, connectionParams, accessToken => { Uri hostUri = new Uri(connectionParams[QvxSalesforceConnectionInfo.CONNECTION_HOST]); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(hostUri, "/services/data/" + QvxSalesforceConnectionInfo.SALESFORCE_API_VERSION + "/query?q=SELECT Name FROM Folder WHERE Type = 'Report' ORDER BY Name")); request.Method = "GET"; WebHeaderCollection headers = new WebHeaderCollection(); headers.Add("Authorization", "Bearer " + accessToken); request.Headers = headers; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (Stream stream = response.GetResponseStream()) { StreamReader reader = new StreamReader(stream, Encoding.UTF8); string responseString = reader.ReadToEnd(); JObject jsonResponse = JObject.Parse(responseString); IEnumerable <JObject> folders = jsonResponse["records"].Values <JObject>(); folders = folders.Where(x => !string.IsNullOrEmpty(x["Name"].Value <string>()) && x["Name"].Value <string>() != "*"); IList <string> folderNames = folders.Select(f => f["Name"].Value <string>()).ToList(); folderNames.Insert(0, "Private Reports"); folderNames.Insert(0, "Public Reports"); return folderNames; } } })); }
public static IDictionary <string, string> GetTableNameList(QvxConnection connection, string databaseName) { IDictionary <string, string> connectionParams = GetParamsFromConnection(connection); if (connectionParams == null) { return(new Dictionary <string, string>()); } return(ValidateAccessTokenAndPerformRequest(connection, connectionParams, accessToken => { Uri hostUri = new Uri(connectionParams[QvxSalesforceConnectionInfo.CONNECTION_HOST]); HttpWebRequest request; WebHeaderCollection headers; string databaseId = ""; if (databaseName == "Public Reports" || databaseName == "Private Reports") { databaseId = databaseName; } else { request = (HttpWebRequest)WebRequest.Create(new Uri(hostUri, "/services/data/" + QvxSalesforceConnectionInfo.SALESFORCE_API_VERSION + string.Format("/query?q=SELECT Id,Name FROM Folder WHERE Type = 'Report' AND Name = '{0}' ORDER BY Name", Uri.EscapeDataString(databaseName)))); request.Method = "GET"; headers = new WebHeaderCollection(); headers.Add("Authorization", "Bearer " + accessToken); request.Headers = headers; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (Stream stream = response.GetResponseStream()) { StreamReader reader = new StreamReader(stream, Encoding.UTF8); string responseString = reader.ReadToEnd(); JObject jsonResponse = JObject.Parse(responseString); IEnumerable <JObject> folders = jsonResponse["records"].Values <JObject>(); if (folders.Count() > 1) { throw new DataMisalignedException("Too many matches for folder: " + databaseName); } JObject firstFolder = folders.First(); databaseId = firstFolder["Id"].Value <string>(); } } } return ValidateAccessTokenAndPerformRequest(connection, connectionParams, newAccessToken => { if (databaseId == "Public Reports" || databaseId == "Private Reports") { request = (HttpWebRequest)WebRequest.Create(new Uri(hostUri, "/services/data/" + QvxSalesforceConnectionInfo.SALESFORCE_API_VERSION + string.Format("/query?q=SELECT Id,Name FROM Report WHERE FolderName = '{0}' ORDER BY Name", databaseId))); } else { request = (HttpWebRequest)WebRequest.Create(new Uri(hostUri, "/services/data/" + QvxSalesforceConnectionInfo.SALESFORCE_API_VERSION + string.Format("/query?q=SELECT Id,Name FROM Report WHERE OwnerId = '{0}' ORDER BY Name", databaseId))); } request.Method = "GET"; headers = new WebHeaderCollection(); headers.Add("Authorization", "Bearer " + newAccessToken); request.Headers = headers; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (Stream stream = response.GetResponseStream()) { StreamReader reader = new StreamReader(stream, Encoding.UTF8); string responseString = reader.ReadToEnd(); JObject jsonResponse = JObject.Parse(responseString); IEnumerable <JObject> tables = jsonResponse["records"].Values <JObject>(); IDictionary <string, string> tableIdDictionary = tables.ToDictionary(r => r["Id"].Value <string>(), r => r["Name"].Value <string>()); return tableIdDictionary; } } }); })); }
/** * QlikView 12 classes */ public override string HandleJsonRequest(string method, string[] userParameters, QvxConnection connection) { QvDataContractResponse response; /** * -- How to get hold of connection details? -- * * Provider, username and password are always available in * connection.MParameters if they exist in the connection * stored in the QlikView Repository Service (QRS). * * If there are any other user/connector defined parameters in the * connection string they can be retrieved in the same way as seen * below */ string provider, host, username, password; connection.MParameters.TryGetValue("provider", out provider); // Set to the name of the connector by QlikView Engine connection.MParameters.TryGetValue("userid", out username); // Set when creating new connection or from inside the QlikView Management Console (QMC) connection.MParameters.TryGetValue("password", out password); // Same as for username connection.MParameters.TryGetValue("host", out host); // Defined when calling createNewConnection in connectdialog.js switch (method) { case "getInfo": response = getInfo(); break; case "getDatabases": response = getDatabases(username, password); break; case "getTables": response = getTables(username, password, connection, userParameters[0], userParameters[1]); break; case "getFields": response = getFields(username, password, connection, userParameters[0], userParameters[1], userParameters[2]); break; case "testConnection": response = testConnection(userParameters[0], userParameters[1]); break; default: response = new Info { qMessage = "Unknown command" }; break; } return(ToJson(response)); // serializes response into JSON string }
public override string HandleJsonRequest(string method, string[] userParameters, QvxConnection connection) { try { QvDataContractResponse response; AppInstance.LoadMemory(); var parameter = ConnectorParameter.Create(connection?.MParameters); logger.Trace($"HandleJsonRequest {method}"); switch (method) { case "getVersion": response = new Info { qMessage = GitVersionInformation.InformationalVersion }; break; case "getUsername": response = new Info { qMessage = parameter.UserName }; break; case "getDatabases": response = GetDatabases(parameter); break; case "getTables": response = GetTables(parameter, userParameters[0]); break; case "getFields": response = GetFields(parameter, userParameters[0], userParameters[1]); break; case "getPreview": response = GetPreview(parameter, userParameters[0], userParameters[1]); break; default: response = new Info { qMessage = "Unknown command" }; break; } AppInstance.SaveMemory(); AppInstance.Dispose(); return(ToJson(response)); } catch (Exception ex) { logger.Error(ex); return(ToJson(new Info { qMessage = "Error " + ex.ToString() })); } }
public string getDictionary(string id, String source, QvxConnection connection) { QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "Getting dictionary"); QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, DateTime.Now.ToLongTimeString()); string d = ""; if(source=="online"){ WebClient client = new WebClient(); client.Headers.Add("Accept", "application/json"); String dictionaryUrl = ConfigurationManager.AppSettings["PublicDictionaryHost"]; if (String.IsNullOrEmpty(dictionaryUrl)) { return null; } dictionaryUrl += "/api/public/dictionary/"; dictionaryUrl += id; String dictionary = client.DownloadString(dictionaryUrl); if (!String.IsNullOrEmpty(dictionary)) { // connection.MParameters["fulldictionary"] = dictionary; QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "Got dictionary"); QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, DateTime.Now.ToLongTimeString()); return dictionary; } } else { string configDirectory = @"C:\Program Files\Common Files\Qlik\Custom Data\GenericRestConnector\configs\"; return new StreamReader(configDirectory + id + "\\dictionary.json").ReadToEnd(); } return d; }
public QvDataContractResponse getDictionaryDef(String id, String source, QvxConnection connection) { //Debugger.Launch(); String dictionary = getDictionary(id, source, connection); if (!String.IsNullOrEmpty(dictionary)) { dynamic dic = JsonConvert.DeserializeObject(dictionary); String factory_oauth_authorize_url; if (dic.auth_options.auth_version!=null && dic.auth_options.auth_version.ToString() == "1.0") { factory_oauth_authorize_url = String.Concat(ConfigurationManager.AppSettings["PublicDictionaryHost"], "/api/oauth1_authorize"); } else { factory_oauth_authorize_url = String.Concat(ConfigurationManager.AppSettings["PublicDictionaryHost"], "/api/oauth2_authorize"); } dic.factory_oauth_authorize_url = factory_oauth_authorize_url; return new Info { qMessage = JsonConvert.SerializeObject(dic) }; } else { return new Info { qMessage = errorHelper.ErrorDownloadingData }; } }
public override string HandleJsonRequest(string method, string[] userParameters, QvxConnection connection) { connection = (Connection)connection; //Debugger.Launch(); QvDataContractResponse response; string provider, url, username, password, dictionary, source; connection.MParameters.TryGetValue("provider", out provider); connection.MParameters.TryGetValue("userid", out username); connection.MParameters.TryGetValue("password", out password); connection.MParameters.TryGetValue("url", out url); connection.MParameters.TryGetValue("dictionary", out dictionary); connection.MParameters.TryGetValue("source", out source); switch (method) { case "getLocalDictionaries": response = getLocalDictionaries(); break; case "updateLocalCatalog": response = updateLocalCatalog(); break; case "getOnlineDictionaries": QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "getting dictionaries"); QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, DateTime.Now.ToLongTimeString()); response = getOnlineDictionaries(); QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "got dictionaries"); QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, DateTime.Now.ToLongTimeString()); break; case "getDictionaryDef": response = getDictionaryDef(userParameters[0], userParameters[1], connection); break; case "getDatabases": response = getDatabases(dictionary, source, connection); break; case "getTables": currentDictionary = JsonConvert.DeserializeObject(userParameters[0]); response = getTables(); break; case "getFields": currentDictionary = JsonConvert.DeserializeObject(userParameters[1]); response = getFields(userParameters[0]); break; case "getPreview": currentDictionary = JsonConvert.DeserializeObject(userParameters[1]); response = getPreview(userParameters[0]); break; case "copyDictionaryToLocal": response = copyDictionaryToLocal(userParameters[0], userParameters[1], userParameters[2]); break; default: response = new Info { qMessage = "Unknown command" }; break; } return ToJson(response); // serializes response into JSON string }
/** * QlikView 12 classes */ public override string HandleJsonRequest(string io_method, string[] io_userParameters, QvxConnection io_connection) { QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "HandleJsonRequest, method: " + io_method); QvDataContractResponse lo_response; switch (io_method) { case "getInfo": lo_response = GetInfo(); break; case "getDatabases": lo_response = GetDatabases(); break; case "getTables": if ((io_connection.MTables == null) && (io_connection.MParameters != null)) { QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "QvxConnection.ReInit()"); io_connection.Init(); } lo_response = GetTables(io_connection, io_userParameters[0], io_userParameters[1]); break; case "getFields": if ((io_connection.MTables == null) && (io_connection.MParameters != null)) { QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "QvxConnection.ReInit()"); io_connection.Init(); } lo_response = GetFields(io_connection, io_userParameters[0], io_userParameters[1], io_userParameters[2]); break; default: lo_response = new Info { qMessage = "Unknown command" }; break; } return(ToJson(lo_response)); // serializes response into JSON string }
public override QvxConnection CreateConnection() { go_qvConnector = new QvConnector(); return(go_qvConnector); }
public static IDictionary <string, SalesforceDataType> GetFieldsFromReport(QvxConnection connection, string reportID) { IDictionary <string, string> connectionParams = GetParamsFromConnection(connection); if (connectionParams == null) { return(new Dictionary <string, SalesforceDataType>()); } return(ValidateAccessTokenAndPerformRequest(connection, connectionParams, accessToken => { Uri hostUri = new Uri(connectionParams[QvxSalesforceConnectionInfo.CONNECTION_HOST]); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(hostUri, "/services/data/" + QvxSalesforceConnectionInfo.SALESFORCE_API_VERSION + "/analytics/reports/" + reportID + "/describe")); request.Method = "GET"; WebHeaderCollection headers = new WebHeaderCollection(); headers.Add("Authorization", "Bearer " + accessToken); request.Headers = headers; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (Stream stream = response.GetResponseStream()) { StreamReader reader = new StreamReader(stream, Encoding.UTF8); string responseString = reader.ReadToEnd(); JObject jsonResponse = JObject.Parse(responseString); JToken columnArray = jsonResponse["reportExtendedMetadata"]["detailColumnInfo"]; IDictionary <string, SalesforceDataType> columns = columnArray.ToDictionary(c => c.First["label"].Value <string>(), t => { SalesforceDataType columnType = SalesforceDataType.String; switch (t.First["dataType"].Value <string>()) { case "string": columnType = SalesforceDataType.String; break; case "int": columnType = SalesforceDataType.Integer; break; case "double": columnType = SalesforceDataType.Double; break; case "boolean": columnType = SalesforceDataType.Boolean; break; case "percent": columnType = SalesforceDataType.Percent; break; case "date": columnType = SalesforceDataType.Date; break; case "datetime": columnType = SalesforceDataType.DateTime; break; case "currency": columnType = SalesforceDataType.Currency; break; } return columnType; }); return columns; } } })); }
public QvDataContractResponse GetTables(QvxConnection io_connection, string io_database, string io_owner) { return(new QvDataContractTableListResponse { qTables = io_connection.MTables }); }
public static IEnumerable <QvxDataRow> GetReportData(QvxConnection connection, QvxFieldsWrapper fields, string reportID) { IDictionary <string, string> connectionParams = GetParamsFromConnection(connection); if (connectionParams == null) { return(new List <QvxDataRow>()); } return(ValidateAccessTokenAndPerformRequest(connection, connectionParams, accessToken => { Uri hostUri = new Uri(connectionParams[QvxSalesforceConnectionInfo.CONNECTION_HOST]); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(hostUri, "/services/data/" + QvxSalesforceConnectionInfo.SALESFORCE_API_VERSION + "/analytics/reports/" + reportID + "?includeDetails=true")); request.Method = "GET"; WebHeaderCollection headers = new WebHeaderCollection(); headers.Add("Authorization", "Bearer " + accessToken); request.Headers = headers; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (Stream stream = response.GetResponseStream()) { StreamReader reader = new StreamReader(stream, Encoding.UTF8); string responseString = reader.ReadToEnd(); JsonReader jsonReader = new JsonTextReader(new StringReader(responseString)); jsonReader.DateParseHandling = DateParseHandling.None; JObject jsonResponse = JObject.Load(jsonReader); IEnumerable <QvxDataRow> rows = jsonResponse["factMap"].First.First["rows"].Values <JObject>().Select( dr => { QvxDataRow row = new QvxDataRow(); for (int i = 0; i < fields.GetLength(); i++) { if (fields.GetFieldType(i) == SalesforceDataType.Double || fields.GetFieldType(i) == SalesforceDataType.Percent) { try { row[fields.GetField(i)] = dr.First.First.ElementAt(i)["value"].Value <double>(); } catch { row[fields.GetField(i)] = null; } } else if (fields.GetFieldType(i) == SalesforceDataType.Integer) { try { row[fields.GetField(i)] = dr.First.First.ElementAt(i)["value"].Value <int>(); } catch { row[fields.GetField(i)] = null; } } else if (fields.GetFieldType(i) == SalesforceDataType.Boolean) { try { row[fields.GetField(i)] = dr.First.First.ElementAt(i)["value"].Value <bool>(); } catch { row[fields.GetField(i)] = null; } } else if (fields.GetFieldType(i) == SalesforceDataType.Currency) { if (dr.First.First.ElementAt(i)["value"].HasValues) { row[fields.GetField(i)] = dr.First.First.ElementAt(i)["value"].Value <double>("amount"); } else { row[fields.GetField(i)] = null; } } else if (fields.GetFieldType(i) == SalesforceDataType.Date || fields.GetFieldType(i) == SalesforceDataType.DateTime) { string dt = dr.First.First.ElementAt(i)["value"].Value <string>(); if (string.IsNullOrWhiteSpace(dt) || dt == "-") { row[fields.GetField(i)] = null; } else { DateTime datetime; if (dt.ToLower(CultureInfo.InvariantCulture).EndsWith("z")) { datetime = DateTime.ParseExact(dt, "yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture); } else { datetime = DateTime.ParseExact(dt, "yyyy-MM-dd", CultureInfo.InvariantCulture); } row[fields.GetField(i)] = datetime.ToOADate(); } } else { row[fields.GetField(i)] = dr.First.First.ElementAt(i)["label"].Value <string>(); } } return row; }); return rows; } } })); }