Exemple #1
0
        private static XmlDocument createOderNode(StructuredDataStructure structuredDataStructure)
        {
            DataStructureManager 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);
                }
            }
            return(doc);
        }
Exemple #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();
            }
        }
Exemple #3
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();
            }
        }
Exemple #4
0
        public List <Variable> getOrderedVariables(long dataStructureID, List <Variable> Variables)
        {
            DataStructureManager    dataStructureManager    = new DataStructureManager();
            StructuredDataStructure structuredDataStructure = dataStructureManager.StructuredDataStructureRepo.Get(dataStructureID);
            XmlDocument             doc = (XmlDocument)structuredDataStructure.Extra;
            XmlNode     order;
            XmlNodeList temp;

            if (doc == null)
            {
                doc = new XmlDocument();
                XmlNode root = doc.CreateNode(System.Xml.XmlNodeType.Element, "extra", null);
                doc.AppendChild(root);
            }
            if (doc.GetElementsByTagName("order").Count == 0)
            {
                if (structuredDataStructure.Variables.Count != 0)
                {
                    order = doc.CreateNode(System.Xml.XmlNodeType.Element, "order", null);
                    foreach (Variable v in structuredDataStructure.Variables)
                    {
                        XmlNode variable = doc.CreateNode(System.Xml.XmlNodeType.Element, "variable", null);
                        variable.InnerText = v.Id.ToString();
                        order.AppendChild(variable);
                    }
                    doc.FirstChild.AppendChild(order);
                    structuredDataStructure.Extra = doc;
                    dataStructureManager.UpdateStructuredDataStructure(structuredDataStructure);
                }
            }

            temp  = doc.GetElementsByTagName("order");
            order = temp[0];
            List <Variable> orderedVariables = new List <Variable>();

            if (Variables.Count != 0)
            {
                foreach (XmlNode x in order)
                {
                    foreach (Variable v in Variables)
                    {
                        if (v.Id == Convert.ToInt64(x.InnerText))
                        {
                            orderedVariables.Add(v);
                        }
                    }
                }
            }
            return(orderedVariables);
        }
Exemple #5
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);
        }
Exemple #6
0
        public string CreateTemplate(StructuredDataStructure dataStructure)
        {
            DataStructureManager 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(variables, path, filename);

            XmlDocument resources = new XmlDocument();

            resources.LoadXml("<Resources><Resource Type=\"Excel\" Edition=\"2010\" Path=\"" + Path.Combine(path, filename) + "\"></Resource></Resources>");
            dataStructure.TemplatePaths = resources;
            dataStructureManager.UpdateStructuredDataStructure(dataStructure);

            return(Path.Combine(path, filename));
        }
        public ActionResult storeVariables(long Id, storeVariableStruct[] variables)
        {
            DataStructureManager dataStructureManager = null;
            DataContainerManager dataContainerManager = null;
            MissingValueManager  missingValueManager  = null;
            UnitManager          um = null;

            try
            {
                dataStructureManager = new DataStructureManager();
                missingValueManager  = new MissingValueManager();
                dataContainerManager = new DataContainerManager();
                um = new UnitManager();
                var structureRepo = dataStructureManager.GetUnitOfWork().GetReadOnlyRepository <StructuredDataStructure>();

                StructuredDataStructure dataStructure = structureRepo.Get(Id);
                MessageModel            returnObject  = new MessageModel();
                MessageModel            messageModel  = MessageModel.validateDataStructureInUse(dataStructure.Id, dataStructure);
                if (messageModel.hasMessage)
                {
                    foreach (Variable v in dataStructure.Variables)
                    {
                        if (variables.Select(svs => svs.Id).ToList().Contains(v.Id))
                        {
                            v.Description = variables.Where(svs => svs.Id == v.Id).FirstOrDefault().Description;
                            dataStructure = dataStructureManager.UpdateStructuredDataStructure(dataStructure);
                        }
                    }
                    return(PartialView("_messageWindow", messageModel));
                }

                if (variables != null && variables.Any())
                {
                    Variable    variable = new Variable();
                    List <long> order    = new List <long>();

                    foreach (Variable v in dataStructure.Variables)
                    {
                        if (!variables.Select(svs => svs.Id).ToList().Contains(v.Id))
                        {
                            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);
                        }
                    }

                    foreach (storeVariableStruct svs in variables.Where(svs => svs.Id == 0).ToList())
                    {
                        if (svs.Lable == null)
                        {
                            svs.Lable = "";
                        }
                        if (svs.Description == null)
                        {
                            svs.Description = "";
                        }

                        DataAttribute dataAttribute = dataContainerManager.DataAttributeRepo.Get(svs.AttributeId);
                        if (dataAttribute != null)
                        {
                            variable = dataStructureManager.AddVariableUsage(dataStructure, dataAttribute, svs.isOptional, svs.Lable.Trim(), null, null, svs.Description.Trim(), um.Repo.Get(svs.UnitId));
                            svs.Id   = variable.Id;
                            foreach (MissingValueStruct mvs in svs.MissingValues)
                            {
                                if (mvs.Id == 0)
                                {
                                    if (String.IsNullOrEmpty(mvs.Placeholder))
                                    {
                                        missingValueManager.Create(mvs.DisplayName, mvs.Description, variable);
                                    }
                                    else
                                    {
                                        missingValueManager.Create(mvs.DisplayName, mvs.Description, variable, mvs.Placeholder);
                                    }
                                }
                            }
                        }
                        else
                        {
                            returnObject = new MessageModel()
                            {
                                hasMessage = true,
                                Message    = "Not all Variables are stored.",
                                CssId      = "0"
                            };
                        }
                    }

                    //dataStructure = structureRepo.Get(Id); // Javad: why it is needed?

                    variables = variables.Where(v => v.Id != 0).ToArray();
                    MissingValue missingValue = new MissingValue();
                    foreach (storeVariableStruct svs in variables.Where(svs => svs.Id != 0).ToList())
                    {
                        if (svs.Lable == null)
                        {
                            svs.Lable = "";
                        }
                        if (svs.Description == null)
                        {
                            svs.Description = "";
                        }

                        variable = dataStructure.Variables.Where(v => v.Id == svs.Id).FirstOrDefault();
                        if (variable != null)
                        {
                            variable.Label           = svs.Lable.Trim();
                            variable.Description     = svs.Description.Trim();
                            variable.Unit            = um.Repo.Get(svs.UnitId);
                            variable.DataAttribute   = dataContainerManager.DataAttributeRepo.Get(svs.AttributeId);
                            variable.IsValueOptional = svs.isOptional;


                            List <MissingValue> missingValues = missingValueManager.Repo.Query(mv => mv.Variable.Id.Equals(svs.Id)).ToList();
                            foreach (MissingValue mv in missingValues)
                            {
                                if (!svs.MissingValues.Select(mvs => mvs.Id).Contains(mv.Id))
                                {
                                    missingValueManager.Delete(mv);
                                }
                            }

                            foreach (MissingValueStruct mvs in svs.MissingValues)
                            {
                                if (mvs.Id == 0)
                                {
                                    if (String.IsNullOrEmpty(mvs.Placeholder))
                                    {
                                        missingValueManager.Create(mvs.DisplayName, mvs.Description, variable);
                                    }
                                    else
                                    {
                                        missingValueManager.Create(mvs.DisplayName, mvs.Description, variable, mvs.Placeholder);
                                    }
                                }
                                else if (mvs.Id > 0)
                                {
                                    missingValue = missingValues.Where(mv => mv.Id.Equals(mvs.Id)).FirstOrDefault();
                                    if (missingValue != null)
                                    {
                                        missingValue.DisplayName = mvs.DisplayName;
                                        missingValue.Description = mvs.Description;
                                        missingValue.Placeholder = mvs.Placeholder;
                                        missingValueManager.Update(missingValue);
                                    }
                                }
                            }
                        }
                    }

                    dataStructure = dataStructureManager.UpdateStructuredDataStructure(dataStructure);
                    DataStructureIO.setVariableOrder(dataStructure, variables.Select(svs => svs.Id).ToList());
                }
                else
                {
                    foreach (Variable v in dataStructure.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);
                    }
                }
                LoggerFactory.LogCustom("Variables for Data Structure " + Id + " stored.");
                return(Json(returnObject, JsonRequestBehavior.AllowGet));
            }
            finally
            {
                dataStructureManager.Dispose();
                dataContainerManager.Dispose();
                um.Dispose();
                missingValueManager.Dispose();
            }
        }
Exemple #8
0
        public MessageModel storeDataStructure(long Id, string Name, bool isStructured, string Description = "", string cssId = "", bool inUse = false)
        {
            Name        = Server.UrlDecode(Name);
            Description = Server.UrlDecode(Description);
            MessageModel DataStructureValidation = MessageModel.validateDataStructureInUse(Id);

            if (DataStructureValidation.hasMessage && inUse == false)
            {
                return(DataStructureValidation);
            }
            else
            {
                DataStructureValidation = MessageModel.validateDataStructureName(Id, Name, cssId);
                if (DataStructureValidation.hasMessage)
                {
                    return(DataStructureValidation);
                }
                else
                {
                    DataStructureManager dataStructureManager = null;
                    try
                    {
                        dataStructureManager = new DataStructureManager();

                        DataStructure dataStructure;
                        if (isStructured)
                        {
                            if (Id == 0)
                            {
                                dataStructure = dataStructureManager.CreateStructuredDataStructure(Name.Trim(), Description.Trim(), null, null, DataStructureCategory.Generic);
                                LoggerFactory.LogData(dataStructure.Id.ToString(), typeof(DataStructure).Name, Vaiona.Entities.Logging.CrudState.Created);
                                return(new MessageModel()
                                {
                                    Message = dataStructure.Id.ToString(),
                                    hasMessage = false,
                                    CssId = "redirect"
                                });
                            }
                            else
                            {
                                StructuredDataStructure StructuredDataStructure = dataStructureManager.StructuredDataStructureRepo.Get(Id);
                                StructuredDataStructure.Name        = Name;
                                StructuredDataStructure.Description = Description;
                                dataStructure = dataStructureManager.UpdateStructuredDataStructure(StructuredDataStructure);
                                LoggerFactory.LogData(dataStructure.Id.ToString(), typeof(DataStructure).Name, Vaiona.Entities.Logging.CrudState.Created);
                                return(new MessageModel()
                                {
                                    Message = Id.ToString(),
                                    hasMessage = false,
                                    CssId = "redirect"
                                });
                            }
                        }
                        else
                        {
                            if (Id == 0)
                            {
                                dataStructure = dataStructureManager.CreateUnStructuredDataStructure(Name.Trim(), Description.Trim());
                                LoggerFactory.LogData(dataStructure.Id.ToString(), typeof(DataStructure).Name, Vaiona.Entities.Logging.CrudState.Created);
                                return(new MessageModel()
                                {
                                    Message = "refresh DataStructureResultGrid",
                                    hasMessage = false,
                                    CssId = "refresh"
                                });
                            }
                            else
                            {
                                UnStructuredDataStructure unStructuredDataStructure = dataStructureManager.UnStructuredDataStructureRepo.Get(Id);
                                unStructuredDataStructure.Name        = Name;
                                unStructuredDataStructure.Description = Description;
                                dataStructure = dataStructureManager.UpdateUnStructuredDataStructure(unStructuredDataStructure);
                                LoggerFactory.LogData(dataStructure.Id.ToString(), typeof(DataStructure).Name, Vaiona.Entities.Logging.CrudState.Created);
                                return(new MessageModel()
                                {
                                    Message = "refresh DataStructureResultGrid",
                                    hasMessage = false,
                                    CssId = "refresh"
                                });
                            }
                        }
                    }
                    finally
                    {
                        dataStructureManager.Dispose();
                    }
                }
            }
        }
Exemple #9
0
        public ActionResult storeVariables(long Id, storeVariableStruct[] variables)
        {
            DataStructureManager dataStructureManager = null;
            DataContainerManager dataContainerManager = null;
            UnitManager          um = null;

            try
            {
                dataStructureManager = new DataStructureManager();
                var structureRepo = dataStructureManager.GetUnitOfWork().GetReadOnlyRepository <StructuredDataStructure>();

                StructuredDataStructure dataStructure = structureRepo.Get(Id);
                MessageModel            returnObject  = new MessageModel();
                MessageModel            messageModel  = MessageModel.validateDataStructureInUse(dataStructure.Id, dataStructure);
                if (messageModel.hasMessage)
                {
                    foreach (Variable v in dataStructure.Variables)
                    {
                        if (variables.Select(svs => svs.Id).ToList().Contains(v.Id))
                        {
                            v.Description = variables.Where(svs => svs.Id == v.Id).FirstOrDefault().Description;
                            dataStructure = dataStructureManager.UpdateStructuredDataStructure(dataStructure);
                        }
                    }
                    return(PartialView("_messageWindow", messageModel));
                }

                if (variables != null && variables.Count() > 0)
                {
                    Variable    variable = new Variable();
                    List <long> order    = new List <long>();

                    foreach (Variable v in dataStructure.Variables)
                    {
                        if (!variables.Select(svs => svs.Id).ToList().Contains(v.Id))
                        {
                            dataStructureManager.RemoveVariableUsage(v);
                        }
                    }

                    foreach (storeVariableStruct svs in variables.Where(svs => svs.Id == 0).ToList())
                    {
                        if (svs.Lable == null)
                        {
                            svs.Lable = "";
                        }
                        if (svs.Description == null)
                        {
                            svs.Description = "";
                        }
                        try
                        {
                            dataContainerManager = new DataContainerManager();
                            DataAttribute dataAttribute = dataContainerManager.DataAttributeRepo.Get(svs.AttributeId);
                            if (dataAttribute != null)
                            {
                                try
                                {
                                    um       = new UnitManager();
                                    variable = dataStructureManager.AddVariableUsage(dataStructure, dataAttribute, svs.isOptional, svs.Lable.Trim(), null, null, svs.Description.Trim(), um.Repo.Get(svs.UnitId));
                                    svs.Id   = variable.Id;
                                }
                                finally
                                {
                                    um.Dispose();
                                }
                            }
                            else
                            {
                                returnObject = new MessageModel()
                                {
                                    hasMessage = true,
                                    Message    = "Not all Variables are stored.",
                                    CssId      = "0"
                                };
                            }
                        }
                        finally
                        {
                            // Javad: would be better to conctruct and dispose this object outside of the loop
                            dataContainerManager.Dispose();
                        }
                    }
                    dataStructure = structureRepo.Get(Id); // Javad: why it is needed?

                    variables = variables.Where(v => v.Id != 0).ToArray();

                    foreach (storeVariableStruct svs in variables.Where(svs => svs.Id != 0).ToList())
                    {
                        if (svs.Lable == null)
                        {
                            svs.Lable = "";
                        }
                        if (svs.Description == null)
                        {
                            svs.Description = "";
                        }

                        variable = dataStructure.Variables.Where(v => v.Id == svs.Id).FirstOrDefault();
                        if (variable != null)
                        {
                            variable.Label       = svs.Lable.Trim();
                            variable.Description = svs.Description.Trim();

                            try
                            {
                                um = new UnitManager();
                                dataContainerManager = new DataContainerManager();

                                variable.Unit            = um.Repo.Get(svs.UnitId);
                                variable.DataAttribute   = dataContainerManager.DataAttributeRepo.Get(svs.AttributeId);
                                variable.IsValueOptional = svs.isOptional;
                            }
                            finally
                            {
                                um.Dispose(); // Javad: would be better to conctruct and dipose these objects outside of the loop
                                dataContainerManager.Dispose();
                            }
                        }
                    }

                    dataStructure = dataStructureManager.UpdateStructuredDataStructure(dataStructure);
                    DataStructureIO.setVariableOrder(dataStructure, variables.Select(svs => svs.Id).ToList());
                }
                else
                {
                    foreach (Variable v in dataStructure.Variables)
                    {
                        dataStructureManager.RemoveVariableUsage(v);
                    }
                }
                LoggerFactory.LogCustom("Variables for Data Structure " + Id + " stored.");
                return(Json(returnObject, JsonRequestBehavior.AllowGet));
            }
            finally
            {
                dataStructureManager.Dispose();
                dataContainerManager.Dispose();
                um.Dispose();
            }
        }