private async Task <ObjectInstance> GetObjectInstance(ObjectDefinition objectDefinition, ObjectType objectType, string objectInstanceID) { Link instancesLink = objectType.GetLink("instances"); ObjectInstance matchedObjectInstance = null; HttpContent objectInstancesContent = await HttpClient.GetContent(new HttpRequestMessage(HttpMethod.Get, instancesLink.href), null, StringUtils.ToPlural(objectDefinition.MIMEType), _OAuthToken); if (objectInstancesContent != null) { ObjectInstances objectInstances = new ObjectInstances(objectDefinition.ToModel(), await objectInstancesContent.ReadAsStreamAsync(), objectInstancesContent.Headers.ContentType.MediaType); foreach (ObjectInstance objectInstance in objectInstances.Items) { Link selfLink = objectInstance.GetLink("self"); if (selfLink != null) { string matchedObjectInstanceID = selfLink.href.Substring(selfLink.href.LastIndexOf('/') + 1); if (matchedObjectInstanceID.Equals(objectInstanceID)) { matchedObjectInstance = objectInstance; break; } } } } return(matchedObjectInstance); }
public IActionResult GetObjectInstances(string clientID, string definitionID) { IActionResult result; Guid definitionIDGuid, clientIDGuid; if (StringUtils.GuidTryDecode(definitionID, out definitionIDGuid) && StringUtils.GuidTryDecode(clientID, out clientIDGuid)) { int organisationID = User.GetOrganisationID(); Model.ObjectDefinition definition = BusinessLogicFactory.ObjectDefinitions.GetObjectDefinition(organisationID, definitionIDGuid); if (definition != null) { Model.Client client = BusinessLogicFactory.Clients.GetClient(clientIDGuid); if (client != null) { List <Model.Object> instances = BusinessLogicFactory.Clients.GetObjects(client, definition.ObjectDefinitionID); if (instances != null) { ObjectInstances response = new ObjectInstances(definition); string rootUrl = Request.GetRootUrl(); string instancesUrl = string.Concat(rootUrl, "/clients/", clientID, "/objecttypes/", StringUtils.GuidEncode(definition.ObjectDefinitionID), "/instances"); response.AddLink("add", instancesUrl, ""); response.PageInfo = Request.GetPageInfo(instances.Count); int endIndex = response.PageInfo.StartIndex + response.PageInfo.ItemsCount; for (int index = response.PageInfo.StartIndex; index < endIndex; index++) { ObjectInstance instance = new ObjectInstance(definition, instances[index]); string instanceUrl = string.Concat(instancesUrl, "/", instances[index].InstanceID); AddObjectInstanceLinks(Request, definition, instance, instanceUrl); response.Add(instance); } result = response.GetAction(); } else { result = new NotFoundResult(); } } else { result = new NotFoundResult(); } } else { result = new NotFoundResult(); } } else { result = new BadRequestResult(); } return(result); }
///-------------------------------------------------------------------------------- /// <summary>This method applies objectinstance deletes.</summary> ///-------------------------------------------------------------------------------- public void ProcessDeleteObjectInstancePerformed(ObjectInstanceEventArgs data) { try { bool isItemMatch = false; if (data != null && data.ObjectInstance != null) { foreach (ObjectInstanceViewModel item in ObjectInstances.ToList <ObjectInstanceViewModel>()) { if (item.ObjectInstance.ObjectInstanceID == data.ObjectInstance.ObjectInstanceID) { // remove item from tabs, if present WorkspaceEventArgs message = new WorkspaceEventArgs(); message.ItemID = item.ObjectInstance.ObjectInstanceID; Mediator.NotifyColleagues <WorkspaceEventArgs>(MediatorMessages.Command_CloseItemRequested, message); // delete children for (int i = item.Items.Count - 1; i >= 0; i--) { if (item.Items[i] is PropertyInstanceViewModel) { PropertyInstanceViewModel child = item.Items[i] as PropertyInstanceViewModel; PropertyInstanceEventArgs childMessage = new PropertyInstanceEventArgs(); childMessage.PropertyInstance = child.PropertyInstance; childMessage.ObjectInstanceID = item.ObjectInstance.ObjectInstanceID; childMessage.Solution = Solution; childMessage.WorkspaceID = child.WorkspaceID; item.ProcessDeletePropertyInstancePerformed(childMessage); } } // delete item isItemMatch = true; ObjectInstances.Remove(item); ModelObject.ObjectInstanceList.Remove(item.ObjectInstance); Items.Remove(item); ModelObject.ResetModified(true); OnUpdated(this, null); break; } } if (isItemMatch == false) { ShowIssue(DisplayValues.Issue_DeleteItemNotFound); } } } catch (Exception ex) { ShowIssue(ex.Message + ex.StackTrace); } }
///-------------------------------------------------------------------------------- /// <summary>This method disposes of resources in the view model.</summary> ///-------------------------------------------------------------------------------- protected override void OnDispose() { if (ObjectInstances != null) { foreach (ObjectInstanceViewModel itemView in ObjectInstances) { itemView.Updated -= Children_Updated; itemView.Dispose(); } ObjectInstances.Clear(); ObjectInstances = null; } Model = null; ModelObject = null; base.OnDispose(); }
///-------------------------------------------------------------------------------- /// <summary>This method applies objectinstance updates.</summary> ///-------------------------------------------------------------------------------- public void ProcessEditObjectInstancePerformed(ObjectInstanceEventArgs data) { try { bool isItemMatch = false; if (data != null && data.ObjectInstance != null) { foreach (ObjectInstanceViewModel item in ObjectInstances) { if (item.ObjectInstance.ObjectInstanceID == data.ObjectInstance.ObjectInstanceID) { isItemMatch = true; item.ObjectInstance.TransformDataFromObject(data.ObjectInstance, null, false); item.OnUpdated(item, null); item.ShowInTreeView(); break; } } if (isItemMatch == false) { // add new ObjectInstance data.ObjectInstance.ModelObject = ModelObject; ObjectInstanceViewModel newItem = new ObjectInstanceViewModel(data.ObjectInstance, Solution); newItem.Updated += new EventHandler(Children_Updated); ObjectInstances.Add(newItem); ModelObject.ObjectInstanceList.Add(newItem.ObjectInstance); Solution.ObjectInstanceList.Add(newItem.ObjectInstance); Items.Add(newItem); OnUpdated(this, null); newItem.ShowInTreeView(); } } } catch (Exception ex) { ShowIssue(ex.Message + ex.StackTrace); } }
public IActionResult GetObjectInstances(string clientID, string definitionID) { IActionResult result; Guid definitionIDGuid, clientIDGuid; if (StringUtils.GuidTryDecode(definitionID, out definitionIDGuid) && StringUtils.GuidTryDecode(clientID, out clientIDGuid)) { int organisationID = User.GetOrganisationID(); Model.ObjectDefinition definition = BusinessLogicFactory.ObjectDefinitions.GetObjectDefinition(organisationID, definitionIDGuid); if (definition != null) { Model.Client client = BusinessLogicFactory.Clients.GetClient(clientIDGuid); if (client != null) { List<Model.Object> instances = BusinessLogicFactory.Clients.GetObjects(client, definition.ObjectDefinitionID); if (instances != null) { ObjectInstances response = new ObjectInstances(definition); string rootUrl = Request.GetRootUrl(); string instancesUrl = string.Concat(rootUrl, "/clients/", clientID, "/objecttypes/", StringUtils.GuidEncode(definition.ObjectDefinitionID), "/instances"); response.AddLink("add", instancesUrl, ""); response.PageInfo = Request.GetPageInfo(instances.Count); int endIndex = response.PageInfo.StartIndex + response.PageInfo.ItemsCount; for (int index = response.PageInfo.StartIndex; index < endIndex; index++) { ObjectInstance instance = new ObjectInstance(definition, instances[index]); string instanceUrl = string.Concat(instancesUrl, "/", instances[index].InstanceID); AddObjectInstanceLinks(Request, definition, instance, instanceUrl); response.Add(instance); } result = response.GetAction(); } else { result = new NotFoundResult(); } } else { result = new NotFoundResult(); } } else { result = new NotFoundResult(); } } else { result = new BadRequestResult(); } return result; }