コード例 #1
0
        /// <summary>
        /// Initialize the object with the ConverterParameter values
        /// Also validates the Schema Mapping field Mapping on the CQ side
        /// </summary>
        /// <param name="convParams"></param>
        public void Initialize(ConverterParameters convParams)
        {
            // store it for future use
            this.m_convParams = convParams;

            m_cqParams.schemaMaps  = convParams.SchemaMaps;
            m_cqParams.exitOnError = convParams.ExitOnError;

            // create the connection to VSTS and ensure that the user
            // is part of Service Accounts group
            m_vstsConn           = new VSTSConnection(m_convParams.TargetConfig);
            m_cqParams.vstsConn  = m_vstsConn;
            CQConstants.VstsConn = m_vstsConn;

            // create a ClearQuest connection handle
            m_cqConnection = new CQConnection(convParams.SourceConfig, convParams.ConfigFile);

            // check for valid CQ installation..
            m_cqParams.uniqueInstId = GetUniqueInstallationId();

            // set the output directory even before making a connection to CQ..
            // IFF some output directory is specified in CQConfig.xml (bug#12110)
            // and only if it is Analyze phase.. no file is dumped in Migration phase in o/p dir
            if (m_convParams.OutputDirectory != null &&
                m_convParams.OutputDirectory.Length >= 0)
            {
                CQConverterUtil.SetOutputDirectory(m_convParams.OutputDirectory, m_convParams.ConfigFile);
            }

            // create a user session and a admin session and execute the query
            m_cqConnection.Initialize();

            // process the schema xml file
            // validate the entities on CQ database
            // for each entity validate the field map on CQ databases
            m_cqParams.cqSession = m_cqConnection.GetUserSession();
            ConverterMain.MigrationReport.Converter = ReportConverter.CQConverter;
        } // end of Initialize
コード例 #2
0
        } // 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()