Esempio n. 1
0
        public void Add(object header)
        {
            //var p=new KeyValuePairEx<object,int>(header,1)

            var pair = new KeyValuePairEx <object, int>(header, 1);

            HeaderTextList.Add(pair);
        }
Esempio n. 2
0
    public void WriteXml(XmlWriter writer)
    {
        XmlSerializer           serializer    = new XmlSerializer(typeof(KeyValuePairEx <TKey, TValue>));
        XmlSerializerNamespaces xmlNameSpaces = new XmlSerializerNamespaces();

        xmlNameSpaces.Add(string.Empty, string.Empty);
        foreach (TKey key in this.Keys)
        {
            TValue value = this[key];
            var    pair  = new KeyValuePairEx <TKey, TValue>(key, value);
            serializer.Serialize(writer, pair, xmlNameSpaces);
        }
    }
Esempio n. 3
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);
        }
        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);
        }