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;
            }
        }
        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;
            }
        }
        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 #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;
        }