Exemplo n.º 1
0
        /// <summary>
        /// Converts an <see cref="EditConceptModel"/> instance to a <see cref="Concept"/> instance.
        /// </summary>
        /// <param name="imsiServiceClient">The ImsiServiceClient instance.</param>
        /// <param name="concept">The concept.</param>
        /// <returns>Returns the converted concept instance.</returns>
        public Concept ToEditConceptModel(ImsiServiceClient imsiServiceClient, Concept concept)
        {
            concept.CreationTime = DateTimeOffset.Now;
            concept.VersionKey   = null;

            if (!string.Equals(this.ConceptClass, concept.ClassKey.ToString()))
            {
                concept.Class = new ConceptClass
                {
                    Key = Guid.Parse(this.ConceptClass)
                };
            }

            concept.Mnemonic = this.Mnemonic;

            if (string.IsNullOrWhiteSpace(AddReferenceTerm) || string.IsNullOrWhiteSpace(RelationshipType))
            {
                return(concept);
            }

            Guid id, relationshipKey;

            if (Guid.TryParse(AddReferenceTerm, out id) && Guid.TryParse(RelationshipType, out relationshipKey))
            {
                var term = imsiServiceClient.Get <ReferenceTerm>(id, null) as ReferenceTerm;
                if (term != null)
                {
                    concept.ReferenceTerms.Add(new ConceptReferenceTerm(term.Key, relationshipKey));
                }
            }

            return(concept);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets a specified model.
        /// </summary>
        /// <typeparam name="TModel">The type of model data to retrieve.</typeparam>
        /// <param name="key">The key of the model.</param>
        /// <param name="versionKey">The version key of the model.</param>
        /// <param name="options">The integrations query options.</param>
        /// <returns>Returns a model.</returns>
        public TModel Get <TModel>(Guid key, Guid?versionKey, IntegrationQueryOptions options = null) where TModel : IdentifiedData
        {
            try
            {
                ImsiServiceClient client = this.GetServiceClient(); //new ImsiServiceClient(ApplicationContext.Current.GetRestClient("imsi"));
                client.Client.Requesting += IntegrationQueryOptions.CreateRequestingHandler(options);
                client.Client.Responding += (o, e) => this.Responding?.Invoke(o, e);
                client.Client.Credentials = this.GetCredentials(client.Client);
                if (client.Client.Credentials == null)
                {
                    return(null);
                }

                this.m_tracer.TraceVerbose("Performing IMSI GET ({0}):{1}v{2}", typeof(TModel).FullName, key, versionKey);
                var retVal = client.Get <TModel>(key, versionKey);

                if (retVal is Bundle)
                {
                    (retVal as Bundle)?.Reconstitute();
                    return((retVal as Bundle).Entry as TModel);
                }
                else
                {
                    return(retVal as TModel);
                }
            }
            catch (TargetInvocationException e)
            {
                throw Activator.CreateInstance(e.InnerException.GetType(), "Error performing action", e) as Exception;
            }
        }