예제 #1
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;
            }
        }
예제 #2
0
        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;
            }
        }
예제 #3
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;
            }
        }
예제 #4
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;
            }
        }
예제 #5
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;
            }
        }
예제 #6
0
파일: uiMethods.asmx.cs 프로젝트: you8/cato
        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;
        }