Пример #1
0
        private ExtractionConfiguration ShallowClone()
        {
            var clone = new ExtractionConfiguration(DataExportRepository, Project);

            CopyShallowValuesTo(clone);

            clone.Name = "Clone of " + Name;
            clone.SaveToDatabase();
            return(clone);
        }
Пример #2
0
        /// <summary>
        /// Creates a complete copy of the <see cref="IExtractionConfiguration"/>, all selected datasets, filters etc.  The copy is created directly into
        /// the <see cref="DatabaseEntity.Repository"/> database using a transaction (to prevent a half succesful clone being generated).
        /// </summary>
        /// <returns></returns>
        public ExtractionConfiguration DeepCloneWithNewIDs()
        {
            var repo = (DataExportRepository)Repository;

            using (repo.BeginNewTransactedConnection())
            {
                try
                {
                    //clone the root object (the configuration) - this includes cloning the link to the correct project and cohort
                    ExtractionConfiguration clone = this.ShallowClone();

                    //find each of the selected datasets for ourselves and clone those too
                    foreach (SelectedDataSets selected in SelectedDataSets)
                    {
                        //clone the link meaning that the dataset is now selected for the clone configuration too
                        var newSelectedDataSet = new SelectedDataSets(repo, clone, selected.ExtractableDataSet, null);

                        // now clone each of the columns for each of the datasets that we just created links to (make them the same as the old configuration
                        foreach (IColumn extractableColumn in GetAllExtractableColumnsFor(selected.ExtractableDataSet))
                        {
                            ExtractableColumn cloneExtractableColumn = ((ExtractableColumn)extractableColumn).ShallowClone();
                            cloneExtractableColumn.ExtractionConfiguration_ID = clone.ID;
                            cloneExtractableColumn.SaveToDatabase();
                        }

                        //clone should copy accross the forced joins (if any)
                        foreach (SelectedDataSetsForcedJoin oldForcedJoin in Repository.GetAllObjectsWithParent <SelectedDataSetsForcedJoin>(selected))
                        {
                            new SelectedDataSetsForcedJoin((IDataExportRepository)Repository, newSelectedDataSet, oldForcedJoin.TableInfo);
                        }


                        try
                        {
                            //clone the root filter container
                            var rootContainer = (FilterContainer)GetFilterContainerFor(selected.ExtractableDataSet);

                            //turns out there wasn't one to clone at all
                            if (rootContainer == null)
                            {
                                continue;
                            }

                            //there was one to clone so clone it recursively (all subcontainers) including filters then set the root filter to the new clone
                            FilterContainer cloneRootContainer = rootContainer.DeepCloneEntireTreeRecursivelyIncludingFilters();
                            newSelectedDataSet.RootFilterContainer_ID = cloneRootContainer.ID;
                            newSelectedDataSet.SaveToDatabase();
                        }
                        catch (Exception e)
                        {
                            clone.DeleteInDatabase();
                            throw new Exception("Problem occurred during cloning filters, problem was " + e.Message + " deleted the clone configuration successfully", e);
                        }
                    }

                    clone.dtCreated     = DateTime.Now;
                    clone.IsReleased    = false;
                    clone.Username      = Environment.UserName;
                    clone.Description   = "TO" + "DO:Populate change log here";
                    clone.ReleaseTicket = null;

                    //wire up some changes
                    clone.ClonedFrom_ID = this.ID;
                    clone.SaveToDatabase();

                    repo.EndTransactedConnection(true);

                    return(clone);
                }
                catch (Exception)
                {
                    repo.EndTransactedConnection(false);
                    throw;
                }
            }
        }