Ejemplo n.º 1
0
        private QvDataContractResponse GetPreview(UserParameter parameter, string appId, string objectId)
        {
            q2gconhypercubemain.Connection connection = null;

            try
            {
                var oId = GetObjectId(objectId);
                if (String.IsNullOrEmpty(oId))
                {
                    throw new Exception("no object id for preview table found.");
                }
                var config  = QlikApp.CreateConfig(parameter, appId);
                var qlikApp = new QlikApp(parameter);
                connection = qlikApp.CreateNewConnection(config);
                var script      = ScriptCode.Create(appId, oId);
                var resultTable = tableFunctions.GetTableInfosFromApp("PreviewTable", script, connection.CurrentApp);
                if (resultTable == null)
                {
                    throw new Exception("no preview table found.");
                }
                return(PreviewResponse.Create(resultTable.Preview));
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"fields from app {appId} and table {objectId} not loaded.");
                return(new PreviewResponse());
            }
            finally
            {
                connection?.Close();
            }
        }
        private ResultTable GetData(ScriptCode script, UserParameter parameter)
        {
            q2gconhypercubemain.Connection connection = null;

            try
            {
                var config  = QlikApp.CreateConfig(parameter, script.AppId);
                var qlikApp = new QlikApp(parameter);
                connection = qlikApp.CreateNewConnection(config);
                if (!connection.Connect())
                {
                    return(null);
                }

                foreach (var filter in script.Filter)
                {
                    logger.Debug($"Filter: {filter}");
                    foreach (var value in filter.Values)
                    {
                        var selection = new QlikSelections(connection.CurrentApp);
                        var result    = selection.SelectValue(filter.Name, value);
                        if (result == false)
                        {
                            logger.Error($"The Dimension \"{filter.Name}\" could not found.");
                            return(null);
                        }
                    }
                }

                var resultTable = tableFunctions.GetTableInfosFromApp($"Table_{script.AppId}_{script.ObjectId}", script, connection.CurrentApp);
                return(resultTable.QvxTable);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "The table script can not be executed.");
                return(null);
            }
            finally
            {
                connection?.Close();
            }
        }
Ejemplo n.º 3
0
        private QvDataContractResponse GetFields(UserParameter parameter, string appId, string objectId)
        {
            q2gconhypercubemain.Connection connection = null;

            using (MappedDiagnosticsLogicalContext.SetScoped("connectionId", connection?.ConnId))
            {
                try
                {
                    var oId = GetObjectId(objectId);
                    if (String.IsNullOrEmpty(oId))
                    {
                        throw new Exception("no object id for field table found.");
                    }
                    var script  = ScriptCode.Create(appId, oId);
                    var config  = QlikApp.CreateConfig(parameter, appId);
                    var qlikApp = new QlikApp(parameter);
                    connection = qlikApp.CreateNewConnection(config);
                    var resultTable = tableFunctions.GetTableInfosFromApp("FieldTable", script, connection.CurrentApp);
                    if (resultTable == null)
                    {
                        throw new Exception("no field table found.");
                    }
                    var qvxTable = TableUtilities.ConvertTable(resultTable.QvxTable);
                    return(new QvDataContractFieldListResponse {
                        qFields = qvxTable.Fields
                    });
                }
                catch (Exception ex)
                {
                    logger.Error(ex, $"fields from app {appId} and table {objectId} not loaded.");
                    return(new QvDataContractFieldListResponse {
                        qFields = new QvxField[0]
                    });
                }
                finally
                {
                    connection?.Close();
                }
            }
        }
Ejemplo n.º 4
0
        private QvDataContractResponse GetTables(UserParameter parameter, string appName)
        {
            var tables = new List <QvxTable>();

            q2gconhypercubemain.Connection connection = null;

            using (MappedDiagnosticsLogicalContext.SetScoped("connectionId", connection?.ConnId))
            {
                try
                {
                    var config  = QlikApp.CreateConfig(parameter, appName);
                    var qlikApp = new QlikApp(parameter);
                    var appId   = qlikApp.GetAllApps(config).FirstOrDefault(a => a.qDocName == appName).qDocId;
                    config     = QlikApp.CreateConfig(parameter, appId);
                    connection = qlikApp.CreateNewConnection(config);

                    var options = new NxGetObjectOptions()
                    {
                        qTypes = new List <string> {
                            "table"
                        }
                    };
                    var tablesObjects = connection.CurrentApp.GetObjectsAsync(options).Result;
                    foreach (var obj in tablesObjects)
                    {
                        var     tableObject = connection.CurrentApp.GetObjectAsync(obj.qInfo.qId).Result;
                        dynamic layout      = tableObject.GetLayoutAsync <JObject>().Result;
                        tables.Add(new QvxTable()
                        {
                            TableName = $"{layout.title} [{obj.qInfo.qId}]"
                        });
                    }

                    options = new NxGetObjectOptions()
                    {
                        qTypes = new List <string> {
                            "masterobject"
                        }
                    };
                    var visualisations = connection.CurrentApp.GetObjectsAsync(options).Result;
                    foreach (var element in visualisations)
                    {
                        var     tableObject = connection.CurrentApp.GetObjectAsync(element.qInfo.qId).Result;
                        dynamic layout      = tableObject.GetLayoutAsync <JObject>().Result;
                        tables.Add(new QvxTable()
                        {
                            TableName = $"{layout.qMeta.title} [{element.qInfo.qId}]"
                        });
                    }

                    return(new QvDataContractTableListResponse {
                        qTables = tables
                    });
                }
                catch (Exception ex)
                {
                    logger.Error(ex, $"tables form app {appName} not loaded.");
                    return(new QvDataContractTableListResponse {
                        qTables = tables
                    });
                }
                finally
                {
                    connection?.Close();
                }
            }
        }