}//END ImportCsvData method. //=================================================================================== /// <summary> /// This method executes a CSV import or export query. /// </summary> /// <param name="UserProfile">Evado.Digital.Model.EdUserProfile object.</param> /// <param name="QueryType">EiQueryTypes: Csv encoded data object.</param> /// <param name="CsvDataList">List of String: Csv encoded data object.</param> /// <returns> Evado.Integration.Model.EiData object</returns> //----------------------------------------------------------------------------------- public Evado.Integration.Model.EiData ImportData( Evado.Digital.Model.EdUserProfile UserProfile, EiQueryTypes QueryType, List <String> CsvDataList) { this.LogMethod("ImportData method."); this.LogDebug("UserProfile: " + UserProfile.CommonName); this.LogDebug("QueryType: " + QueryType); this.writeProcessLog("CSV Import Service - Commence processing query data."); // // Initialise the methods variables and objects. // Evado.Integration.Model.EiData resultData = new Evado.Integration.Model.EiData( ); Evado.Digital.Model.EdQueryParameters queryParameters = new Evado.Digital.Model.EdQueryParameters( ); // // Get extract the data from the CSV file. // EiData ImportData = this.getDataObjectFromCsv( CsvDataList, QueryType); /* * if ( this.Settings.LoggingLevel > 4 ) * { * foreach ( EiColumnParameters parm in ImportData.Columns ) * { * string content = String.Format ( "Parm: Field: {0}, Type: {1}, Index: {2}", parm.EvadoFieldId, parm.DataType, parm.Index ); * this.LogValue ( content ); * } * } */ // // Execute the query. // resultData = EI_Services.ProcessQuery(ImportData); this.LogClass(EI_Services.Log); this._ProcessLog.AppendLine(resultData.ProcessLog); this.LogMethodEnd("ImportData"); return(resultData); }//END ImportCsvData method.
//================================================================================== /// <summary> /// This method initialises the clas and sets the project identifier. /// </summary> /// <param name="ProjectId">String: project identifier</param> /// <param name="QueryType">EiQueryTypes: Query Type</param> //----------------------------------------------------------------------------------- public EiData(String ProjectId, EiQueryTypes QueryType) { this.AddQueryParameter(EiQueryParameterNames.Project_Id, ProjectId); this.QueryType = QueryType; }
}//END ImportCsvData method. #endregion #region private methods //=================================================================================== /// <summary> /// This method converts a CSV datafile into a integration data object. /// </summary> /// <param name="CsvDataList">List of String: Csv encoded data object.</param> /// <param name="QueryType">EiQueryTypes: Csv encoded data object.</param> /// <returns> Evado.Integration.Model.EiData object</returns> //----------------------------------------------------------------------------------- private EiData getDataObjectFromCsv( List <String> CsvDataList, EiQueryTypes QueryType) { this.LogMethod("GetDataObjectFromCsv method"); this.LogDebug("CsvDataList.Count: " + CsvDataList.Count); this.LogDebug("QueryType: " + QueryType); this.writeProcessLog("Processing in CSV data object."); // // Initialise the mathods variables and objects. // EiData dataObject = new EiData( ); String stFileContent = String.Empty; String line = String.Empty; dataObject.DataRows = new List <EiDataRow> ( ); dataObject.Columns = new List <EiColumnParameters> ( ); dataObject.ParameterList = new List <EiQueryParameter> ( ); this.LogDebug("CSV File read: data rows: " + CsvDataList.Count); try { // // Iterate through the csv rows. // for (int csvRowIndex = 0; csvRowIndex < CsvDataList.Count; csvRowIndex++) { this.LogDebug("csvRowIndex: " + csvRowIndex); String csvRow = CsvDataList [csvRowIndex]; // // Skip all empty rows. // if (csvRow == String.Empty) { this.LogDebug("SKIP ROW: empty data"); continue; } // // the csv content as an array of string. // String [] csvRowArray = GetCsvDataArray(csvRow); this.LogDebug("CSV data row length: " + csvRowArray.Length); // // skip columns less than 2 cels. // if (csvRowArray.Length < 2) { this.LogDebug("SKIP ROW: data row less than 2 columns"); continue; } if (csvRowArray [0] == String.Empty) { this.LogDebug("SKIP ROW: No data"); continue; } if (csvRowArray [0] == EiData.CONST_QUERY_TYPE) { this.LogDebug("SKIP ROW: Query type"); continue; } // // Skip the paramater rows if they are present // if (csvRowArray [0] == EiData.CONST_PARAMETER) { this.LogDebug("SKIP ROW: Parameter row"); continue; } dataObject.QueryType = QueryType; this.LogDebug("PROCESSING DATA"); // // Iterate throught the columns of the row. // for (int csvColumnIndex = 1; csvColumnIndex < csvRowArray.Length; csvColumnIndex++) { // // Add parameter if column 0 has paramter value. // if (csvRowArray [0] == EiData.CONST_COLUMN_FIELD_ID || csvRowArray [0] == EiData.CONST_COLUMN_NAME || csvRowArray [0] == EiData.CONST_COLUMN_DATA_TYPE || csvRowArray [0] == EiData.CONST_COLUMN_INDEX) { this.processDataParameters( dataObject, csvRowArray, csvColumnIndex); continue; }//END data column paramater // // Process the data row. // if (csvRowArray [0] == EiData.CONST_DATA_ROW) { this.processDataRow( dataObject, csvRowArray, csvColumnIndex); } //END data row. } //END column iteration loop. } //END Row iteration loop this.LogDebug("DataRows.Count: " + dataObject.DataRows.Count); // // Add the project Identifier. // if (dataObject.DataRows != null) { int columnIndex = dataObject.getColumnNo( "Org_Id"); if (dataObject.DataRows.Count > 0 && columnIndex > -1) { String orgId = dataObject.DataRows [0].Values [columnIndex]; dataObject.ParameterList.Add(new EiQueryParameter(EiQueryParameterNames.Organisation_Id, orgId)); this.LogDebug("OrgId: " + orgId); } } } catch (Exception Ex) { this.LogEvent(Evado.Model.EvStatics.getException(Ex)); return(dataObject); } this.LogMethodEnd("GetDataObjectFromCsv"); // // return the data object. // return(dataObject); }//END GetDataObjectFromCsv method