Example #1
0
        public static string GetConnectionTypes()
        {
            FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates();
            string sErr = "";

            DataTable dt = new DataTable();

            dt = ft.getConnectionTypes(ref sErr);
            if (!string.IsNullOrEmpty(sErr))
            {
                throw new Exception("Connection Type lookup error: " + sErr);
            }
            else
            {
                string sHTML = "<select name=\"ddlConnectionType\" style=\"width: 200px;\" id=\"ddlConnectionType\">";
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        sHTML += "<option value=\"" + dr["connection_type"].ToString() + "\">" + dr["connection_type"].ToString() + "</option>";
                    }
                }
                sHTML += "</select>";
                return(sHTML);
            }
        }
Example #2
0
        public static string wmGetVars(string sStepID)
        {
            FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates();
            string sErr = "";
            Step oStep = new Step(sStepID, "", ref sErr);
            if (!string.IsNullOrEmpty(sErr))
                throw new Exception("No data row found for step_id [" + sStepID + "].<br />" + sErr);

            if (oStep != null)
                return ft.GetVariablesForStepForEdit(oStep);
            else
                return "";
        }
Example #3
0
        public static string wmGetVars(string sStepID)
        {
            FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates();
            string sErr  = "";
            Step   oStep = new Step(sStepID, "", ref sErr);

            if (!string.IsNullOrEmpty(sErr))
            {
                throw new Exception("No data row found for step_id [" + sStepID + "].<br />" + sErr);
            }

            if (oStep != null)
            {
                return(ft.GetVariablesForStepForEdit(oStep));
            }
            else
            {
                return("");
            }
        }
Example #4
0
        public void wmSaveDefaultParameterXML(Dictionary<string, string> args)
        {
            //this web method accepts a json object as properties, which is received by .net as a Dictionary!

            dataAccess dc = new dataAccess();

            acUI.acUI ui = new acUI.acUI();
            taskMethods tm = new taskMethods();

            try
            {
                string sUserID = ui.GetSessionUserID();

                if (ui.IsGUID(args["sID"]) && ui.IsGUID(sUserID))
                {
                    string sErr = "";
                    string sSQL = "";
                    string sTaskID = "";
                    string sID = args["sID"];
                    string sType = args["sType"];

                    //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.)
                    string sXML = ui.unpackJSON(args["sXML"]);

                    //we gotta peek into the XML and encrypt any newly keyed values
                    PrepareAndEncryptParameterXML(ref sXML);

                    //so, like when we read it, we gotta spin and compare, and build an XML that only represents *changes*
                    //to the defaults on the task.

                    if (sType == "action") {
                        //what is the task associated with this action?
                        sSQL = "select t.task_id" +
                            " from ecotemplate_action ea" +
                            " join task t on ea.original_task_id = t.original_task_id" +
                            " and t.default_version = 1" +
                            " where ea.action_id = '" + sID + "'";
                    } else if (sType == "runtask") {
                        sTaskID = args["sTaskID"];
                    }

                    if (string.IsNullOrEmpty(sTaskID))
                        if (!dc.sqlGetSingleString(ref sTaskID, sSQL, ref sErr))
                            throw new Exception(sErr);

                    if (!ui.IsGUID(sTaskID))
                        throw new Exception("Unable to find Task ID for Action.");

                    string sOverrideXML = "";
                    XDocument xTPDoc = new XDocument();
                    XDocument xADDoc = new XDocument();

                    //get the parameter XML from the TASK
                    string sTaskParamXML = tm.wmGetParameterXML("task", sTaskID, "");
                    if (!string.IsNullOrEmpty(sTaskParamXML))
                    {
                        xTPDoc = XDocument.Parse(sTaskParamXML);
                        if (xTPDoc == null)
                            throw new Exception("Task Parameter XML data is invalid.");

                        XElement xTPParams = xTPDoc.XPathSelectElement("/parameters");
                        if (xTPParams == null)
                            throw new Exception("Task Parameter XML data does not contain 'parameters' root node.");
                    }

                    //we had the ACTION defaults handed to us
                    if (!string.IsNullOrEmpty(sXML))
                    {
                        xADDoc = XDocument.Parse(sXML);
                        if (xADDoc == null)
                            throw new Exception("Action Defaults XML data is invalid.");

                        XElement xADParams = xADDoc.XPathSelectElement("/parameters");
                        if (xADParams == null)
                            throw new Exception("Action Defaults XML data does not contain 'parameters' root node.");
                    }

                    //spin the nodes in the ACTION xml, then dig in to the task XML and UPDATE the value if found.
                    //(if the node no longer exists, delete the node from the action XML)
                    //and action "values" take precedence over task values.

                    //this does a regular loop because we can't remove from an IEnumerable
                    int x = xADDoc.XPathSelectElements("//parameter").Count();
                    for (int i = (x-1); i>=0; i--)
                    {
                        XElement xDefault = xADDoc.XPathSelectElements("//parameter").ElementAt(i);

                        //look it up in the task param xml
                        XElement xADName = xDefault.XPathSelectElement("name");
                        string sADName = (xADName == null ? "" : xADName.Value);
                        XElement xADValues = xDefault.XPathSelectElement("values");
                        //string sValues = (xValues == null ? "" : xValues.ToString());

                        //now we have the name of the parameter, go find it in the TASK param XML
                        XElement xTaskParam = xTPDoc.XPathSelectElement("//parameter/name[. = '" + sADName + "']/..");  //NOTE! the /.. gets the parent of the name node!

                        //if it doesn't exist in the task params, remove it from this document
                        if (xTaskParam == null)
                        {
                            xDefault.Remove();
                            continue;
                        }

                        //and the "values" collection will be the 'next' node
                        XElement xTaskParamValues = xTaskParam.XPathSelectElement("values");

                        //so... it might be
                        //a) just an oev (original encrypted value) so de-base64 it
                        //b) a value flagged for encryption

                        //note we don't care about dirty unencrypted values... they'll compare down below just fine.

                        //is it encrypted?
                        bool bEncrypted = false;
                        if (xTaskParam.Attribute("encrypt") != null)
                            bEncrypted = dc.IsTrue(xTaskParam.Attribute("encrypt").Value);

                        if (bEncrypted)
                        {
                            foreach (XElement xVal in xADValues.XPathSelectElements("value"))
                            {
                                if (xVal.HasAttributes) {
                                    //a) is it an oev?  unpackJSON it (that's just an obfuscation wrapper)
                                    if (xVal.Attribute("oev") != null)
                                    {
                                        if (dc.IsTrue(xVal.Attribute("oev").Value))
                                        {
                                            xVal.Value = ui.unpackJSON(xVal.Value);
                                            xVal.SetAttributeValue("oev", null);
                                        }
                                    }

                                    //b) is it do_encrypt?  (remove the attribute to keep the db clutter down)
                                    if (xVal.Attribute("do_encrypt") != null)
                                    {
                                        xVal.Value = dc.EnCrypt(xVal.Value);
                                        xVal.SetAttributeValue("do_encrypt", null);
                                    }
                                }
                            }
                        }

                        //now that the encryption is sorted out,
                        // if the combined values of the parameter happens to match what's on the task
                        //  we just remove it.

                        //we're doing combined because of lists (the whole list must match for it to be a dupe)

                        //it's easy to look at all the values in a node with the node.Value property.
                        //but we'll have to manually concatenate all the oev attributes

                        string sTaskVals = "";
                        string sDefVals = "";

                        if (bEncrypted)
                        {
                            // the task document already has the oev obfuscated
                            foreach (XAttribute xa in xTaskParamValues.Elements("value").Attributes("oev"))
                            {
                                sTaskVals += xa.Value;
                            }
                            //but the XML we just got from the client doesn't... it's in the value.
                            foreach (XElement xe in xADValues.Elements("value"))
                            {
                                sDefVals += ui.packJSON(xe.Value);
                            }
                            if (sTaskVals.Equals(sDefVals))
                            {
                                xDefault.Remove();
                                continue;
                            }
                        }
                        else
                        {
                            if (xTaskParamValues.Value.Equals(xADValues.Value))
                            {
                                xDefault.Remove();
                                continue;
                            }
                        }

                    }

                    //done
                    sOverrideXML = xADDoc.ToString(SaveOptions.DisableFormatting);

                    //FINALLY, we have an XML that represents only the differences we wanna save.
                    if (sType == "action") {
                        sSQL = "update ecotemplate_action set" +
                            " parameter_defaults = '" + sOverrideXML + "'" +
                            " where action_id = '" + sID + "'";

                        if (!dc.sqlExecuteUpdate(sSQL, ref sErr))
                            throw new Exception("Unable to update Action [" + sID + "]." + sErr);

                        if (sType == "action")
                            ui.WriteObjectChangeLog(Globals.acObjectTypes.EcoTemplate, sID, sID, "Default parameters updated: [" + sOverrideXML + "]");
                    } else if (sType == "runtask") {
                        //WICKED!!!!
                        //I can use my super awesome xml functions!
                        FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates();
                        ft.RemoveFromCommandXML(sID, "//parameters");
                        ft.AddToCommandXML(sID, "//function", sOverrideXML);
                    }
                }
                else
                {
                    throw new Exception("Unable to update Eco Template Action. Missing or invalid Action ID.");
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return;
        }
        public void wmFnExistsAddVar(string sStepID)
        {
            FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates();
            try
            {
                ft.AddToCommandXML(sStepID, "//function", "<variable>" +
                    "<name input_type=\"text\"></name><is_true>0</is_true>" +
                    "</variable>");

                return;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public string wmDeleteTaskParam(string sType, string sID, string sParamID)
        {
            dataAccess dc = new dataAccess();

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

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

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

            if (!string.IsNullOrEmpty(sParamID) && ui.IsGUID(sID))
            {
                // need the name and values for logging
                string sXML = "";

                sSQL = "select parameter_xml" +
                    " from " + sTable +
                    " where " + sType + "_id = '" + sID + "'";

                if (!dc.sqlGetSingleString(ref sXML, sSQL, ref sErr))
                    throw new Exception("Unable to get parameter_xml.  " + sErr);

                if (sXML != "")
                {
                    XDocument xd = XDocument.Parse(sXML);
                    if (xd == null) throw new Exception("XML parameter data is invalid.");

                    XElement xName = xd.XPathSelectElement("//parameter[@id = \"" + sParamID + "\"]/name");
                    string sName = (xName == null ? "" : xName.Value);
                    XElement xValues = xd.XPathSelectElement("//parameter[@id = \"" + sParamID + "\"]/values");
                    string sValues = (xValues == null ? "" : xValues.ToString());

                    // add security log
                    ui.WriteObjectDeleteLog(Globals.acObjectTypes.Parameter, "", sID, "");

                    if (sType == "task") { ui.WriteObjectChangeLog(Globals.acObjectTypes.Task, sID, "Deleted Parameter:[" + sName + "]", sValues); };
                    if (sType == "ecosystem") { ui.WriteObjectChangeLog(Globals.acObjectTypes.Ecosystem, sID, "Deleted Parameter:[" + sName + "]", sValues); };
                }

                //do the whack
                ft.RemoveNodeFromXMLColumn(sTable, "parameter_xml", sType + "_id = '" + sID + "'", "//parameter[@id = \"" + sParamID + "\"]");

                return "";
            }
            else
            {
                throw new Exception("Invalid or missing Task or Parameter ID.");
            }
        }
        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 wmGetMergedParameterXML(string sType, string sID, string sEcosystemID)
        {
            dataAccess dc = new dataAccess();
            acUI.acUI ui = new acUI.acUI();
            taskMethods tm = new taskMethods();
            FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates();

            if (string.IsNullOrEmpty(sID))
                throw new Exception("ID required to look up default Parameter values.");

            string sErr = "";

            //what is the task associated with this action?
            //and get the XML for it
            string sSQL = "";
            string sDefaultsXML = "";
            string sTaskID = "";

            if (sType == "action")
            {
                sDefaultsXML = tm.wmGetObjectParameterXML(sType, sID, "");

                sSQL = "select t.task_id" +
                     " from ecotemplate_action ea" +
                     " join task t on ea.original_task_id = t.original_task_id" +
                     " and t.default_version = 1" +
                     " where ea.action_id = '" + sID + "'";
            }
            else if (sType == "instance")
            {
                sDefaultsXML = tm.wmGetObjectParameterXML(sType, sID, sEcosystemID);

                //IMPORTANT!!! if the ID is not a guid, it's a specific instance ID, and we'll need to get the task_id
                //but if it is a GUID, but the type is "instance", taht means the most recent INSTANCE for this TASK_ID
                if (ui.IsGUID(sID))
                    sTaskID = sID;
                else
                    sSQL = "select task_id" +
                         " from task_instance" +
                         " where task_instance = '" + sID + "'";
            }
            else if (sType == "plan")
            {
                sDefaultsXML = tm.wmGetObjectParameterXML(sType, sID, "");

                sSQL = "select task_id" +
                    " from action_plan" +
                    " where plan_id = '" + sID + "'";
            }
            else if (sType == "schedule")
            {
                sDefaultsXML = tm.wmGetObjectParameterXML(sType, sID, "");

                sSQL = "select task_id" +
                    " from action_schedule" +
                    " where schedule_id = '" + sID + "'";
            }

            //if we didn't get a task id directly, use the SQL to look it up
            if (string.IsNullOrEmpty(sTaskID))
                if (!dc.sqlGetSingleString(ref sTaskID, sSQL, ref sErr))
                    throw new Exception(sErr);

            if (!ui.IsGUID(sTaskID))
                throw new Exception("Unable to find Task ID for record.");

            XDocument xTPDoc = new XDocument();
            XDocument xDefDoc = new XDocument();

            //get the parameter XML from the TASK
            string sTaskParamXML = tm.wmGetParameterXML("task", sTaskID, "");
            if (!string.IsNullOrEmpty(sTaskParamXML))
            {
                xTPDoc = XDocument.Parse(sTaskParamXML);
                if (xTPDoc == null)
                    throw new Exception("Task Parameter XML data is invalid.");

                XElement xTPParams = xTPDoc.XPathSelectElement("/parameters");
                if (xTPParams == null)
                    throw new Exception("Task Parameter XML data does not contain 'parameters' root node.");
            }

            //we populated this up above too
            if (!string.IsNullOrEmpty(sDefaultsXML))
            {
                xDefDoc = XDocument.Parse(sDefaultsXML);
                if (xDefDoc == null)
                    throw new Exception("Defaults XML data is invalid.");

                XElement xDefParams = xDefDoc.XPathSelectElement("/parameters");
                if (xDefParams == null)
                    throw new Exception("Defaults XML data does not contain 'parameters' root node.");
            }

            //spin the nodes in the DEFAULTS xml, then dig in to the task XML and UPDATE the value if found.
            //(if the node no longer exists, delete the node from the defaults xml IF IT WAS AN ACTION)
            //and default "values" take precedence over task values.
            foreach (XElement xDefault in xDefDoc.XPathSelectElements("//parameter"))
            {
                //nothing to do if it's empty
                if (xDefault == null)
                    break;

                //look it up in the task param xml
                XElement xDefName = xDefault.XPathSelectElement("name");
                string sDefName = (xDefName == null ? "" : xDefName.Value);
                XElement xDefValues = xDefault.XPathSelectElement("values");

                //nothing to do if there is no values node...
                if (xDefValues == null)
                    break;
                //or if it contains no values.
                if (!xDefValues.HasElements)
                    break;
                //or if there is no parameter name
                if (string.IsNullOrEmpty(sDefName))
                    break;

                //so, we have some valid data in the defaults xml... let's merge!

                //we have the name of the parameter... go find it in the TASK param XML
                XElement xTaskParam = xTPDoc.XPathSelectElement("//parameter/name[. = '" + sDefName + "']/..");  //NOTE! the /.. gets the parent of the name node!

                //if it doesn't exist in the task params, remove it from this document, permanently
                //but only for action types... instance data is historical and can't be munged
                if (xTaskParam == null && sType == "action")
                {
                    ft.RemoveNodeFromXMLColumn("ecotemplate_action", "parameter_defaults", "action_id = '" + sID + "'", "//parameter/name[. = '" + sDefName + "']/..");
                    continue;
                }

                //is this an encrypted parameter?
                string sEncrypt = "";
                if (xTaskParam.Attribute("encrypt") != null)
                    sEncrypt = xTaskParam.Attribute("encrypt").Value;

                //and the "values" collection will be the 'next' node
                XElement xTaskParamValues = xTaskParam.XPathSelectElement("values");

                string sPresentAs = xTaskParamValues.Attribute("present_as").Value;
                if (sPresentAs == "dropdown")
                {
                    //dropdowns get a "selected" indicator
                    string sValueToSelect = xDefValues.XPathSelectElement("value").Value;

                    //find the right one by value and give it the "selected" attribute.
                    XElement xVal = xTaskParamValues.XPathSelectElement("value[. = '" + sValueToSelect + "']");
                    if (xVal != null)
                        xVal.SetAttributeValue("selected", "true");
                }
                else if (sPresentAs == "list")
                {
                    //first, a list gets ALL the values replaced...
                    xTaskParamValues.ReplaceNodes(xDefValues);
               	}
                else
                {
                    //IMPORTANT NOTE:
                    //remember... both these XML documents came from wmGetObjectParameterXML...
                    //so any encrypted data IS ALREADY OBFUSCATED and base64'd in the oev attribute.

                    //it's a single value, so just replace it with the default.
                    XElement xVal = xTaskParamValues.XPathSelectElement("value[1]");
                    if (xVal != null)
                    {
                        //if this is an encrypted parameter, we'll be replacing (if a default exists) the oev attribute
                        //AND the value... don't want them to get out of sync!
                        if (dc.IsTrue(sEncrypt))
                        {
                            if (xDefValues.XPathSelectElement("value") != null)
                                if (xDefValues.XPathSelectElement("value").Attribute("oev") != null)
                                {
                                    xVal.SetAttributeValue("oev", xDefValues.XPathSelectElement("value").Attribute("oev").Value);
                                    xVal.Value = xDefValues.XPathSelectElement("value").Value;
                                }
                        }
                        else
                        {
                            //not encrypted, just replace the value.
                            if (xDefValues.XPathSelectElement("value") != null)
                                xVal.Value = xDefValues.XPathSelectElement("value").Value;
                        }
                    }
                }
            }

            return xTPDoc.ToString(SaveOptions.DisableFormatting); ;
        }
Example #10
0
        public void wmFnWaitForTasksRemoveHandle(string sStepID, int iIndex)
        {
            FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates();
            try
            {
                if (iIndex > 0)
                {
                    ft.RemoveFromCommandXML(sStepID, "//function/handle[" + iIndex.ToString() + "]");

                    return;
                }
                else
                {
                    throw new Exception("Unable to modify step. Invalid index.");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #11
0
        public void wmDeleteRegistryNode(string sObjectID, string sXPath)
        {
            FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates();

            //fail on missing values
            if (string.IsNullOrEmpty(sXPath))
                throw new Exception("Missing XPath to add to.");

            if (sObjectID == "global") sObjectID = "1";
            ft.RemoveNodeFromXMLColumn("object_registry", "registry_xml", "object_id = '" + sObjectID + "'", sXPath);

            return;
        }
Example #12
0
        public void wmAddRegistryNode(string sObjectID, string sXPath, string sName)
        {
            FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates();

            //fail on missing values
            if (string.IsNullOrEmpty(sXPath))
                throw new Exception("Missing XPath to add to.");

            //fail on empty name
            if (string.IsNullOrEmpty(sName))
                throw new Exception("Node Name required.");

            string sNewXML = "<" + sName + " />";

            if (sObjectID == "global") sObjectID = "1";
            ft.AddNodeToRegistry(sObjectID, sXPath, sNewXML);

            return;
        }
Example #13
0
        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;
        }
Example #14
0
        public void wmRenameRegistryNode(string sObjectID, string sXPath, string sOldName, string sNewName)
        {
            FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates();

            //fail on missing values
            if (string.IsNullOrEmpty(sXPath))
                throw new Exception("Missing XPath to update.");

            if (sObjectID == "global") sObjectID = "1";
            ft.SetNodeNameinXMLColumn("object_registry", "registry_xml", "object_id = '" + sObjectID + "'", sXPath, sOldName, sNewName);

            return;
        }
Example #15
0
        public void wmFnVarRemoveVar(string sStepID, int iIndex)
        {
            FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates();
            //NOTE: this function supports both the set_varible AND clear_variable commands
            try
            {
                if (iIndex > 0)
                {
                    ft.RemoveFromCommandXML(sStepID, "//function/variable[" + iIndex.ToString() + "]");

                    return;
                }
                else
                {
                    throw new Exception("Unable to modify step. Invalid index.");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #16
0
        public void wmFnWaitForTasksAddHandle(string sStepID)
        {
            FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates();
            try
            {
                ft.AddToCommandXML(sStepID, "//function", "<handle><name input_type=\"text\"></name></handle>");

                return;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #17
0
        public static string GetConnectionTypes()
        {
            FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates();
            string sErr = "";

            DataTable dt = new DataTable();
            dt = ft.getConnectionTypes(ref sErr);
            if (!string.IsNullOrEmpty(sErr))
            {
                throw new Exception("Connection Type lookup error: " + sErr);
            }
            else
            {
                string sHTML = "<select name=\"ddlConnectionType\" style=\"width: 200px;\" id=\"ddlConnectionType\">";
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        sHTML += "<option value=\"" + dr["connection_type"].ToString() + "\">" + dr["connection_type"].ToString() + "</option>";
                    }
                }
                sHTML += "</select>";
                return sHTML;
            }
        }
Example #18
0
        public string wmGetClips()
        {
            dataAccess dc = new dataAccess();
            FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates();
            acUI.acUI ui = new acUI.acUI();

            try
            {
                string sUserID = ui.GetSessionUserID();
                string sErr = "";

                //note: some literal values are selected here.  That's because DrawReadOnlyStep
                //requires a more detailed record, but the snip doesn't have some of those values
                //so we hardcode them.
                string sSQL = "select s.clip_dt, s.step_id, s.step_desc, s.function_name, s.function_xml," +
                    " f.function_label, f.category_name, c.category_label, f.icon," +
                    " s.output_parse_type, s.output_row_delimiter, s.output_column_delimiter, s.variable_xml," +
                    " -1 as step_order, 0 as commented " +
                    " from task_step_clipboard s" +
                    " join lu_task_step_function f on s.function_name = f.function_name" +
                    " join lu_task_step_function_category c on f.category_name = c.category_name" +
                    " where s.user_id = '" + sUserID + "'" +
                    " and s.codeblock_name is null" +
                    " order by s.clip_dt desc";

                DataTable dt = new DataTable();
                if (!dc.sqlGetDataTable(ref dt, sSQL, ref sErr))
                {
                    throw new Exception(sErr);
                }

                string sHTML = "";

                foreach (DataRow dr in dt.Rows)
                {
                    string sStepID = dr["step_id"].ToString();
                    string sLabel = dr["function_label"].ToString();
                    string sIcon = dr["icon"].ToString();
                    string sClipDT = dr["clip_dt"].ToString();
                    string sDesc = ui.GetSnip(dr["step_desc"].ToString(), 75);

                    sHTML += "<li" +
                        " id=\"clip_" + sStepID + "\"" +
                        " name=\"clip_" + sStepID + "\"" +
                        " class=\"command_item function clip\"" +
                        ">";

                    //a table for the label so the clear icon can right align
                    sHTML += "<table width=\"99%\" border=\"0\"><tr>";
                    sHTML += "<td width=\"1px\"><img alt=\"\" src=\"../images/" + sIcon + "\" /></td>";
                    sHTML += "<td style=\"vertical-align: middle; padding-left: 5px;\">" + sLabel + "</td>";
                    sHTML += "<td width=\"1px\" style=\"vertical-align: middle;\">";

                    //view icon
                    //due to the complexity of telling the core routines to look in the clipboard table, it
                    //it not possible to easily show the complex command types
                    // without a redesign of how this works.  NSC 4-19-2011
                    //due to several reasons, most notable being that the XML node for each of those commands
                    //that contains the step_id is hardcoded and the node names differ.
                    //and GetSingleStep requires a step_id which must be mined from the XML.
                    //so.... don't show a preview icon for them
                    string sFunction = dr["function_name"].ToString();
                    if (!"loop,exists,if,while".Contains(sFunction))
                    {
                        sHTML += "<span id=\"btn_view_clip\" view_id=\"v_" + sStepID + "\">" +
                            "<img src=\"../images/icons/search.png\" style=\"width: 16px; height: 16px;\" alt=\"\" />" +
                            "</span>";
                    }
                    sHTML += "</td></tr>";

                    sHTML += "<tr><td>&nbsp;</td><td><span class=\"code\">" + sClipDT + "</span></td>";
                    sHTML += "<td>";
                    //delete icon
                    sHTML += "<span id=\"btn_clear_clip\" remove_id=\"" + sStepID + "\">" +
                        "<img src=\"../images/icons/fileclose.png\" style=\"width: 16px; height: 16px;\" alt=\"\" />" +
                        "</span>";
                    sHTML += "</td></tr></table>";

                    sHTML += "<div class=\"hidden\" id=\"help_text_clip_" + sStepID + "\">" + sDesc + "</div>";

                    //we use this function because it draws a smaller version than DrawReadOnlyStep
                    string sStepHTML = "";
                    //and don't draw those complex ones either
                    if (!"loop,exists,if,while".Contains(sFunction))
                        sStepHTML = ft.DrawEmbeddedReadOnlyStep(dr, true);

                    sHTML += "<div class=\"hidden\" id=\"v_" + sStepID + "\">" + sStepHTML + "</div>";
                    sHTML += "</li>";

                }

                return sHTML;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Example #19
0
        public string wmGetClips()
        {
            FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates();
            acUI.acUI ui = new acUI.acUI();

            try
            {
                string sUserID = ui.GetSessionUserID();
                string sHTML = "";

                ClipboardSteps oCSteps = new ClipboardSteps(sUserID);
                if (oCSteps != null)
                {
                    foreach (ClipboardStep cs in oCSteps.Values)
                    {
                        string sStepID = cs.ID;
                        string sLabel = cs.Function.Label;
                        string sIcon = cs.Function.Icon;
                        string sDesc = ui.GetSnip(cs.Description, 75);
                        string sClipDT = cs.ClipDT;

                        sHTML += "<li" +
                            " id=\"clip_" + sStepID + "\"" +
                                " name=\"clip_" + sStepID + "\"" +
                                " class=\"command_item function clip\"" +
                                ">";

                        //a table for the label so the clear icon can right align
                        sHTML += "<table width=\"99%\" border=\"0\"><tr>";
                        sHTML += "<td width=\"1px\"><img alt=\"\" src=\"../images/" + sIcon + "\" /></td>";
                        sHTML += "<td style=\"vertical-align: middle; padding-left: 5px;\">" + sLabel + "</td>";
                        sHTML += "<td width=\"1px\" style=\"vertical-align: middle;\">";

                        //view icon
                        //due to the complexity of telling the core routines to look in the clipboard table, it
                        //it not possible to easily show the complex command types
                        // without a redesign of how this works.  NSC 4-19-2011
                        //due to several reasons, most notable being that the XML node for each of those commands
                        //that contains the step_id is hardcoded and the node names differ.
                        //and GetSingleStep requires a step_id which must be mined from the XML.
                        //so.... don't show a preview icon for them
                        string sFunction = cs.Function.Name;

                        if (!"loop,exists,if,while".Contains(sFunction))
                        {
                            sHTML += "<span id=\"btn_view_clip\" view_id=\"v_" + sStepID + "\">" +
                                "<img src=\"../images/icons/search.png\" style=\"width: 16px; height: 16px;\" alt=\"\" />" +
                                    "</span>";
                        }
                        sHTML += "</td></tr>";

                        sHTML += "<tr><td>&nbsp;</td><td><span class=\"code\">" + sClipDT + "</span></td>";
                        sHTML += "<td>";
                        //delete icon
                        sHTML += "<span id=\"btn_clear_clip\" remove_id=\"" + sStepID + "\">" +
                            "<img src=\"../images/icons/fileclose.png\" style=\"width: 16px; height: 16px;\" alt=\"\" />" +
                                "</span>";
                        sHTML += "</td></tr></table>";

                        sHTML += "<div class=\"hidden\" id=\"help_text_clip_" + sStepID + "\">" + sDesc + "</div>";

                        //we use this function because it draws a smaller version than DrawReadOnlyStep
                        string sStepHTML = "";
                        //and don't draw those complex ones either
                        if (!"loop,exists,if,while".Contains(sFunction))
                            sStepHTML = ft.DrawClipboardStep(cs, true);

                        sHTML += "<div class=\"hidden\" id=\"v_" + sStepID + "\">" + sStepHTML + "</div>";
                        sHTML += "</li>";
                    }
                }
                return sHTML;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Example #20
0
        public string wmGetStep(string sStepID)
        {
            FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates();
            acUI.acUI ui = new acUI.acUI();

            try
            {

                string sStepHTML = "";
                string sErr = "";

                if (!ui.IsGUID(sStepID))
                    throw new Exception("Unable to get step. Invalid or missing Step ID. [" + sStepID + "]" + sErr);

                string sUserID = ui.GetSessionUserID();

                DataRow dr = ft.GetSingleStep(sStepID, sUserID, ref sErr);
                if (dr != null && sErr == "")
                {
                    //embedded steps...
                    //if the step_order is -1 and the codeblock_name is a guid, this step is embedded
                    //within another step
                    if (dr["step_order"].ToString() == "-1" && ui.IsGUID(dr["codeblock_name"].ToString()))
                        sStepHTML += ft.DrawEmbeddedStep(dr);
                    else
                        sStepHTML += ft.DrawFullStep(dr);
                }
                else
                    sStepHTML += "<span class=\"red_text\">" + sErr + "</span>";

                //return the html
                return sStepHTML;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #21
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;
            }
        }
Example #22
0
        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 "";
        }
Example #23
0
        public void wmFnIfRemoveSection(string sStepID, int iIndex)
        {
            FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates();
            acUI.acUI ui = new acUI.acUI();

            try
            {
                if (!ui.IsGUID(sStepID))
                    throw new Exception("Unable to remove section from step. Invalid or missing Step ID. [" + sStepID + "]");

                string sEmbStepID = "";

                if (iIndex > 0)
                {
                    //is there an embedded step?
                    sEmbStepID = ft.GetNodeValueFromCommandXML(sStepID, "//function/tests/test[" + iIndex.ToString() + "]/action[1]");

                    if (ui.IsGUID(sEmbStepID))
                        wmDeleteStep(sEmbStepID); //whack it

                    //now adjust the XML
                    ft.RemoveFromCommandXML(sStepID, "//function/tests/test[" + iIndex.ToString() + "]");
                }
                else if (iIndex == -1)
                {
                    //is there an embedded step?
                    sEmbStepID = ft.GetNodeValueFromCommandXML(sStepID, "//function/else[1]");

                    if (ui.IsGUID(sEmbStepID))
                        wmDeleteStep(sEmbStepID); //whack it

                    //now adjust the XML
                    ft.RemoveFromCommandXML(sStepID, "//function/else[1]");
                }
                else
                {
                    throw new Exception("Unable to modify step. Invalid index.");
                }

                return;

            }

            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #24
0
        public string wmAddStep(string sTaskID, string sCodeblockName, string sItem)
        {
            dataAccess dc = new dataAccess();
            FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates();
            acUI.acUI ui = new acUI.acUI();

            try
            {
                string sUserID = ui.GetSessionUserID();

                string sStepHTML = "";
                string sErr = "";
                string sSQL = "";
                string sNewStepID = "";

                if (!ui.IsGUID(sTaskID))
                    throw new Exception("Unable to add step. Invalid or missing Task ID. [" + sTaskID + "]" + sErr);

                //now, the sItem variable may have a function name (if it's a new command)
                //or it may have a guid (if it's from the clipboard)

                //so, if it's a guid after stripping off the prefix, it's from the clipboard

                //the function has a fn_ or clip_ prefix on it from the HTML.  Strip it off.
                //FIX... test the string to see if it BEGINS with fn_ or clip_
                //IF SO... cut off the beginning... NOT a replace operation.
                if (sItem.StartsWith("fn_")) sItem = sItem.Remove(0, 3);
                if (sItem.StartsWith("clip_")) sItem = sItem.Remove(0, 5);

                //NOTE: !! yes we are adding the step with an order of -1
                //the update event on the client does not know the index at which it was dropped.
                //so, we have to insert it first to get the HTML... but the very next step
                //will serialize and update the entire sortable...
                //immediately replacing this -1 with the correct position

                if (ui.IsGUID(sItem))
                {
                    sNewStepID = sItem;

                    //copy from the clipboard (using the root_step_id to get ALL associated steps)
                    sSQL = "insert into task_step (step_id, task_id, codeblock_name, step_order, step_desc," +
                        " commented, locked, output_parse_type, output_row_delimiter, output_column_delimiter," +
                        " function_name, function_xml, variable_xml)" +
                        " select step_id, '" + sTaskID + "'," +
                        " case when codeblock_name is null then '" + sCodeblockName + "' else codeblock_name end," +
                        "-1,step_desc," +
                        "0,0,output_parse_type,output_row_delimiter,output_column_delimiter," +
                        "function_name,function_xml,variable_xml" +
                        " from task_step_clipboard" +
                        " where user_id = '" + sUserID + "'" +
                        " and root_step_id = '" + sItem + "'";

                    if (!dc.sqlExecuteUpdate(sSQL, ref sErr))
                        throw new Exception("Unable to add step." + sErr);

                    ui.WriteObjectChangeLog(Globals.acObjectTypes.Task, sTaskID, sItem,
                        "Added Command from Clipboard to Codeblock:" + sCodeblockName);
                }
                else
                {
                    //add a new command
                    sNewStepID = ui.NewGUID();

                    //NOTE: !! yes we are doing some command specific logic here.
                    //Certain commands have different 'default' values for delimiters, etc.
                    //sOPM: 0=none, 1=delimited, 2=parsed
                    string sOPM = "0";

                    switch (sItem)
                    {
                        case "sql_exec":
                            sOPM = "1";
                            break;
                        case "win_cmd":
                            sOPM = "1";
                            break;
                        case "dos_cmd":
                            sOPM = "2";
                            break;
                        case "cmd_line":
                            sOPM = "2";
                            break;
                        case "http":
                            sOPM = "2";
                            break;
                        case "parse_text":
                            sOPM = "2";
                            break;
                        case "read_file":
                            sOPM = "2";
                            break;
                    }

                    sSQL = "insert into task_step (step_id, task_id, codeblock_name, step_order," +
                        " commented, locked, output_parse_type, output_row_delimiter, output_column_delimiter," +
                        " function_name, function_xml)" +
                           " select '" + sNewStepID + "'," +
                           "'" + sTaskID + "'," +
                           (string.IsNullOrEmpty(sCodeblockName) ? "NULL" : "'" + sCodeblockName + "'") + "," +
                           "-1," +
                           "0,0," + sOPM + ",0,0," +
                           "'" + sItem + "'," +
                           " xml_template" +
                           " from lu_task_step_function" +
                           " where function_name = '" + sItem + "' limit 1";

                    if (!dc.sqlExecuteUpdate(sSQL, ref sErr))
                        throw new Exception("Unable to add step." + sErr);

                    ui.WriteObjectChangeLog(Globals.acObjectTypes.Task, sTaskID, sItem,
                        "Added Command Type:" + sItem + " to Codeblock:" + sCodeblockName);
                }

                if (!string.IsNullOrEmpty(sNewStepID))
                {
                    //now... get the newly inserted step and draw it's HTML
                    DataRow dr = ft.GetSingleStep(sNewStepID, sUserID, ref sErr);
                    if (dr != null && sErr == "")
                        sStepHTML += ft.DrawFullStep(dr);
                    else
                        sStepHTML += "<span class=\"red_text\">" + sErr + "</span>";

                    //return the html
                    return sNewStepID + sStepHTML;
                }
                else
                {
                    throw new Exception("Unable to add step.  No new step_id." + sErr);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #25
0
        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;
            }
        }
Example #26
0
        public void wmFnAddPair(string sStepID)
        {
            FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates();
            try
            {
                ft.AddToCommandXML(sStepID, "//function", "<pair><key input_type=\"text\"></key><value input_type=\"text\"></value></pair>");

                return;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #27
0
        public void wmFnNodeArrayRemove(string sStepID, string sXPathToDelete)
        {
            FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates();
            try
            {
                //string sErr = "";

                ////gotta have a valid index
                //if (iIndex < 1)
                //    throw new Exception("Unable to modify step. Invalid index.");

                if (sStepID.Length > 0)
                {
                    if (sXPathToDelete != "")
                    {
                        ////so, let's get the XML for this step...
                        //string sXML = ft.GetStepCommandXML(sStepID, ref sErr);
                        //if (sErr != "") throw new Exception(sErr);

                        string sNodeToRemove = "//" + sXPathToDelete;

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

                        ft.RemoveNodeFromXMLColumn("task_step", "function_xml", "step_id = '" + sStepID + "'", sNodeToRemove);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #28
0
        public void wmFnIfAddSection(string sStepID, int iIndex)
        {
            FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates();
            try
            {
                if (iIndex > 0)
                {
                    //an index > 0 means its one of many 'else if' sections
                    ft.AddToCommandXML(sStepID, "//function/tests", "<test><eval input_type=\"text\" /><action input_type=\"text\" /></test>");
                }
                else if (iIndex == -1)
                {
                    //whereas an index of -1 means its the ONLY 'else' section
                    ft.AddToCommandXML(sStepID, "//function", "<else input_type=\"text\" />");
                }
                else
                {
                    //and of course a missing or 0 index is an error
                    throw new Exception("Unable to modify step. Invalid index.");
                }

                return;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #29
0
        public void wmFnSetvarAddVar(string sStepID)
        {
            FunctionTemplates.HTMLTemplates ft = new FunctionTemplates.HTMLTemplates();
            try
            {
                ft.AddToCommandXML(sStepID, "//function", "<variable>" +
                    "<name input_type=\"text\"></name>" +
                    "<value input_type=\"text\"></value>" +
                    "<modifier input_type=\"select\">DEFAULT</modifier>" +
                    "</variable>");

                return;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }