private void AlsoCopyEmbeddedStepsToClipboard(string sUserID, string sSourceStepID, string sRootStepID, string sNewParentStepID, ref string sErr) { dataAccess dc = new dataAccess(); FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates(); acUI.acUI ui = new acUI.acUI(); //get all the steps that have the calling stepid as a parent (codeblock) string sSQL = "select step_id" + " from task_step" + " where codeblock_name = '" + sSourceStepID + "'"; DataTable dt = new DataTable(); if (!dc.sqlGetDataTable(ref dt, sSQL, ref sErr)) throw new Exception(sErr); foreach (DataRow dr in dt.Rows) { string sThisStepID = dr["step_id"].ToString(); string sThisNewID = ui.NewGUID(); //put them in the table sSQL = "delete from task_step_clipboard" + " where user_id = '" + sUserID + "'" + " and src_step_id = '" + sThisStepID + "'"; if (!dc.sqlExecuteUpdate(sSQL, ref sErr)) throw new Exception("Unable to clean embedded steps of [" + sSourceStepID + "]." + sErr); sSQL = " insert into task_step_clipboard" + " (user_id, clip_dt, src_step_id, root_step_id, step_id, function_name, function_xml, step_desc," + " output_parse_type, output_row_delimiter, output_column_delimiter, variable_xml, codeblock_name)" + " select '" + sUserID + "', now(), step_id, '" + sRootStepID + "', '" + sThisNewID + "'," + " function_name, function_xml, step_desc," + " output_parse_type, output_row_delimiter, output_column_delimiter, variable_xml, '" + sNewParentStepID + "'" + " from task_step" + " where step_id = '" + sThisStepID + "'"; if (!dc.sqlExecuteUpdate(sSQL, ref sErr)) throw new Exception("Unable to copy embedded steps of [" + sSourceStepID + "]." + sErr); //we need to update the "action" XML of the parent too... /*OK here's the deal..I'm out of time This should not be hardcoded, it should be smart enough to find an XML node with a specific value and update that node. I just don't know enought about xpath to figure it out, and don't have time to do it before I gotta start chilling at tmo. So, I've hardcoded it to the known cases so it will work. Add a new dynamic command type that has embedded steps, and this will probably no longer work. */ ft.SetNodeValueinXMLColumn("task_step_clipboard", "function_xml", "user_id = '" + sUserID + "'" + " and step_id = '" + sNewParentStepID + "'", "//action[text() = '" + sThisStepID + "']", sThisNewID); ft.SetNodeValueinXMLColumn("task_step_clipboard", "function_xml", "user_id = '" + sUserID + "'" + " and step_id = '" + sNewParentStepID + "'", "//else[text() = '" + sThisStepID + "']", sThisNewID); ft.SetNodeValueinXMLColumn("task_step_clipboard", "function_xml", "user_id = '" + sUserID + "'" + " and step_id = '" + sNewParentStepID + "'", "//positive_action[text() = '" + sThisStepID + "']", sThisNewID); ft.SetNodeValueinXMLColumn("task_step_clipboard", "function_xml", "user_id = '" + sUserID + "'" + " and step_id = '" + sNewParentStepID + "'", "//negative_action[text() = '" + sThisStepID + "']", sThisNewID); //END OF HARDCODED HACK // and check this one for children too AlsoCopyEmbeddedStepsToClipboard(sUserID, sThisStepID, sRootStepID, sThisNewID, ref sErr); } }
public string wmRenameCodeblock(string sTaskID, string sOldCodeblockName, string sNewCodeblockName) { dataAccess dc = new dataAccess(); acUI.acUI ui = new acUI.acUI(); FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates(); try { if (ui.IsGUID(sTaskID)) { // first make sure we are not trying to rename it something that already exists. string sErr = ""; string sSQL = "select count(*) from task_codeblock where task_id = '" + sTaskID + "'" + " and codeblock_name = '" + sNewCodeblockName + "'"; int iCount = 0; if (!dc.sqlGetSingleInteger(ref iCount, sSQL, ref sErr)) { throw new Exception("Unable to check codeblock names for task." + sErr); } if (iCount != 0) { return ("Codeblock Name already in use, choose another."); } // do it dataAccess.acTransaction oTrans = new dataAccess.acTransaction(ref sErr); //update the codeblock table sSQL = "update task_codeblock set codeblock_name = '" + sNewCodeblockName + "' where codeblock_name = '" + sOldCodeblockName + "' and task_id = '" + sTaskID + "'"; oTrans.Command.CommandText = sSQL; if (!oTrans.ExecUpdate(ref sErr)) { throw new Exception(sErr); } //and any steps in that codeblock sSQL = "update task_step set codeblock_name = '" + sNewCodeblockName + "' where codeblock_name = '" + sOldCodeblockName + "' and task_id = '" + sTaskID + "'"; oTrans.Command.CommandText = sSQL; if (!oTrans.ExecUpdate(ref sErr)) { throw new Exception(sErr); } //the fun part... rename it where it exists in any steps //but this must be in a loop of only the steps where that codeblock reference exists. sSQL = "select step_id from task_step" + " where task_id = '" + sTaskID + "'" + " and ExtractValue(function_xml, '//codeblock[1]') = '" + sOldCodeblockName + "'"; oTrans.Command.CommandText = sSQL; DataTable dtSteps = new DataTable(); if (!oTrans.ExecGetDataTable(ref dtSteps, ref sErr)) { throw new Exception("Unable to get steps referencing the Codeblock." + sErr); } foreach (DataRow dr in dtSteps.Rows) { ft.SetNodeValueinXMLColumn("task_step", "function_xml", "step_id = '" + dr["step_id"].ToString() + "'", "//codeblock[. = '" + sOldCodeblockName + "']", sNewCodeblockName); } //all done oTrans.Commit(); return sErr; } else { throw new Exception("Unable to get codeblocks for task. Missing or invalid task_id."); } } 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 ""; }
public void wmUpdateRegistryValue(string sObjectID, string sXPath, string sValue, string sEncrypt) { dataAccess dc = new dataAccess(); FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates(); //fail on missing values if (string.IsNullOrEmpty(sXPath)) throw new Exception("Missing XPath to update."); //masked means update an attribute AND encrypt the value sEncrypt = (dc.IsTrue(sEncrypt) ? "true" : "false"); sValue = (dc.IsTrue(sEncrypt) ? dc.EnCrypt(sValue) : sValue); //update if (sObjectID == "global") sObjectID = "1"; ft.SetNodeValueinXMLColumn("object_registry", "registry_xml", "object_id = '" + sObjectID + "'", sXPath, sValue); ft.SetNodeAttributeinXMLColumn("object_registry", "registry_xml", "object_id = '" + sObjectID + "'", sXPath, "encrypt", sEncrypt); return; }