Ejemplo n.º 1
0
        /// <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, DatasetView 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);

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <UnStructuredDataStructure> repo = uow.GetRepository <UnStructuredDataStructure>();
                repo.Reload(dataStructure);
                repo.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);

                repo.Put(dataStructure);
                uow.Commit();
            }
            //throw new NotImplementedException();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds a spanning view to the passed unstructured data structure. Spanning views are available and applicable to all datasets associated with the data structure.
        /// </summary>
        /// <param name="dataStructure">The unstructured 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.UnStructuredDataStructure dataStructure, DatasetView 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<UnStructuredDataStructure>() != null && Contract.Result<UnStructuredDataStructure>().Id >= 0);

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <UnStructuredDataStructure> repo = uow.GetRepository <UnStructuredDataStructure>();

                repo.Reload(dataStructure);
                repo.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);

                repo.Put(dataStructure);
                uow.Commit();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Applies changes to the data structure and persists them in the database.
        /// </summary>
        /// <param name="entity">The entity containing the changes.</param>
        /// <returns>The data structure entity with the changes applied.</returns>
        public UnStructuredDataStructure UpdateUnStructuredDataStructure(UnStructuredDataStructure entity)
        {
            Contract.Requires(entity != null, "provided entity can not be null");
            Contract.Requires(entity.Id >= 0, "provided entity must have a permant ID");
            Contract.Ensures(Contract.Result<UnStructuredDataStructure>() != null && Contract.Result<UnStructuredDataStructure>().Id >= 0, "No entity is persisted!");

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<UnStructuredDataStructure> repo = uow.GetRepository<UnStructuredDataStructure>();
                repo.Put(entity); // Merge is required here!!!!
                uow.Commit();
            }
            return (entity);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// If the <paramref name="entity"/> is not associated to any <see cref="Dateset"/>, the method deletes it from the database.
        /// </summary>
        /// <param name="entity">The data structure object to be deleted.</param>
        /// <returns>True if the data structure is deleted, False otherwise.</returns>
        /// <remarks>Database exceptions are not handled intentionally, so that if the data structure is related to some datasets, a proper exception will be thrown.</remarks>
        public bool DeleteUnStructuredDataStructure(UnStructuredDataStructure entity)
        {
            Contract.Requires(entity != null);
            Contract.Requires(entity.Id >= 0);

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<UnStructuredDataStructure> repo = uow.GetRepository<UnStructuredDataStructure>();

                entity = repo.Reload(entity);
                repo.Delete(entity);

                uow.Commit();
            }
            return (true);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates an unstructured data structure <seealso cref="UnStructuredDataStructure"/> and persists it in the database.
        /// </summary>
        /// <param name="name">The name of the data structure</param>
        /// <param name="description">A free text describing the purpose, usage, and/or the domain of the data structure usage.</param>
        public UnStructuredDataStructure CreateUnStructuredDataStructure(string name, string description)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(name));
            Contract.Ensures(Contract.Result<UnStructuredDataStructure>() != null && Contract.Result<UnStructuredDataStructure>().Id >= 0);

            UnStructuredDataStructure e = new UnStructuredDataStructure()
            {
                Name = name,
                Description = description,
            };

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<UnStructuredDataStructure> repo = uow.GetRepository<UnStructuredDataStructure>();
                repo.Put(e);
                uow.Commit();
            }
            return (e);
        }
Ejemplo n.º 6
0
        // create unstructured DataStructures
        public DataStructure CreateDataStructure(string fileType)
        {
            DataStructureManager dataStructureManager = new DataStructureManager();
            UnStructuredDataStructure dataStructure = new UnStructuredDataStructure();

            // values of DataStructure
            string name = fileType;
            string description = "old BExIS unstrctured data structure: " + fileType;

            UnStructuredDataStructure existDS = dataStructureManager.UnStructuredDataStructureRepo.Get(s => name.Equals(s.Name)).FirstOrDefault();
            if (existDS == null)
            {
                // create dataStructure
                return dataStructureManager.CreateUnStructuredDataStructure(name, description);
            }
            else
            {
                return existDS;
            }
        }