Пример #1
0
        private DataStructureType GetDataStructureType(long id)
        {
            DataStructureManager dataStructureManager = new DataStructureManager();


            try
            {
                DataStructure dataStructure = dataStructureManager.AllTypesDataStructureRepo.Get(id);

                if (dataStructure is StructuredDataStructure)
                {
                    return(DataStructureType.Structured);
                }

                if (dataStructure is UnStructuredDataStructure)
                {
                    return(DataStructureType.Unstructured);
                }

                return(DataStructureType.Structured);
            }
            finally
            {
                dataStructureManager.Dispose();
            }
        }
Пример #2
0
        public string CreateTemplate(StructuredDataStructure dataStructure)
        {
            DataStructureManager dataStructureManager = null;

            try
            {
                dataStructureManager = new DataStructureManager();
                //List<Variable> variables = getOrderedVariables(dataStructure);

                string rgxPattern = "[<>?\":|\\\\/*]";
                string rgxReplace = "-";
                Regex  rgx        = new Regex(rgxPattern);

                string filename = filename = dataStructure.Id + "_" + rgx.Replace(dataStructure.Name, rgxReplace) + ".xlsm";

                string path = Path.Combine("DataStructures", dataStructure.Id.ToString());

                CreateTemplate(dataStructure.Variables.Select(p => p.Id).ToList(), path, filename);

                XmlDocument resources = new XmlDocument();

                resources.LoadXml("<Resources><Resource Type=\"Excel\" Edition=\"2010\" Path=\"" + Path.Combine(path, filename) + "\"></Resource></Resources>");
                dataStructure = this.GetUnitOfWork().GetReadOnlyRepository <StructuredDataStructure>().Get(dataStructure.Id); //Javad: This line should not be here, but I could not find where oes the dataStructure come from!!
                dataStructure.TemplatePaths = resources;
                dataStructureManager.UpdateStructuredDataStructure(dataStructure);

                return(Path.Combine(path, filename));
            }
            finally
            {
                dataStructureManager.Dispose();
            }
        }
        public ActionResult Index(long DataStructureId = 0)
        {
            ViewBag.Title = PresentationModel.GetViewTitleForTenant("Data Structure Edit", this.Session.GetTenant());
            DataStructureManager dsm = null;

            try
            {
                dsm = new DataStructureManager();
                if (DataStructureId != 0 && dsm.StructuredDataStructureRepo.Get(DataStructureId) != null)
                {
                    return(View(DataStructureId));
                }
                else if (DataStructureId == 0)
                {
                    return(View(DataStructureId));
                }
                else
                {
                    return(RedirectToAction("Index", "DataStructureSearch"));
                }
            }
            finally
            {
                dsm.Dispose();
            }
        }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        /// <remarks></remarks>
        /// <seealso cref=""/>
        /// <param name="variableIds"></param>
        /// <param name="dataStructureId"></param>
        /// <param name="path"></param>
        /// <param name="filename"></param>
        /// <returns></returns>
        public SpreadsheetDocument CreateTemplate(List <long> variableIds, long dataStructureId, string path, string filename)
        {
            DataStructureManager dataStructureManager = null;

            try
            {
                dataStructureManager = new DataStructureManager();
                StructuredDataStructure dataStructure = dataStructureManager.StructuredDataStructureRepo.Get(dataStructureId);

                if (dataStructure != null)
                {
                    //List<Variable> variables = dataStructure.Variables.Where(p => variableIds.Contains(p.Id)).ToList();
                    //variables = getOrderedVariables(variables);
                    return(CreateTemplate(variableIds, path, filename));
                }
                else
                {
                    return(null);
                }
            }
            finally
            {
                dataStructureManager.Dispose();
            }
        }
Пример #5
0
        /// <summary>
        ///
        /// </summary>
        /// <remarks></remarks>
        /// <seealso cref=""/>
        public DataStructureTree()
        {
            dataStructureTreeList = new List <DataStructureTreeList>();
            DataStructureManager dataStructureManager = null;

            try
            {
                dataStructureManager = new DataStructureManager();
                DataStructureTreeList treeList = new DataStructureTreeList();
                if (dataStructureManager.StructuredDataStructureRepo.Get() != null)
                {
                    treeList = new DataStructureTreeList(dataStructureManager.StructuredDataStructureRepo.Get());
                }
                dataStructureTreeList.Add(treeList);
                if (dataStructureManager.UnStructuredDataStructureRepo.Get() != null)
                {
                    treeList = new DataStructureTreeList(dataStructureManager.UnStructuredDataStructureRepo.Get());
                }
                dataStructureTreeList.Add(treeList);
            }
            finally
            {
                dataStructureManager.Dispose();
            }
        }
Пример #6
0
        public FileResult downloadTemplate(long id)
        {
            if (id != 0)
            {
                DataStructureManager dataStructureManager = null;
                try
                {
                    dataStructureManager = new DataStructureManager();

                    StructuredDataStructure dataStructure = new StructuredDataStructure();
                    dataStructure = dataStructureManager.StructuredDataStructureRepo.Get(id);

                    if (dataStructure != null)
                    {
                        ExcelTemplateProvider provider = new ExcelTemplateProvider("BExISppTemplate_Clean.xlsm");

                        string path = Path.Combine(AppConfiguration.DataPath, provider.CreateTemplate(dataStructure));
                        return(File(path, MimeMapping.GetMimeMapping(path), Path.GetFileName(path)));
                    }
                }
                finally
                {
                    dataStructureManager.Dispose();
                }
            }
            return(File(Path.Combine(AppConfiguration.GetModuleWorkspacePath("RPM"), "Template", "BExISppTemplate_Clean.xlsm"), "application/xlsm", "Template_" + id + "_No_Data_Structure.xlsm"));
        }
Пример #7
0
        //[MeasurePerformance]
        public static DataTable ConvertPrimaryDataToDatatable(DatasetManager datasetManager, DatasetVersion datasetVersion, string tableName = "", bool useLabelsAsColumnNames = false)
        {
            DataStructureManager dsm = new DataStructureManager();

            try
            {
                DataTable dt = new DataTable();
                if (string.IsNullOrEmpty(tableName))
                {
                    dt.TableName = "Primary data table";
                }
                else
                {
                    dt.TableName = tableName;
                }
                StructuredDataStructure sds = dsm.StructuredDataStructureRepo.Get(datasetVersion.Dataset.DataStructure.Id);
                var tupleIds = datasetManager.GetDatasetVersionEffectiveTupleIds(datasetVersion);

                if (tupleIds != null && tupleIds.Count > 0 && sds != null)
                {
                    buildTheHeader(sds, useLabelsAsColumnNames, dt);
                    buildTheBody(datasetManager, tupleIds, dt, sds, useLabelsAsColumnNames);
                }

                return(dt);
            }
            finally
            {
                dsm.Dispose();
            }
        }
Пример #8
0
        private string[] getUnits(long datastuctureId, string[] columns)
        {
            using (DataStructureManager datasetStructureManager = new DataStructureManager())
            {
                List <string> units = new List <string>();

                try
                {
                    var sds = datasetStructureManager.StructuredDataStructureRepo.Get(datastuctureId);

                    if (sds != null)
                    {
                        var varList = sds.Variables.ToList();
                        if (columns != null && columns.Count() > 0)
                        {
                            varList = varList.Where(v => columns.Contains(v.Label)).ToList();
                        }

                        varList.ForEach(v => units.Add(v.Unit.Abbreviation));
                    }

                    return(units.ToArray());
                }
                finally
                {
                    datasetStructureManager.Dispose();
                }
            }
        }
Пример #9
0
        private bool unitInUse(Unit unit)
        {
            DataStructureManager dataStructureManager = null;
            DataContainerManager dataAttributeManager = null;

            try
            {
                dataAttributeManager = new DataContainerManager();
                dataStructureManager = new DataStructureManager();
                bool inUse = false;
                if (unit.Name.ToLower() == "none")
                {
                    inUse = true;
                }
                else if (dataAttributeManager.DataAttributeRepo.Query(d => d.Unit.Id.Equals(unit.Id)).Count() > 0)
                {
                    inUse = true;
                }
                else if (dataStructureManager.VariableRepo.Query(d => d.Unit.Id.Equals(unit.Id)).Count() > 0)
                {
                    inUse = true;
                }
                return(inUse);
            }
            finally
            {
                dataAttributeManager.Dispose();
                dataStructureManager.Dispose();
            }
        }
Пример #10
0
        public List <ListViewItemWithType> LoadDataStructureViewList()
        {
            DataStructureManager dsm = new DataStructureManager();

            try
            {
                List <ListViewItemWithType> temp = new List <ListViewItemWithType>();

                foreach (DataStructure dataStructure in dsm.AllTypesDataStructureRepo.Get())
                {
                    string title = dataStructure.Name;
                    string type  = "";
                    if (dataStructure is StructuredDataStructure)
                    {
                        type = "structured";
                    }

                    if (dataStructure is UnStructuredDataStructure)
                    {
                        type = "unstructured";
                    }

                    temp.Add(new ListViewItemWithType(dataStructure.Id, title, dataStructure.Description, type));
                }

                return(temp.OrderBy(p => p.Title).ToList());
            }
            finally
            {
                dsm.Dispose();
            }
        }
Пример #11
0
        public ActionResult CreateTestDatasets(int n)
        {
            DatasetManager           datasetManager           = new DatasetManager();
            DataStructureManager     dataStructureManager     = new DataStructureManager();
            MetadataStructureManager metadataStructureManager = new MetadataStructureManager();
            ResearchPlanManager      researchPlanManager      = new ResearchPlanManager();


            try
            {
                var structure         = dataStructureManager.UnStructuredDataStructureRepo.Get(1);
                var metadatastructure = metadataStructureManager.Repo.Get(1);
                var researchplan      = researchPlanManager.Repo.Get(1);
                var xmlDatasetHelper  = new XmlDatasetHelper();

                var xmlMetadatWriter = new XmlMetadataWriter(XmlNodeMode.xPath);
                var metadataXml      = xmlMetadatWriter.CreateMetadataXml(metadatastructure.Id);

                for (int i = 0; i < n; i++)
                {
                    var dataset = datasetManager.CreateEmptyDataset(structure, researchplan, metadatastructure);


                    if (datasetManager.IsDatasetCheckedOutFor(dataset.Id, "test") || datasetManager.CheckOutDataset(dataset.Id, "test"))
                    {
                        DatasetVersion workingCopy = datasetManager.GetDatasetWorkingCopy(dataset.Id);

                        datasetManager.EditDatasetVersion(workingCopy, null, null, null);
                        datasetManager.CheckInDataset(dataset.Id, "", "test", ViewCreationBehavior.None);


                        workingCopy.Metadata = Xml.Helpers.XmlWriter.ToXmlDocument(metadataXml);

                        string xpath = xmlDatasetHelper.GetInformationPath(metadatastructure.Id, NameAttributeValues.title);

                        workingCopy.Metadata.SelectSingleNode(xpath).InnerText = i.ToString();
                        workingCopy.Title = i.ToString();

                        datasetManager.EditDatasetVersion(workingCopy, null, null, null);
                        datasetManager.CheckInDataset(dataset.Id, "", "test", ViewCreationBehavior.None);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                datasetManager.Dispose();
                dataStructureManager.Dispose();
                metadataStructureManager.Dispose();
                researchPlanManager.Dispose();
            }


            return(View("Index"));
        }
Пример #12
0
        public DataStructureResultsModel fill(long[] previewIds, string saerchTerms)
        {
            DataStructureResultStruct dataStructureResult = new DataStructureResultStruct();

            DataStructureManager dataStructureManager = null;

            try
            {
                dataStructureManager = new DataStructureManager();
                foreach (DataStructure ds in getStucturedDataStructures(saerchTerms, dataStructureManager))
                {
                    dataStructureResult             = new DataStructureResultStruct();
                    dataStructureResult.Id          = ds.Id;
                    dataStructureResult.Title       = ds.Name;
                    dataStructureResult.Description = ds.Description;

                    if (ds.Datasets.Count > 0)
                    {
                        dataStructureResult.inUse = true;
                    }

                    dataStructureResult.Structured = true;

                    if (previewIds != null && previewIds.Contains(ds.Id))
                    {
                        dataStructureResult.Preview = true;
                    }

                    this.dataStructureResults.Add(dataStructureResult);
                }

                foreach (DataStructure ds in getUnStucturedDataStructures(saerchTerms, dataStructureManager))
                {
                    dataStructureResult             = new DataStructureResultStruct();
                    dataStructureResult.Id          = ds.Id;
                    dataStructureResult.Title       = ds.Name;
                    dataStructureResult.Description = ds.Description;

                    if (ds.Datasets.Count > 0)
                    {
                        dataStructureResult.inUse = true;
                    }

                    if (previewIds != null && previewIds.Contains(ds.Id))
                    {
                        dataStructureResult.Preview = true;
                    }

                    this.dataStructureResults.Add(dataStructureResult);
                }
                return(this);
            }
            finally
            {
                dataStructureManager.Dispose();
            }
        }
Пример #13
0
        public List <Variable> getOrderedVariables(StructuredDataStructure structuredDataStructure)
        {
            DataStructureManager dsm = null;

            try
            {
                dsm = new DataStructureManager();
                XmlDocument doc = (XmlDocument)structuredDataStructure.Extra;
                XmlNode     order;

                if (doc == null)
                {
                    doc = new XmlDocument();
                    XmlNode root = doc.CreateNode(XmlNodeType.Element, "extra", null);
                    doc.AppendChild(root);
                }
                if (doc.GetElementsByTagName("order").Count == 0)
                {
                    if (structuredDataStructure.Variables.Count > 0)
                    {
                        order = doc.CreateNode(XmlNodeType.Element, "order", null);

                        foreach (Variable v in structuredDataStructure.Variables)
                        {
                            XmlNode variable = doc.CreateNode(XmlNodeType.Element, "variable", null);
                            variable.InnerText = v.Id.ToString();
                            order.AppendChild(variable);
                        }

                        doc.FirstChild.AppendChild(order);
                        structuredDataStructure.Extra = doc;
                        dsm.UpdateStructuredDataStructure(structuredDataStructure);
                    }
                }

                order = doc.GetElementsByTagName("order")[0];
                List <Variable> orderedVariables = new List <Variable>();
                if (structuredDataStructure.Variables.Count != 0)
                {
                    foreach (XmlNode x in order)
                    {
                        foreach (Variable v in structuredDataStructure.Variables)
                        {
                            if (v.Id == Convert.ToInt64(x.InnerText))
                            {
                                orderedVariables.Add(v);
                            }
                        }
                    }
                }
                return(orderedVariables);
            }
            finally
            {
                dsm.Dispose();
            }
        }
Пример #14
0
        public ActionResult deleteDataStructure(long Id, string cssId = "")
        {
            MessageModel DataStructureDeleteValidation = MessageModel.validateDataStructureDelete(Id);

            if (DataStructureDeleteValidation.hasMessage)
            {
                return(PartialView("_messageWindow", DataStructureDeleteValidation));
            }
            else
            {
                DataStructureManager dataStructureManager = null;
                MissingValueManager  missingValueManager  = null;

                try
                {
                    dataStructureManager = new DataStructureManager();
                    missingValueManager  = new MissingValueManager();
                    var structureRepo = dataStructureManager.GetUnitOfWork().GetReadOnlyRepository <StructuredDataStructure>();
                    StructuredDataStructure structuredDataStructure = structureRepo.Get(Id);

                    if (structuredDataStructure != null) // Javad: This one retrieves the entity withough using it, and then the next line agian fetches the same!
                    {
                        DataStructureIO.deleteTemplate(structuredDataStructure.Id);
                        foreach (Variable v in structuredDataStructure.Variables)
                        {
                            List <MissingValue> missingValues = missingValueManager.Repo.Query(mv => mv.Variable.Id.Equals(v.Id)).ToList();
                            foreach (MissingValue mv in missingValues)
                            {
                                missingValueManager.Delete(mv);
                            }
                            dataStructureManager.RemoveVariableUsage(v);
                        }
                        dataStructureManager.DeleteStructuredDataStructure(structuredDataStructure);
                        LoggerFactory.LogData(structuredDataStructure.Id.ToString(), typeof(DataStructure).Name, Vaiona.Entities.Logging.CrudState.Deleted);
                    }
                    else
                    {
                        var unStructureRepo = dataStructureManager.GetUnitOfWork().GetReadOnlyRepository <UnStructuredDataStructure>();
                        UnStructuredDataStructure unStructuredDataStructure = unStructureRepo.Get(Id);
                        dataStructureManager.DeleteUnStructuredDataStructure(unStructuredDataStructure);
                        LoggerFactory.LogData(unStructuredDataStructure.Id.ToString(), typeof(DataStructure).Name, Vaiona.Entities.Logging.CrudState.Deleted);
                    }
                    return(PartialView("_message", new MessageModel()
                    {
                        Message = "DataStructure" + Id + "deleted",
                        hasMessage = false,
                        CssId = "deleted"
                    }));
                }
                finally
                {
                    dataStructureManager.Dispose();
                    missingValueManager.Dispose();
                }
            }
        }
Пример #15
0
        /// <summary>
        ///
        /// </summary>
        /// <remarks></remarks>
        /// <seealso cref=""/>
        /// <param name="ID"></param>
        /// <param name="structured"></param>
        /// <returns></returns>
        public DataStructure GetDataStructureByID(long ID, bool structured)
        {
            this.structured = structured;
            if (structured)
            {
                return(this.GetDataStructureByID(ID));
            }
            else
            {
                DataStructureManager dsm = null;
                try
                {
                    dsm = new DataStructureManager();
                    UnStructuredDataStructure unStructuredDataStructure = dsm.UnStructuredDataStructureRepo.Get(ID);
                    this.dataStructure = unStructuredDataStructure;

                    if (this.dataStructure != null)
                    {
                        this.variableStructs = null;
                        if (this.dataStructure.Datasets == null)
                        {
                            inUse = false;
                        }
                        else
                        {
                            if (this.dataStructure.Datasets.Count > 0)
                            {
                                inUse = true;
                                //DatasetListElement datasetListElement = new DatasetListElement();
                                //DatasetManager dm = new DatasetManager();
                                //foreach (Dataset d in unStructuredDataStructure.Datasets)
                                //{
                                //    datasetListElement = new DatasetListElement(d.Id, XmlDatasetHelper.GetInformation(d,AttributeNames.title));
                                //    datasets.Add(datasetListElement);
                                //}
                            }
                            else
                            {
                                inUse = false;
                            }
                        }
                        return(unStructuredDataStructure);
                    }
                    else
                    {
                        this.dataStructure = new StructuredDataStructure();
                        return(unStructuredDataStructure);
                    }
                }
                finally
                {
                    dsm.Dispose();
                }
            }
        }
Пример #16
0
        public DataStructurePreviewModel fill(long dataStructureId)
        {
            if (dataStructureId > 0)
            {
                DataStructureManager dataStructureManager = null;
                try
                {
                    dataStructureManager = new DataStructureManager();
                    if (dataStructureManager.StructuredDataStructureRepo.Get(dataStructureId) != null)
                    {
                        StructuredDataStructure dataStructure = dataStructureManager.StructuredDataStructureRepo.Get(dataStructureId);
                        VariablePreviewStruct   variablePreview;

                        this.Id          = dataStructure.Id;
                        this.Name        = dataStructure.Name;
                        this.Description = dataStructure.Description;

                        if (dataStructure.Datasets.Count > 0)
                        {
                            this.inUse = true;
                        }

                        foreach (Variable v in DataStructureIO.getOrderedVariables(dataStructure))
                        {
                            variablePreview = new VariablePreviewStruct().fill(v);
                            this.VariablePreviews.Add(variablePreview);
                        }
                    }
                    else if (dataStructureManager.UnStructuredDataStructureRepo.Get(dataStructureId) != null)
                    {
                        UnStructuredDataStructure dataStructure = dataStructureManager.UnStructuredDataStructureRepo.Get(dataStructureId);

                        this.Id               = dataStructure.Id;
                        this.Name             = dataStructure.Name;
                        this.Description      = dataStructure.Description;
                        this.VariablePreviews = null;

                        if (dataStructure.Datasets.Count > 0)
                        {
                            this.inUse = true;
                        }
                    }
                    return(this);
                }
                finally
                {
                    dataStructureManager.Dispose();
                }
            }
            else
            {
                return(new DataStructurePreviewModel());
            }
        }
Пример #17
0
        public static MessageModel validateDataStructureDelete(long Id)
        {
            DataStructureManager dataStructureManager = null;

            try
            {
                dataStructureManager = new DataStructureManager();
                DataStructure dataStructure = dataStructureManager.AllTypesDataStructureRepo.Get(Id);
                return(validateDataStructureDelete(Id, dataStructure));
            }
            finally
            {
                dataStructureManager.Dispose();
            }
        }
Пример #18
0
        //private FileStream loadFile (string file)
        //{
        //    if (File.Exists(file))
        //        return File.Open(file, FileMode.Open, FileAccess.ReadWrite);

        //    else
        //        return null;
        //}

        /// <summary>
        ///
        /// </summary>
        /// <remarks></remarks>
        /// <seealso cref=""/>
        /// <param name="id"></param>
        public void CreateTemplate(long id)
        {
            DataStructureManager dataStructureManager = null;

            try
            {
                dataStructureManager = new DataStructureManager();
                StructuredDataStructure dataStructure = dataStructureManager.StructuredDataStructureRepo.Get(id);
                CreateTemplate(dataStructure);
            }
            finally
            {
                dataStructureManager.Dispose();
            }
        }
Пример #19
0
        public DataStructureDataList(long datasetId) : this()
        {
            var dataset = this.GetUnitOfWork().GetReadOnlyRepository <Dataset>().Get(datasetId);

            if (dataset != null && dataset.DataStructure.Id != 0)
            {
                DataStructureManager dataStructureManager = null;
                try
                {
                    dataStructureManager = new DataStructureManager();
                    DataStructure dataStructure = dataStructureManager.AllTypesDataStructureRepo.Get(dataset.DataStructure.Id);
                    if (dataStructure != null)
                    {
                        this.Id          = dataStructure.Id;
                        this.Title       = dataStructure.Name;
                        this.Description = dataStructure.Description;

                        if (dataStructure.Datasets.Count > 0)
                        {
                            this.inUse = true;
                        }
                        else
                        {
                            this.inUse = false;
                        }

                        this.Structured = false;
                        this.Variables  = new List <VariableElement>();

                        if (dataStructureManager.StructuredDataStructureRepo.Get(dataset.DataStructure.Id) != null)
                        {
                            StructuredDataStructure structuredDataStructure = dataStructureManager.StructuredDataStructureRepo.Get(dataset.DataStructure.Id);
                            this.Structured = true;
                            foreach (Variable vs in structuredDataStructure.Variables)
                            {
                                vs.Materialize();
                                this.Variables.Add(new VariableElement(vs));
                            }
                        }
                    }
                }
                finally
                {
                    dataStructureManager.Dispose();
                }
            }
        }
Пример #20
0
        public static MessageModel validateDataStructureName(long Id, string Name, string cssId = "")
        {
            if (Name.Trim() == "" || string.IsNullOrEmpty(Name))
            {
                return(new MessageModel()
                {
                    hasMessage = true,
                    Message = "The name field is required.",
                    CssId = cssId
                });
            }
            else
            {
                DataStructureManager dataStructureManager = null;
                try
                {
                    dataStructureManager = new DataStructureManager();
                    List <DataStructure> dataStructures = dataStructureManager.AllTypesDataStructureRepo.Get().ToList();

                    foreach (DataStructure ds in dataStructures)
                    {
                        if (Id != ds.Id)
                        {
                            if (ds.Name.Trim().ToLower() == Name.Trim().ToLower())
                            {
                                return(new MessageModel()
                                {
                                    hasMessage = true,
                                    Message = "A data structure with the same name already exists.",
                                    CssId = cssId
                                });
                            }
                        }
                    }
                }
                finally
                {
                    dataStructureManager.Dispose();
                }
            }
            return(new MessageModel()
            {
                CssId = cssId
            });
        }
Пример #21
0
        public void PurgeAllDataStructures()
        {
            var manager = new DataStructureManager();

            try
            {
                var sts = manager.StructuredDataStructureRepo.Query().ToList();
                sts.ForEach(p => manager.DeleteStructuredDataStructure(p));
                //manager.DeleteStructuredDataStructure(sts); // Does not delete all the entities of the list!!!! Javad, 29.08.2018

                var unsts = manager.UnStructuredDataStructureRepo.Query().ToList();
                unsts.ForEach(p => manager.DeleteUnStructuredDataStructure(p));
                //manager.DeleteUnStructuredDataStructure(unsts);
            }
            finally
            {
                manager.Dispose();
            }
        }
Пример #22
0
        public List <ListViewItem> LoadDatasetVersionViewList(DataStructureType dataStructureType)
        {
            EntityPermissionManager entityPermissionManager = new EntityPermissionManager();
            DataStructureManager    dataStructureManager    = new DataStructureManager();
            DatasetManager          dm = new DatasetManager();

            try
            {
                List <long> datasetIds = entityPermissionManager.GetKeys(GetUsernameOrDefault(), "Dataset", typeof(Dataset), RightType.Write).ToList();

                List <ListViewItem> tempStructured   = new List <ListViewItem>();
                List <ListViewItem> tempUnStructured = new List <ListViewItem>();

                var DatasetVersions = dm.GetDatasetLatestVersions(datasetIds, false);

                foreach (var dsv in DatasetVersions)
                {
                    if (dsv.Dataset.DataStructure.Self.GetType().Equals(typeof(StructuredDataStructure)))
                    {
                        tempStructured.Add(new ListViewItem(dsv.Dataset.Id, dsv.Title));
                    }
                    else
                    {
                        tempUnStructured.Add(new ListViewItem(dsv.Dataset.Id, dsv.Title));
                    }
                }

                if (dataStructureType.Equals(DataStructureType.Structured))
                {
                    return(tempStructured.OrderBy(p => p.Title).ToList());
                }
                else
                {
                    return(tempUnStructured.OrderBy(p => p.Title).ToList());
                }
            }
            finally
            {
                entityPermissionManager.Dispose();
                dataStructureManager.Dispose();
                dm.Dispose();
            }
        }
Пример #23
0
        public static StructuredDataStructure setVariableOrder(StructuredDataStructure structuredDataStructure, List <long> orderList)
        {
            DataStructureManager dsm = null;

            try
            {
                dsm = new DataStructureManager();
                foreach (Variable v in structuredDataStructure.Variables)
                {
                    v.OrderNo = orderList.IndexOf(v.Id) + 1;
                }
                structuredDataStructure = dsm.UpdateStructuredDataStructure(structuredDataStructure);
            }
            finally
            {
                dsm.Dispose();
            }
            return(structuredDataStructure);
        }
Пример #24
0
        public StructuredDataStructure GetDataStructureByID(long ID)
        {
            DataStructureManager dsm = null;

            try
            {
                dsm = new DataStructureManager();
                StructuredDataStructure structuredDataStructure = dsm.StructuredDataStructureRepo.Get(ID);
                this.dataStructure = structuredDataStructure;

                if (this.dataStructure != null)
                {
                    this.variableStructs = getOrderedVariableStructs(structuredDataStructure);

                    if (this.dataStructure.Datasets == null)
                    {
                        inUse = false;
                    }
                    else
                    {
                        if (this.dataStructure.Datasets.Count > 0)
                        {
                            inUse = true;
                        }
                        else
                        {
                            inUse = false;
                        }
                    }
                    this.BuildDataTable();
                    return(structuredDataStructure);
                }
                else
                {
                    this.dataStructure = new StructuredDataStructure();
                    return(structuredDataStructure);
                }
            }
            finally
            {
                dsm.Dispose();
            }
        }
Пример #25
0
        private List <ListViewItem> LoadVariableLableList()
        {
            DataStructureManager datastructureManager = new DataStructureManager();

            try
            {
                StructuredDataStructure structuredDatastructure = datastructureManager.StructuredDataStructureRepo.Get(Convert.ToInt64(TaskManager.Bus["DataStructureId"]));

                return((from var in structuredDatastructure.Variables
                        select new ListViewItem
                {
                    Id = var.Id,
                    Title = var.Label
                }).ToList());
            }
            finally
            {
                datastructureManager.Dispose();
            }
        }
Пример #26
0
        /// <summary>
        ///
        /// </summary>
        /// <remarks></remarks>
        /// <seealso cref=""/>
        /// <param name="dataStrctureId"></param>
        public void deleteTemplate(long dataStrctureId)
        {
            DataStructureManager DSM = null;

            try
            {
                DSM = new DataStructureManager();
                StructuredDataStructure dataStructure = DSM.StructuredDataStructureRepo.Get(dataStrctureId);
                string path = "";
                try
                {
                    XmlNode resources = dataStructure.TemplatePaths.FirstChild;

                    XmlNodeList resource = resources.ChildNodes;

                    foreach (XmlNode x in resource)
                    {
                        path = Path.Combine(AppConfiguration.DataPath, x.Attributes.GetNamedItem("Path").Value);
                        if (File.Exists(path))
                        {
                            File.Delete(path);
                        }
                    }

                    path = Path.Combine(AppConfiguration.DataPath, "DataStructures", dataStructure.Id.ToString());

                    if (Directory.Exists(path) && !(Directory.EnumerateFileSystemEntries(path).Any()))
                    {
                        Directory.Delete(path);
                    }
                }
                catch
                {
                }
            }
            finally
            {
                DSM.Dispose();
            }
        }
Пример #27
0
        /// <summary>
        /// Get a html file of the data structure from a dataset
        /// </summary>
        /// <param name="id">dataset id</param>
        /// <returns>html file</returns>
        public ActionResult GetDataStructureAsHtmlFile(long id)
        {
            DatasetManager       dm  = new DatasetManager();
            DataStructureManager dsm = new DataStructureManager();

            try
            {
                using (var uow = this.GetUnitOfWork())
                {
                    long           dsId          = dm.GetDatasetLatestVersion(id).Id;
                    DatasetVersion ds            = uow.GetUnitOfWork().GetReadOnlyRepository <DatasetVersion>().Get(dsId);
                    DataStructure  dataStructure = null;
                    if (ds != null)
                    {
                        dataStructure = uow.GetReadOnlyRepository <DataStructure>().Get(ds.Dataset.DataStructure.Id);
                    }

                    if (dataStructure != null && dataStructure.Self is StructuredDataStructure)
                    {
                        SimpleDataStructureModel model = new SimpleDataStructureModel((StructuredDataStructure)dataStructure.Self);

                        string htmlPage = PartialView("SimpleDataStructure", model).RenderToString();
                        byte[] content  = Encoding.ASCII.GetBytes(htmlPage);

                        return(File(content, "text/html", "dataStructure.html"));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dm.Dispose();
                dsm.Dispose();
            }

            return(null);
        }
Пример #28
0
        public List <ListViewItem> LoadDataStructureViewList(DataStructureType dataStructureType)
        {
            DataStructureManager dsm = new DataStructureManager();

            try
            {
                List <ListViewItem> temp = new List <ListViewItem>();

                foreach (DataStructure datasStructure in dsm.StructuredDataStructureRepo.Get())
                {
                    string title = datasStructure.Name;

                    temp.Add(new ListViewItem(datasStructure.Id, title));
                }

                return(temp.OrderBy(p => p.Title).ToList());
            }
            finally
            {
                dsm.Dispose();
            }
        }
Пример #29
0
        public ActionResult SimpleDataStructure(long id)
        {
            DatasetManager       dm  = new DatasetManager();
            DataStructureManager dsm = new DataStructureManager();

            try
            {
                using (var uow = this.GetUnitOfWork())
                {
                    long           dsId          = dm.GetDatasetLatestVersion(id).Id;
                    DatasetVersion ds            = uow.GetUnitOfWork().GetReadOnlyRepository <DatasetVersion>().Get(dsId);
                    DataStructure  dataStructure = null;
                    if (ds != null)
                    {
                        dataStructure = uow.GetReadOnlyRepository <DataStructure>().Get(ds.Dataset.DataStructure.Id);
                    }

                    if (dataStructure != null && dataStructure.Self is StructuredDataStructure)
                    {
                        SimpleDataStructureModel model = new SimpleDataStructureModel((StructuredDataStructure)dataStructure.Self);

                        return(PartialView("SimpleDataStructure", model));
                    }
                }

                return(null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dm.Dispose();
                dsm.Dispose();
            }
        }
Пример #30
0
        public ActionResult _CustomDataStructureBinding(GridCommand command, long datasetID)
        {
            DataStructureManager dsm = new DataStructureManager();
            DatasetManager       dm  = new DatasetManager();


            try
            {
                long id = datasetID;
                if (dm.IsDatasetCheckedIn(id))
                {
                    DatasetVersion ds = dm.GetDatasetLatestVersion(id);
                    if (ds != null)
                    {
                        StructuredDataStructure sds = dsm.StructuredDataStructureRepo.Get(ds.Dataset.DataStructure.Id);
                        dsm.StructuredDataStructureRepo.LoadIfNot(sds.Variables);
                        //StructuredDataStructure sds = (StructuredDataStructure)(ds.Dataset.DataStructure.Self);
                        SearchUIHelper suh   = new SearchUIHelper();
                        DataTable      table = suh.ConvertStructuredDataStructureToDataTable(sds);

                        return(View(new GridModel(table)));
                    }
                }
                else
                {
                    ModelState.AddModelError(String.Empty, "Dataset is just in processing.");
                }
            }
            finally
            {
                dm.Dispose();
                dsm.Dispose();
            }

            return(View(new GridModel(new DataTable())));
        }