public CQRecordStoredQueryQuery( Session userSession, CQRecordFilter recordFilter, string hwmStr, IServiceProvider serviceProvider) : base(userSession, recordFilter, serviceProvider) { if (!(recordFilter is CQRecordStoredQueryFilter)) { throw new ArgumentException("recordFilter is not CQRecordStoredQueryFilter"); } ClearQuestMigrationContext cqContext = serviceProvider.GetService(typeof(ClearQuestMigrationContext)) as ClearQuestMigrationContext; m_queryTimeDelimiter = (cqContext == null) ? ClearQuestConstants.CQQueryDefaultTimeDelimiter : cqContext.CQQueryTimeDelimiter; m_queryDef = CQWrapper.GetQueryDef( CQWrapper.GetWorkSpace(m_userSession), ((CQRecordStoredQueryFilter)m_recordFilter).StoredQueryName); string originalQueryString = NormalizeSqlQuery(m_queryDef.SQL); if (string.IsNullOrEmpty(hwmStr)) { m_queryStr = originalQueryString; } else { m_queryStr = UtilityMethods.Format(QueryBase, originalQueryString, m_queryTimeDelimiter, hwmStr, m_queryTimeDelimiter); } Query(); }
public CQRecordStoredQueryQuery( Session userSession, CQRecordFilter recordFilter, string hwmStr, IServiceProvider serviceProvider) : base(userSession, recordFilter, serviceProvider) { if (!(recordFilter is CQRecordStoredQueryFilter)) { throw new ArgumentException("recordFilter is not CQRecordStoredQueryFilter"); } m_queryDef = CQWrapper.GetQueryDef( CQWrapper.GetWorkSpace(m_userSession), ((CQRecordStoredQueryFilter)m_recordFilter).StoredQueryName); string originalQueryString = NormalizeSqlQuery(m_queryDef.SQL); if (string.IsNullOrEmpty(hwmStr)) { m_queryStr = originalQueryString; } else { m_queryStr = UtilityMethods.Format(QueryBase, originalQueryString, hwmStr); } Query(); }
private CQRecordStoredQueryQuery(CQRecordStoredQueryQuery src) : base(src.m_userSession, src.m_recordFilter, src.m_serviceProvider) { m_queryStr = src.m_queryStr; m_resultSetDbIds = src.m_resultSetDbIds; m_queryDef = src.m_queryDef; }
} // end of CQConnection Ctor /// <summary> /// Creates User session, Admin session and executes the query /// </summary> public void Initialize() { m_pwd = System.Environment.GetEnvironmentVariable("CQUserPwd"); if (m_pwd != null) { m_pwd = m_pwd.Trim(); } if (m_pwd == null) { Console.Write(UtilityMethods.Format(CQResource.CQ_ENTER_PWD, m_user)); m_pwd = Microsoft.TeamFoundation.Converters.Utility.LocalizedPasswordReader.ReadLine(); Display.NewLine(); } CreateUserSession(); CreateAdminSession(); try { m_queryDef = CQWrapper.GetQueryDef(CQWrapper.GetWorkSpace(cqUserSession), m_query); } catch (ConverterException conEx) { string errMsg = UtilityMethods.Format(CQResource.CQ_INVALID_QUERY, CurConResource.Analysis, m_query, m_configFile); Logger.Write(LogSource.CQ, TraceLevel.Error, errMsg); ConverterMain.MigrationReport.WriteIssue(String.Empty, errMsg, string.Empty /* no item */, null, "Config", ReportIssueType.Critical); throw new ConverterException(errMsg, conEx); } }
public String Pedidos_CQ_Instant() { SessionClass session = new SessionClass(); session.UserLogon("admin", "admin", "PRESU", 2, "BPD_DESA"); OAdQuerydef queryDef = (OAdQuerydef)session.BuildQuery("Pedido_Pago"); queryDef.BuildField("id"); queryDef.BuildField("Importe_Total"); OAdResultset resultset = (OAdResultset)session.BuildResultSet(queryDef); resultset.Execute(); var Status = resultset.MoveNext(); String data = ""; while (Convert.ToInt32(Status) == 1) { data = (String)resultset.GetColumnValue(2); Status = resultset.MoveNext(); } return(data); }
public ArrayList Pedidos_CQ() { SessionClass session = new SessionClass(); session.UserLogon("admin", "admin", "PRESU", 2, "BPD_DESA"); OAdQuerydef queryDef = (OAdQuerydef)session.BuildQuery("Pedido_Pago"); queryDef.BuildField("id"); queryDef.BuildField("Importe_Total"); OAdResultset resultset = (OAdResultset)session.BuildResultSet(queryDef); ArrayList PedidosdePagos = new ArrayList(); resultset.Execute(); var Status = resultset.MoveNext(); while (Convert.ToInt32(Status) == 1) { Pedido_Pago data = new Pedido_Pago(); data.id_pedido = (String)resultset.GetColumnValue(1); data.importe_total = (String)resultset.GetColumnValue(2); PedidosdePagos.Add(data); Status = resultset.MoveNext(); } return(PedidosdePagos); }
internal static void BuildField(OAdQuerydef queryDef, string fieldName) { try { queryDef.BuildField(fieldName); } catch (COMException ex) { InteropErrorHandler.HandleCQException(ex); } }
public CQRecordStoredQueryFilter(string storedQueryName, ClearQuestOleServer.Session userSession) : base(string.Empty) { StoredQueryName = storedQueryName; if (null != userSession) { OAdQuerydef qryDef = CQWrapper.GetQueryDef(CQWrapper.GetWorkSpace(userSession), StoredQueryName); base.RecordType = CQWrapper.GetPrimaryEntityDefName(qryDef); } }
internal static OAdResultset BuildResultSet(Session cqSession, OAdQuerydef qryDef) { OAdResultset resultSet = null; try { resultSet = (OAdResultset)cqSession.BuildResultSet(qryDef); } catch (COMException ex) { InteropErrorHandler.HandleCQException(ex); } return(resultSet); }
internal static string GetPrimaryEntityDefName(OAdQuerydef queryDef) { string retval = null; try { retval = queryDef.GetPrimaryEntityDefName(); } catch (COMException ex) { InteropErrorHandler.HandleCQException(ex); } return(retval); }
internal static IOAdQueryFilterNode CreateTopNode(OAdQuerydef queryDef, int bool_op) { IOAdQueryFilterNode retVal = null; try { retVal = queryDef.CreateTopNode(bool_op) as IOAdQueryFilterNode; } catch (COMException ex) { InteropErrorHandler.HandleCQException(ex); } return(retVal); }
internal static OAdQuerydef GetQueryDef(WORKSPACE ws, string queryName) { OAdQuerydef retval = null; try { retval = (OAdQuerydef)ws.GetQueryDef(queryName); } catch (COMException ex) { InteropErrorHandler.HandleCQException(ex); } return(retval); }
public static Dictionary <string, bool> GetQueryListWithValidity(Session session) { Dictionary <string, bool> validQueries = new Dictionary <string, bool>(); IEnumerable <string> queryList = GetQueryList(session); foreach (string query in queryList) { OAdQuerydef qryDef = CQWrapper.GetQueryDef(CQWrapper.GetWorkSpace(session), query); string str = CQWrapper.GetPrimaryEntityDefName(qryDef); validQueries[query] = !string.Equals(str, "All_UCM_Activities"); } return(validQueries); }
} // end of ValidateFieldMapOnCQ /// <summary> /// Execute the Query and migrate the data /// </summary> /// <param name="baseEntityName">Base Entity Name</param> private void MigrateData(string baseEntityName, string baseEntityWitName) { Session cqSession = m_cqConnection.GetUserSession(); OAdQuerydef qryDef = m_cqConnection.QueryDefinition; // edit the query and add dbid field // dbid is suppose to be unique within a Entity CQWrapper.BuildField(qryDef, "dbid"); // prepare result set OAdResultset result = CQWrapper.BuildResultSet(cqSession, qryDef); // process records for base entity CQEntity baseEntityRecords = m_cqParams.entityRecords[baseEntityName]; // enable record count before execute so that no of records can be fetched CQWrapper.EnableRecordCount(result); // execute the query CQWrapper.ExecuteResultSet(result); int columnCount = CQWrapper.GetResultSetColumnCount(result); // lookup for dbid column bool dbidExist = false; int dbidColumnIndex = 0; for (int colIter = 1; colIter <= columnCount; colIter++) { if (string.Equals(CQWrapper.GetColumnLabel(result, colIter), "dbid", StringComparison.OrdinalIgnoreCase)) { dbidExist = true; dbidColumnIndex = colIter; break; } } if (!dbidExist) { // neither query contain dbid nor can be edited to include a new column string errMsg = UtilityMethods.Format(CQResource.CQ_NO_DBID_IN_QUERY, m_cqConnection.QueryName, m_convParams.ConfigFile); PostMigrationReport.WriteIssue(null, null, RepStatus.Failed, ReportIssueType.Critical, String.Empty, baseEntityName, IssueGroup.Config, errMsg); Logger.Write(LogSource.CQ, TraceLevel.Error, errMsg); throw new ConverterException(errMsg); } // start the progress thread for updating the progress m_progressThread = new Thread(new ThreadStart(CQConverter.UpdateProgress)); m_progressThread.Name = "Progress"; try { // get the work item helper handle TotalRecords = CQWrapper.GetRecordCount(result); m_progressThread.Start(); while (CQWrapper.ResultSetMoveNext(result) == CQConstants.SUCCESS) { string dbid = (string)CQWrapper.GetColumnValue(result, dbidColumnIndex); // create a CQEntity for that CQEntityRec record = new CQEntityRec(int.Parse(dbid), baseEntityName, m_cqParams); try { // populate and migrate the record and all referenced records RecordsProcessed++; baseEntityRecords.AddRecord(record); if (record.Populate() == false && m_cqParams.exitOnError == true) { return; // stop processing more records } } catch (ConverterException conEx) { // log the error and continue with next item string errMsg = UtilityMethods.Format(CQResource.CQ_WI_READ_FAILED, dbid, conEx.Message); ReportWorkItemFailure(errMsg, dbid, baseEntityName, baseEntityWitName, m_cqParams.exitOnError); if (m_cqParams.exitOnError == true) { // throw the error back .. should not continue with the current record throw; } } } } finally { // terminate the progress thread m_progressThread.Abort(); Thread.Sleep(5000); // allow the display thread to stop } } // end of MigrateData
} // end of Initialize /// <summary> /// Starts the actual schema migration followed by data migration /// </summary> public void Convert() { Session cqSession = m_cqConnection.GetUserSession(); OAdQuerydef qryDef = m_cqConnection.QueryDefinition; // get the base entity definition to analyze string baseEntityDefName = CQWrapper.GetPrimaryEntityDefName(qryDef); Debug.Assert(baseEntityDefName != null); Logger.WritePerf(LogSource.CQ, "Start Analyze"); // set o/p directory only if it is not specified in the CQConfig file.. // otherwise its already set / created in Initialize section if (String.IsNullOrEmpty(m_convParams.OutputDirectory)) { CQConverterUtil.SetOutputDirectory(baseEntityDefName, m_convParams.ConfigFile); } if (baseEntityDefName != null) { string[] refEntities = CQConverterUtil.GetReferencedEntityDefNames(cqSession, baseEntityDefName, m_convParams.ConfigFile); StringBuilder infoMsg1 = new StringBuilder(UtilityMethods.Format(CQResource.CQ_ENTITY_MIGRATED)); foreach (string str in refEntities) { infoMsg1.Append(str); infoMsg1.Append(", "); // REVIEW - GautamG: String not localized } infoMsg1.Remove(infoMsg1.Length - 2, 1); // remove last comma infoMsg1.Append(Environment.NewLine); Logger.Write(LogSource.CQ, TraceLevel.Info, infoMsg1.ToString()); Display.DisplayMessage(infoMsg1.ToString()); // create the schema map file so that for each WITD xml generation // the entries are added in schema map WITSchemaMappings schemaMap = new WITSchemaMappings(); int reportEntityIndex = 0; ConverterMain.MigrationReport.Summary.SourceAndDestination.WorkItemTypes.WorkItemTypeTypes = new WorkItemTypeTypes[refEntities.Length]; foreach (string entityToMigrate in refEntities) { if (entityToMigrate != null) { // process the given entity definition and generate xml for each entity // one for the base entity and one for each of referenced entities OAdEntityDef entityDef = CQWrapper.GetEntityDef(cqSession, entityToMigrate); string entityDefName = entityDef.GetName(); string schemaXmlFile = entityDefName + ".xml"; // get the file name prepended with the path.. to be generated under base entity name folder schemaXmlFile = CQConverterUtil.GetFileNameWithPath(schemaXmlFile); string fieldMapXmlFile = entityDefName + CQConstants.FieldMapFileSuffix; fieldMapXmlFile = CQConverterUtil.GetFileNameWithPath(fieldMapXmlFile); // add the default map to schema schemaMap.Mappings.AddSchemaMap(entityDefName, entityDefName, schemaXmlFile, fieldMapXmlFile); ConverterMain.MigrationReport.AddOutput(CQResource.Witd, schemaXmlFile); ConverterMain.MigrationReport.AddOutput(CQResource.WitFieldMap, fieldMapXmlFile); WITDXMLGenerator currEntityXML = new WITDXMLGenerator(schemaXmlFile, fieldMapXmlFile, cqSession, entityDef, m_vstsConn); currEntityXML.GenerateSchemaXml(); // add the entity information in migration report WorkItemTypeTypes wiType = new WorkItemTypeTypes(); wiType.From = wiType.To = entityDefName; ConverterMain.MigrationReport.Summary.SourceAndDestination.WorkItemTypes.WorkItemTypeTypes[reportEntityIndex++] = wiType; // add the link type mappings MapLinkTypes(refEntities, entityToMigrate, entityDef); } } // foreach (string entityToMigrate in refEntities) Display.NewLine(); // generated the schemas and the corresponding field maps // finally serialize the schema map file string schemaMapFile = CQConverterUtil.GetFileNameWithPath(CQConstants.SchemaMapFile); string userMapFile = CQConverterUtil.GetFileNameWithPath(CQConstants.UserMapFile); ConverterMain.MigrationReport.AddOutput(CQResource.SchemaMap, schemaMapFile); ConverterMain.MigrationReport.AddOutput(CQResource.UserMap, userMapFile); schemaMap.GenerateSchemaMappings(schemaMapFile, userMapFile); GenerateDefaultUserMaps(userMapFile); ConverterMain.MigrationReport.Statistics.NumberOfItems = refEntities.Length; // generate the link type mapping file GenerateLinkTypeMappings(); } Logger.WritePerf(LogSource.CQ, "End Analyze"); } // end of Convert()