protected void AddMultiValueRelation(IAssetType assetType, Asset asset, string TableName, string attributeName, string valueList)
        {
            IAttributeDefinition customerAttribute = assetType.GetAttributeDefinition(attributeName);

            string[] values = valueList.Split(';');
            foreach (string value in values)
            {
                //SPECIAL CASE: Skip "Member:20" for Scope.Members attribute.
                if (assetType.Token == "Scope" && attributeName == "Members" && value == "Member:20")
                {
                    continue;
                }

                if (String.IsNullOrEmpty(value))
                {
                    continue;
                }

                string newAssetOID = GetNewAssetOIDFromDB(value, TableName);

                if (String.IsNullOrEmpty(newAssetOID) == false)
                {
                    //SPECIAL CASE: Epic conversion issue. If setting story dependants or dependencies, ensure that we do not set for Epic values.
                    if ((attributeName == "Dependants" || attributeName == "Dependencies") && newAssetOID.Contains("Epic"))
                    {
                        continue;
                    }
                    else
                    {
                        asset.AddAttributeValue(customerAttribute, newAssetOID);
                    }
                }
            }
        }
        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 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)
        {
            //if (AssetType.StartsWith("Custom_"))
            //{
            //    return null;
            //}

            IAssetType assetType = _metaAPI.GetAssetType(AssetType);
            //_logger.Info("CheckForDuplicateInV1: assetType is {0} amd value is {1} ", AssetType, AttributeValue);

            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);
            }
        }
Exemple #5
0
        public void ValidateSingleFieldByName()
        {
            IAssetType defectType = AssetType(DefectTypeName);

            Assert.IsTrue(validator.IsRequired(defectType, TitleAttributeName));
            Assert.IsFalse(validator.IsRequired(defectType, ParentAttributeName));
        }
        internal AttributeSelection BuildSelection(IAssetType assetType)
        {
            var attributes = new AttributeSelection();

            attributes.AddRange(Selectors.Select(property => assetType.GetAttributeDefinition(ResolvePropertyName(property))));
            return(attributes);
        }
        private void SetParentEpics()
        {
            SqlDataReader sdr            = GetImportDataFromDBTable("Epics");
            int           setParentCount = 0;

            while (sdr.Read())
            {
                IAssetType assetType = _metaAPI.GetAssetType("Epic");
                Asset      asset     = GetAssetFromV1(sdr["NewAssetOID"].ToString());

                string newSuperAssetOID = string.Empty;

                //SPECIAL CASE: Need to account for epic conversion.
                IAttributeDefinition parentAttribute = assetType.GetAttributeDefinition("Super");
                if (sdr["AssetOID"].ToString().Contains("Story"))
                {
                    asset.SetAttributeValue(parentAttribute, GetNewEpicAssetOIDFromDB(sdr["Super"].ToString()));
                }
                else
                {
                    newSuperAssetOID = GetNewAssetOIDFromDB(sdr["Super"].ToString(), "Epics");
                    asset.SetAttributeValue(parentAttribute, newSuperAssetOID);
                }
                _dataAPI.Save(asset);
                _logger.Info("-> Set Parent for {0} Epic to {1}.", sdr["NewAssetOID"].ToString(), newSuperAssetOID);
                setParentCount++;
            }
            sdr.Close();
            _logger.Info("-> {0} Parents have been Set", setParentCount);
        }
        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());
        }
        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);
            }
        }
        // ---------------- Constructor ----------------

        protected AssetModel(IAssetManagerApi api, Asset asset, int assetTypeId, IAssetType assetType)
        {
            this.Api         = api;
            this.Asset       = asset;
            this.AssetTypeId = assetTypeId;
            this.AssetType   = assetType;
        }
        //private string GetConversationBelongsTo(string MemberOid, string conversation, string newConversation)
        private String GetConversationBelongsTo(string memberOID, SqlDataReader sdr)
        {
            string newConversationOID = GetNewConversationOIDFromDB(sdr["Conversation"].ToString(), "Conversations");

            if (String.IsNullOrEmpty(newConversationOID) == true)
            {
                IAssetType assetType = _metaAPI.GetAssetType("Conversation");
                Asset      newAsset  = _dataAPI.New(assetType, null);

                IAttributeDefinition authoredAtAttribute = assetType.GetAttributeDefinition("Participants");

                newAsset.AddAttributeValue(authoredAtAttribute, memberOID);

                _dataAPI.Save(newAsset);

                UpdateNewConversationOIDInDB("Conversations", sdr["AssetOid"].ToString(), newAsset.Oid.Momentless.ToString());

                return(newAsset.Oid.Momentless.ToString());
            }
            else
            {
                //UpdateNewConversationOIDInDB("Conversations", sdr["AssetOid"].ToString(), newConversationOID);
                //return newConversationOID;
                return(String.Empty);
            }
        }
        internal static string GetAssetIDFromName(string AssetType, string Name, IMetaModel MetaAPI, IServices DataAPI)
        {
            IAssetType           assetType     = MetaAPI.GetAssetType(AssetType);
            Query                query         = new Query(assetType);
            IAttributeDefinition nameAttribute = assetType.GetAttributeDefinition("Name");
            FilterTerm           term          = new FilterTerm(nameAttribute);

            term.Equal(Name);
            query.Filter = term;

            QueryResult result;

            try
            {
                result = DataAPI.Retrieve(query);
            }
            catch
            {
                return(String.Empty);
            }

            if (result.TotalAvaliable > 0)
            {
                return(result.Assets[0].Oid.Token);
            }
            else
            {
                return(String.Empty);
            }
        }
 public TestAttributeDefinition(IAssetType assetType, bool isMultiValue, bool isReadOnly, bool isRequired)
 {
     this.assetType = assetType;
     this.isMultiValue = isMultiValue;
     this.isReadOnly = isReadOnly;
     this.isRequired = isRequired;
 }
        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()));
        }
Exemple #15
0
        public override int Import()
        {
            SqlDataReader sdr = GetImportDataFromSproc("spGetLinksForImport");

            int importCount = 0;

            while (sdr.Read())
            {
                try
                {
                    //SPECIAL CASE: Link must have an associated asset.
                    if (String.IsNullOrEmpty(sdr["Asset"].ToString()))
                    {
                        UpdateImportStatus("Links", sdr["AssetOID"].ToString(), ImportStatuses.FAILED, "Link has no associated asset.");
                        continue;
                    }

                    //SPECIAL CASE: Link assocated asset must exist in target system.
                    string newAssetOID = GetNewAssetOIDFromDB(sdr["Asset"].ToString());
                    if (String.IsNullOrEmpty(newAssetOID))
                    {
                        UpdateImportStatus("Links", sdr["AssetOID"].ToString(), ImportStatuses.FAILED, "Link associated asset does not exist in target.");
                        continue;
                    }

                    IAssetType assetType = _metaAPI.GetAssetType("Link");
                    Asset      asset     = _dataAPI.New(assetType, null);

                    IAttributeDefinition onMenuAttribute = assetType.GetAttributeDefinition("OnMenu");
                    asset.SetAttributeValue(onMenuAttribute, sdr["OnMenu"].ToString());

                    IAttributeDefinition urlAttribute = assetType.GetAttributeDefinition("URL");
                    asset.SetAttributeValue(urlAttribute, sdr["URL"].ToString());

                    IAttributeDefinition nameAttribute = assetType.GetAttributeDefinition("Name");
                    asset.SetAttributeValue(nameAttribute, sdr["Name"].ToString());

                    IAttributeDefinition assetAttribute = assetType.GetAttributeDefinition("Asset");
                    asset.SetAttributeValue(assetAttribute, newAssetOID);

                    _dataAPI.Save(asset);
                    UpdateNewAssetOIDAndStatus("Links", sdr["AssetOID"].ToString(), asset.Oid.Momentless.ToString(), ImportStatuses.IMPORTED, "Link imported.");
                    importCount++;
                }
                catch (Exception ex)
                {
                    if (_config.V1Configurations.LogExceptions == true)
                    {
                        UpdateImportStatus("Links", sdr["AssetOID"].ToString(), ImportStatuses.FAILED, ex.Message);
                        continue;
                    }
                    else
                    {
                        throw ex;
                    }
                }
            }
            sdr.Close();
            return(importCount);
        }
        private void SetDefectDependencies()
        {
            SqlDataReader sdr = GetImportDataFromDBTable("Defects");

            while (sdr.Read())
            {
                IAssetType assetType = _metaAPI.GetAssetType("Defect");
                Asset      asset     = GetAssetFromV1(sdr["NewAssetOID"].ToString());

                IAttributeDefinition duplicateOfAttribute = assetType.GetAttributeDefinition("DuplicateOf");
                asset.SetAttributeValue(duplicateOfAttribute, GetNewAssetOIDFromDB(sdr["DuplicateOf"].ToString()));

                if (String.IsNullOrEmpty(sdr["AffectedPrimaryWorkitems"].ToString()) == false)
                {
                    IAttributeDefinition affectedPrimaryWorkitemsAttribute = assetType.GetAttributeDefinition("AffectedPrimaryWorkitems");
                    string[]             assetList = sdr["AffectedPrimaryWorkitems"].ToString().Split(';');
                    foreach (string item in assetList)
                    {
                        string assetOID = GetNewAssetOIDFromDB(item, "Stories");
                        if (String.IsNullOrEmpty(assetOID) == false)
                        {
                            asset.AddAttributeValue(affectedPrimaryWorkitemsAttribute, assetOID);
                        }
                    }
                }

                if (String.IsNullOrEmpty(sdr["AffectedByDefects"].ToString()) == false)
                {
                    AddMultiValueRelation(assetType, asset, "Defects", "AffectedByDefects", sdr["AffectedByDefects"].ToString());
                }
                _dataAPI.Save(asset);
            }
            sdr.Close();
        }
        /// <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);
        }
        public bool V1TestConnection(V1Connector CurrentV1Connection)
        {
            V1Logging Logs       = new V1Logging();
            bool      TestResult = false;
            IServices services   = new Services(CurrentV1Connection);

            try
            {
                Logs.LogEvent("Operation - Attempting Test Connection to VersionOne");

                Logs.LogEvent("Test - Testing URI - Pulling Meta");
                IAssetType defectType = services.Meta.GetAssetType("Scope");
                Logs.LogEvent("Test - Testing URI - SUCCESS");


                Logs.LogEvent("Test - Testing Token - Pulling Data");
                Oid        projectId = services.GetOid("Scope:0");
                IAssetType ScopeType = services.Meta.GetAssetType("Scope");
                Asset      NewScope  = services.New(defectType, projectId);

                Logs.LogEvent("Test - Testing Token - SUCCESS");

                TestResult = true;

                Logs.LogEvent("Operation - VersionOne Connection Test Complete - " + TestResult.ToString());
            }
            catch (Exception ex)
            {
                Logs.LogEvent("ERROR - Test Failure - " + ex.ToString());
                Logs.LogEvent("Operation - VersionOne Connection Test Complete - " + TestResult.ToString());
            }

            return(TestResult);
        }
Exemple #19
0
        private static IEnumerable <IAttributeDefinition> GetSuggestedSelection(IAssetType assetType, Type type)
        {
            var result = new AttributeSelection();

            for (var t = type; t != null; t = t.BaseType)
            {
                var attributes = t.GetCustomAttributes(typeof(MetaDataAttribute), false);

                foreach (MetaDataAttribute attrib in attributes)
                {
                    var names = attrib.DefaultAttributeSelectionNames;

                    if (!string.IsNullOrEmpty(names))
                    {
                        foreach (var name in names.Split(','))
                        {
                            IAttributeDefinition def;

                            if (assetType.TryGetAttributeDefinition(name, out def))
                            {
                                if (!result.Contains(def))
                                {
                                    result.Add(def);
                                }
                            }
                        }
                    }
                }
            }

            return(result);
        }
        protected void AddMultiValueRelation(IAssetType assetType, Asset asset, string TableName, string attributeName, string valueList)
        {
            IAttributeDefinition customerAttribute = assetType.GetAttributeDefinition(attributeName);
            string[] values = valueList.Split(';');
            foreach (string value in values)
            {
                //SPECIAL CASE: Skip "Member:20" for Scope.Members attribute.
                if (assetType.Token == "Scope" && attributeName == "Members" && value == "Member:20") continue;

                if (String.IsNullOrEmpty(value)) continue;

                string newAssetOID = GetNewAssetOIDFromDB(value, TableName);

                if (String.IsNullOrEmpty(newAssetOID) == false)

                    //SPECIAL CASE: Epic conversion issue. If setting story dependants or dependencies, ensure that we do not set for Epic values.
                    if ((attributeName == "Dependants" || attributeName == "Dependencies") && newAssetOID.Contains("Epic"))
                    {
                        continue;
                    }
                    else
                    {
                        asset.AddAttributeValue(customerAttribute, newAssetOID);
                    }
            }
        }
        internal QueryFind BuildFind(IAssetType assetType)
        {
            if (!string.IsNullOrEmpty(Find.SearchString))
            {
                var attributes = new AttributeSelection();

                if (Find.Fields.Count > 0)
                {
                    attributes.AddRange(Find.Fields.Select(field => assetType.GetAttributeDefinition(ResolvePropertyName(field))));
                }
                else
                {
                    if (assetType.ShortNameAttribute != null)
                    {
                        attributes.Add(assetType.ShortNameAttribute);
                    }

                    if (assetType.NameAttribute != null)
                    {
                        attributes.Add(assetType.NameAttribute);
                    }

                    if (assetType.DescriptionAttribute != null)
                    {
                        attributes.Add(assetType.DescriptionAttribute);
                    }
                }

                return(new QueryFind(Find.SearchString, attributes));
            }

            return(null);
        }
Exemple #22
0
        private void SetStoryDependencies()
        {
            _logger.Info("*****Setting Story Dependencies");

            SqlDataReader sdr = GetImportDataFromDBTable("Stories");

            while (sdr.Read())
            {
                IAssetType assetType = _metaAPI.GetAssetType("Story");
                Asset      asset     = null;

                if (String.IsNullOrEmpty(sdr["NewAssetOID"].ToString()) == false)
                {
                    asset = GetAssetFromV1(sdr["NewAssetOID"].ToString());
                }
                else
                {
                    continue;
                }

                if (String.IsNullOrEmpty(sdr["Dependencies"].ToString()) == false)
                {
                    AddMultiValueRelation(assetType, asset, "Stories", "Dependencies", sdr["Dependencies"].ToString());
                }

                if (String.IsNullOrEmpty(sdr["Dependants"].ToString()) == false)
                {
                    AddMultiValueRelation(assetType, asset, "Stories", "Dependants", sdr["Dependants"].ToString());
                }
                _dataAPI.Save(asset);
            }
            sdr.Close();
        }
Exemple #23
0
 public Asset(double expectedrate, IAssetType type)
 {
     this.expectedrate = expectedrate;
     this.assetType    = type;
     result            = assetType.evaluator();
     result_20ys       = Math.Pow((1 + expectedrate), 20) * result;
 }
Exemple #24
0
        public Asset New(IAssetType assetType, Oid context)
        {
            var doc = new XmlDocument();

            var path = assetType.Token;

            if (context != null && !context.IsNull)
            {
                path += "?ctx=" + context.Token;
            }

            try
            {
                Stream stream;
                if (_connector != null)
                {
                    path   = "New/" + path;
                    stream = _connector.GetData(path);
                }
                else
                {
                    _v1Connector.UseNewApi();
                    stream = _v1Connector.GetData(path);
                }
                doc.Load(stream);
                stream.Dispose();

                return(ParseNewAssetNode(doc.DocumentElement, assetType));
            }
            catch (Exception ex)
            {
                throw new APIException("Failed to get new asset!", assetType.Token, ex);
            }
        }
        public Asset(Oid oid) {
            if(oid.IsNull) {
                throw new ArgumentOutOfRangeException("oid", oid, "Cannot initialize Asset with NULL Oid");
            }

            this.oid = oid;
            assetType = oid.AssetType;
        }
 /// <summary>
 /// Get required fields for asset type.
 /// </summary>
 /// <param name="assetType">Asset type</param>
 private void GetRequiredFields(IAssetType assetType)
 {
     if (!requiredFields.ContainsKey(assetType))
     {
         ICollection <IAttributeDefinition> requiredFieldsForType = LoadRequiredFields(assetType);
         requiredFields.Add(assetType, requiredFieldsForType);
     }
 }
 public void Setup()
 {
     var environment = new EnvironmentContext();
     _metaModel = environment.MetaModel;
     _services = environment.Services;
     _storyAssetType = _metaModel.GetAssetType("Story");
     _projectId = LegacyIntegrationTestHelper.ProjectId;
 }
        internal IFilterTerm BuildFilter(IAssetType assetType, V1Instance instance)
        {
            var builder = new FilterBuilder(assetType, instance);

            InternalModifyFilter(builder);
            InternalModifyState(builder);
            return(builder.Root.HasTerms ? builder.Root : null);
        }
        public override int Import()
        {
            SqlDataReader sdr = GetImportDataFromDBTable("ListTypes");

            int importCount = 0;

            while (sdr.Read())
            {
                try
                {
                    //DUPLICATE CHECK:
                    string currentAssetOID = CheckForDuplicateInV1(sdr["AssetType"].ToString(), "Name", sdr["Name"].ToString());
                    if (string.IsNullOrEmpty(currentAssetOID) == false)
                    {
                        UpdateNewAssetOIDAndStatus("ListTypes", sdr["AssetOID"].ToString(), currentAssetOID, ImportStatuses.SKIPPED, "Duplicate list type.");
                    }
                    else
                    {
                        IAssetType assetType = _metaAPI.GetAssetType(sdr["AssetType"].ToString());
                        Asset      asset     = _dataAPI.New(assetType, null);

                        IAttributeDefinition fullNameAttribute = assetType.GetAttributeDefinition("Name");
                        asset.SetAttributeValue(fullNameAttribute, sdr["Name"].ToString());

                        IAttributeDefinition descAttribute = assetType.GetAttributeDefinition("Description");
                        asset.SetAttributeValue(descAttribute, sdr["Description"].ToString());

                        _dataAPI.Save(asset);
                        UpdateNewAssetOIDAndStatus("ListTypes", sdr["AssetOID"].ToString(), asset.Oid.Momentless.ToString(), ImportStatuses.IMPORTED, "List type imported.");
                        importCount++;
                        //_logger.Info("New List, AssetOID is {0} and Count is {1}", sdr["AssetOID"].ToString(), importCount);
                    }

                    //SPECIAL CASE: Need to handle conversion of epic list types.
                    if (sdr["AssetType"].ToString() == "StoryStatus" || sdr["AssetType"].ToString() == "StoryCategory" || sdr["AssetType"].ToString() == "WorkitemPriority")
                    {
                        importCount += ConvertEpicListType(sdr["AssetOID"].ToString(), sdr["AssetType"].ToString(), sdr["Name"].ToString(), sdr["Description"].ToString());
                    }
                }
                catch (Exception ex)
                {
                    //_logger.Info("Catching:  AssetOID is {0}", sdr["AssetOID"].ToString());


                    if (_config.V1Configurations.LogExceptions == true)
                    {
                        UpdateImportStatus("ListTypes", sdr["AssetOID"].ToString(), ImportStatuses.FAILED, ex.Message);
                        continue;
                    }
                    else
                    {
                        throw ex;
                    }
                }
            }
            sdr.Close();
            return(importCount);
        }
Exemple #30
0
        public Oid SaveAttachment(string filePath, Asset asset, string attachmentName)
        {
            if (string.IsNullOrWhiteSpace(filePath))
            {
                throw new ArgumentNullException("filePath");
            }
            if (!File.Exists(filePath))
            {
                throw new APIException(string.Format("File \"{0}\" does not exist.", filePath));
            }

            var                  mimeType              = MimeType.Resolve(filePath);
            IAssetType           attachmentType        = Meta.GetAssetType("Attachment");
            IAttributeDefinition attachmentAssetDef    = attachmentType.GetAttributeDefinition("Asset");
            IAttributeDefinition attachmentContent     = attachmentType.GetAttributeDefinition("Content");
            IAttributeDefinition attachmentContentType = attachmentType.GetAttributeDefinition("ContentType");
            IAttributeDefinition attachmentFileName    = attachmentType.GetAttributeDefinition("Filename");
            IAttributeDefinition attachmentNameAttr    = attachmentType.GetAttributeDefinition("Name");
            Asset                attachment            = New(attachmentType, Oid.Null);

            attachment.SetAttributeValue(attachmentNameAttr, attachmentName);
            attachment.SetAttributeValue(attachmentFileName, filePath);
            attachment.SetAttributeValue(attachmentContentType, mimeType);
            attachment.SetAttributeValue(attachmentContent, string.Empty);
            attachment.SetAttributeValue(attachmentAssetDef, asset.Oid);
            Save(attachment);

            string key = attachment.Oid.Key.ToString();

            using (Stream input = new FileStream(filePath, FileMode.Open, FileAccess.Read))
            {
                using (Stream output = _connector != null ? _connector.BeginRequest(key.Substring(key.LastIndexOf('/') + 1)) : _v1Connector.BeginRequest(key.Substring(key.LastIndexOf('/') + 1)))
                {
                    byte[] buffer = new byte[input.Length + 1];
                    while (true)
                    {
                        int read = input.Read(buffer, 0, buffer.Length);
                        if (read <= 0)
                        {
                            break;
                        }

                        output.Write(buffer, 0, read);
                    }
                }
            }
            if (_connector != null)
            {
                _connector.EndRequest(key.Substring(key.LastIndexOf('/') + 1), mimeType);
            }
            else
            {
                _v1Connector.UseAttachmentApi();
                _v1Connector.EndRequest(key.Substring(key.LastIndexOf('/') + 1), mimeType);
            }

            return(attachment.Oid);
        }
Exemple #31
0
        private void UpdateIterationName(string AssetOID, string Name)
        {
            Asset                asset             = GetAssetFromV1(AssetOID);
            IAssetType           assetType         = _metaAPI.GetAssetType("Timebox");
            IAttributeDefinition fullNameAttribute = assetType.GetAttributeDefinition("Name");

            asset.SetAttributeValue(fullNameAttribute, Name);
            _dataAPI.Save(asset);
        }
Exemple #32
0
        public void Setup()
        {
            var environment = new EnvironmentContext();

            _metaModel      = environment.MetaModel;
            _services       = environment.Services;
            _storyAssetType = _metaModel.GetAssetType("Story");
            _projectId      = LegacyIntegrationTestHelper.ProjectId;
        }
        public Oid(IAssetType assetType, int id, int? moment) {
            if(assetType == null) {
                throw new ArgumentNullException("assetType");
            }

            type = assetType;
            this.id = id;
            this.moment = moment;
        }
        public bool Is(IAssetType targettype) {
            for(IAssetType thistype = this; thistype != null; thistype = thistype.Base) {
                if (thistype == targettype) {
                    return true;
                }
            }

            return false;
        }
        [Test] public void Story()
        {
            IAssetType story = Meta.GetAssetType("Story");

            Assert.AreEqual("Story", story.Token);
            Assert.AreEqual("AssetType'Story", story.DisplayName);
            Assert.AreEqual("PrimaryWorkitem", story.Base.Token);
            Assert.AreEqual("Story.Order", story.DefaultOrderBy.Token);
        }
        private void CreateEffort(Asset asset, double effortValue)
        {
            effortType = connector.MetaModel.GetAssetType("Actual");
            var effort = connector.Services.New(effortType, asset.Oid);

            effort.SetAttributeValue(effortType.GetAttributeDefinition("Value"), effortValue);
            effort.SetAttributeValue(effortType.GetAttributeDefinition("Date"), DateTime.Now);
            connector.Services.Save(effort);
        }
        [Test] public void BaseAsset()
        {
            IAssetType baseasset = Meta.GetAssetType("BaseAsset");

            Assert.AreEqual("BaseAsset", baseasset.Token);
            Assert.AreEqual("AssetType'BaseAsset", baseasset.DisplayName);
            Assert.IsNull(baseasset.Base);
            Assert.AreEqual("BaseAsset.Name", baseasset.DefaultOrderBy.Token);
        }
        public static void Initialize(TestContext context)
        {
            Context = context;
            Configure(Context);
            ConfigureRoute(Context, "/meta.v1//", MetaSamplePayloads.FullSubset);
            var connector = CreateConnector();
            SUT = new Services(connector, true); // preLoadMeta = true!S

            AssetTypeType = SUT.Meta.GetAssetType("AssetType");
            PrimaryRelationType = SUT.Meta.GetAssetType("PrimaryRelation");
        }
 public GroupFilterTerm GetFilter(IAssetType type) {
     var filterArray = filters.Select(item => item.GetFilter(type)).ToArray();
     
     switch(groupAction) {
         case FilterActions.And:
             return new AndFilterTerm(filterArray);
         case FilterActions.Or:
             return new OrFilterTerm(filterArray);
         default:
             throw new NotSupportedException();
     }
 }
        public static void Initialize(TestContext context)
        {
            Context = context;
            Configure(Context);
            ConfigureRoute(Context, "/meta.v1//AssetType", MetaSamplePayloads.AssetTypeType);
            ConfigureRoute(Context, "/meta.v1//PrimaryRelation", MetaSamplePayloads.PrimaryRelationType);

            var connector = CreateConnector();
            SUT = new Services(connector);

            AssetTypeType = SUT.Meta.GetAssetType("AssetType");
            PrimaryRelationType = SUT.Meta.GetAssetType("PrimaryRelation");
        }
		public void TestFixtureSetUp()
		{
			V1APIConnector dataConnector = new V1APIConnector(v1Url + dataPath, username, password);
			V1APIConnector metaConnector = new V1APIConnector(v1Url + metaPath);
			V1APIConnector localConnector = new V1APIConnector(v1Url + localizationPath);
			
			localizer = new Localizer(localConnector);
			metaModel = new MetaModel(metaConnector);
			services = new Services(metaModel, dataConnector);

			timeboxType = metaModel.GetAssetType("Timebox");
			timeboxName = timeboxType.GetAttributeDefinition("Name");
			timeboxID = timeboxType.GetAttributeDefinition("ID");
		}
        public Query(Oid oid, bool historical) {
            Find = null;
            if(oid.IsNull) {
                throw new ApplicationException("Invalid Query OID Parameter");
            }
  
            if(oid.HasMoment && historical) {
                throw new NotSupportedException("Historical Query with Momented OID not supported");
            }

            isHistorical = historical;
            assetType = oid.AssetType;
            this.oid = oid;
        }
		public void TestFixtureSetUp() {
			var metaConnector = new V1APIConnector(V1Url + "/meta.v1/");
			var dataConnector = new V1APIConnector(V1Url + "/rest-1.v1/", Username, Password);
			metaModel = new MetaModel(metaConnector);
			services = new Services(metaModel, dataConnector);
			
			storyType = metaModel.GetAssetType("Story");
			storyDeleteOperation = storyType.GetOperation("Delete");

			nameDef = storyType.GetAttributeDefinition("Name");
			scopeDef = storyType.GetAttributeDefinition("Scope");
			changeDateDef = storyType.GetAttributeDefinition("ChangeDate");
			momentDef = storyType.GetAttributeDefinition("Moment");
			attributesToQuery = new[] {nameDef, scopeDef, changeDateDef, momentDef};
		}
        internal OrderBy BuildOrderBy(IAssetType assetType, IAttributeDefinition defaultOrderBy) {
            var order = new OrderBy();
            
            if (OrderBy.Count > 0) {
                foreach(var s in OrderBy) {
                    order.MinorSort(assetType.GetAttributeDefinition(ResolvePropertyName(s)), APIClient.OrderBy.Order.Ascending);
                }
            } else {
                if(defaultOrderBy != null) {
                    order.MinorSort(defaultOrderBy, APIClient.OrderBy.Order.Ascending);
                }
            }

            return order;
        }
        private void AddSelection(Query query, string typePrefix, IAssetType type) {
            foreach (var attrInfo in attributesToQuery.Where(attrInfo => attrInfo.Prefix == typePrefix)) {
                IAttributeDefinition def;
                
                if (attrInfo.IsOptional) {
                    if (!type.TryGetAttributeDefinition(attrInfo.Attr, out def)) {
                        continue;
                    }
                } else {
                    def = type.GetAttributeDefinition(attrInfo.Attr);
                }

                query.Selection.Add(def);
            }
        }
        public Query(IAssetType assetType, bool historical, IAttributeDefinition parentRelation) {
            Find = null;
            this.assetType = assetType;
            isHistorical = historical;
            oid = Oid.Null;
            this.parentRelation = parentRelation;
            
            if (this.parentRelation != null) {
                if(this.parentRelation.AttributeType != AttributeType.Relation) {
                    throw new ApplicationException("Parent Relation must be a Relation Attribute Type");
                }

                if(this.parentRelation.IsMultiValue) {
                    throw new ApplicationException("Parent Relation cannot be multi-value");
                }
            }
        }
 /// <summary>
 /// Get required fields for asset type.
 /// </summary>
 /// <param name="assetType">Asset type</param>
 private void GetRequiredFields(IAssetType assetType)
 {
     if (!requiredFields.ContainsKey(assetType))
     {
         ICollection<IAttributeDefinition> requiredFieldsForType = LoadRequiredFields(assetType);
         requiredFields.Add(assetType, requiredFieldsForType);
     }
 }
 public Query(IAssetType assetType, IAttributeDefinition parentrelation) : this(assetType, false, parentrelation) {}
 /// <summary>
 /// Check whether the attribute corresponding to the attributeName is required in current VersionOne server setup.
 /// </summary>
 /// <param name="assetType">Asset type</param>
 /// <param name="attributeName">Attribute name</param>
 /// <returns></returns>
 public bool IsRequired(IAssetType assetType, string attributeName)
 {
     return IsRequired(assetType.GetAttributeDefinition(attributeName));
 }
		public TestOid(IAssetType assetType, int id, int? moment)
			: base(assetType, id, moment)
		{
		}
        protected void AddRallyMentionsValue(IAssetType assetType, Asset asset, string baseAssetType, string assetOID)
        {
            IAttributeDefinition mentionsAttribute = assetType.GetAttributeDefinition("Mentions");
            string newAssetOID = String.Empty;

            if (baseAssetType == "Story")
            {
                //First try stories table.
                newAssetOID = GetNewAssetOIDFromDB(assetOID, "Stories");

                //If not found, try epics table.
                if (String.IsNullOrEmpty(newAssetOID) == true)
                {
                    newAssetOID = GetNewAssetOIDFromDB(assetOID, "Epics");
                }
            }
            else if (baseAssetType == "Defect")
            {
                newAssetOID = GetNewAssetOIDFromDB(assetOID, "Defects");
            }
            else if (baseAssetType == "Task")
            {
                newAssetOID = GetNewAssetOIDFromDB(assetOID, "Tasks");
            }
            else if (baseAssetType == "Test")
            {
                //First try tests table.
                newAssetOID = GetNewAssetOIDFromDB(assetOID, "Tests");

                //If not found, try regression tests table.
                if (String.IsNullOrEmpty(newAssetOID) == true)
                {
                    newAssetOID = GetNewAssetOIDFromDB(assetOID, "RegressionTests");
                }
            }

            if (String.IsNullOrEmpty(newAssetOID) == false)
                asset.AddAttributeValue(mentionsAttribute, newAssetOID);
        }
		public bool TryGetAssetType(string token, out IAssetType type)
		{
			type = null;
			try { type = LookupAssetType(token); } catch (Exception) { }
			return type != null;
		}
		private void SaveAssetType(IAssetType assettype)
		{
			_map[assettype.Token] = assettype;
		}
 public Query(IAssetType assetType, bool historical) : this(assetType, historical, null) {}
        /// <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;
        }
 public Asset New(IAssetType assetType, Oid context)
 {
     return _wrapped.New(assetType, context);
 }
 private static bool IsRequiredField(IAssetType assetType, string name)
 {
     IAttributeDefinition def = assetType.GetAttributeDefinition(name);
     return def.IsRequired && !def.IsReadOnly;
 }
        public IAttributeDefinition Downcast(IAssetType assetType)
        {
            if (AttributeType == AttributeType.Relation)
            {
                if (assetType.Is(RelatedAsset))
                {
                    return metaModel.GetAttributeDefinition(Token + ":" + assetType.Token);
                }

                throw new MetaException("Cannot downcast to unrelated type");
            }

            throw new MetaException("Cannot downcast non-relation attributes");
        }
 public IAttributeDefinition Downcast(IAssetType assetType)
 {
     throw new System.NotImplementedException();
 }
 public Query(IAssetType assetType) : this(assetType, false) {}