/// <summary>
        /// Initialize the QvFacebookConnection.
        /// </summary>
        public override void Init()
        {
            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "Init()");

            // Log in to facebook
            LoginToFacebook();

            MTables = new List <QvxTable>();

            // Create all supported tables
            var tableDictionary = new Dictionary <FacebookMetadataTag, Func <FacebookMetadataTag, QvxTable> >
            {
                { FacebookMetadataTag.friends, x => CreatePersonsTable(x) },
                { FacebookMetadataTag.family, x => CreatePersonsTable(x) },
                { FacebookMetadataTag.movies, x => CreateEntertainmentTable(x) },
                { FacebookMetadataTag.television, x => CreateEntertainmentTable(x) },
                { FacebookMetadataTag.likes, x => CreateEntertainmentTable(x) },
                { FacebookMetadataTag.books, x => CreateEntertainmentTable(x) },
                { FacebookMetadataTag.music, x => CreateEntertainmentTable(x) },
                { FacebookMetadataTag.games, x => CreateEntertainmentTable(x) },
            };

            if (tableDictionary.Keys.Count != Enum.GetNames(typeof(FacebookMetadataTag)).Length)
            {
                QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Warning, "Init() - Mismatch between the number of supported metadata tags and tables");
            }

            foreach (var key in tableDictionary.Keys)
            {
                MTables.Add(tableDictionary[key](key));
            }
        }
        public QvDataContractResponse getTables(IQlikSimpleConnector driver, string database, string owner, Dictionary <string, string> userParameters)
        {
            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "+ getTables()");

            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, String.Format("getTables() : {0}", String.Join(", ", userParameters.Select(kv => String.Format("{0} : {1}", kv.Key, kv.Value)))));

            QvDataContractTableListResponse retVal;

            try {
                Database db = driver.getDatabases(userParameters).Find(x => x.qName == database);
                string   ow = driver.getOwners(db, userParameters).Find(x => x == owner);

                retVal = new QvDataContractTableListResponse
                {
                    qTables = driver
                              .getTables(db, ow, userParameters)
                              .ToList()
                };
            }
            catch (Exception e)
            {
                QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Error, "getTables() : " + e.Message);
                throw e;
            }

            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "- getTables()");

            return(retVal);
        }
        public QvDataContractResponse getFields(IQlikSimpleConnector driver, string database, string owner, string table, Dictionary <string, string> userParameters)
        {
            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "+ getFields()");

            QvDataContractResponse retVal;

            try {
                Database db = driver.getDatabases(userParameters).Find(x => x.qName == database);
                string   ow = driver.getOwners(db, userParameters).Find(x => x == owner);
                QvxTable tb = driver.getTables(db, ow, userParameters).Find(x => x.TableName == table);

                retVal = new QvDataContractFieldListResponse
                {
                    qFields = driver.getFields(db, ow, tb, userParameters).ToArray()
                };
            }
            catch (Exception e)
            {
                QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Error, "getFields() : " + e.Message);
                throw e;
            }

            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "- getFields()");

            return(retVal);
        }
        public QvDataContractResponse getDriverConnectParams(IQlikSimpleConnector driver)
        {
            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "+ getDriverConnectParams()");

            QvDataContractDriverParamListResponse retVal;

            try
            {
                retVal = new QvDataContractDriverParamListResponse
                {
                    qDriverParamList = driver
                                       .getDriverParams()
                                       .ToList()
                };
            }
            catch (Exception e)
            {
                QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Error, "getDriverConnectParams() : " + e.Message);
                throw e;
            }

            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "- getDriverConnectParams()");

            return(retVal);
        }
        public QvDataContractResponse getOwners(IQlikSimpleConnector driver, string database, Dictionary <string, string> userParameters)
        {
            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "+ getOwners()");

            QvDataContractResponse retVal;

            try
            {
                Database db = driver.getDatabases(userParameters).Find(x => x.qName == database);

                retVal = new QvDataContractOwnerListResponse()
                {
                    qOwners = driver
                              .getOwners(db, userParameters)
                              .ToList()
                };
            }
            catch (Exception e)
            {
                QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Error, "getOwners() : " + e.Message);
                throw e;
            }

            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "- getOwners()");

            return(retVal);
        }
        public Dictionary <string, string> readParams(string qConnectionId)
        {
            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "+ readParams()");

            XElement rootElement;

            lock (this._lock)
            {
                if (!File.Exists(this.getConnectionFile(qConnectionId)))
                {
                    return(null);
                }

                rootElement = XElement.Parse(File.ReadAllText(this.getConnectionFile(qConnectionId)));
            }

            Dictionary <string, string> dict = new Dictionary <string, string>();

            foreach (var el in rootElement.Elements())
            {
                dict.Add(el.Name.LocalName.Replace("___", " "), el.Value);
            }

            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "- readParams()");

            return(dict);
        }
        private void writeParams(string qConnectionId, Dictionary <string, string> dict)
        {
            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "+ writeParams()");

            XElement newEl = new XElement(
                "root",
                dict.Select(kv =>
            {
                QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "writeParams() : (" + kv.Key + ", " + kv.Value + ")");

                return(new XElement(
                           kv.Key.Replace(" ", "___"),
                           kv.Value
                           ));
            }
                            )
                );

            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "writeParams() : dic generated!");

            lock (this._lock)
            {
                newEl.Save(this.getConnectionFile(qConnectionId));
            }

            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "- writeParams()");
        }
        public Dictionary <string, string> ToDictionary(string[] param)
        {
            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "+ ToDictionary()");

            Dictionary <string, string> retVal;
            JsonSerializer js = new JsonSerializer();

            try {
                retVal = param.ToList().SelectMany(
                    (f) => {
                    QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "ToDictionary() : " + f);
                    return(ToDriverParamList(JsonConvert.DeserializeObject <List <DriverParamDeserial> >(f)));
                }
                    ).ToList().SelectMany(f => driverParamToDictionary(f))
                         .ToDictionary(f => f.Key, f => f.Value);
            }
            catch (Exception e)
            {
                QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Error, "ToDictionary() : " + e.Message);
                throw e;
            }

            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "- ToDictionary()");

            return(retVal);
        }
        public string GetResponse()
        {
            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "+ GetResponse()");

            StreamReader reader = this.GetResponseStream();

            if (reader != null)
            {
                // Read the content fully up to the end.
                string responseFromServer = reader.ReadToEnd();

                QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "GetResponse() : convert to string OK!");

                // Clean up the streams.
                this.CloseStreams(reader);

                QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "- GetResponse()");

                return(responseFromServer);
            }

            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "- GetResponse()");

            return(null);
        }
示例#10
0
        private IEnumerable <QvxDataRow> GetSystemEvents()
        {
            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "GetSystemEvents()");
            log.Debug("GetSystemEvents()");

            return(GetEvents("System", "SystemEventLog"));
        }
        public QvDataContractResponse createConnectionString(Dictionary <string, string> userParameters)
        {
            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "+ createConnectionString()");

            Info retVal;

            try
            {
                retVal = new QvInfo {
                    qMessage = "Connection string creation failed", qOk = false
                };

                if (userParameters.ContainsKey("qConnectionId"))
                {
                    retVal = new QvInfo {
                        qMessage = "qConnectionId=" + userParameters["qConnectionId"], qOk = true
                    };
                }
            }
            catch (Exception e)
            {
                QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Error, "createConnectionString() : " + e.Message);
                throw e;
            }

            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "- createConnectionString()");

            return(retVal);
        }
        public QvDataContractResponse testConnection(IQlikSimpleConnector driver, Dictionary <string, string> userParameters)
        {
            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "+ testConnection()");

            Info retVal;

            try
            {
                retVal = new QvInfo {
                    qMessage = "Connection failed", qOk = false
                };

                if (driver.testConnection(userParameters))
                {
                    retVal = new QvInfo {
                        qMessage = "Connection OK!", qOk = true
                    };
                }
            }
            catch (Exception e)
            {
                QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Error, "testConnection() : " + e.Message);
                throw e;
            }

            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "- testConnection()");

            return(retVal);
        }
示例#13
0
        public override QvxDataTable ExtractQuery(string query, List <QvxTable> tables)
        {
            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "ExtractQuery()");
            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, query);

            return(base.ExtractQuery(query, tables));
        }
        public dynamic GetJSON()
        {
            //Debugger.Launch();
            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "Getting JSON");
            IsMore = false;
            String json = "";

            try
            {
                json = client.DownloadString(ActiveUrl);
                QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "Json was - " + json);
                ActiveResults = JsonConvert.DeserializeObject(json);
                //PageActiveUrl();
                return(ActiveResults);
            }
            catch (WebException ex)
            {
                QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Error, "Downloading Web Response - " + ex.Status + ": " + ex.Message);
                QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "Url was - " + ActiveUrl);
                QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "Json was - " + json);
            }
            catch (Exception ex)
            {
                QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Error, "Converting Web Response - " + ex.Message);
                QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "Url was - " + ActiveUrl);
                QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "Json was - " + json);
            }
            return(null);
        }
示例#15
0
        private void doneButton_Click(object sender, EventArgs e)
        {
            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "doneButton_Click()");
            log.Debug("doneButton_Click()");

            Application.Exit();
        }
        public override void Init()
        {
            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "+ Init()");

            try {
                if (this.MParameters != null)
                {
                    QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "Init() : " + String.Join("|", this.MParameters.Select(k => k.Key + ": " + k.Value).ToArray()));

                    if (this.MParameters.ContainsKey("qConnectionId"))
                    {
                        this.args = parent.readParams(this.MParameters["qConnectionId"]);

                        if (this.args != null)
                        {
                            parent.Registered(this.args["qDriver"]).Init(this.args);
                            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "Init() : " + this.args["qDriver"]);
                        }
                    }
                }

                QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "Init()");
            }
            catch (Exception e)
            {
                QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Error, "Init() : " + e.Message);
                throw e;
            }

            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "- Init()");
        }
        public MyWebRequest(string url, string method, string data, string auth, string user, string password)
            : this(url, method, auth, user, password)
        {
            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, String.Format("MyWebRequest() : {0}", url));

            if (data != null)
            {
                // Create POST data and convert it to a byte array.
                string postData  = data;
                byte[] byteArray = Encoding.UTF8.GetBytes(postData);

                // Set the ContentType property of the WebRequest.
                request.ContentType = "application/x-www-form-urlencoded";

                // Set the ContentLength property of the WebRequest.
                request.ContentLength = byteArray.Length;

                // Get the request stream.
                dataStream = request.GetRequestStream();

                // Write the data to the request stream.
                dataStream.Write(byteArray, 0, byteArray.Length);

                // Close the Stream object.
                dataStream.Close();
            }
        }
        public override void Init()
        {
            QvxLog.SetLogLevels(true, true);

            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "Init()");

            var eventLogFields = new QvxField[]
            {
                new QvxField("Category", QvxFieldType.QVX_TEXT, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII),
                new QvxField("EntryType", QvxFieldType.QVX_TEXT, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII),
                new QvxField("Message", QvxFieldType.QVX_TEXT, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII),
                new QvxField("CategoryNumber", QvxFieldType.QVX_TEXT, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII),
                new QvxField("Index", QvxFieldType.QVX_TEXT, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII),
                new QvxField("MachineName", QvxFieldType.QVX_TEXT, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII),
                new QvxField("Source", QvxFieldType.QVX_TEXT, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII),
                new QvxField("TimeGenerated", QvxFieldType.QVX_TEXT, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII)
            };

            MTables = new List <QvxTable>
            {
                new QvxTable
                {
                    TableName = "ApplicationsEventLog",
                    GetRows   = GetApplicationEvents,
                    Fields    = eventLogFields
                }
            };
        }
示例#19
0
        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 override void Init()
        {
            QvxLog.SetLogLevels(false, true);

            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "Init()");

            var bucketsListFields = new QvxField[]
            {
                new QvxField("BucketName", QvxFieldType.QVX_TEXT, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII),
                new QvxField("CreationDate", QvxFieldType.QVX_TEXT, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII)
            };

            var objectFields = new QvxField[]
            {
                new QvxField("BucketName", QvxFieldType.QVX_TEXT, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII),
                new QvxField("ETag", QvxFieldType.QVX_TEXT, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII),
                new QvxField("Key", QvxFieldType.QVX_TEXT, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII),
                new QvxField("LastModified", QvxFieldType.QVX_TEXT, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.INTEGER),
                new QvxField("OwnerName", QvxFieldType.QVX_TEXT, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII),
                new QvxField("OwnerId", QvxFieldType.QVX_TEXT, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII),
                new QvxField("Size", QvxFieldType.QVX_TEXT, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.INTEGER),
                new QvxField("StorageClass", QvxFieldType.QVX_TEXT, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII)
            };

            var dummyFields = new QvxField[]
            {
                new QvxField("DummyField", QvxFieldType.QVX_TEXT, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII)
            };


            MTables = new List <QvxTable>
            {
                new QvxTable
                {
                    TableName = "ListBuckets",
                    Fields    = bucketsListFields
                },
                new QvxTable
                {
                    TableName = "BucketObjects",
                    Fields    = objectFields
                },
                new QvxTable
                {
                    TableName = "DownloadObject",
                    Fields    = dummyFields
                }
                //new QvxTable
                //    {
                //        TableName = "UploadObject",
                //        Fields = dummyFields
                //    },
                //new QvxTable
                //    {
                //        TableName = "DeleteLocalObject",
                //        Fields = dummyFields
                //    }
            };
        }
示例#21
0
 private IEnumerable <QvxDataRow> GetTestRows()
 {
     QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "GetTestRows");
     for (int i = 1; i <= 3; ++i)
     {
         yield return(MakeEntry(i, FindTable("TestTable", MTables)));
     }
 }
        public static QvxDataTable DownloadObject(QvxTable downloadObjectTable, IDictionary <string, string> fields, IDictionary <string, string> MParameters)
        {
            RegionEndpoint region   = null;
            AmazonS3Client s3Client = null;

            fields.TryGetValue("bucketname", out string bucketName);
            fields.TryGetValue("objectname", out string objectName);
            fields.TryGetValue("localpath", out string localPath);

            MParameters.TryGetValue("access-key", out string accessKey);
            MParameters.TryGetValue("secret-key-encrypted", out string secretKeyEncrypted);
            MParameters.TryGetValue("aws-region", out string awsRegion);

            string secretKey = EncryptDecrypt.DecryptString(secretKeyEncrypted);

            if (String.IsNullOrEmpty(bucketName))
            {
                throw new QvxPleaseSendReplyException(QvxResult.QVX_UNKNOWN_COMMAND, String.Format("Missing required param: {0}", "BucketName"));
            }

            if (String.IsNullOrEmpty(objectName))
            {
                throw new QvxPleaseSendReplyException(QvxResult.QVX_UNKNOWN_COMMAND, String.Format("Missing required param: {0}", "ObjectName"));
            }

            if (String.IsNullOrEmpty(localPath))
            {
                throw new QvxPleaseSendReplyException(QvxResult.QVX_UNKNOWN_COMMAND, String.Format("Missing required param: {0}", "LocalPath"));
            }


            try
            {
                region   = RegionEndpoint.GetBySystemName(awsRegion);
                s3Client = new AmazonS3Client(accessKey, secretKey, region);

                GetObjectRequest request = new GetObjectRequest()
                {
                    BucketName = bucketName,
                    Key        = objectName
                };

                using (GetObjectResponse response = s3Client.GetObject(request))
                {
                    string title = response.Metadata["x-amz-meta-title"];
                    string dest  = localPath;
                    response.WriteResponseStreamToFile(dest);
                }

                downloadObjectTable.GetRows = DownloadObjectRows(downloadObjectTable);
            }
            catch (Exception ex)
            {
                QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Error, ex.Message);
                throw new QvxPleaseSendReplyException(QvxResult.QVX_UNKNOWN_COMMAND, "Error downloading object from AWS S3: " + ex.Message);
            }
            return(new QvxDataTable(downloadObjectTable));
        }
示例#23
0
        /// <summary>
        /// Parses the query and fills the following properties: fields, liveTable, file, where
        /// </summary>
        /// <param name="query"></param>
        /// <param name="qvxTables"></param>
        /// <returns>the table in use</returns>
        public override QvxDataTable ExtractQuery(string query, List <QvxTable> qvxTables)
        {
            #if DEBUG
            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "ExtractQuery()");
            #endif

            QueryExtractor.ExtractQueryDetails(query, out selectedFields, out string liveTable, out file, out where);

            using (GAMSHelper gh = new GAMSHelper(_source, file))
            {
                gh.LoadGAMSFile(this);
                qTable = FindTable(liveTable, MTables);
                if (qTable == null)
                {
                    throw new QvxPleaseSendReplyException(QvxResult.QVX_TABLE_NOT_FOUND, String.Format("The symbol \"{0}\" is not valid", liveTable));
                }

                // create a list with all fields that appear in SELECT and WHERE
                HashSet <string> referencedFields = new HashSet <string>(selectedFields);
                referencedFields.UnionWith(where.ConvertAll(item => item.Field));

                // before returning the table to Qlik, we check if the fields were selected by position or name, in order to use the name selected by the user
                Regex rx = new Regex("^@([0-9]+)$");
                foreach (string referencedField in referencedFields)
                {
                    Match match = rx.Match(referencedField);
                    if (match.Success)
                    {
                        // the column is selected by position
                        Group group          = match.Groups[1];
                        int   columnPosition = int.Parse(group.Value);
                        if (columnPosition >= qTable.Fields.Length)
                        {
                            throw new QvxPleaseSendReplyException(QvxResult.QVX_FIELD_NOT_FOUND, String.Format("The field position \"{0}\" is not valid", referencedField));
                        }
                        else if (referencedFields.Contains(qTable.Fields[columnPosition].FieldName))
                        {
                            throw new QvxPleaseSendReplyException(QvxResult.QVX_FIELD_NOT_FOUND, String.Format("The same field cannot be selected by position and name: \"{0}\", \"{1}\"",
                                                                                                               referencedField, qTable.Fields[columnPosition].FieldName));
                        }
                        else
                        {
                            // we update the QvxTable, so internally the field is always called by the name selected by the user
                            qTable.Fields[columnPosition].FieldName = referencedField;
                        }
                    }
                    else
                    {
                        // the column is selected by name, so we only check if the name is right
                        if (!Array.Exists(qTable.Fields, tableField => tableField.FieldName.Equals(referencedField)))
                        {
                            throw new QvxPleaseSendReplyException(QvxResult.QVX_FIELD_NOT_FOUND, String.Format("The field \"{0}\" is not valid", referencedField));
                        }
                    }
                }
                return(new QvxDataTable(qTable));
            }
        }
        private void getPlugins()
        {
            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "+ getPlugins()");

            try
            {
                string   path        = Application.StartupPath + "\\connectors";
                string[] pluginFiles = new string[] { };

                QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "getPlugins() : path = " + path);

                pluginFiles = Directory.GetFiles(path, "*.DLL");
                QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "getPlugins() : found " + pluginFiles.Length + " dlls...");

                IQlikSimpleConnector[] ipi = new IQlikSimpleConnector[pluginFiles.Length];

                for (int i = 0; i < pluginFiles.Length; i++)
                {
                    Type ObjType = null;

                    Assembly ass = Assembly.LoadFrom(pluginFiles[i]);
                    QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "getPlugins() : Assembly loaded...");

                    if (ass != null)
                    {
                        Type[] types = ass.GetTypes();
                        foreach (Type t in types)
                        {
                            if (t.GetInterface(typeof(IQlikSimpleConnector).FullName) != null)
                            {
                                QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "getPlugins() : found plugin: " + t.ToString() + " in " + pluginFiles[i]);
                                ObjType = t;
                            }
                        }
                    }

                    if (ObjType != null)
                    {
                        QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "getPlugins() : creating instance... :)");

                        ipi[i] = (IQlikSimpleConnector)Activator.CreateInstance(ObjType);

                        QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "getPlugins() : registering plugin...");

                        ipi[i].Host = this;
                        this.Register(ipi[i]);
                    }
                }
            }
            catch (Exception e)
            {
                QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Error, "getPlugins() : " + e.Message);
                throw e;
            }

            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "- getPlugins()");
        }
示例#25
0
        private IEnumerable <QvxDataRow> GetJSONRows(DataTable dt, List <QvxTable> MTables, Func <string, IEnumerable <QvxTable>, QvxTable> FindTable)
        {
            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "GetJSONRows()");

            foreach (DataRow dr in dt.Rows)
            {
                yield return(MakeEntry(dr, FindTable(dt.TableName, MTables)));
            }
        }
        public override string CreateConnectionString()
        {
            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "+ CreateConnectionString()");

            string retVal = "FOOBAR;";

            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "- CreateConnectionString()");

            return(retVal);
        }
        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);
        }
示例#28
0
 public void SetProperty(string io_nameProperty, object[] io_params)
 {
     try {
         CurrentObject.GetType().InvokeMember(io_nameProperty, BindingFlags.Public | BindingFlags.SetProperty, null, CurrentObject, io_params);
     }
     catch (Exception lo_ex) {
         QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Error, lo_ex.Message);
         Debug.WriteLine(lo_ex.Message);
     }
 }
        public static QvxTable.GetRowsHandler ListBucketsRows(QvxTable table, IDictionary <string, string> MParameters)
        {
            RegionEndpoint region   = null;
            AmazonS3Client s3Client = null;

            string GCPProjectId = "";

            List <QvxDataRow> rows = new List <QvxDataRow>();

            MParameters.TryGetValue("access-key", out string accessKey);
            MParameters.TryGetValue("secret-key-encrypted", out string secretKeyEncrypted);
            MParameters.TryGetValue("aws-region", out string awsRegion);

            string secretKey = EncryptDecrypt.DecryptString(secretKeyEncrypted);

            return(() =>
            {
                try
                {
                    region = RegionEndpoint.GetBySystemName("eu-west-2");
                    s3Client = new AmazonS3Client(accessKey, secretKey, region);
                }
                catch (Exception ex)
                {
                    QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Error, ex.Message);
                    throw new QvxPleaseSendReplyException(QvxResult.QVX_UNKNOWN_COMMAND, "Error getting the data from Google Storage");
                }

                ListBucketsResponse response = s3Client.ListBuckets();

                int length = 0;
                foreach (S3Bucket bucket in response.Buckets)
                {
                    length++;
                }

                if (length == 0)
                {
                    throw new QvxPleaseSendReplyException(QvxResult.QVX_UNKNOWN_COMMAND, String.Format("No buckets found for project {0}", GCPProjectId));
                }
                else
                {
                    foreach (S3Bucket bucket in response.Buckets)
                    {
                        var row = new QvxDataRow();
                        row[table.Fields[0]] = bucket.BucketName.ToString();
                        row[table.Fields[1]] = bucket.CreationDate.ToString();
                        rows.Add(row);
                    }
                }

                return rows;
            });
        }
        private void connectButton_Click(object sender, EventArgs e)
        {
            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "connectButton_Click()");

            if (_qvsos != null)
            {
                _connectString = _qvsos.CreateConnectionString();
                logTextBox.AppendText(String.Format("Connect string: {0}\n", _connectString));
                logTextBox.AppendText(Environment.NewLine);
            }
        }