public GroupFilterTerm GetFilter(IAssetType type) {
            var terms = new List<IFilterTerm>();

            foreach (var value in values) {
                var term = new FilterTerm(type.GetAttributeDefinition(Name));

                switch(value.Action) {
                    case FilterValuesActions.Equal:
                        term.Equal(value.Value);
                        break;
                    case FilterValuesActions.NotEqual:
                        term.NotEqual(value.Value);
                        break;
                    case FilterValuesActions.Greater:
                        term.Greater(value.Value);
                        break;
                    default:
                        throw new NotSupportedException();
                }

                terms.Add(term);
            }

            return Operation == FilterActions.And ? (GroupFilterTerm) new AndFilterTerm(terms.ToArray()) : new OrFilterTerm(terms.ToArray());
        }
        public DateTime? GetMostRecentChangeDateTime()
        {
            var defectType = _meta.GetAssetType("Defect");
            var query = new Query(defectType);
            var projectAttribute = defectType.GetAttributeDefinition("Scope");
            var projectTerm = new FilterTerm(projectAttribute);
            projectTerm.Equal(MonitoredProjects.Select(project => project.ScopeId).Cast<Object>().ToArray());

            var changeAttribute = defectType.GetAttributeDefinition("ChangeDateUTC");
            query.Selection.Add(changeAttribute);
            if (_mostRecentChangeDateTime.HasValue)
            {
                var changeTerm = new FilterTerm(changeAttribute);
                changeTerm.Greater(_mostRecentChangeDateTime.Value.ToString("yyyy-MM-ddTHH:mm:ss.fff", CultureInfo.InvariantCulture));
                query.Filter = new AndFilterTerm(changeTerm, projectTerm);
            } else
            {
                query.Filter = projectTerm;
            }

            var result = _services.Retrieve(query);

            if (result.TotalAvaliable > 0)
            {
                foreach (var asset in result.Assets)
                {
                    var projectChangeDateTime = DB.DateTime(asset.GetAttribute(changeAttribute).Value);
                    if ((!_mostRecentChangeDateTime.HasValue) || (projectChangeDateTime > _mostRecentChangeDateTime))
                    {
                        _mostRecentChangeDateTime = projectChangeDateTime;
                    }
                }
            }
            return _mostRecentChangeDateTime;
        }
        /// <summary>
        /// Load required fields attribute definitions for provided Asset type.
        /// </summary>
        /// <returns>Collection of attribute definitions for required fields</returns>
        private ICollection <IAttributeDefinition> LoadRequiredFields(IAssetType assetType)
        {
            ICollection <IAttributeDefinition> requiredFieldsForType = new List <IAttributeDefinition>();

            IAssetType           attributeDefinitionAssetType = metaModel.GetAssetType("AttributeDefinition");
            IAttributeDefinition nameAttributeDef             = attributeDefinitionAssetType.GetAttributeDefinition("Name");
            IAttributeDefinition assetNameAttributeDef        =
                attributeDefinitionAssetType.GetAttributeDefinition("Asset.AssetTypesMeAndDown.Name");

            Query query = new Query(attributeDefinitionAssetType);

            query.Selection.Add(nameAttributeDef);
            FilterTerm assetTypeTerm = new FilterTerm(assetNameAttributeDef);

            assetTypeTerm.Equal(assetType.Token);
            query.Filter = new AndFilterTerm(new IFilterTerm[] { assetTypeTerm });

            QueryResult result = services.Retrieve(query);

            foreach (Asset asset in result.Assets)
            {
                string name = asset.GetAttribute(nameAttributeDef).Value.ToString();
                if (IsRequiredField(assetType, name))
                {
                    IAttributeDefinition definition = assetType.GetAttributeDefinition(name);
                    requiredFieldsForType.Add(definition);
                }
            }

            return(requiredFieldsForType);
        }
Example #4
0
        public FilterTerm Term(IAttributeDefinition def)
        {
            var term = new FilterTerm(def);

            terms.Add(term);
            return(term);
        }
        protected Object GetSingleListValue(VersionOne.SDK.APIClient.Attribute attribute)
        {
            if (attribute.Value != null && attribute.Value.ToString() != "NULL")
            {
                IAssetType assetType = _metaAPI.GetAssetType("List");
                Query query = new Query(assetType);

                IAttributeDefinition assetIDAttribute = assetType.GetAttributeDefinition("ID");
                query.Selection.Add(assetIDAttribute);

                IAttributeDefinition nameAttribute = assetType.GetAttributeDefinition("Name");
                query.Selection.Add(nameAttribute);

                FilterTerm assetName = new FilterTerm(assetIDAttribute);
                assetName.Equal(attribute.Value.ToString());
                query.Filter = assetName;

                QueryResult result = _dataAPI.Retrieve(query);
                return result.Assets[0].GetAttribute(nameAttribute).Value.ToString();
            }
            else
            {
                return DBNull.Value;
            }
        }
        public static string GetAssetOid(string jiraId, string assetTypeStr)
        {
            var config = (JiraConnectionConfiguration)ConfigurationManager.GetSection("jiraAttachments");

            var metaconnector = new VersionOneAPIConnector(config.V1Connection.ServerUrl + "/meta.v1/");
            var dataconnector =
                new VersionOneAPIConnector(config.V1Connection.ServerUrl + "/rest-1.v1/")
                    .WithVersionOneUsernameAndPassword(config.V1Connection.Username, config.V1Connection.Password);

            MetaModel metaModel = new MetaModel(metaconnector);
            Services services = new Services(metaModel, dataconnector);

            var assetType = metaModel.GetAssetType(assetTypeStr);
            var query = new Query(assetType);
            var jiraIdAttribute = assetType.GetAttributeDefinition(GetV1IdCustomFieldName(assetTypeStr));
            query.Selection.Add(jiraIdAttribute);
            var jiraIdTerm = new FilterTerm(jiraIdAttribute);
            jiraIdTerm.Equal(jiraId);
            query.Filter = jiraIdTerm;

            var result = services.Retrieve(query);

            if (result.Assets.Count == 0)
            {
                return String.Empty;
            }
            return result.Assets[0].Oid.ToString();
        }
        public void FilterExist() {
            var assetType = Instance.ApiClient.MetaModel.GetAssetType("Story");

            var customFilter = new FilterTerm(assetType.GetAttributeDefinition("Timebox"));
            customFilter.Exists();

            var query = new Query(assetType) {Filter = customFilter};
            Instance.ApiClient.Services.Retrieve(query);
        }
 public User CreateUserToDeactivate(string username) {
     User user = CreateTestUser(username);
     user.Deactivate = true;
     IAssetType member = model.GetAssetType("Member");
     Query query = new Query(member);
     FilterTerm term = new FilterTerm(member.GetAttributeDefinition("Username"));
     term.Equal(username);
     query.Filter = term;
     QueryResult result = services.Retrieve(query);
     user.V1MemberAsset = result.Assets[0];
     return user;
 }
        public override int Export()
        {
            IAssetType assetType = _metaAPI.GetAssetType("AttributeDefinition");
            Query query = new Query(assetType);

            IAttributeDefinition nameAttribute = assetType.GetAttributeDefinition("Name");
            query.Selection.Add(nameAttribute);

            IAttributeDefinition isBasicAttribute = assetType.GetAttributeDefinition("IsBasic");
            query.Selection.Add(isBasicAttribute);

            IAttributeDefinition nativeValueAttribute = assetType.GetAttributeDefinition("NativeValue");
            query.Selection.Add(nativeValueAttribute);

            IAttributeDefinition isCustomAttribute = assetType.GetAttributeDefinition("IsCustom");
            query.Selection.Add(isCustomAttribute);

            IAttributeDefinition isReadOnlyAttribute = assetType.GetAttributeDefinition("IsReadOnly");
            query.Selection.Add(isReadOnlyAttribute);

            IAttributeDefinition isRequiredAttribute = assetType.GetAttributeDefinition("IsRequired");
            query.Selection.Add(isRequiredAttribute);

            IAttributeDefinition attributeTypeAttribute = assetType.GetAttributeDefinition("AttributeType");
            query.Selection.Add(attributeTypeAttribute);

            IAttributeDefinition assetNameAttribute = assetType.GetAttributeDefinition("Asset.Name");
            query.Selection.Add(assetNameAttribute);

            //Filter on asset type and if attribute definition is custom.
            FilterTerm assetName = new FilterTerm(assetNameAttribute);
            assetName.Equal(_InternalAssetType);
            FilterTerm isCustom = new FilterTerm(isCustomAttribute);
            isCustom.Equal("true");
            query.Filter = new AndFilterTerm(assetName, isCustom);

            QueryResult result = _dataAPI.Retrieve(query);

            int customFieldCount = 0;
            foreach (Asset asset in result.Assets)
            {
                string attributeName = GetScalerValue(asset.GetAttribute(nameAttribute)).ToString();
                string attributeType = GetScalerValue(asset.GetAttribute(attributeTypeAttribute)).ToString();
                if (attributeName.StartsWith("Custom_"))
                {
                    _logger.Info("The CustomField is {0} and Type is {1}", attributeName, attributeType);
                    customFieldCount += GetCustomFields(attributeName, attributeType);
                }
            }
            return customFieldCount;
        }
        private void CreateMultipleScopeFilter(FilterBuilder builder) {
            builder.Relation("Scope", projects);

            var metaModel = builder.Instance.ApiClient.MetaModel;
            var epicType = metaModel.GetAssetType("Epic");

            var scopeAttribute = epicType.GetAttributeDefinition("Scope");
            var scopeTerm = new FilterTerm(scopeAttribute);
            scopeTerm.Operate(FilterTerm.Operator.Equal, projects.Select(x => x.ToString()).Cast<object>().ToArray());
            var superAndUpAttribute = epicType.GetAttributeDefinition("SuperAndUp").Filter(scopeTerm);

            var superAndUpTerm = builder.Root.Term(superAndUpAttribute);
            superAndUpTerm.NotExists();
        }
        public static string GetV1IdCustomFieldName(string internalAssetTypeName)
        {
            var config = (JiraConnectionConfiguration)ConfigurationManager.GetSection("jiraAttachments");

            if (!String.IsNullOrEmpty(config.V1Connection.CustomField))
            {
                string customFieldName = String.Empty;

                var metaconnector = new VersionOneAPIConnector(config.V1Connection.ServerUrl + "/meta.v1/");
                var dataconnector =
                    new VersionOneAPIConnector(config.V1Connection.ServerUrl + "/rest-1.v1/")
                        .WithVersionOneUsernameAndPassword(config.V1Connection.Username, config.V1Connection.Password);

                MetaModel metaApi = new MetaModel(metaconnector);
                Services dataApi = new Services(metaApi,dataconnector);

                IAssetType assetType = metaApi.GetAssetType("AttributeDefinition");
                Query query = new Query(assetType);

                IAttributeDefinition nameAttribute = assetType.GetAttributeDefinition("Name");
                query.Selection.Add(nameAttribute);

                IAttributeDefinition isCustomAttribute = assetType.GetAttributeDefinition("IsCustom");
                query.Selection.Add(isCustomAttribute);

                IAttributeDefinition assetNameAttribute = assetType.GetAttributeDefinition("Asset.Name");
                query.Selection.Add(assetNameAttribute);

                FilterTerm assetName = new FilterTerm(assetNameAttribute);
                assetName.Equal(internalAssetTypeName);
                FilterTerm isCustom = new FilterTerm(isCustomAttribute);
                isCustom.Equal("true");
                query.Filter = new AndFilterTerm(assetName, isCustom);

                QueryResult result = dataApi.Retrieve(query);

                foreach (Asset asset in result.Assets)
                {
                    string attributeValue = asset.GetAttribute(nameAttribute).Value.ToString();
                    if (attributeValue.StartsWith(config.V1Connection.CustomField))
                    {
                        customFieldName = attributeValue;
                        break;
                    }
                }
                return customFieldName;
            }
            return null;
        }
        internal static string GetAssetIDFromCode(string AssetType, string Code, IMetaModel MetaAPI, IServices DataAPI)
        {
            IAssetType assetType = MetaAPI.GetAssetType(AssetType);
            Query query = new Query(assetType);
            IAttributeDefinition codeAttribute = assetType.GetAttributeDefinition("Code");
            FilterTerm term = new FilterTerm(codeAttribute);
            term.Equal(Code);
            query.Filter = term;
            QueryResult result = DataAPI.Retrieve(query);

            if (result.TotalAvaliable > 0)
                return result.Assets[0].Oid.Token;
            else
                return String.Empty;
        }
 public bool HasChangedSince(DateTime? lastCheckedDateTime)
 {
     if (!lastCheckedDateTime.HasValue)
     {
         return true;
     }
     var defectType = _meta.GetAssetType("Defect");
     var query = new Query(defectType);
     var changeAttribute = defectType.GetAttributeDefinition("ChangeDateUTC");
     var changeTerm = new FilterTerm(changeAttribute);
     changeTerm.Greater(lastCheckedDateTime.Value.ToString("yyyy-MM-ddTHH:mm:ss.fff", CultureInfo.InvariantCulture));
     var projectAttribute = defectType.GetAttributeDefinition("Scope");
     var projectTerm = new FilterTerm(projectAttribute);
     projectTerm.Equal(MonitoredProjects.Select(project => project.ScopeId).Cast<Object>().ToArray());
     query.Filter = new AndFilterTerm(changeTerm, projectTerm);
     var result = _services.Retrieve(query);
     return result.TotalAvaliable > 0;
 }
        private void CreateSingleScopeFilter(FilterBuilder builder) {
            var project = projects.First();

            var metaModel = builder.Instance.ApiClient.MetaModel;
            var epicType = metaModel.GetAssetType("Epic");
            var scopeType = metaModel.GetAssetType("Scope");

            var notClosedScopeAttribute = scopeType.GetAttributeDefinition("AssetState");
            var notClosedScopeTerm = new FilterTerm(notClosedScopeAttribute);
            notClosedScopeTerm.NotEqual("Closed");
            var scopeAttribute = epicType.GetAttributeDefinition("Scope.ParentMeAndUp").Filter(notClosedScopeTerm);
            var scopeTerm = builder.Root.Term(scopeAttribute);
            scopeTerm.Equal(project.ToString());

            var superAndUpAttribute = epicType.GetAttributeDefinition("SuperAndUp");
            superAndUpAttribute = superAndUpAttribute.Filter(scopeTerm);
            var superAndUpTerm = builder.Root.Term(superAndUpAttribute);
            superAndUpTerm.NotExists();
        }
        private List<RequiredFieldsDto> GetRequiredFields(string assetType) {
            var fields = new List<RequiredFieldsDto>();
            var attributeDefinitionAssetType = metaModel.GetAssetType("AttributeDefinition");
            var nameAttributeDef = attributeDefinitionAssetType.GetAttributeDefinition("Name");
            var assetNameAttributeDef = attributeDefinitionAssetType.GetAttributeDefinition("Asset.AssetTypesMeAndDown.Name");
            var taskType = metaModel.GetAssetType(assetType);

            var query = new Query(attributeDefinitionAssetType);
            query.Selection.Add(nameAttributeDef);
            var assetTypeTerm = new FilterTerm(assetNameAttributeDef);
            assetTypeTerm.Equal(assetType);
            query.Filter = new AndFilterTerm(new IFilterTerm[] { assetTypeTerm });

            QueryResult result;
            try {
                result = services.Retrieve(query);
            } catch (Exception ex) {
                logger.Error("Cannot get meta data for " + assetType, ex);
                return null;
            }

            foreach (var asset in result.Assets) {
                try {
                    var name = asset.GetAttribute(nameAttributeDef).Value.ToString();
                    
                    if(IsRequiredField(taskType, name)) {
                        var reqFieldData = new RequiredFieldsDto(name, taskType.GetAttributeDefinition(name).DisplayName);
                        fields.Add(reqFieldData);
                    }
                } catch(Exception ex) {
                    logger.Error("Cannot get meta data for " + assetType, ex);
                }
            }

            return fields;
        }
Example #16
0
        static void Main(string[] args)
        {
            var dataConnector = new VersionOneAPIConnector(BASE_URL + "/rest-1.v1/").WithOAuth2(SecretsFile, CredsFile);
            var metaConnector = new VersionOneAPIConnector(BASE_URL + "/meta.v1/");

            var metaModel = new MetaModel(metaConnector);
            var services = new Services(metaModel, dataConnector);

            var scopeType = metaModel.GetAssetType("Member");
            var nameAttr = scopeType.GetAttributeDefinition("Name");
            var descAttr = scopeType.GetAttributeDefinition("Nickname");
            var worksItemsNameAttr = scopeType.GetAttributeDefinition("OwnedWorkitems.Name");

            var query = new Query(scopeType);
            var whereAdmin = new FilterTerm(descAttr);
            whereAdmin.Equal("admin");
            var whereNotTheAdmin = new FilterTerm(nameAttr);
            whereNotTheAdmin.NotEqual("theAdmin");
            var andFilter = new AndFilterTerm(whereAdmin, whereNotTheAdmin);
            query.Filter = andFilter;
            query.Selection.AddRange(new[] { nameAttr, descAttr, worksItemsNameAttr });
            var result = services.Retrieve(query);

            foreach (var asset in result.Assets)
            {
                Console.WriteLine("Name: " + asset.GetAttribute(nameAttr).Value);
                Console.WriteLine("Description: " + asset.GetAttribute(descAttr).Value);
                var workItems = asset.GetAttribute(worksItemsNameAttr).ValuesList;
                Console.WriteLine("Workitems count: " + workItems.Count);
                foreach (var workitem in workItems)
                {
                        Console.WriteLine("Workitem: " + workitem);
                }
            }
            Console.ReadLine();
        }
        /// <summary>
        /// Gets collection of custom list fields for specified asset type.
        /// </summary>
        /// <param name="assetTypeName">Name of the asset type</param>
        /// <param name="fieldType">Field type</param>
        /// <returns>collection of custom list fields</returns>
        public IList<string> GetCustomFields(string assetTypeName, FieldType fieldType) {
            var attrType = services.Meta.GetAssetType("AttributeDefinition");
            var assetType = services.Meta.GetAssetType(assetTypeName);
            var isCustomAttributeDef = attrType.GetAttributeDefinition("IsCustom");
            var nameAttrDef = attrType.GetAttributeDefinition("Name");

            var termType = new FilterTerm(attrType.GetAttributeDefinition("Asset.AssetTypesMeAndDown.Name"));
            termType.Equal(assetTypeName);
            
            IAttributeDefinition inactiveDef;
            FilterTerm termState = null;

            if (assetType.TryGetAttributeDefinition("Inactive", out inactiveDef)) {
                termState = new FilterTerm(inactiveDef);
                termState.Equal("False");
            }

            var fieldTypeName = string.Empty;
            var attributeTypeName = string.Empty;

            switch(fieldType) {
                case FieldType.List:
                    fieldTypeName = "OneToManyRelationDefinition";
                    attributeTypeName = "Relation";
                    break;
                case FieldType.Numeric:
                    fieldTypeName = "SimpleAttributeDefinition";
                    attributeTypeName = "Numeric";
                    break;
                case FieldType.Text:
                    fieldTypeName = "SimpleAttributeDefinition";
                    attributeTypeName = "Text";
                    break;
            }

            var assetTypeTerm = new FilterTerm(attrType.GetAttributeDefinition("AssetType"));
            assetTypeTerm.Equal(fieldTypeName);

            var attributeTypeTerm = new FilterTerm(attrType.GetAttributeDefinition("AttributeType"));
            attributeTypeTerm.Equal(attributeTypeName);

            var isCustomTerm = new FilterTerm(isCustomAttributeDef);
            isCustomTerm.Equal("true");
            
            var result = GetFieldList(new AndFilterTerm(termState, termType, assetTypeTerm, isCustomTerm, attributeTypeTerm),
                new List<IAttributeDefinition> {nameAttrDef});

            var fieldList = new List<string>();
            result.ForEach(x => fieldList.Add(x.GetAttribute(nameAttrDef).Value.ToString()));

            return fieldList;
        }
        public override int Export()
        {
            IAssetType assetType = _metaAPI.GetAssetType("Test");
            Query query = new Query(assetType);

            IAttributeDefinition assetStateAttribute = assetType.GetAttributeDefinition("AssetState");
            query.Selection.Add(assetStateAttribute);

            IAttributeDefinition assetNumberAttribute = assetType.GetAttributeDefinition("Number");
            query.Selection.Add(assetNumberAttribute);

            IAttributeDefinition ownersAttribute = assetType.GetAttributeDefinition("Owners.ID");
            query.Selection.Add(ownersAttribute);

            IAttributeDefinition goalsAttribute = assetType.GetAttributeDefinition("Goals.ID");
            query.Selection.Add(goalsAttribute);

            IAttributeDefinition descriptionAttribute = assetType.GetAttributeDefinition("Description");
            query.Selection.Add(descriptionAttribute);

            IAttributeDefinition nameAttribute = assetType.GetAttributeDefinition("Name");
            query.Selection.Add(nameAttribute);

            IAttributeDefinition referenceAttribute = assetType.GetAttributeDefinition("Reference");
            query.Selection.Add(referenceAttribute);

            IAttributeDefinition toDoAttribute = assetType.GetAttributeDefinition("ToDo");
            query.Selection.Add(toDoAttribute);

            IAttributeDefinition detailEstimateAttribute = assetType.GetAttributeDefinition("DetailEstimate");
            query.Selection.Add(detailEstimateAttribute);

            IAttributeDefinition stepsAttribute = assetType.GetAttributeDefinition("Steps");
            query.Selection.Add(stepsAttribute);

            IAttributeDefinition inputsAttribute = assetType.GetAttributeDefinition("Inputs");
            query.Selection.Add(inputsAttribute);

            IAttributeDefinition setupAttribute = assetType.GetAttributeDefinition("Setup");
            query.Selection.Add(setupAttribute);

            IAttributeDefinition orderAttribute = assetType.GetAttributeDefinition("Order");
            query.Selection.Add(orderAttribute);

            IAttributeDefinition estimateAttribute = assetType.GetAttributeDefinition("Estimate");
            query.Selection.Add(estimateAttribute);

            IAttributeDefinition versionTestedAttribute = assetType.GetAttributeDefinition("VersionTested");
            query.Selection.Add(versionTestedAttribute);

            IAttributeDefinition actualResultsAttribute = assetType.GetAttributeDefinition("ActualResults");
            query.Selection.Add(actualResultsAttribute);

            IAttributeDefinition expectedResultsAttribute = assetType.GetAttributeDefinition("ExpectedResults");
            query.Selection.Add(expectedResultsAttribute);

            IAttributeDefinition statusAttribute = assetType.GetAttributeDefinition("Status");
            query.Selection.Add(statusAttribute);

            IAttributeDefinition categoryAttribute = assetType.GetAttributeDefinition("Category");
            query.Selection.Add(categoryAttribute);

            IAttributeDefinition parentAttribute = assetType.GetAttributeDefinition("Parent");
            query.Selection.Add(parentAttribute);

            IAttributeDefinition generatedFromAttribute = assetType.GetAttributeDefinition("GeneratedFrom");
            query.Selection.Add(generatedFromAttribute);

            //Filter on parent scope.
            IAttributeDefinition parentScopeAttribute = assetType.GetAttributeDefinition("Scope.ParentMeAndUp");
            FilterTerm term = new FilterTerm(parentScopeAttribute);
            term.Equal(_config.V1SourceConnection.Project);
            query.Filter = term;

            string SQL = BuildTestInsertStatement();

            if (_config.V1Configurations.PageSize != 0)
            {
                query.Paging.Start = 0;
                query.Paging.PageSize = _config.V1Configurations.PageSize;
            }

            int assetCounter = 0;
            int assetTotal = 0;

            do
            {
                QueryResult result = _dataAPI.Retrieve(query);
                assetTotal = result.TotalAvaliable;

                foreach (Asset asset in result.Assets)
                {
                    using (SqlCommand cmd = new SqlCommand())
                    {
                        //NAME NPI MASK:
                        object name = GetScalerValue(asset.GetAttribute(nameAttribute));
                        if (_config.V1Configurations.UseNPIMasking == true && name != DBNull.Value)
                        {
                            name = ExportUtils.RemoveNPI(name.ToString());
                        }

                        //DESCRIPTION NPI MASK:
                        object description = GetScalerValue(asset.GetAttribute(descriptionAttribute));
                        if (_config.V1Configurations.UseNPIMasking == true && description != DBNull.Value)
                        {
                            description = ExportUtils.RemoveNPI(description.ToString());
                        }

                        //REFERENCE NPI MASK:
                        object reference = GetScalerValue(asset.GetAttribute(referenceAttribute));
                        if (_config.V1Configurations.UseNPIMasking == true && reference != DBNull.Value)
                        {
                            reference = ExportUtils.RemoveNPI(reference.ToString());
                        }

                        //STEPS NPI MASK:
                        object steps = GetScalerValue(asset.GetAttribute(stepsAttribute));
                        if (_config.V1Configurations.UseNPIMasking == true && steps != DBNull.Value)
                        {
                            steps = ExportUtils.RemoveNPI(steps.ToString());
                        }

                        //INPUTS NPI MASK:
                        object inputs = GetScalerValue(asset.GetAttribute(inputsAttribute));
                        if (_config.V1Configurations.UseNPIMasking == true && inputs != DBNull.Value)
                        {
                            inputs = ExportUtils.RemoveNPI(inputs.ToString());
                        }

                        //SETUP NPI MASK:
                        object setup = GetScalerValue(asset.GetAttribute(setupAttribute));
                        if (_config.V1Configurations.UseNPIMasking == true && setup != DBNull.Value)
                        {
                            setup = ExportUtils.RemoveNPI(setup.ToString());
                        }

                        //VERSION TESTED NPI MASK:
                        object versionTested = GetScalerValue(asset.GetAttribute(versionTestedAttribute));
                        if (_config.V1Configurations.UseNPIMasking == true && versionTested != DBNull.Value)
                        {
                            versionTested = ExportUtils.RemoveNPI(versionTested.ToString());
                        }

                        //ACTUAL RESULTS NPI MASK:
                        object actualResults = GetScalerValue(asset.GetAttribute(actualResultsAttribute));
                        if (_config.V1Configurations.UseNPIMasking == true && actualResults != DBNull.Value)
                        {
                            actualResults = ExportUtils.RemoveNPI(actualResults.ToString());
                        }

                        //EXPECTED RESULTS NPI MASK:
                        object expectedResults = GetScalerValue(asset.GetAttribute(expectedResultsAttribute));
                        if (_config.V1Configurations.UseNPIMasking == true && expectedResults != DBNull.Value)
                        {
                            expectedResults = ExportUtils.RemoveNPI(expectedResults.ToString());
                        }

                        cmd.Connection = _sqlConn;
                        cmd.CommandText = SQL;
                        cmd.CommandType = System.Data.CommandType.Text;
                        cmd.Parameters.AddWithValue("@AssetOID", asset.Oid.ToString());
                        cmd.Parameters.AddWithValue("@AssetState", GetScalerValue(asset.GetAttribute(assetStateAttribute)));
                        cmd.Parameters.AddWithValue("@AssetNumber", GetScalerValue(asset.GetAttribute(assetNumberAttribute)));
                        cmd.Parameters.AddWithValue("@Owners", GetMultiRelationValues(asset.GetAttribute(ownersAttribute)));
                        cmd.Parameters.AddWithValue("@Goals", GetMultiRelationValues(asset.GetAttribute(goalsAttribute)));
                        cmd.Parameters.AddWithValue("@Description", description);
                        cmd.Parameters.AddWithValue("@Name", name);
                        cmd.Parameters.AddWithValue("@Reference", reference);
                        cmd.Parameters.AddWithValue("@ToDo", GetScalerValue(asset.GetAttribute(toDoAttribute)));
                        cmd.Parameters.AddWithValue("@DetailEstimate", GetScalerValue(asset.GetAttribute(detailEstimateAttribute)));
                        cmd.Parameters.AddWithValue("@Steps", steps);
                        cmd.Parameters.AddWithValue("@Inputs", inputs);
                        cmd.Parameters.AddWithValue("@Setup", setup);
                        cmd.Parameters.AddWithValue("@Order", GetScalerValue(asset.GetAttribute(orderAttribute)));
                        cmd.Parameters.AddWithValue("@Estimate", GetScalerValue(asset.GetAttribute(estimateAttribute)));
                        cmd.Parameters.AddWithValue("@VersionTested", versionTested);
                        cmd.Parameters.AddWithValue("@ActualResults", actualResults);
                        cmd.Parameters.AddWithValue("@ExpectedResults", expectedResults);
                        cmd.Parameters.AddWithValue("@Status", GetSingleRelationValue(asset.GetAttribute(statusAttribute)));
                        cmd.Parameters.AddWithValue("@Category", GetSingleRelationValue(asset.GetAttribute(categoryAttribute)));
                        cmd.Parameters.AddWithValue("@Parent", GetSingleRelationValue(asset.GetAttribute(parentAttribute)));
                        cmd.Parameters.AddWithValue("@GeneratedFrom", GetSingleRelationValue(asset.GetAttribute(generatedFromAttribute)));
                        cmd.ExecuteNonQuery();
                    }
                    assetCounter++;
                }
                query.Paging.Start = assetCounter;
            } while (assetCounter != assetTotal);
            DeleteEpicTests();
            return assetCounter;
        }
Example #19
0
        //Verifies the connection to the V1 source instance.
        private static void VerifyV1TargetConnection()
        {
            try
            {
                _targetMetaConnector = new V1APIConnector(_config.V1TargetConnection.Url + "/meta.v1/");

                if (_config.V1TargetConnection.AuthenticationType == "standard")
                {
                    _targetDataConnector = new V1APIConnector(_config.V1TargetConnection.Url + "/rest-1.v1/", _config.V1TargetConnection.Username, _config.V1TargetConnection.Password, false);
                    _targetImageConnector = new V1APIConnector(_config.V1TargetConnection.Url + "/attachment.img/", _config.V1TargetConnection.Username, _config.V1TargetConnection.Password, false);
                }
                else if (_config.V1TargetConnection.AuthenticationType == "windows")
                {
                    _logger.Info("Connecting with user {0}.", System.Security.Principal.WindowsIdentity.GetCurrent().Name);
                    _targetDataConnector = new V1APIConnector(_config.V1TargetConnection.Url + "/rest-1.v1/", null, null, true);
                    _targetImageConnector = new V1APIConnector(_config.V1TargetConnection.Url + "/attachment.img/", null, null, true);

                }
                else if (_config.V1TargetConnection.AuthenticationType == "oauth")
                {
                    throw new Exception("OAuth authentication is not supported -- yet.");
                }
                else
                {
                    throw new Exception("Unable to determine the V1TargetConnection authentication type in the config file. Value used must be standard|windows|oauth.");
                }

                _targetMetaAPI = new MetaModel(_targetMetaConnector);
                _targetDataAPI = new Services(_targetMetaAPI, _targetDataConnector);

                IAssetType assetType = _targetMetaAPI.GetAssetType("Member");
                Query query = new Query(assetType);
                IAttributeDefinition nameAttribute = assetType.GetAttributeDefinition("Username");
                query.Selection.Add(nameAttribute);
                FilterTerm idFilter = new FilterTerm(nameAttribute);
                idFilter.Equal(_config.V1TargetConnection.Username);
                query.Filter = idFilter;
                QueryResult result = _targetDataAPI.Retrieve(query);
                if (result.TotalAvaliable > 0)
                {
                    _logger.Info("-> Connection to V1 target instance \"{0}\" verified.", _config.V1TargetConnection.Url);
                    _logger.Info("-> V1 target instance version: {0}.", _targetMetaAPI.Version.ToString());
                    MigrationStats.WriteStat(_sqlConn, "Target API Version", _targetMetaAPI.Version.ToString());
                }
                else
                {
                    throw new Exception(String.Format("Unable to validate connection to {0} with username {1}. You may not have permission to access this instance.", _config.V1TargetConnection.Url, _config.V1TargetConnection.Username));
                }
            }
            catch (Exception ex)
            {
                _logger.Error("-> Unable to connect to V1 source instance \"{0}\".", _config.V1TargetConnection.Url);
                throw ex;
            }
        }
        private Query GetPropertyValuesQuery(string propertyName, out IAttributeDefinition nameDef)
        {
            var assetType = metaModel.GetAssetType(propertyName);
            nameDef = assetType.GetAttributeDefinition(Entity.NameProperty);

            IAttributeDefinition inactiveDef;

            var query = new Query(assetType);
            query.Selection.Add(nameDef);

            if (assetType.TryGetAttributeDefinition(Entity.InactiveProperty, out inactiveDef)) {
                var filter = new FilterTerm(inactiveDef);
                filter.Equal("False");
                query.Filter = filter;
            }

            query.OrderBy.MajorSort(assetType.DefaultOrderBy, OrderBy.Order.Ascending);
            return query;
        }
 public static Tuple<string, object, FilterTerm.Operator> Get(string field,
                                                              object value, FilterTerm.Operator oper = FilterTerm.Operator.Equal)
 {
     return new Tuple<string, object, FilterTerm.Operator>(field, value, oper);
 }
        /// <summary>
        /// Get Source values from VersionOne server
        /// </summary>
        public List<string> GetSourceList() {
            var assetType = services.Meta.GetAssetType("StorySource");
            var nameDef = assetType.GetAttributeDefinition("Name");
            IAttributeDefinition inactiveDef;

            var query = new Query(assetType);
            query.Selection.Add(nameDef);
            
            if(assetType.TryGetAttributeDefinition("Inactive", out inactiveDef)) {
                var filter = new FilterTerm(inactiveDef);
                filter.Equal("False");
                query.Filter = filter;
            }

            query.OrderBy.MajorSort(assetType.DefaultOrderBy, OrderBy.Order.Ascending);

            return services.Retrieve(query).Assets.Select(asset => asset.GetAttribute(nameDef).Value.ToString()).ToList();
        }
        protected string GetCustomListTypeAssetOIDFromV1(string AssetType, string AssetValue)
        {
            IAssetType assetType = _metaAPI.GetAssetType(AssetType);
            Query query = new Query(assetType);
            IAttributeDefinition nameAttribute = assetType.GetAttributeDefinition("Name");
            FilterTerm term = new FilterTerm(nameAttribute);
            term.Equal(AssetValue);
            query.Filter = term;

            QueryResult result;
            try
            {
                result = _dataAPI.Retrieve(query);
            }
            catch
            {
                return null;
            }

            if (result.TotalAvaliable > 0)
                return result.Assets[0].Oid.Token.ToString();
            else
                return null;
        }
        protected string CheckForDuplicateIterationByDate(string ScheduleOID, string BeginDate)
        {
            IAssetType assetType = _metaAPI.GetAssetType("Timebox");
            Query query = new Query(assetType);

            IAttributeDefinition scheduleAttribute = assetType.GetAttributeDefinition("Schedule");
            query.Selection.Add(scheduleAttribute);
            FilterTerm scheduleFilter = new FilterTerm(scheduleAttribute);
            scheduleFilter.Equal(GetNewAssetOIDFromDB(ScheduleOID));

            IAttributeDefinition beginDateAttribute = assetType.GetAttributeDefinition("BeginDate");
            query.Selection.Add(beginDateAttribute);
            FilterTerm beginDateFilter = new FilterTerm(beginDateAttribute);
            beginDateFilter.Equal(BeginDate);

            //IAttributeDefinition endDateAttribute = assetType.GetAttributeDefinition("EndDate");
            //query.Selection.Add(endDateAttribute);
            //FilterTerm endDateFilter = new FilterTerm(endDateAttribute);
            //endDateFilter.Equal(EndDate);

            query.Filter = new AndFilterTerm(scheduleFilter, beginDateFilter);
            QueryResult result = _dataAPI.Retrieve(query);

            if (result.TotalAvaliable > 0)
                return result.Assets[0].Oid.Token.ToString();
            else
                return null;
        }
        protected string CheckForDuplicateIterationByName(string ScheduleOID, string Name)
        {
            IAssetType assetType = _metaAPI.GetAssetType("Timebox");
            Query query = new Query(assetType);

            IAttributeDefinition scheduleAttribute = assetType.GetAttributeDefinition("Schedule");
            query.Selection.Add(scheduleAttribute);
            FilterTerm scheduleFilter = new FilterTerm(scheduleAttribute);
            scheduleFilter.Equal(GetNewAssetOIDFromDB(ScheduleOID));

            IAttributeDefinition nameAttribute = assetType.GetAttributeDefinition("Name");
            query.Selection.Add(nameAttribute);
            FilterTerm nameFilter = new FilterTerm(nameAttribute);
            nameFilter.Equal(Name);

            query.Filter = new AndFilterTerm(scheduleFilter, nameFilter);
            QueryResult result = _dataAPI.Retrieve(query);

            if (result.TotalAvaliable > 0)
                return result.Assets[0].Oid.Token.ToString();
            else
                return null;
        }
        protected string CheckForDuplicateInV1(string AssetType, string AttributeName, string AttributeValue)
        {
            IAssetType assetType = _metaAPI.GetAssetType(AssetType);
            Query query = new Query(assetType);

            IAttributeDefinition valueAttribute = assetType.GetAttributeDefinition(AttributeName);
            query.Selection.Add(valueAttribute);
            FilterTerm idFilter = new FilterTerm(valueAttribute);
            idFilter.Equal(AttributeValue);
            query.Filter = idFilter;
            QueryResult result = _dataAPI.Retrieve(query);

            if (result.TotalAvaliable > 0)
                return result.Assets[0].Oid.Token.ToString();
            else
                return null;
        }
        private string GetStoryNumber(string depOid)
        {
            IAssetType assetType = _metaAPI.GetAssetType("Story");
            Query query = new Query(assetType);

            IAttributeDefinition numberAttribute = assetType.GetAttributeDefinition("Number");
            query.Selection.Add(numberAttribute);

            //Filter on Story OID
            IAttributeDefinition assetIDAttribute = assetType.GetAttributeDefinition("ID");
            FilterTerm term = new FilterTerm(assetIDAttribute);
            term.Equal(depOid);
            query.Filter = term;

            QueryResult result = _dataAPI.Retrieve(query);

            Asset asset = result.Assets[0];
            string attributeName = GetScalerValue(asset.GetAttribute(numberAttribute)).ToString();
            return attributeName;
        
        }
        public override int Export()
        {
            IAssetType assetType = _metaAPI.GetAssetType("Story");
            Query query = new Query(assetType);

            IAttributeDefinition assetStateAttribute = assetType.GetAttributeDefinition("AssetState");
            query.Selection.Add(assetStateAttribute);

            IAttributeDefinition assetNumberAttribute = assetType.GetAttributeDefinition("Number");
            query.Selection.Add(assetNumberAttribute);

            IAttributeDefinition timeboxAttribute = assetType.GetAttributeDefinition("Timebox");
            query.Selection.Add(timeboxAttribute);

            IAttributeDefinition customerAttribute = assetType.GetAttributeDefinition("Customer");
            query.Selection.Add(customerAttribute);

            IAttributeDefinition ownersAttribute = assetType.GetAttributeDefinition("Owners.ID");
            query.Selection.Add(ownersAttribute);

            IAttributeDefinition identifiedInAttribute = assetType.GetAttributeDefinition("IdentifiedIn");
            query.Selection.Add(identifiedInAttribute);

            IAttributeDefinition teamAttribute = assetType.GetAttributeDefinition("Team");
            query.Selection.Add(teamAttribute);

            IAttributeDefinition goalsAttribute = assetType.GetAttributeDefinition("Goals.ID");
            query.Selection.Add(goalsAttribute);

            IAttributeDefinition affectedByDefectsAttribute = assetType.GetAttributeDefinition("AffectedByDefects.ID");
            query.Selection.Add(affectedByDefectsAttribute);

            IAttributeDefinition superAttribute = assetType.GetAttributeDefinition("Super");
            query.Selection.Add(superAttribute);

            IAttributeDefinition descriptionAttribute = assetType.GetAttributeDefinition("Description");
            query.Selection.Add(descriptionAttribute);

            IAttributeDefinition nameAttribute = assetType.GetAttributeDefinition("Name");
            query.Selection.Add(nameAttribute);

            IAttributeDefinition referenceAttribute = assetType.GetAttributeDefinition("Reference");
            query.Selection.Add(referenceAttribute);

            IAttributeDefinition toDoAttribute = assetType.GetAttributeDefinition("ToDo");
            query.Selection.Add(toDoAttribute);

            IAttributeDefinition detailEstimateAttribute = assetType.GetAttributeDefinition("DetailEstimate");
            query.Selection.Add(detailEstimateAttribute);

            IAttributeDefinition orderAttribute = assetType.GetAttributeDefinition("Order");
            query.Selection.Add(orderAttribute);

            IAttributeDefinition estimateAttribute = assetType.GetAttributeDefinition("Estimate");
            query.Selection.Add(estimateAttribute);

            IAttributeDefinition lastVersionAttribute = assetType.GetAttributeDefinition("LastVersion");
            query.Selection.Add(lastVersionAttribute);

            IAttributeDefinition originalEstimateAttribute = assetType.GetAttributeDefinition("OriginalEstimate");
            query.Selection.Add(originalEstimateAttribute);

            IAttributeDefinition requestedByAttribute = assetType.GetAttributeDefinition("RequestedBy");
            query.Selection.Add(requestedByAttribute);

            IAttributeDefinition valueAttribute = assetType.GetAttributeDefinition("Value");
            query.Selection.Add(valueAttribute);

            IAttributeDefinition scopeAttribute = assetType.GetAttributeDefinition("Scope");
            query.Selection.Add(scopeAttribute);

            IAttributeDefinition statusAttribute = assetType.GetAttributeDefinition("Status");
            query.Selection.Add(statusAttribute);

            IAttributeDefinition categoryAttribute = assetType.GetAttributeDefinition("Category");
            query.Selection.Add(categoryAttribute);

            IAttributeDefinition riskAttribute = assetType.GetAttributeDefinition("Risk");
            query.Selection.Add(riskAttribute);

            IAttributeDefinition sourceAttribute = assetType.GetAttributeDefinition("Source");
            query.Selection.Add(sourceAttribute);

            IAttributeDefinition priorityAttribute = assetType.GetAttributeDefinition("Priority");
            query.Selection.Add(priorityAttribute);

            IAttributeDefinition dependenciesAttribute = assetType.GetAttributeDefinition("Dependencies.ID");
            query.Selection.Add(dependenciesAttribute);

            IAttributeDefinition dependantsAttribute = assetType.GetAttributeDefinition("Dependants.ID");
            query.Selection.Add(dependantsAttribute);

            IAttributeDefinition parentAttribute = assetType.GetAttributeDefinition("Parent");
            query.Selection.Add(parentAttribute);

            IAttributeDefinition requestsAttribute = assetType.GetAttributeDefinition("Requests.ID");
            query.Selection.Add(requestsAttribute);

            IAttributeDefinition blockingIssuesAttribute = assetType.GetAttributeDefinition("BlockingIssues.ID");
            query.Selection.Add(blockingIssuesAttribute);

            IAttributeDefinition issuesAttribute = assetType.GetAttributeDefinition("Issues.ID");
            query.Selection.Add(issuesAttribute);

            IAttributeDefinition benefitsAttribute = assetType.GetAttributeDefinition("Benefits");
            query.Selection.Add(benefitsAttribute);

            IAttributeDefinition subStateAttribute = null;
            if (_metaAPI.Version.Major < 12)
            {
                subStateAttribute = assetType.GetAttributeDefinition("SubState");
                query.Selection.Add(subStateAttribute);
            }

            //Filter on parent scope.
            IAttributeDefinition parentScopeAttribute = assetType.GetAttributeDefinition("Scope.ParentMeAndUp");
            FilterTerm term = new FilterTerm(parentScopeAttribute);
            term.Equal(_config.V1SourceConnection.Project);
            query.Filter = term;

            string SQL = BuildStoryInsertStatement();

            if (_config.V1Configurations.PageSize != 0)
            {
                query.Paging.Start = 0;
                query.Paging.PageSize = _config.V1Configurations.PageSize;
            }

            int assetCounter = 0;
            int assetTotal = 0;

            do
            {
                QueryResult result = _dataAPI.Retrieve(query);
                assetTotal = result.TotalAvaliable;

                foreach (Asset asset in result.Assets)
                {
                    using (SqlCommand cmd = new SqlCommand())
                    {
                        
                        
                        //NAME NPI MASK:
                        object name = GetScalerValue(asset.GetAttribute(nameAttribute));
                        if (_config.V1Configurations.UseNPIMasking == true && name != DBNull.Value)
                        {
                            name = ExportUtils.RemoveNPI(name.ToString());
                        }

                        //DESCRIPTION NPI MASK:
                        object description = GetScalerValue(asset.GetAttribute(descriptionAttribute));
                        if (_config.V1Configurations.UseNPIMasking == true && description != DBNull.Value)
                        {
                            description = ExportUtils.RemoveNPI(description.ToString());
                        }

                        //REFERENCE NPI MASK:
                        object reference = GetScalerValue(asset.GetAttribute(referenceAttribute));
                        if (_config.V1Configurations.UseNPIMasking == true && reference != DBNull.Value)
                        {
                            reference = ExportUtils.RemoveNPI(reference.ToString());
                        }

                        //REQUESTED BY NPI MASK:
                        object requestedBy = GetScalerValue(asset.GetAttribute(requestedByAttribute));
                        if (_config.V1Configurations.UseNPIMasking == true && requestedBy != DBNull.Value)
                        {
                            requestedBy = ExportUtils.RemoveNPI(requestedBy.ToString());
                        }

                        //LAST VERSION NPI MASK:
                        object lastVersion = GetScalerValue(asset.GetAttribute(lastVersionAttribute));
                        if (_config.V1Configurations.UseNPIMasking == true && lastVersion != DBNull.Value)
                        {
                            lastVersion = ExportUtils.RemoveNPI(lastVersion.ToString());
                        }

                        //BENEFITS NPI MASK:
                        object benefits = GetScalerValue(asset.GetAttribute(lastVersionAttribute));
                        if (_config.V1Configurations.UseNPIMasking == true && benefits != DBNull.Value)
                        {
                            benefits = ExportUtils.RemoveNPI(benefits.ToString());
                        }
                        

                        cmd.Connection = _sqlConn;
                        cmd.CommandText = SQL;
                        cmd.CommandType = System.Data.CommandType.Text;
                        cmd.Parameters.AddWithValue("@AssetOID", asset.Oid.ToString());
                        cmd.Parameters.AddWithValue("@AssetState", CheckStoryState(asset.GetAttribute(assetStateAttribute)));
                        cmd.Parameters.AddWithValue("@AssetNumber", GetScalerValue(asset.GetAttribute(assetNumberAttribute)));

                        if (_metaAPI.Version.Major < 12)
                            cmd.Parameters.AddWithValue("@SubState", GetScalerValue(asset.GetAttribute(subStateAttribute)));

                        cmd.Parameters.AddWithValue("@Timebox", GetSingleRelationValue(asset.GetAttribute(timeboxAttribute)));
                        cmd.Parameters.AddWithValue("@Customer", GetSingleRelationValue(asset.GetAttribute(customerAttribute)));
                        cmd.Parameters.AddWithValue("@Owners", GetMultiRelationValues(asset.GetAttribute(ownersAttribute)));
                        cmd.Parameters.AddWithValue("@IdentifiedIn", GetSingleRelationValue(asset.GetAttribute(identifiedInAttribute)));
                        cmd.Parameters.AddWithValue("@Team", GetSingleRelationValue(asset.GetAttribute(teamAttribute)));
                        cmd.Parameters.AddWithValue("@Goals", GetMultiRelationValues(asset.GetAttribute(goalsAttribute)));
                        cmd.Parameters.AddWithValue("@AffectedByDefects", GetMultiRelationValues(asset.GetAttribute(affectedByDefectsAttribute)));
                        cmd.Parameters.AddWithValue("@Super", GetSingleRelationValue(asset.GetAttribute(superAttribute)));
                        cmd.Parameters.AddWithValue("@Description", description);
                        cmd.Parameters.AddWithValue("@Name", name);
                        cmd.Parameters.AddWithValue("@Reference", reference);
                        cmd.Parameters.AddWithValue("@ToDo", GetScalerValue(asset.GetAttribute(toDoAttribute)));
                        cmd.Parameters.AddWithValue("@DetailEstimate", GetScalerValue(asset.GetAttribute(detailEstimateAttribute)));
                        cmd.Parameters.AddWithValue("@Order", GetScalerValue(asset.GetAttribute(orderAttribute)));
                        cmd.Parameters.AddWithValue("@Estimate", GetScalerValue(asset.GetAttribute(estimateAttribute)));
                        cmd.Parameters.AddWithValue("@LastVersion", lastVersion);
                        cmd.Parameters.AddWithValue("@OriginalEstimate", GetScalerValue(asset.GetAttribute(originalEstimateAttribute)));
                        cmd.Parameters.AddWithValue("@RequestedBy", requestedBy);
                        cmd.Parameters.AddWithValue("@Value", GetScalerValue(asset.GetAttribute(valueAttribute)));
                        cmd.Parameters.AddWithValue("@Scope", GetSingleRelationValue(asset.GetAttribute(scopeAttribute)));
                        cmd.Parameters.AddWithValue("@Status", GetSingleRelationValue(asset.GetAttribute(statusAttribute)));
                        cmd.Parameters.AddWithValue("@Category", GetSingleRelationValue(asset.GetAttribute(categoryAttribute)));
                        cmd.Parameters.AddWithValue("@Risk", GetSingleRelationValue(asset.GetAttribute(riskAttribute)));
                        cmd.Parameters.AddWithValue("@Source", GetSingleRelationValue(asset.GetAttribute(sourceAttribute)));
                        cmd.Parameters.AddWithValue("@Priority", GetSingleRelationValue(asset.GetAttribute(priorityAttribute)));
                        cmd.Parameters.AddWithValue("@Dependencies", GetMultiRelationValues(asset.GetAttribute(dependenciesAttribute)));
                        cmd.Parameters.AddWithValue("@Dependants", GetMultiRelationValues(asset.GetAttribute(dependantsAttribute)));
                        cmd.Parameters.AddWithValue("@Parent", GetSingleRelationValue(asset.GetAttribute(parentAttribute)));
                        cmd.Parameters.AddWithValue("@Requests", GetMultiRelationValues(asset.GetAttribute(requestsAttribute)));
                        cmd.Parameters.AddWithValue("@BlockingIssues", GetMultiRelationValues(asset.GetAttribute(blockingIssuesAttribute)));
                        cmd.Parameters.AddWithValue("@Issues", GetMultiRelationValues(asset.GetAttribute(issuesAttribute)));
                        cmd.Parameters.AddWithValue("@Benefits", benefits);
                        cmd.ExecuteNonQuery();
                    }
                    assetCounter++;
                }
                query.Paging.Start = assetCounter;
            } while (assetCounter != assetTotal);

            if (_config.V1Configurations.MigrateTemplates == false)
            {
                DeleteStoryTemplates();
            }

            //Check for Epics as Stories from V1 Major < 12
            //ExportEpics epicStory = new ExportEpics(_sqlConn, _metaAPI, _dataAPI, _config);
            //epicStory.Export();
            int rc = ExportEpicsFromStories();
            
            return assetCounter;
        }
        /// <summary>
        /// Load required fields attribute definitions for provided Asset type.
        /// </summary>
        /// <returns>Collection of attribute definitions for required fields</returns>
        private ICollection<IAttributeDefinition> LoadRequiredFields(IAssetType assetType)
        {
            ICollection<IAttributeDefinition> requiredFieldsForType = new List<IAttributeDefinition>();

            IAssetType attributeDefinitionAssetType = metaModel.GetAssetType("AttributeDefinition");
            IAttributeDefinition nameAttributeDef = attributeDefinitionAssetType.GetAttributeDefinition("Name");
            IAttributeDefinition assetNameAttributeDef =
                attributeDefinitionAssetType.GetAttributeDefinition("Asset.AssetTypesMeAndDown.Name");

            Query query = new Query(attributeDefinitionAssetType);
            query.Selection.Add(nameAttributeDef);
            FilterTerm assetTypeTerm = new FilterTerm(assetNameAttributeDef);
            assetTypeTerm.Equal(assetType.Token);
            query.Filter = new AndFilterTerm(new IFilterTerm[] { assetTypeTerm });

            QueryResult result = services.Retrieve(query);

            foreach (Asset asset in result.Assets)
            {
                string name = asset.GetAttribute(nameAttributeDef).Value.ToString();
                if (IsRequiredField(assetType, name))
                {
                    IAttributeDefinition definition = assetType.GetAttributeDefinition(name);
                    requiredFieldsForType.Add(definition);
                }
            }

            return requiredFieldsForType;
        }
        protected string GetV1IDCustomFieldName(string InternalAssetTypeName)
        {
            if (String.IsNullOrEmpty(_config.V1Configurations.CustomV1IDField) == false)
            {
                string customFieldName = String.Empty;

                IAssetType assetType = _metaAPI.GetAssetType("AttributeDefinition");
                Query query = new Query(assetType);

                IAttributeDefinition nameAttribute = assetType.GetAttributeDefinition("Name");
                query.Selection.Add(nameAttribute);

                IAttributeDefinition isCustomAttribute = assetType.GetAttributeDefinition("IsCustom");
                query.Selection.Add(isCustomAttribute);

                IAttributeDefinition assetNameAttribute = assetType.GetAttributeDefinition("Asset.Name");
                query.Selection.Add(assetNameAttribute);

                FilterTerm assetName = new FilterTerm(assetNameAttribute);
                assetName.Equal(InternalAssetTypeName);
                FilterTerm isCustom = new FilterTerm(isCustomAttribute);
                isCustom.Equal("true");
                query.Filter = new AndFilterTerm(assetName, isCustom);

                QueryResult result = _dataAPI.Retrieve(query);

                foreach (Asset asset in result.Assets)
                {
                    string attributeValue = asset.GetAttribute(nameAttribute).Value.ToString();
                    if (attributeValue.StartsWith(_config.V1Configurations.CustomV1IDField) == true)
                    {
                        customFieldName = attributeValue;
                        break;
                    }
                }
                return customFieldName;
            }
            else
            {
                return null;
            }
        }
        private Query GetPropertyValuesQuery(string propertyName, out IAttributeDefinition nameDef) {
            IAssetType assetType;
            
            try {
                assetType = services.Meta.GetAssetType(propertyName);
            } catch(MetaException ex) {
                throw new AssetTypeException(string.Format("{0} is unknown asset type.", propertyName), ex);
            }
            
            nameDef = assetType.GetAttributeDefinition("Name");

            IAttributeDefinition inactiveDef;
            var query = new Query(assetType);
            query.Selection.Add(nameDef);

            if (assetType.TryGetAttributeDefinition("Inactive", out inactiveDef)) {
                var filter = new FilterTerm(inactiveDef);
                filter.Equal("False");
                query.Filter = filter;
            }
            
            query.OrderBy.MajorSort(assetType.DefaultOrderBy, OrderBy.Order.Ascending);
            return query;
        }
        public List<ProjectWrapper> GetProjectList() {
            var projectType = services.Meta.GetAssetType(ProjectTypeToken);
            var scopeQuery = new Query(projectType, projectType.GetAttributeDefinition("Parent"));
            var stateTerm = new FilterTerm(projectType.GetAttributeDefinition("AssetState"));
            stateTerm.NotEqual(AssetState.Closed);
            scopeQuery.Filter = stateTerm;
            var nameDef = projectType.GetAttributeDefinition("Name");
            scopeQuery.Selection.Add(nameDef);
            scopeQuery.OrderBy.MajorSort(projectType.DefaultOrderBy, OrderBy.Order.Ascending);

            var result = services.Retrieve(scopeQuery);

            var roots = new List<ProjectWrapper>(result.Assets.Count);
            
            foreach (Asset asset in result.Assets) {
                roots.AddRange(GetProjectWrapperList(asset, nameDef, 0));
            }
            
            return roots;
        }