private void LoadAttributes(EAV.Model.IModelContainer container) { bool containerWasUnmodified = container.ObjectState == EAV.Model.ObjectState.Unmodified; HttpResponseMessage response = client.GetAsync(String.Format("api/metadata/containers/{0}/attributes", container.ContainerID.GetValueOrDefault())).Result; if (response.IsSuccessStatusCode) { container.Attributes.Clear(); var attributes = response.Content.ReadAsAsync <IEnumerable <EAVModelLibrary.ModelAttribute> >().Result; foreach (EAVModelLibrary.ModelAttribute attribute in attributes.OrderBy(it => it.Sequence)) { attribute.MarkUnmodified(); LoadAttributeUnits(attribute); container.Attributes.Add(attribute); attribute.MarkUnmodified(); } if (containerWasUnmodified) { container.MarkUnmodified(); } } else { throw (new ApplicationException("Attempt to get attributes failed.")); } }
private void LoadChildContainers(EAV.Model.IModelContainer parentContainer) { bool parentContainerWasUnmodified = parentContainer.ObjectState == EAV.Model.ObjectState.Unmodified; HttpResponseMessage response = client.GetAsync(String.Format("api/metadata/containers/{0}/containers", parentContainer.ContainerID.GetValueOrDefault())).Result; if (response.IsSuccessStatusCode) { parentContainer.ChildContainers.Clear(); var childContainers = response.Content.ReadAsAsync <IEnumerable <EAVModelLibrary.ModelChildContainer> >().Result; foreach (EAVModelLibrary.ModelChildContainer childContainer in childContainers.OrderBy(it => it.Sequence)) { childContainer.MarkUnmodified(); LoadAttributes(childContainer); LoadChildContainers(childContainer); parentContainer.ChildContainers.Add(childContainer); childContainer.MarkUnmodified(); } if (parentContainerWasUnmodified) { parentContainer.MarkUnmodified(); } } else { throw (new ApplicationException("Attempt to get root containers failed.")); } }
private void LoadChildInstances(EAV.Model.IModelInstance parentInstance, IEnumerable <EAV.Model.IModelContainer> containers) { bool ifParentInstanceWasUnmodified = parentInstance.ObjectState == EAV.Model.ObjectState.Unmodified; Dictionary <int?, bool> containerWasUnmodified = containers.ToDictionary(key => key.ContainerID, val => val.ObjectState == EAV.Model.ObjectState.Unmodified); HttpResponseMessage response = client.GetAsync(String.Format("api/data/instances/{0}/instances", parentInstance.InstanceID.GetValueOrDefault())).Result; if (response.IsSuccessStatusCode) { parentInstance.ChildInstances.Clear(); var childInstances = response.Content.ReadAsAsync <IEnumerable <EAVModelLibrary.ModelChildInstance> >().Result; foreach (EAVModelLibrary.ModelChildInstance childInstance in childInstances) { childInstance.MarkUnmodified(); EAV.Model.IModelContainer container = containers.Single(it => it.ContainerID == childInstance.ContainerID); childInstance.Container = container; if (container.Attributes.Any()) { LoadValues(childInstance, container.Attributes); } if (container.ChildContainers.Any()) { LoadChildInstances(childInstance, container.ChildContainers); } parentInstance.ChildInstances.Add(childInstance); childInstance.MarkUnmodified(); } if (ifParentInstanceWasUnmodified) { parentInstance.MarkUnmodified(); } foreach (var container in containers) { if (containerWasUnmodified[container.ContainerID]) { container.MarkUnmodified(); } } } else { throw (new ApplicationException("Attempt to get child instances failed.")); } }