Exemplo n.º 1
0
        public void SaveMetadata(EAV.Model.IModelRootContainer container)
        {
            HttpResponseMessage response;

            if (container.Context.ObjectState != EAV.Model.ObjectState.Unmodified)
            {
                SaveContext(container.Context);
            }

            if (container.ObjectState == EAV.Model.ObjectState.New)
            {
                response = client.PostAsJsonAsync <EAV.Store.IStoreContainer>(String.Format("api/metadata/contexts/{0}/containers", container.ContextID.GetValueOrDefault()), container).Result;
                if (response.IsSuccessStatusCode)
                {
                    EAVModelLibrary.ModelContainer newContainer = response.Content.ReadAsAsync <EAVModelLibrary.ModelRootContainer>().Result;

                    container.ContainerID = newContainer.ContainerID;

                    container.MarkUnmodified();
                }
                else
                {
                    throw (new ApplicationException("Attempt to create metadata failed."));
                }
            }
            else if (container.ObjectState == EAV.Model.ObjectState.Modified)
            {
                response = client.PatchAsJsonAsync <EAV.Store.IStoreContainer>("api/metadata/containers", container).Result;
                if (response.IsSuccessStatusCode)
                {
                    container.MarkUnmodified();
                }
                else
                {
                    throw (new ApplicationException("Attempt to update metadata failed."));
                }
            }

            foreach (EAVModelLibrary.ModelAttribute attribute in container.Attributes)
            {
                SaveAttribute(attribute);
            }

            foreach (EAVModelLibrary.ModelChildContainer childContainer in container.ChildContainers)
            {
                SaveChildContainer(childContainer);
            }

            if (container.ObjectState == EAV.Model.ObjectState.Deleted)
            {
                response = client.DeleteAsync(String.Format("api/metadata/containers/{0}", container.ContainerID.GetValueOrDefault())).Result;
                if (response.IsSuccessStatusCode)
                {
                }
                else
                {
                    throw (new ApplicationException("Attempt to delete metadata failed."));
                }
            }
        }
Exemplo n.º 2
0
        public void LoadMetadata(EAV.Model.IModelRootContainer container)
        {
            try
            {
                bool containerWasUnmodified = container.ObjectState == EAV.Model.ObjectState.Unmodified;

                LoadAttributes(container);
                LoadChildContainers(container);

                if (containerWasUnmodified)
                {
                    container.MarkUnmodified();
                }
            }
            catch (Exception ex)
            {
                throw (new ApplicationException("Attempt to get metadata failed.", ex));
            }
        }
Exemplo n.º 3
0
        public void LoadRootInstances(EAV.Model.IModelSubject subject, EAV.Model.IModelRootContainer container)
        {
            bool subjectWasUnmodified   = subject.ObjectState == EAV.Model.ObjectState.Unmodified;
            bool containerWasUnmodified = container.ObjectState == EAV.Model.ObjectState.Unmodified;

            HttpResponseMessage response = client.GetAsync(String.Format("api/data/subjects/{0}/instances?container={1}", subject.SubjectID.GetValueOrDefault(), container != null ? container.ContainerID : null)).Result;

            if (response.IsSuccessStatusCode)
            {
                subject.Instances.Clear();

                var rootInstances = response.Content.ReadAsAsync <IEnumerable <EAVModelLibrary.ModelRootInstance> >().Result;
                foreach (EAVModelLibrary.ModelRootInstance rootInstance in rootInstances)
                {
                    rootInstance.MarkUnmodified();

                    rootInstance.Container = container;

                    if (container.Attributes.Any())
                    {
                        LoadValues(rootInstance, container.Attributes);
                    }

                    subject.Instances.Add(rootInstance);

                    rootInstance.MarkUnmodified();
                }

                if (containerWasUnmodified)
                {
                    container.MarkUnmodified();
                }

                if (subjectWasUnmodified)
                {
                    subject.MarkUnmodified();
                }
            }
            else
            {
                throw (new ApplicationException("Attempt to get root instances failed."));
            }
        }
Exemplo n.º 4
0
        public static EAV.Model.IModelRootInstance Create(EAV.Model.IModelRootContainer container, EAV.Model.IModelSubject subject)
        {
            ModelRootInstance instance = new ModelRootInstance()
            {
                Container = container,
                Subject   = subject,
            };

            foreach (ModelAttribute attribute in container.Attributes)
            {
                ModelValue.Create(attribute, instance);
            }

            foreach (ModelChildContainer childContainer in container.ChildContainers)
            {
                ModelChildInstance.Create(childContainer, subject, instance);
            }

            return(instance);
        }