Example #1
0
        /// <summary>
        /// Obtains the fields in a table
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="_source"></param>
        /// <param name="database"></param>
        /// <param name="owner"></param>
        /// <param name="table"></param>
        /// <returns></returns>
        public QvDataContractResponse getFields(QvGamsConnection connection, string _source, string database, string owner, string table)
        {
            string file = database + "\\" + owner;

            if (database != string.Empty && owner != string.Empty)
            {
                using (GAMSHelper gh = new GAMSHelper(_source, file))
                {
                    gh.LoadGAMSFile(connection);

                    var currentTable = connection.FindTable(table, connection.MTables);

                    return(new QvDataContractFieldListResponse
                    {
                        qFields = (currentTable != null) ? currentTable.Fields : new QvxField[0]
                    });
                }
            }
            else
            {
                return(new QvDataContractFieldListResponse
                {
                    qFields = new QvxField[0]
                });
            }
        }
Example #2
0
        /// <summary>
        /// Obtains the owners (files) with extension "gdx"
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="_source"></param>
        /// <param name="database"></param>
        /// <returns></returns>
        public QvDataContractResponse getOwners(QvGamsConnection connection, string _source, string database)
        {
            string finalPath = _source + "\\" + database;

            if (PathUtils.IsBaseOf(_source, finalPath))
            {
                List <string> files     = GetFilesAux(finalPath);
                Owner[]       auxOwners = new Owner[files.Count()];
                int           i         = 0;
                foreach (String file in files)
                {
                    Owner owner = new Owner()
                    {
                        qName = file
                    };
                    auxOwners[i++] = owner;
                }

                return(new OwnerResponse
                {
                    qOwners = auxOwners
                });
            }
            else
            {
                return(new OwnerResponse
                {
                    qOwners = new Owner[0]
                });
            }
        }
Example #3
0
        /// <summary>
        /// Obtains the databases (sub-folders)
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="_source"></param>
        /// <returns></returns>
        public QvDataContractResponse getDatabases(QvGamsConnection connection, string _source)
        {
            List <string> directories = GetDirectoriesAux(_source);

            Database[] auxDatabases = new Database[directories.Count()];
            int        i            = 0;

            foreach (String directory in directories)
            {
                auxDatabases[i++] = new Database {
                    qName = directory
                };
            }

            return(new QvDataContractDatabaseListResponse
            {
                qDatabases = auxDatabases
            });
        }
Example #4
0
        /// <summary>
        /// Obtains the data for the preview using the high level Gams API
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="_source"></param>
        /// <param name="database"></param>
        /// <param name="owner"></param>
        /// <param name="tableName"></param>
        /// <returns></returns>
        private PreviewResponse getPreview(QvGamsConnection connection, string _source, string database, string owner, string tableName)
        {
            string file = database + "\\" + owner;

            var result = new PreviewResponse();

            if (database != string.Empty && owner != string.Empty && tableName != string.Empty)
            {
                using (GAMSHelper gh = new GAMSHelper(_source, file))
                {
                    gh.LoadGAMSFile(connection);
                    string symbolName   = tableName.Trim();
                    var    currentTable = connection.FindTable(tableName, connection.MTables);

                    // Store the table Header
                    var row = new PreviewRow();
                    foreach (var field in currentTable.Fields)
                    {
                        row.qValues.Add(field.FieldName);
                    }
                    result.qPreview.Add(row);

                    // Getting the preview data
                    string[,] PreviewTableData = gh.GetPreviewData(currentTable, 9);

                    int FinalNumberOfRows = PreviewTableData.GetLength(0);
                    int NumberOfColumns   = PreviewTableData.GetLength(1);

                    for (int i = 0; i < FinalNumberOfRows; i++)
                    {
                        row = new PreviewRow();
                        for (int j = 0; j < NumberOfColumns; j++)
                        {
                            row.qValues.Add(PreviewTableData[i, j]);
                        }
                        result.qPreview.Add(row);
                    }
                }
            }
            return(result);
        }
Example #5
0
 /// <summary>
 /// This method obtains the list of tables and assigns it to connection.MTables
 /// </summary>
 /// <param name="connection"></param>
 /// <param name="_source"></param>
 /// <param name="_file"></param>
 public void LoadGAMSFile(QvGamsConnection connection)
 {
     connection.MTables = new List <QvxTable>();
     foreach (GAMSSymbol sym in this.Db)
     {
         var GamsFields = new QvxField[this.GetColumnCount(sym)];
         int i          = 0;
         foreach (var item in this.GetColumnHeaders(sym))
         {
             GamsFields[i++] = new QvxField(item.Item1, item.Item2, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA);
         }
         connection.MTables.Add(
             new QvxTable
         {
             TableName = sym.Name,
             GetRows   = connection.GetData,
             Fields    = GamsFields
         }
             );
     }
     ;
 }
Example #6
0
        /// <summary>
        /// Obtains the tables (gams symbols)
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="_source"></param>
        /// <param name="database"></param>
        /// <param name="owner"></param>
        /// <returns></returns>
        public QvDataContractResponse getTables(QvGamsConnection connection, string _source, string database, string owner)
        {
            string file = database + "\\" + owner;

            if (database != string.Empty && owner != string.Empty)
            {
                using (GAMSHelper gh = new GAMSHelper(_source, file))
                {
                    gh.LoadGAMSFile(connection);

                    return(new QvDataContractTableListResponse
                    {
                        qTables = connection.MTables
                    });
                }
            }
            else
            {
                return(new QvDataContractTableListResponse
                {
                    qTables = new List <QvxTable>()
                });
            }
        }