/// <summary> /// Adds a spanning view to the passed structured data structure. Spanning views are available and applicable to all datasets associated with the data structure. /// </summary> /// <param name="dataStructure">The structured data structure to add the data view to.</param> /// <param name="view">The data view to be linked to the data structure as a spanning view.</param> public void AddDataView(BExIS.Dlm.Entities.DataStructure.StructuredDataStructure dataStructure, DataView view) { // view should not be connected to a Dataset. if so throw an exception and the caller must remove the relationship to that dataset and then add to a data structure Contract.Requires(dataStructure != null && dataStructure.Id >= 0); Contract.Requires(view != null && view.Id >= 0); Contract.Requires(view.Dataset == null); //Contract.Ensures(Contract.Result<StructuredDataStructure>() != null && Contract.Result<StructuredDataStructure>().Id >= 0); StructuredDataStructureRepo.Reload(dataStructure); StructuredDataStructureRepo.LoadIfNot(dataStructure.Views); int count = (from v in dataStructure.Views where v.Id.Equals(view.Id) select v ) .Count(); if (count > 0) throw new Exception(string.Format("There is a connection between data structure {0} and view {1}", dataStructure.Id, view.Id)); dataStructure.Views.Add(view); view.DataStructures.Add(dataStructure); using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository<StructuredDataStructure> repo = uow.GetRepository<StructuredDataStructure>(); repo.Put(dataStructure); uow.Commit(); } }
public DataView CreateDataView(string name, string contentSelectionCriterion, string containerSelectionCriterion, BExIS.Dlm.Entities.DataStructure.DataStructure dataStructure) { Contract.Requires(!string.IsNullOrWhiteSpace(name)); Contract.Requires(!string.IsNullOrWhiteSpace(contentSelectionCriterion) || !string.IsNullOrWhiteSpace(containerSelectionCriterion)); Contract.Requires(dataStructure != null); Contract.Ensures(Contract.Result<DataView>() != null); DataView e = new DataView() { Name = name, ContentSelectionCriterion = contentSelectionCriterion, ContainerSelectionCriterion = containerSelectionCriterion, Dataset = null, }; dataStructure.Views.Add(e); e.DataStructures.Add(dataStructure); using (IUnitOfWork uow = this.GetUnitOfWork()) { // maybe there is a need for persisting the data structure also! IRepository<DataView> repo = uow.GetRepository<DataView>(); repo.Put(e); uow.Commit(); } return (e); }
/// <summary> /// Removes the relationship between the structured data structure and the view, neither the data structure nor the view. /// </summary> /// <param name="dataStructure">The data structure to be release from the relationship.</param> /// <param name="view">The view to be release from the relationship.</param> public void RemoveDataView(BExIS.Dlm.Entities.DataStructure.UnStructuredDataStructure dataStructure, DataView view) { Contract.Requires(dataStructure != null && dataStructure.Id >= 0); Contract.Requires(view != null && view.Id >= 0); Contract.Requires(view.Dataset == null); //Contract.Ensures(Contract.Result<UnStructuredDataStructure>() != null && Contract.Result<UnStructuredDataStructure>().Id >= 0); UnStructuredDataStructureRepo.Reload(dataStructure); UnStructuredDataStructureRepo.LoadIfNot(dataStructure.Views); int count = (from v in dataStructure.Views where v.Id.Equals(view.Id) select v ) .Count(); if (count <= 0) throw new Exception(string.Format("There is no connection between data structure {0} and view {1}", dataStructure.Id, view.Id)); dataStructure.Views.Remove(view); view.DataStructures.Remove(dataStructure); using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository<UnStructuredDataStructure> repo = uow.GetRepository<UnStructuredDataStructure>(); repo.Put(dataStructure); uow.Commit(); } //throw new NotImplementedException(); }