UpdateStructuredDataStructure() public method

Applies changes to the data structure and persists them in the database.
public UpdateStructuredDataStructure ( StructuredDataStructure entity ) : StructuredDataStructure
entity BExIS.Dlm.Entities.DataStructure.StructuredDataStructure The entity containing the changes.
return BExIS.Dlm.Entities.DataStructure.StructuredDataStructure
Example #1
0
        public static XmlDocument setVariableOrder(StructuredDataStructure structuredDataStructure, List<long> orderList)
        {
            DataStructureManager dsm = new DataStructureManager();
            XmlDocument doc = createOderNode(structuredDataStructure);
            XmlNode order = doc.GetElementsByTagName("order")[0];

            doc.FirstChild.RemoveChild(order);
            order = doc.CreateNode(XmlNodeType.Element, "order", null);

            foreach (long l in orderList)
            {
                XmlNode variable = doc.CreateNode(XmlNodeType.Element, "variable", null);
                variable.InnerText = l.ToString();
                order.AppendChild(variable);
            }

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

            return doc;
        }
 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 = 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"
                     };
                 }
             }
         }
     }
 }
        public List<Variable> getOrderedVariables(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);
                }
            }

            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;
        }
        public ActionResult storeVariables(long Id, storeVariableStruct[] variables)
        {
            DataStructureManager dataStructureManager = new DataStructureManager();
            StructuredDataStructure dataStructure = dataStructureManager.StructuredDataStructureRepo.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 = "";

                    DataAttribute dataAttribute = new DataContainerManager().DataAttributeRepo.Get(svs.AttributeId);
                    if (dataAttribute != null)
                    {
                        variable = dataStructureManager.AddVariableUsage(dataStructure, dataAttribute, svs.isOptional, svs.Lable.Trim(), null, null, svs.Description.Trim(), new UnitManager().Repo.Get(svs.UnitId));
                        svs.Id = variable.Id;
                    }
                    else
                    {
                        returnObject = new MessageModel()
                        {
                            hasMessage = true,
                            Message = "Not all Variables are stored.",
                            CssId = "0"
                        };
                    }
                }
                dataStructure = dataStructureManager.StructuredDataStructureRepo.Get(Id);

                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();
                        variable.Unit = new UnitManager().Repo.Get(svs.UnitId);
                        variable.DataAttribute = new DataContainerManager().DataAttributeRepo.Get(svs.AttributeId);
                        variable.IsValueOptional = svs.isOptional;
                    }
                }

                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);
        }
Example #5
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;
        }
Example #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);
        }