Пример #1
0
        public string GetValueFromEncodedTemplateOperand(string operand, TemplateElement currentElement)
        {
            List <string> operandsList = BaseObject.ExtractPlaceholdersToListWithoutOutputConcat(operand);

            if (operandsList.Count < 3)
            {
                ExceptionHandling.Handling.GetException("Unexpected",
                                                        new Exception("The overloaded list is not valid"));
            }
            string ueid = operandsList[1], name = operandsList[2];

            if (ueid == "")
            {
                ueid    = currentElement.UEID;
                operand = operand.Replace(BaseObject.ConvertStringToPlaceholderString(""), BaseObject.ConvertStringToPlaceholderString(ueid));
            }

            foreach (var ueidToRessource in AvailableResources)
            {
                if (ueidToRessource.Value is Text && ueidToRessource.Key == operand)
                {
                    return(((Text)ueidToRessource.Value).Value.ReadString());
                }
            }

            ExceptionHandling.Handling.GetException("Unexpected", new Exception(
                                                        "Your template element could not get the output from the desired element... sorry get better templates"));
            return(null);
        }
Пример #2
0
        private void UpdateElement()
        {
            string text = "";

            for (int i = 0; i < comboBox1.Items.Count; i++)
            {
                if (comboBox1.SelectedIndex == i)
                {
                    text = comboBox1.Items[i].ToString();
                }
            }
            if (text == "")
            {
                return;
            }
            foreach (var baseObject in availableBaseObjects)
            {
                if (((BaseObject)baseObject).GetType().Name == text)
                {
                    if (baseObject is BrowserCommand)
                    {
                        TemplateElement = new TemplateElement(textBoxName.Text, baseObject);
                    }
                    else
                    {
                        BrowserAction browserAction = new BrowserAction();
                        browserAction.ActionObject = baseObject;
                        TemplateElement            = new TemplateElement(textBoxName.Text, browserAction);
                    }
                    textBoxDescription.Text = ((BaseObject)baseObject).Description;
                }
            }
        }
Пример #3
0
 protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
 {
     if (keyData == Keys.Escape)
     {
         TemplateElement = null;
         this.Close();
         return(true);
     }
     return(base.ProcessCmdKey(ref msg, keyData));
 }
        private void buttonRemoveTemplateElement_Click(object sender, EventArgs e)
        {
            TemplateElement templateElement = GetCurrentSelectedTemplateElement();

            if (templateElement != null)
            {
                Template.TemplateElements.Remove(templateElement);
                RefreshUi();
            }
            if (listBoxTemplateElements.Items.Count > 0)
            {
                listBoxTemplateElements.SelectedIndex = 0;
            }
        }
        private void buttonEditTemplateElement_Click(object sender, EventArgs e)
        {
            int             selectedIndex   = listBoxTemplateElements.SelectedIndex;
            TemplateElement templateElement = GetCurrentSelectedTemplateElement();

            if (templateElement == null)
            {
                return;
            }
            RefreshUi();

            ManipulateTemplateElement manipulateTemplateElement = new ManipulateTemplateElement(templateElement, Template);

            manipulateTemplateElement.ShowDialog();

            RefreshUi();
            listBoxTemplateElements.SelectedIndex = selectedIndex;
        }
        private void buttonCloneTemplateElement_Click(object sender, EventArgs e)
        {
            int selectedIndex = listBoxTemplateElements.SelectedIndex;

            if (selectedIndex >= 0)
            {
                TemplateElement templateElement = GetCurrentSelectedTemplateElement();
                if (templateElement == null)
                {
                    return;
                }
                TemplateElement newTemplateElement = (TemplateElement)templateElement.Clone();
                newTemplateElement.Name = "Clone " + newTemplateElement.Name + " " + DateTime.Now.ToString() + Guid.NewGuid();
                newTemplateElement.GenerateNewUeid();
                Template.TemplateElements.Insert(selectedIndex + 1, newTemplateElement);

                RefreshUi();
                listBoxTemplateElements.SelectedIndex = selectedIndex;
            }
        }
        private void CleanTemplateElement(TemplateElement templateElement)
        {
            BaseObject baseObject = ((BaseObject)templateElement.BrowserActionOrCommand);

            if (templateElement.BrowserActionOrCommand is BrowserAction)
            {
                baseObject.InputParameterAvailable = null;
            }
            if (templateElement.AppendedTemplateElement != null)
            {
                CleanTemplateElement(templateElement.AppendedTemplateElement);
            }
            foreach (var conditionsToTemplateElement in templateElement.ConditionBasedAppendedTemplateElements)
            {
                if (conditionsToTemplateElement.Value != null)
                {
                    CleanTemplateElement(conditionsToTemplateElement.Value);
                }
            }
        }
        private TemplateElement GetCurrentSelectedTemplateElement()
        {
            if (listBoxTemplateElements.SelectedIndex == -1)
            {
                return(null);
            }
            TemplateElement templateElement = null;

            foreach (var cTemplateElement in Template.TemplateElements)
            {
                for (int i = 0; i < listBoxTemplateElements.Items.Count; i++)
                {
                    if (listBoxTemplateElements.GetSelected(i) &&
                        listBoxTemplateElements.Items[i].ToString() == GenerateTemplateElementString(cTemplateElement, true))
                    {
                        templateElement = cTemplateElement;
                    }
                }
            }
            return(templateElement);
        }
        public static string GenerateTemplateElementString(TemplateElement templateElement, bool includeUeid = true)
        {
            if (templateElement == null)
            {
                return("");
            }
            string text = "";

            if (templateElement.BrowserActionOrCommand is BrowserCommand)
            {
                text = templateElement.BrowserActionOrCommand.GetType().Name;
            }
            else
            {
                text = templateElement.BrowserActionOrCommand.GetType().Name + ": " +
                       ((BrowserAction)templateElement.BrowserActionOrCommand).ActionObject.GetType().Name;
            }
            return(templateElement.Name + " | " + text + (includeUeid
                       ? (" (UEID: " +
                          templateElement.UEID + ")")
                       : ""));
        }
Пример #10
0
        //Returns true on success or false on timeout/fail...
        public bool RunTemplate(TemplateElement element, CefControl cefControl)
        {
            LastTemplateElement = element.Name + " @ TemplateElement-ID " + element.UEID;
            BaseObject baseObject = null;

            if (element.BrowserActionOrCommand is BrowserCommand)
            {
                baseObject = ((BaseObject)element.BrowserActionOrCommand);
                if (baseObject.TimeoutInSec != null)
                {
                    baseObject.Timeout = new TimeSpan(0, 0, baseObject.TimeoutInSec.Value);
                }
            }
            else if (element.BrowserActionOrCommand is BrowserAction)
            {
                baseObject = ((BaseObject)((BrowserAction)element.BrowserActionOrCommand).ActionObject);
                if (baseObject.TimeoutInSec != null)
                {
                    baseObject.Timeout = new TimeSpan(0, 0, baseObject.TimeoutInSec.Value);
                }
            }
            //rework anyhow?
            //@ requirement calculation: is required a pwdef placeholder?
            foreach (var requiredParameterString in element.RequiredParameters)
            {
                foreach (var availableResource in AvailableResources)
                {
                    if (requiredParameterString == availableResource.Key && availableResource.Value is Text)
                    {
                        KeyValuePairEx <string, string> data =
                            new KeyValuePairEx <string, string>(requiredParameterString,
                                                                ((Text)availableResource.Value).Value.ReadString());
                        baseObject.OverloadData.Add(data);
                    }
                }
            }

            if (element.BrowserActionOrCommand is BrowserCommand)
            {
                BrowserCommand command = (BrowserCommand)element.BrowserActionOrCommand;
                command.UID = UID;
                command.GenerateNewUcid(UTID);

                _cefControl.AddCefBrowserCommand(element.BrowserActionOrCommand);

                while (true)
                {
                    Thread.Sleep(100);
                    if (CefControl.BrowserCommandsCompleted.ContainsKey(command.UCID))
                    {
                        BrowserCommand browserCommandCompleted = (BrowserCommand)CefControl.BrowserCommandsCompleted[command.UCID];

                        foreach (var outputPlacholderToValuePair in browserCommandCompleted.ReturnedOutput)
                        {
                            string identifier = EncodeTemplateElementIdWithOutputName(element.UEID,
                                                                                      outputPlacholderToValuePair.Key);
                            int?forRemoving = null;
                            for (var i = 0; i < AvailableResources.Count; i++)
                            {
                                if (AvailableResources[i].Key ==
                                    identifier /* && AvailableResources[i].ExpectedValue == null*/)
                                {
                                    forRemoving = i;
                                }
                            }
                            if (forRemoving != null)
                            {
                                AvailableResources.RemoveAt((int)forRemoving);
                            }
                            AvailableResources.Add(
                                new KeyValuePairEx <string, object>(
                                    identifier, new Text(new ProtectedString(true, outputPlacholderToValuePair.Value != null ? outputPlacholderToValuePair.Value : ""))));
                            //else
                            //{
                            //    //Console.WriteLine("w000T");
                            //}
                        }
                        foreach (var conditionsToTemplateElement in element.ConditionBasedAppendedTemplateElements)
                        {
                            bool success = true;
                            foreach (var condition in conditionsToTemplateElement.Key)
                            {
                                string firstOperand    = condition.FirstOperand,
                                         secondOperand = condition.SecondOperand;
                                if (firstOperand == BaseObject.ConvertStringToPlaceholderString("successfull"))
                                {
                                    firstOperand = browserCommandCompleted.Successful.ToString();
                                }
                                else if (firstOperand == BaseObject.ConvertStringToPlaceholderString("completed"))
                                {
                                    firstOperand = browserCommandCompleted.Completed.ToString();
                                }
                                else if (firstOperand.Contains(BaseObject.ConvertStringToPlaceholderString("output")))
                                {
                                    firstOperand = GetValueFromEncodedTemplateOperand(firstOperand, conditionsToTemplateElement.Value);
                                }
                                else if (element.RequiredParameters.Contains(firstOperand))
                                {
                                    foreach (var availableResource in AvailableResources)
                                    {
                                        if (availableResource.Key == firstOperand)
                                        {
                                            firstOperand = availableResource.Value.ToString();
                                            break;
                                        }
                                    }
                                }
                                if (secondOperand == BaseObject.ConvertStringToPlaceholderString("successfull"))
                                {
                                    secondOperand = browserCommandCompleted.Successful.ToString();
                                }
                                else if (secondOperand == BaseObject.ConvertStringToPlaceholderString("completed"))
                                {
                                    secondOperand = browserCommandCompleted.Completed.ToString();
                                }
                                else if (secondOperand.Contains(BaseObject.ConvertStringToPlaceholderString("output")))
                                {
                                    secondOperand = GetValueFromEncodedTemplateOperand(firstOperand, conditionsToTemplateElement.Value);
                                }
                                else if (element.RequiredParameters.Contains(secondOperand))
                                {
                                    foreach (var availableResource in AvailableResources)
                                    {
                                        if (availableResource.Key == secondOperand)
                                        {
                                            secondOperand = availableResource.Value.ToString();
                                            break;
                                        }
                                    }
                                }
                                if (!condition.Compare(firstOperand, secondOperand))
                                {
                                    success = false;
                                    break;
                                }
                            }
                            if (success)
                            {
                                if (!RunTemplate(conditionsToTemplateElement.Value, _cefControl))
                                {
                                    return(false);
                                }
                            }
                        }
                        foreach (var elementSuccessCondition in element.SuccessConditions)
                        {
                            string firstOperand    = elementSuccessCondition.FirstOperand,
                                     secondOperand = elementSuccessCondition.SecondOperand;
                            if (firstOperand == BaseObject.ConvertStringToPlaceholderString("successfull"))
                            {
                                firstOperand = browserCommandCompleted.Successful.ToString();
                            }
                            else if (firstOperand == BaseObject.ConvertStringToPlaceholderString("completed"))
                            {
                                firstOperand = browserCommandCompleted.Completed.ToString();
                            }
                            else if (firstOperand.Contains(BaseObject.ConvertStringToPlaceholderString("output")))
                            {
                                firstOperand = GetValueFromEncodedTemplateOperand(firstOperand, element);
                            }
                            else if (element.RequiredParameters.Contains(firstOperand))
                            {
                                foreach (var availableResource in AvailableResources)
                                {
                                    if (availableResource.Key == firstOperand)
                                    {
                                        firstOperand = availableResource.Value.ToString();
                                        break;
                                    }
                                }
                            }
                            if (secondOperand == BaseObject.ConvertStringToPlaceholderString("successfull"))
                            {
                                secondOperand = browserCommandCompleted.Successful.ToString();
                            }
                            else if (secondOperand == BaseObject.ConvertStringToPlaceholderString("completed"))
                            {
                                secondOperand = browserCommandCompleted.Completed.ToString();
                            }
                            else if (secondOperand.Contains(BaseObject.ConvertStringToPlaceholderString("output")))
                            {
                                secondOperand = GetValueFromEncodedTemplateOperand(firstOperand, element);
                            }
                            else if (element.RequiredParameters.Contains(secondOperand))
                            {
                                foreach (var availableResource in AvailableResources)
                                {
                                    if (availableResource.Key == secondOperand)
                                    {
                                        secondOperand = availableResource.Value.ToString();
                                        break;
                                    }
                                }
                            }
                            if (!elementSuccessCondition.Compare(firstOperand, secondOperand))
                            {
                                LastTemplateElementFailureReason = "Failed @ following success condition: " +
                                                                   elementSuccessCondition.ConditionToString(
                                    firstOperand, secondOperand);
                                return(false);
                            }
                        }
                        if (element.AppendedTemplateElement != null)
                        {
                            if (!RunTemplate(element.AppendedTemplateElement, _cefControl))
                            {
                                return(false);
                            }
                        }
                        break;
                    }
                    if (CefBrowserControl.Timeout.ShouldBreakDueTimeout(baseObject))
                    {
                        LastTemplateElementFailureReason = "Command Timeout";
                        return(false);
                    }
                }
                if (!((BrowserCommand)CefControl.BrowserCommandsCompleted[command.UCID]).Successful)
                {
                    LastTemplateElementFailureReason = "Failed Browser Command in CefBrowser";
                    return(false);
                }
            }
            else if (element.BrowserActionOrCommand is BrowserAction)
            {
                BrowserAction action = (BrowserAction)element.BrowserActionOrCommand;
                action.UID = UID;
                action.GenerateNewUCID(UTID);
                ((BaseObject)action.ActionObject).OverloadData = baseObject.OverloadData;
                cefControl.AddCefBrowserAction(element.BrowserActionOrCommand);

                while (true)
                {
                    Thread.Sleep(100);
                    if (CefControl.BrowserActionsCompleted.ContainsKey(action.UCID))
                    {
                        BrowserAction browserActionCompleted = (BrowserAction)CefControl.BrowserActionsCompleted[action.UCID];
                        BaseObject    subObject = (BaseObject)browserActionCompleted.ActionObject;

                        foreach (var outputPlacholderToValuePair in subObject.ReturnedOutput)
                        {
                            string identifier = EncodeTemplateElementIdWithOutputName(element.UEID,
                                                                                      outputPlacholderToValuePair.Key);
                            int?forRemoving = null;
                            for (var i = 0; i < AvailableResources.Count; i++)
                            {
                                if (AvailableResources[i].Key ==
                                    identifier /* && AvailableResources[i].ExpectedValue == null*/)
                                {
                                    forRemoving = i;
                                }
                            }
                            if (forRemoving != null)
                            {
                                AvailableResources.RemoveAt((int)forRemoving);
                            }
                            AvailableResources.Add(
                                new KeyValuePairEx <string, object>(
                                    identifier, new Text(new ProtectedString(true, outputPlacholderToValuePair.Value != null ? outputPlacholderToValuePair.Value : ""))));
                            //else
                            //{
                            //    //Console.WriteLine("w000T");
                            //}
                        }

                        foreach (var templateElement in TemplateElements)
                        {
                            if (templateElement.UEID == element.UEID)
                            {
                                templateElement.BrowserActionOrCommand = CefControl.BrowserActionsCompleted[action.UCID];
                            }
                        }
                        foreach (var conditionsToTemplateElement in element.ConditionBasedAppendedTemplateElements)
                        {
                            bool success = true;
                            foreach (var condition in conditionsToTemplateElement.Key)
                            {
                                string firstOperand    = condition.FirstOperand,
                                         secondOperand = condition.SecondOperand;
                                if (firstOperand == BaseObject.ConvertStringToPlaceholderString("successfull"))
                                {
                                    firstOperand = subObject.Successful.ToString();
                                }
                                else if (firstOperand == BaseObject.ConvertStringToPlaceholderString("completed"))
                                {
                                    firstOperand = subObject.Completed.ToString();
                                }
                                else if (firstOperand.Contains(BaseObject.ConvertStringToPlaceholderString("output")))
                                {
                                    firstOperand = GetValueFromEncodedTemplateOperand(firstOperand, conditionsToTemplateElement.Value);
                                }
                                else if (element.RequiredParameters.Contains(firstOperand))
                                {
                                    foreach (var availableResource in AvailableResources)
                                    {
                                        if (availableResource.Key == firstOperand)
                                        {
                                            firstOperand = availableResource.Value.ToString();
                                            break;
                                        }
                                    }
                                }
                                if (secondOperand == BaseObject.ConvertStringToPlaceholderString("successfull"))
                                {
                                    secondOperand = subObject.Successful.ToString();
                                }
                                else if (secondOperand == BaseObject.ConvertStringToPlaceholderString("completed"))
                                {
                                    secondOperand = subObject.Completed.ToString();
                                }
                                else if (secondOperand.Contains(BaseObject.ConvertStringToPlaceholderString("output")))
                                {
                                    secondOperand = GetValueFromEncodedTemplateOperand(firstOperand, conditionsToTemplateElement.Value);
                                }
                                else if (element.RequiredParameters.Contains(secondOperand))
                                {
                                    foreach (var availableResource in AvailableResources)
                                    {
                                        if (availableResource.Key == secondOperand)
                                        {
                                            secondOperand = availableResource.Value.ToString();
                                            break;
                                        }
                                    }
                                }
                                if (!condition.Compare(firstOperand, secondOperand))
                                {
                                    success = false;
                                    break;
                                }
                            }
                            if (success)
                            {
                                if (!RunTemplate(conditionsToTemplateElement.Value, _cefControl))
                                {
                                    return(false);
                                }
                            }
                        }
                        foreach (var elementSuccessCondition in element.SuccessConditions)
                        {
                            string firstOperand    = elementSuccessCondition.FirstOperand,
                                     secondOperand = elementSuccessCondition.SecondOperand;
                            if (firstOperand == BaseObject.ConvertStringToPlaceholderString("successfull"))
                            {
                                firstOperand = subObject.Successful.ToString();
                            }
                            else if (firstOperand == BaseObject.ConvertStringToPlaceholderString("completed"))
                            {
                                firstOperand = subObject.Completed.ToString();
                            }
                            else if (firstOperand.Contains(BaseObject.ConvertStringToPlaceholderString("output")))
                            {
                                firstOperand = GetValueFromEncodedTemplateOperand(firstOperand, element);
                            }
                            else if (element.RequiredParameters.Contains(firstOperand))
                            {
                                foreach (var availableResource in AvailableResources)
                                {
                                    if (availableResource.Key == firstOperand)
                                    {
                                        firstOperand = availableResource.Value.ToString();
                                        break;
                                    }
                                }
                            }
                            if (secondOperand == BaseObject.ConvertStringToPlaceholderString("successfull"))
                            {
                                secondOperand = subObject.Successful.ToString();
                            }
                            else if (secondOperand == BaseObject.ConvertStringToPlaceholderString("completed"))
                            {
                                secondOperand = subObject.Completed.ToString();
                            }
                            else if (secondOperand.Contains(BaseObject.ConvertStringToPlaceholderString("output")))
                            {
                                secondOperand = GetValueFromEncodedTemplateOperand(secondOperand, element);
                            }
                            else if (element.RequiredParameters.Contains(secondOperand))
                            {
                                foreach (var availableResource in AvailableResources)
                                {
                                    if (availableResource.Key == secondOperand)
                                    {
                                        secondOperand = availableResource.Value.ToString();
                                        break;
                                    }
                                }
                            }
                            if (!elementSuccessCondition.Compare(firstOperand, secondOperand))
                            {
                                LastTemplateElementFailureReason = "Failed @ following success condition: " +
                                                                   elementSuccessCondition.ConditionToString(
                                    firstOperand, secondOperand);
                                return(false);
                            }
                        }
                        if (element.AppendedTemplateElement != null)
                        {
                            if (!RunTemplate(element.AppendedTemplateElement, _cefControl))
                            {
                                return(false);
                            }
                        }
                        break;
                    }
                    if (CefBrowserControl.Timeout.ShouldBreakDueTimeout(baseObject))
                    {
                        LastTemplateElementFailureReason = "Action Timeout";
                        return(false);
                    }
                }
                if (!((BaseObject)((BrowserAction)CefControl.BrowserActionsCompleted[action.UCID]).ActionObject).Successful)
                {
                    string text = "";
                    foreach (var keyValuePair in ((BaseObject)action.ActionObject).ReturnedOutput)
                    {
                        text += "Entry: " + keyValuePair.Key + " --> " + keyValuePair.Value + ".";
                    }
                    LastTemplateElementFailureReason = "Failed Browser Action in CefBrowser: " + text;
                    return(false);
                }
            }
            return(true);
        }
        private void buttonCreateDemoTemplate_Click(object sender, EventArgs e)
        {
            List <TemplateElement> templateElements = new List <TemplateElement>();


            SwitchWindowVisibility visibility = new SwitchWindowVisibility();

            visibility.NewInstance();
            visibility.Visible.Value = true;
            templateElements.Add(new TemplateElement("show window", visibility));

            //Dont forget to change identifier to real one!
            LoadUrl url = new LoadUrl();

            url.NewInstance();
            url.Url.Value = "http://keepass.info/help/kb/testform.html";
            templateElements.Add(new TemplateElement("Load Site", url));

            BrowserAction actionLoaded = new BrowserAction();
            SiteLoaded    siteLoaded   = new SiteLoaded();

            siteLoaded.NewInstance();
            siteLoaded.ExpectedSiteToLoad.Value         = url.Url;
            siteLoaded.ExpectedSiteToLoad.IsRegex.Value = false;
            actionLoaded.ActionObject = siteLoaded;
            templateElements.Add(new TemplateElement("Check if Site has loaded", actionLoaded));

            BrowserAction checkNumberOfElements1 = new CefBrowserControl.BrowserAction();
            ElementToLoad loadElement            = new ElementToLoad();

            loadElement.NewInstance();
            loadElement.Selector.SelectorExecuteActionOn  = BrowserAction.ExecuteActionOn.Id;
            loadElement.Selector.SelectorString           = "LoginFormUser";
            loadElement.Selector.ExpectedNumberOfElements = new InsecureInt(1);
            checkNumberOfElements1.ActionObject           = loadElement;
            templateElements.Add(new TemplateElement("Check if Form exists", checkNumberOfElements1));


            BrowserAction imageAction = new BrowserAction();
            GetImage      getImage1   = new GetImage();

            getImage1.NewInstance();
            imageAction.ActionObject                   = getImage1;
            getImage1.Selector.SelectorString          = "/html/body/table/tbody/tr[1]/td/table/tbody/tr/td[1]/img";
            getImage1.Selector.SelectorExecuteActionOn = BrowserAction.ExecuteActionOn.Xpath;
            TemplateElement getImageTemplateElement = new TemplateElement("Download KeePass Image", imageAction);

            templateElements.Add(getImageTemplateElement);


            GetInputFromUser input = new GetInputFromUser();

            input.NewInstance();
            input.InputNeeded.Value = true;
            input.InsecureDisplayObjects.Add(new InsecureText("Please type in 'OK'. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."));
            input.InsecureDisplayObjects.Add(new InsecureImage(Template.EncodeTemplateElementIdWithOutputName(getImageTemplateElement.UEID, GetImage.KeyList.Base64String.ToString())));
            TemplateElement templateElement1 = new TemplateElement("Get OK from User", input);

            templateElement1.SuccessConditions.Add(new Condition("Contains", Template.EncodeTemplateElementIdWithOutputName("", GetInputFromUser.KeyList.UserInputResult.ToString()), "OK"));
            templateElements.Add(templateElement1);


            //----------------------------


            BrowserAction checkNumberOfElements2 = new CefBrowserControl.BrowserAction();
            ElementToLoad elementToLoad2         = new ElementToLoad();

            elementToLoad2.NewInstance();
            checkNumberOfElements2.ActionObject                    = elementToLoad2;
            elementToLoad2.Selector.SelectorExecuteActionOn        = BrowserAction.ExecuteActionOn.Name;
            elementToLoad2.Selector.SelectorString                 = "pwd";
            elementToLoad2.Selector.ExpectedNumberOfElements.Value = 1;
            templateElements.Add(new TemplateElement("Check if Form Field 'pwd' exists", checkNumberOfElements2));

            BrowserAction checkNumberOfElements3 = new CefBrowserControl.BrowserAction();
            ElementToLoad elementToLoad3         = new ElementToLoad();

            elementToLoad3.NewInstance();
            checkNumberOfElements3.ActionObject                    = elementToLoad3;
            elementToLoad3.Selector.SelectorExecuteActionOn        = BrowserAction.ExecuteActionOn.Name;
            elementToLoad3.Selector.SelectorString                 = "LoginForm";
            elementToLoad3.Selector.ExpectedNumberOfElements.Value = 1;
            templateElements.Add(new TemplateElement("Check if Form Field 'LoginForm' exists", checkNumberOfElements3));

            BrowserAction enteryUserName       = new BrowserAction();
            SetAttribute  setAttributeUserName = new SetAttribute();

            setAttributeUserName.NewInstance();
            enteryUserName.ActionObject = setAttributeUserName;
            setAttributeUserName.AttributeName.Value = "Value";
            setAttributeUserName.ValueToSet.Value    = BaseObject.ConvertStringToPlaceholderString(PwDefs.UserNameField);
            setAttributeUserName.Selector.ExpectedNumberOfElements.Value = 1;
            setAttributeUserName.Selector.SelectorExecuteActionOn        = BrowserAction.ExecuteActionOn.Id;
            setAttributeUserName.Selector.SelectorString = "LoginFormUser";
            templateElements.Add(new TemplateElement("enter username", enteryUserName));

            BrowserAction enterPassword        = new BrowserAction();
            SetAttribute  setAttributePassword = new SetAttribute();

            setAttributePassword.NewInstance();
            enterPassword.ActionObject = setAttributePassword;
            setAttributePassword.AttributeName.Value = "Value";
            setAttributePassword.ValueToSet.Value    = BaseObject.ConvertStringToPlaceholderString(PwDefs.PasswordField) + " " + BaseObject.ConvertStringToPlaceholderString("");
            setAttributePassword.Selector.ExpectedNumberOfElements.Value = 1;
            setAttributePassword.Selector.SelectorExecuteActionOn        = BrowserAction.ExecuteActionOn.Name;
            setAttributePassword.Selector.SelectorString = "pwd";
            templateElements.Add(new TemplateElement("enter password", enterPassword));

            BrowserAction handleJsDialog = new BrowserAction();
            SetJsPrompt   setJsPrompt    = new SetJsPrompt();

            setJsPrompt.NewInstance();
            handleJsDialog.ActionObject                   = setJsPrompt;
            setJsPrompt.ExpectedDialogType.Value          = GetJsPrompt.DialogTypes.Alert;
            setJsPrompt.ExpectedMessageText.IsRegex.Value = true;
            setJsPrompt.ExpectedMessageText.Value.Value   = "The following data would have been submitted";
            templateElements.Add(new TemplateElement("set jsdialog handler", handleJsDialog));

            SwitchWindowVisibility visibility2 = new SwitchWindowVisibility();

            visibility2.NewInstance();
            visibility2.Visible.Value = false;
            templateElements.Add(new TemplateElement("hide window", visibility2));

            BrowserAction clickSubmit  = new BrowserAction();
            InvokeSubmit  invokeSubmit = new InvokeSubmit();

            invokeSubmit.NewInstance();
            clickSubmit.ActionObject = invokeSubmit;
            invokeSubmit.Selector.SelectorExecuteActionOn        = BrowserAction.ExecuteActionOn.Name;
            invokeSubmit.Selector.SelectorString                 = "LoginForm";
            invokeSubmit.Selector.ExpectedNumberOfElements.Value = 1;
            templateElements.Add(new TemplateElement("submit form", clickSubmit));

            BrowserAction checkJsDialog = new BrowserAction();
            GetJsPrompt   getJsPrompt   = new GetJsPrompt();

            getJsPrompt.NewInstance();
            checkJsDialog.ActionObject                    = getJsPrompt;
            getJsPrompt.ExpectedDialogType.Value          = GetJsPrompt.DialogTypes.Alert;
            getJsPrompt.ExpectedMessageText.IsRegex.Value = true;
            getJsPrompt.ExpectedMessageText.Value.Value   = "The following data would have been submitted";
            TemplateElement templateElement2 = new TemplateElement("get jsdialog", checkJsDialog);

            templateElement2.SuccessConditions.Add(new Condition("Contains",
                                                                 Template.EncodeTemplateElementIdWithOutputName("", GetJsPrompt.KeyList.MessageText.ToString()),
                                                                 "The following data would have been submitted"));
            templateElements.Add(templateElement2);

            Template template = new Template(1,
                                             new StringOrRegex()
            {
                IsRegex = new InsecureBool(true), Value = new InsecureText("keepass")
            },
                                             "KeePass TestForm, some illegal chars: \"M\"\\a/ry/ h**ad:>> a\\/:*?\"| li*tt|le|| la\"mb.?", new PasswordCreationPolicy(), templateElements);

            AddTemplate(template);
            RefreshUI();
        }
Пример #12
0
 private void buttonCancel_Click(object sender, EventArgs e)
 {
     TemplateElement = null;
     Close();
 }
        public object Clone()
        {
            Type   type = BrowserActionOrCommand.GetType();
            string browserOrActionCommand =
                SerializationDotNet2.Xml.Serializer.SerializeObjectToString(BrowserActionOrCommand, type);
            string appendedTemplate = "";

            if (AppendedTemplateElement != null)
            {
                appendedTemplate = SerializationDotNet2.Xml.Serializer.SerializeObjectToString(AppendedTemplateElement, AppendedTemplateElement.GetType());
            }
            string conditions = SerializationDotNet2.Xml.Serializer.SerializeObjectToString(SuccessConditions, SuccessConditions.GetType());
            string conditionBasedTemplateElements = SerializationDotNet2.Xml.Serializer.SerializeObjectToString(ConditionBasedAppendedTemplateElements, ConditionBasedAppendedTemplateElements.GetType());
            //return (TemplateElement) this.MemberwiseClone();

            //BaseObject baseObjectOriginal;
            //if (BrowserActionOrCommand is BrowserCommand)
            //    baseObjectOriginal = (BaseObject)BrowserActionOrCommand;
            //else
            //{
            //    baseObjectOriginal = (BaseObject)((BrowserAction)BrowserActionOrCommand).ActionObject;
            //}
            //List<KeyValuePairEx<string, object>> inputParametersAvailable = baseObjectOriginal.InputParameterAvailable;
            //string serializedInputParametersAvailable = SerializationDotNet2.Xml.Serializer.SerializeObjectToString(inputParametersAvailable, typeof(List<KeyValuePairEx<string, object>>));



            TemplateElement newTemplateElement = (TemplateElement)this.MemberwiseClone();

            newTemplateElement.BrowserActionOrCommand = SerializationDotNet2.Xml.Deserializer.DeserializeObjectFromString(browserOrActionCommand, type);

            if (appendedTemplate != "")
            {
                newTemplateElement.AppendedTemplateElement = (TemplateElement)SerializationDotNet2.Xml.Deserializer.DeserializeObjectFromString(appendedTemplate, AppendedTemplateElement.GetType());
            }
            newTemplateElement.SuccessConditions = (List <Condition>)SerializationDotNet2.Xml.Deserializer.DeserializeObjectFromString(conditions, SuccessConditions.GetType());
            newTemplateElement.ConditionBasedAppendedTemplateElements = (List <KeyValuePairEx <List <Condition>, TemplateElement> >)SerializationDotNet2.Xml.Deserializer.DeserializeObjectFromString(conditionBasedTemplateElements, ConditionBasedAppendedTemplateElements.GetType());

            //run for every templateelment in there:
            if (newTemplateElement.AppendedTemplateElement != null)
            {
                newTemplateElement.AppendedTemplateElement = (TemplateElement)newTemplateElement.AppendedTemplateElement.Clone();
            }

            List <KeyValuePairEx <List <Condition>, TemplateElement> > newConditionBasedAppendedTemplateElements = new List <KeyValuePairEx <List <Condition>, TemplateElement> >();

            foreach (var conditionsToTemplateElement in newTemplateElement.ConditionBasedAppendedTemplateElements)
            {
                KeyValuePairEx <List <Condition>, TemplateElement> newKeyValuePairEx = new KeyValuePairEx <List <Condition>, TemplateElement>(conditionsToTemplateElement.Key, conditionsToTemplateElement.Value);
                if (newKeyValuePairEx.Value != null)
                {
                    newKeyValuePairEx.Value = (TemplateElement)conditionsToTemplateElement.Value.Clone();
                }
                newConditionBasedAppendedTemplateElements.Add(newKeyValuePairEx);
            }
            newTemplateElement.ConditionBasedAppendedTemplateElements = newConditionBasedAppendedTemplateElements;

            //BaseObject baseObjectCloned;
            //if (newTemplateElement.BrowserActionOrCommand is BrowserCommand)
            //    baseObjectCloned = (BaseObject)newTemplateElement.BrowserActionOrCommand;
            //else
            //{
            //    baseObjectCloned = (BaseObject)((BrowserAction)newTemplateElement.BrowserActionOrCommand).ActionObject;
            //}
            //List<KeyValuePairEx<string, object>> deSerializedInputParametersAvailable = (List < KeyValuePairEx < string, object>> )SerializationDotNet2.Xml.Deserializer.DeserializeObjectFromString(serializedInputParametersAvailable, typeof(List<KeyValuePairEx<string, object>>));
            //baseObjectCloned.InputParameterAvailable = deSerializedInputParametersAvailable;


            return(newTemplateElement);
        }