public void wmFnNodeArrayAdd(string sStepID, string sGroupNode)
        {
            dataAccess dc = new dataAccess();
            FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates();
            try
            {
                string sErr = "";

                //what's the command type?
                string sFunctionName = "";
                string sSQL = "select function_name from task_step where step_id = '" + sStepID + "'";
                if (!dc.sqlGetSingleString(ref sFunctionName, sSQL, ref sErr))
                    throw new Exception(sErr);

                if (sFunctionName.Length > 0)
                {
                    //so, let's get the one we want from the XML template for this step... adjust the indexes, and add it.
                    string sXML = ft.GetCommandXMLTemplate(sFunctionName, ref sErr);
                    if (sErr != "") throw new Exception(sErr);

                    //validate it
                    //parse the doc from the table
                    XDocument xd = XDocument.Parse(sXML);
                    if (xd == null) throw new Exception("Error: Unable to parse Function XML.");

                    //get the original "group" node from the xml_template
                    //here's the rub ... the "sGroupNode" from the actual command instance might have xpath indexes > 1...
                    //but the template DOESN'T!
                    //So, I'm regexing any [#] on the string back to a [1]... that value should be in the template.

                    Regex rx = new Regex(@"\[[0-9]*\]");
                    string sTemplateNode = rx.Replace(sGroupNode, "[1]");

                    XElement xGroupNode = xd.XPathSelectElement("//" + sTemplateNode);
                    if (xGroupNode == null) throw new Exception("Error: Unable to add.  Source node not found in Template XML. [" + sTemplateNode + "]");

                    //yeah, this wicked single line aggregates the string value of each node
                    string sNewXML = xGroupNode.Nodes().Aggregate("", (str, node) => str += node.ToString());

                    if (sNewXML != "")
                        ft.AddNodeToXMLColumn("task_step", "function_xml", "step_id = '" + sStepID + "'", "//" + sGroupNode, sNewXML);

                }
                else
                    throw new Exception("Error: Could not loop up XML for command type [" + sFunctionName + "].");

                return;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public string wmUpdateTaskParam(string sType, string sID, string sParamID,
            string sName, string sDesc,
            string sRequired, string sPrompt, string sEncrypt, string sPresentAs, string sValues)
        {
            dataAccess dc = new dataAccess();

            acUI.acUI ui = new acUI.acUI();
            FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates();

            if (!ui.IsGUID(sID))
                throw new Exception("Invalid or missing ID.");

            string sErr = "";
            string sSQL = "";

            //we encoded this in javascript before the ajax call.
            //the safest way to unencode it is to use the same javascript lib.
            //(sometimes the javascript and .net libs don't translate exactly, google it.)
            sDesc = ui.unpackJSON(sDesc).Trim();

            //normalize and clean the values
            sRequired = (dc.IsTrue(sRequired) ? "true" : "false");
            sPrompt = (dc.IsTrue(sPrompt) ? "true" : "false");
            sEncrypt = (dc.IsTrue(sEncrypt) ? "true" : "false");
            sName = sName.Trim().Replace("'", "''");

            string sTable = "";
            string sXML = "";
            string sParameterXPath = "//parameter[@id = \"" + sParamID + "\"]";  //using this to keep the code below cleaner.

            if (sType == "ecosystem")
                sTable = "ecosystem";
            else if (sType == "task")
                sTable = "task";

            bool bParamAdd = false;
            //bool bParamUpdate = false;

            //if sParamID is empty, we are adding
            if (string.IsNullOrEmpty(sParamID))
            {
                sParamID = "p_" + ui.NewGUID();
                sParameterXPath = "//parameter[@id = \"" + sParamID + "\"]";  //reset this if we had to get a new id

                //does the task already have parameters?
                sSQL = "select parameter_xml from " + sTable + " where " + sType + "_id = '" + sID + "'";
                if (!dc.sqlGetSingleString(ref sXML, sSQL, ref sErr))
                    throw new Exception(sErr);

                string sAddXML = "<parameter id=\"" + sParamID + "\" required=\"" + sRequired + "\" prompt=\"" + sPrompt + "\" encrypt=\"" + sEncrypt + "\">" +
                    "<name>" + sName + "</name>" +
                    "<desc>" + sDesc + "</desc>" +
                    "</parameter>";

                if (string.IsNullOrEmpty(sXML))
                {
                    //XML doesn't exist at all, add it to the record
                    sAddXML = "<parameters>" + sAddXML + "</parameters>";

                    sSQL = "update " + sTable + " set " +
                        " parameter_xml = '" + sAddXML + "'" +
                        " where " + sType + "_id = '" + sID + "'";

                    if (!dc.sqlExecuteUpdate(sSQL, ref sErr))
                        throw new Exception(sErr);

                    bParamAdd = true;
                }
                else
                {
                    //XML exists, add the node to it
                    ft.AddNodeToXMLColumn(sTable, "parameter_xml", sType + "_id = '" + sID + "'", "//parameters", sAddXML);
                    bParamAdd = true;
                }
            }
            else
            {
                //update the node values
                ft.SetNodeValueinXMLColumn(sTable, "parameter_xml", sType + "_id = '" + sID + "'", sParameterXPath + "/name", sName);
                ft.SetNodeValueinXMLColumn(sTable, "parameter_xml", sType + "_id = '" + sID + "'", sParameterXPath + "/desc", sDesc);
                //and the attributes
                ft.SetNodeAttributeinXMLColumn(sTable, "parameter_xml", sType + "_id = '" + sID + "'", sParameterXPath, "required", sRequired);
                ft.SetNodeAttributeinXMLColumn(sTable, "parameter_xml", sType + "_id = '" + sID + "'", sParameterXPath, "prompt", sPrompt);
                ft.SetNodeAttributeinXMLColumn(sTable, "parameter_xml", sType + "_id = '" + sID + "'", sParameterXPath, "encrypt", sEncrypt);

                bParamAdd = false;
            }

            // not clean at all handling both tasks and ecosystems in the same method, but whatever.
            if (bParamAdd)
            {
                if (sType == "task") { ui.WriteObjectAddLog(Globals.acObjectTypes.Task, sID, "Parameter", "Added Parameter:" + sName ); };
                if (sType == "ecosystem") { ui.WriteObjectAddLog(Globals.acObjectTypes.Ecosystem, sID, "Parameter", "Added Parameter:" + sName); };
            }
            else
            {
                // would be a lot of trouble to add the from to, why is it needed you have each value in the log, just scroll back
                // so just add a changed message to the log
                if (sType == "task") { dc.addSecurityLog(ui.GetSessionUserID(), Globals.SecurityLogTypes.Object, Globals.SecurityLogActions.ObjectModify, Globals.acObjectTypes.Task, sID, "Parameter Changed:[" + sName + "]", ref sErr); };
                if (sType == "ecosystem") { dc.addSecurityLog(ui.GetSessionUserID(), Globals.SecurityLogTypes.Object, Globals.SecurityLogActions.ObjectModify, Globals.acObjectTypes.Ecosystem, sID, "Parameter Changed:[" + sName + "]", ref sErr); };
            }

            //update the values
            string[] aValues = sValues.Split('|');
            string sValueXML = "";

            foreach (string sVal in aValues)
            {
                string sReadyValue = "";

                //if encrypt is true we MIGHT want to encrypt this value.
                //but it might simply be a resubmit of an existing value in which case we DON'T
                //if it has oev: as a prefix, it needs no additional work
                if (dc.IsTrue(sEncrypt))
                {
                    if (sVal.IndexOf("oev:") > -1)
                        sReadyValue = sVal.Replace("oev:", "");
                    else
                        sReadyValue = dc.EnCrypt(ui.unpackJSON(sVal));
                } else {
                    sReadyValue = ui.unpackJSON(sVal);
                }

                sValueXML += "<value id=\"pv_" + ui.NewGUID() + "\">" + sReadyValue + "</value>";
            }

            sValueXML = "<values present_as=\"" + sPresentAs + "\">" + sValueXML + "</values>";

            //whack-n-add
            ft.RemoveNodeFromXMLColumn(sTable, "parameter_xml", sType + "_id = '" + sID + "'", sParameterXPath + "/values");
            ft.AddNodeToXMLColumn(sTable, "parameter_xml", sType + "_id = '" + sID + "'", sParameterXPath, sValueXML);

            return "";
        }
Exemple #3
0
        public void wmFnNodeArrayAdd(string sStepID, string sGroupNode)
        {
            FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates();
            try
            {
                //so, let's get the one we want from the XML template for this step... adjust the indexes, and add it.
                Function func = Function.GetFunctionForStep(sStepID);
                if (func == null)
                    throw new Exception("Unable to look up Function definition for Step [" + sStepID + "] in Function class.");

                //validate it
                //parse the doc from the table
                XDocument xd = func.TemplateXDoc;
                if (xd == null) throw new Exception("Unable to get Function Template.");

                //get the original "group" node from the xml_template
                //here's the rub ... the "sGroupNode" from the actual command instance might have xpath indexes > 1...
                //but the template DOESN'T!
                //So, I'm regexing any [#] on the string back to a [1]... that value should be in the template.

                Regex rx = new Regex(@"\[[0-9]*\]");
                string sTemplateNode = rx.Replace(sGroupNode, "[1]");

                XElement xGroupNode = xd.XPathSelectElement("//" + sTemplateNode);
                if (xGroupNode == null) throw new Exception("Error: Unable to add.  Source node not found in Template XML. [" + sTemplateNode + "]");

                //yeah, this wicked single line aggregates the string value of each node
                string sNewXML = xGroupNode.Nodes().Aggregate("", (str, node) => str += node.ToString());

                if (sNewXML != "")
                    ft.AddNodeToXMLColumn("task_step", "function_xml", "step_id = '" + sStepID + "'", "//" + sGroupNode, sNewXML);
                return;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }