/// <summary>
        /// Loads all the elements found in the elements file.
        /// </summary>
        /// <param name="includeDisabled"></param>
        /// <returns>An array of the the elements found.</returns>
        public ElementInfo[] LoadInfoFromFile(bool includeDisabled)
        {
            // Logging disabled to boost performance
            //using (LogGroup logGroup = LogGroup.StartDebug("Loading the elements from the XML file."))
            //{
            if (Elements == null)
            {
                List<ElementInfo> validElements = new List<ElementInfo>();

                ElementInfo[] elements = new ElementInfo[]{};

                using (StreamReader reader = new StreamReader(File.OpenRead(FileNamer.ElementsInfoFilePath)))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(ElementInfo[]));
                    elements = (ElementInfo[])serializer.Deserialize(reader);
                }

                foreach (ElementInfo element in elements)
                    if (element.Enabled || includeDisabled)
                        validElements.Add(element);

                Elements = validElements.ToArray();
            }
            //}
            return Elements;
        }
        public override DecodedObject<object> decodeString(DecodedObject<object> decodedTag, System.Type objectClass, ElementInfo elementInfo, System.IO.Stream stream)
        {
            if (!PERCoderUtils.is7BitEncodedString(elementInfo))
                return base.decodeString(decodedTag, objectClass, elementInfo, stream);
            else
            {
                DecodedObject<object> result = new DecodedObject<object>();
                int strLen = decodeLength(elementInfo, stream);

                if (strLen <= 0)
                {
                    result.Value = ("");
                    return result;
                }

                BitArrayInputStream bitStream = (BitArrayInputStream) stream;
                byte[] buffer = new byte[strLen];
                // 7-bit decoding of string
                for (int i = 0; i < strLen; i++)
                    buffer[i] = (byte)bitStream.readBits(7);
                result.Value = new string(
                    System.Text.ASCIIEncoding.ASCII.GetChars(buffer)
                );
                return result;
            }
        }
Beispiel #3
0
 public override int encode(IASN1TypesEncoder encoder, object obj, Stream stream, ElementInfo elementInfo)
 {
     Object result = null;
     ASN1ElementMetadata saveInfo = elementInfo.PreparedASN1ElementInfo;
     elementInfo.PreparedInfo = (valueFieldMeta);
     if (!CoderUtils.isNullField(valueField, elementInfo))
     {
         result = encoder.invokeGetterMethodForField(valueField, obj, elementInfo);
     }
     if (saveInfo != null)
     {
         if (!saveInfo.HasTag
             && elementInfo.hasPreparedASN1ElementInfo()
             && elementInfo.PreparedASN1ElementInfo.HasTag)
         {
             ASN1ElementMetadata elData = new ASN1ElementMetadata(
                 saveInfo.Name,
                 saveInfo.IsOptional,
                 elementInfo.PreparedASN1ElementInfo.HasTag,
                 elementInfo.PreparedASN1ElementInfo.IsImplicitTag,
                 elementInfo.PreparedASN1ElementInfo.TagClass,
                 elementInfo.PreparedASN1ElementInfo.Tag,
                 saveInfo.HasDefaultValue
                 );
             elementInfo.PreparedASN1ElementInfo = elData;
         }
         else
             elementInfo.PreparedASN1ElementInfo = (saveInfo);
     }
     return valueFieldMeta.TypeMetadata.encode(encoder, result, stream, elementInfo);
 }
Beispiel #4
0
        public override int encodeSequence(Object obj, System.IO.Stream stream, ElementInfo elementInfo)
        {
            if(!CoderUtils.isSequenceSet(elementInfo))
                return base.encodeSequence(obj, stream, elementInfo);
            else {
                int resultSize = 0;
                PropertyInfo[] fields = null;
                if (elementInfo.hasPreparedInfo())
                {
                    fields = elementInfo.getProperties(obj.GetType());
                }
                else
                {
                    SortedList<int, PropertyInfo> fieldOrder = CoderUtils.getSetOrder(obj.GetType());
                    //TO DO Performance optimization need (unnecessary copy)
                    fields = new PropertyInfo[fieldOrder.Count];
                    fieldOrder.Values.CopyTo(fields, 0);
                }

                for (int i = 0; i < fields.Length; i++)
                {
                    PropertyInfo field = fields[fields.Length - 1 - i];
                    resultSize += encodeSequenceField(obj, fields.Length - 1 - i, field, stream, elementInfo);
                }

                resultSize += encodeHeader(
                    BERCoderUtils.getTagValueForElement(
                        elementInfo,
                        TagClasses.Universal,
                        ElementType.Constructed,
                        UniversalTags.Set)
                    , resultSize, stream);
                return resultSize;
            }
        }
Beispiel #5
0
        public override DecodedObject<object> decodeAny(DecodedObject<object> decodedTag, System.Type objectClass, ElementInfo elementInfo, System.IO.Stream stream)
        {
            int bufSize = elementInfo.MaxAvailableLen;
            if (bufSize == 0)
                return null;
            System.IO.MemoryStream anyStream = new System.IO.MemoryStream(1024);
            /*int tagValue = (int)decodedTag.Value;
            for (int i = 0; i < decodedTag.Size; i++)
            {
                anyStream.WriteByte((byte)tagValue);
                tagValue = tagValue >> 8;
            }*/

            if(bufSize<0)
                bufSize = 1024;
            int len = 0;
            if (bufSize > 0)
            {
                byte[] buffer = new byte[bufSize];
                int readed = stream.Read(buffer, 0, buffer.Length);
                while (readed > 0)
                {
                    anyStream.Write(buffer, 0, readed);
                    len += readed;
                    if (elementInfo.MaxAvailableLen > 0)
                        break;
                    readed = stream.Read(buffer, 0, buffer.Length);
                }
            }
            CoderUtils.checkConstraints(len, elementInfo);
            return new DecodedObject<object>(anyStream.ToArray(), len);
        }
Beispiel #6
0
 public static bool is7BitEncodedString(ElementInfo info)
 {
     bool is7Bit = false;
     int stringType = CoderUtils.getStringTagForElement(info);
     is7Bit = (
                  stringType == UniversalTags.PrintableString
                  || stringType == UniversalTags.VisibleString
              );
     return is7Bit;
 }
Beispiel #7
0
        /// <summary>
        /// Creates a new copy of this ElementInfo.
        /// </summary>
        /// <returns>A new ElementInfo that is a copy of this instance.</returns>
        public ElementInfo Clone()
        {
            var cloneElementInfo = new ElementInfo();

            cloneElementInfo.Texture = Texture.Clone();
            cloneElementInfo.XOffset = XOffset;
            cloneElementInfo.YOffset = YOffset;

            return cloneElementInfo;
        }
Beispiel #8
0
 public override DecodedObject<object> decodeBitString(DecodedObject<object> decodedTag, System.Type objectClass, ElementInfo elementInfo, System.IO.Stream stream)
 {
     if (!checkTagForObject(decodedTag, TagClasses.Universal, ElementType.Primitive, UniversalTags.Bitstring, elementInfo))
         return null;
     DecodedObject<int> len = decodeLength(stream);
     int trailBitCnt = stream.ReadByte();
     CoderUtils.checkConstraints(len.Value * 8 - trailBitCnt, elementInfo);
     byte[] byteBuf = new byte[len.Value - 1];
     stream.Read(byteBuf,0,byteBuf.Length);
     return new DecodedObject<object>( new BitString(byteBuf,trailBitCnt), len.Value + len.Size);
 }
Beispiel #9
0
 public override DecodedObject<object> decodeBoolean(DecodedObject<object> decodedTag, System.Type objectClass, ElementInfo elementInfo, System.IO.Stream stream)
 {
     if (!checkTagForObject(decodedTag, TagClasses.Universal, ElementType.Primitive, UniversalTags.Boolean, elementInfo))
         return null;
     DecodedObject<object> result = decodeIntegerValue(stream);
     int val = (int) result.Value;
     if (val != 0)
         result.Value  = true;
     else
         result.Value = false;
     return result;
 }
Beispiel #10
0
        /**
         * tries to group the chained elements into blocks
         *
         * the elements must be in a valid order allready
         *
         * this function also translates all constraints into the blocks of TranslateInfo
         *
         */
        public static TranslateInfo translateIntoBlocks(List<int> elements, List<CausalSets.Constraint> constraints)
        {
            int i;
            int elementI;
            int blockIdCounter;
            bool blockIdCounterWasIncremented;
            TranslateInfo resultTranslateInfo;

            ElementInfo[] elementInfos;

            debugInput(elements, constraints);

            resultTranslateInfo = new TranslateInfo();

            elementInfos = new ElementInfo[elements.Count];

            for( i = 0; i < elements.Count; i++ )
            {
                elementInfos[i] = new ElementInfo();
            }

            // go througth all the constraints and search the index of the dependencies and the element then store it in the array
            storeDependenciesIntoElementInfos(elements, elementInfos, constraints);

            // search in the array for interlinked blocks, label the elements with a blockcounter
            blockIdCounter = 0;
            blockIdCounterWasIncremented = false;

            for( elementI = 1; elementI < elements.Count; elementI++ )
            {
                if( elementInfos[elementI].dependencies.Count > 0 && elementInfos[elementI].dependencies.Contains(elementI-1) )
                {
                    elementInfos[elementI].blockId = blockIdCounter;
                }
                else
                {
                    blockIdCounter++;
                    elementInfos[elementI].blockId = blockIdCounter;
                }
            }

            // store the elements into the blocks
            // and transfer the orginal constraints to the blocks
            storeElementsIntoBlocks(elements, elementInfos, resultTranslateInfo);
            checkInvariantForBlocks(elements, resultTranslateInfo);
            transferConstraintsToBlocks(resultTranslateInfo, constraints);

            debugResultTranslateInfo(resultTranslateInfo);

            return resultTranslateInfo;
        }
Beispiel #11
0
  static bool handleProperties (XmlNode node, ElementInfo ei) {
    if (ei.properties == null)
      ei.properties = new ArrayList ();

    XmlElement elt = node as XmlElement;
    if (elt == null)
      return true;

    foreach (XmlElement property in elt.ChildNodes) {
      if (IsHidden (property))
        continue;

      PropertyInfo pi = new PropertyInfo ();
      pi.name = property["name"].InnerText;
      pi.managed_name = (property["managed_name"] != null) ? property["managed_name"].InnerText : null;
      pi.type = property["type"].InnerText;
      pi.readable = property["flags"].InnerText.IndexOf ('R') != -1;
      pi.writeable = property["flags"].InnerText.IndexOf ('W') != -1;

      if (property["enum-values"] != null) {
        pi.enuminfo = new EnumInfo ();
        pi.enuminfo.flag = false;
        pi.enuminfo.values = new ArrayList ();

        foreach (XmlNode val in property["enum-values"].ChildNodes) {
          EnumValue env = new EnumValue ();

          env.name = val.Attributes["nick"].InnerText;
          env.value = Int32.Parse (val.Attributes["value"].InnerText);
          pi.enuminfo.values.Add (env);
        }
      } else if (property["flags-values"] != null) {
        pi.enuminfo = new EnumInfo ();
        pi.enuminfo.flag = true;
        pi.enuminfo.values = new ArrayList ();

        foreach (XmlNode val in property["flags-values"].ChildNodes) {
          FlagValue env = new FlagValue ();

          env.name = val.Attributes["nick"].InnerText;
          env.value = UInt32.Parse (val.Attributes["value"].InnerText);
          pi.enuminfo.values.Add (env);
        }
      }

      ei.properties.Add (pi);
    }

    return true;
  }
Beispiel #12
0
  static bool handlePads (XmlNode node, ElementInfo ei) {
    if (ei.pads == null)
      ei.pads = new ArrayList ();

    XmlElement elt = node as XmlElement;
    if (elt == null)
      return true;

    foreach (XmlElement pad in elt.ChildNodes)
      if (!IsHidden (pad) && !IsHidden (pad["name"]))
        ei.pads.Add (pad["name"].InnerText);

    return true;
  }
        /// <summary>
        /// Stores the element in an extension.
        /// </summary>
        /// <param name="extensible">The object that is being extended.</param>
        /// <param name="element">The element to store.</param>
        /// <returns>This method always returns true.</returns>
        public bool StoreElement(IExtensible extensible, ElementInfo element)
        {
            GenericExtension extension;

            extension = extensible.Extensions.FirstOrDefault((e) => e.Name == GenericExtensionHandler.ExtensionName) as GenericExtension;
            if (extension == null)
            {
                extension = new GenericExtension(GenericExtensionHandler.ExtensionName);
                extensible.Extensions.Add(extension);
            }

            Utilities.SetParent(element.Element, extensible as XliffElement);
            extension.AddChild(element);

            return true;
        }
        /// <summary>
        /// Stores the <see cref="XliffElement"/> as a child of this <see cref="XliffElement"/>.
        /// </summary>
        /// <param name="child">The child to add.</param>
        /// <returns>True if the child was stored, otherwise false.</returns>
        protected override bool StoreChild(ElementInfo child)
        {
            bool result;

            result = true;
            if (child.Element is Match)
            {
                this.Matches.Add((Match)child.Element);
            }
            else
            {
                result = base.StoreChild(child);
            }

            return result;
        }
        /// <summary>
        /// Stores the <see cref="XliffElement"/> as a child of this <see cref="XliffElement"/>.
        /// </summary>
        /// <param name="child">The child to add.</param>
        /// <returns>True if the child was stored, otherwise false.</returns>
        protected override bool StoreChild(ElementInfo child)
        {
            bool result;

            result = true;
            if (child.Element is XliffDocument)
            {
                Utilities.ThrowIfPropertyNotNull(this, PropertyNames.Document, this.Document);
                this.Document = (XliffDocument)child.Element;
            }
            else
            {
                result = base.StoreChild(child);
            }

            return result;
        }
Beispiel #16
0
        public static DecodedObject<int> getTagValueForElement(ElementInfo info, int tagClass, int elemenType, int universalTag)
        {
            DecodedObject<int> result = new DecodedObject<int>();
            // result.Value =  tagClass | elemenType | universalTag;
            if (universalTag < UniversalTags.LastUniversal)
            {
                result.Value = tagClass | elemenType | universalTag;
            }
            else
                result = getTagValue(tagClass, elemenType, universalTag, universalTag, tagClass);

            result.Size = 1;
            if (info.hasPreparedInfo())
            {
                ASN1ElementMetadata meta = info.PreparedASN1ElementInfo;
                if (meta != null && meta.HasTag)
                {
                    result = getTagValue(tagClass, elemenType, universalTag,
                                         meta.Tag,
                                         meta.TagClass
                        );
                }
            }
            else
            {
                ASN1Element elementInfo = null;
                if (info.ASN1ElementInfo != null)
                {
                    elementInfo = info.ASN1ElementInfo;
                }
                else if (info.isAttributePresent<ASN1Element>())
                {
                    elementInfo = info.getAttribute<ASN1Element>();
                }

                if (elementInfo != null)
                {
                    if (elementInfo.HasTag)
                    {
                        result = getTagValue(tagClass, elemenType, universalTag, elementInfo.Tag, elementInfo.TagClass);
                    }
                }
            }
            return result;
        }
        /// <summary>
        /// Saves the provided elements to file.
        /// </summary>
        /// <param name="elements">An array of the elements to save to file.</param>
        public void SaveInfoToFile(ElementInfo[] elements)
        {
            // Logging disabled to boost performance
            //using (LogGroup logGroup = LogGroup.StartDebug("Saving the provided elements to XML file."))
            //{
            string path = FileNamer.ElementsInfoFilePath;

            //LogWriter.Debug("Path : " + path);

            if (!Directory.Exists(Path.GetDirectoryName(path)))
                Directory.CreateDirectory(Path.GetDirectoryName(path));

            using (StreamWriter writer = File.CreateText(path))
            {
                XmlSerializer serializer = new XmlSerializer(elements.GetType());
                serializer.Serialize(writer, elements);
                writer.Close();
            }
            //}
        }
        public override int encodeString(System.Object obj, System.IO.Stream stream, ElementInfo elementInfo)
        {
            if (!PERCoderUtils.is7BitEncodedString(elementInfo))
                return base.encodeString(obj, stream, elementInfo);
            else
            {
                int resultSize = 0;
                byte[] val = System.Text.ASCIIEncoding.ASCII.GetBytes((string)obj);
                resultSize = encodeLength(val.Length, elementInfo, stream);
                if (val.Length == 0)
                    return resultSize;

                BitArrayOutputStream bitStream = (BitArrayOutputStream) stream;
                // 7-bit encoding of string
                for (int i = 0; i < val.Length; i++)
                {
                    bitStream.writeBits(val[i], 7);
                }
                return resultSize;
            }
        }
Beispiel #19
0
        public override DecodedObject<object> decodeSequence(DecodedObject<object> decodedTag, System.Type objectClass, ElementInfo elementInfo, System.IO.Stream stream)
        {
            bool isSet = false;
            if (!CoderUtils.isSequenceSet(elementInfo))
            {
                if (!checkTagForObject(decodedTag, TagClasses.Universal, ElementType.Constructed, UniversalTags.Sequence, elementInfo))
                {
                    return null;
                }
            }
            else
            {
                if (checkTagForObject(decodedTag, TagClasses.Universal, ElementType.Constructed, UniversalTags.Set, elementInfo))
                {
                    isSet = true;
                }
                else
                    return null;
            }
            DecodedObject<int> len = decodeLength(stream);
            int saveMaxAvailableLen = elementInfo.MaxAvailableLen;
            elementInfo.MaxAvailableLen = (len.Value);

            DecodedObject<object> result = null;
            if(!isSet)
                result =base.decodeSequence(decodedTag, objectClass, elementInfo, stream);
            else
                result = decodeSet(decodedTag, objectClass, elementInfo, len.Value, stream);
            if (result.Size != len.Value)
                throw new System.ArgumentException("Sequence '" + objectClass.ToString() + "' size is incorrect!");
            result.Size = result.Size + len.Size;
            elementInfo.MaxAvailableLen = (saveMaxAvailableLen);
            return result;
        }
Beispiel #20
0
 void IWindowExplorer.HighLightElement(ElementInfo ElementInfo, bool locateElementByItLocators = false)
 {
     HighLightElement(ElementInfo);
 }
 private void ShowControlActions(ElementInfo EI)
 {
     //AvailableControlActionsGrid.DataSourceList = EI.GetAvailableActions();
 }
        public static RunnableConditionalActions LoadActionSets(ElementInfo root)
        {
            var ret = new RunnableConditionalActions();

            if (root.Name != "ConditionalActions")
            {
                throw new FormatException("Condtional actions root element wasn't named \"ConditionalActions\"!");
            }

            foreach (var conditionInfo in root.Children)
            {
                var set = new SerializableConditionalActionSet();

                #region Conditions

                if (ConditionManager.TryLoadCustomCondition(conditionInfo, out var customCondition))
                {
                    set.Condition = customCondition;
                }
                else
                {
                    switch (conditionInfo.Name)
                    {
                    case "OnAdminGained":
                        set.Condition = new SCOnAdminGained()
                        {
                            target = conditionInfo.Attributes.GetOrThrow("target", "No target found for OnAdminGained condition!")
                        };
                        break;

                    case "OnConnect":
                        set.Condition = new SCOnConnect()
                        {
                            target               = conditionInfo.Attributes.GetOrThrow("target", "No target found for OnConnect condition!"),
                            requiredFlags        = conditionInfo.Attributes.GetString("requiredFlags", null),
                            needsMissionComplete = conditionInfo.Attributes.GetBool("needsMissionComplete")
                        };
                        break;

                    case "HasFlags":
                        set.Condition = new SCHasFlags()
                        {
                            requiredFlags = conditionInfo.Attributes.GetString("requiredFlags", null)
                        };
                        break;

                    case "Instantly":
                        set.Condition = new SCInstantly()
                        {
                            needsMissionComplete = conditionInfo.Attributes.GetBool("needsMissionComplete")
                        };
                        break;

                    case "OnDisconnect":
                        set.Condition = new SCOnDisconnect()
                        {
                            target = conditionInfo.Attributes.GetOrDefault("target")
                        };
                        break;

                    case "DoesNotHaveFlags":
                        set.Condition = new SCDoesNotHaveFlags()
                        {
                            Flags = conditionInfo.Attributes.GetString("Flags", null)
                        };
                        break;
                    }
                }

                if (set.Condition == null)
                {
                    throw new FormatException($"Condition {conditionInfo.Name} could not be found!");
                }

                #endregion

                set.Actions.AddRange(conditionInfo.Children.Select(ReadAction));

                ret.Actions.Add(set);
            }

            return(ret);
        }
Beispiel #23
0
 public void HighLightElement(ElementInfo ElementInfo, bool locateElementByItLocators = false)
 {
 }
Beispiel #24
0
 public override int encode(IASN1TypesEncoder encoder, object obj, Stream stream, ElementInfo elementInfo)
 {
     return(encoder.encodeString(obj, stream, elementInfo));
 }
Beispiel #25
0
 void IWindowExplorer.HighLightElement(ElementInfo ElementInfo)
 {
     HighLightElement(ElementInfo);
 }
Beispiel #26
0
        public override void StartElement(string name, Variant attributes, Variant.EnumType variantType)
        {
            ElementInfo context = new ElementInfo(name, attributes, variantType);

            if (m_stack.Count != 0)
            {
                ElementInfo parentContext = m_stack.Peek();

                switch (parentContext.m_type)
                {
                case Variant.EnumType.Any:
                    if (!parentContext.m_isTyped)
                    {
                        // Untyped elements with children are converted to Bags
                        parentContext.m_type    = Variant.EnumType.Bag;
                        parentContext.m_element = new Variant(parentContext.m_type);
                    }
                    break;

                case Variant.EnumType.None:
                case Variant.EnumType.String:
                case Variant.EnumType.Int32:
                case Variant.EnumType.UInt32:
                case Variant.EnumType.Int64:
                case Variant.EnumType.UInt64:
                case Variant.EnumType.Float:
                case Variant.EnumType.Double:
                case Variant.EnumType.Boolean:
                case Variant.EnumType.Date:
                case Variant.EnumType.Time:
                case Variant.EnumType.DateTime:
                case Variant.EnumType.Buffer:
                    throw new VariantException("Unexpected start element");

                case Variant.EnumType.TimeSeries:
                    if (context.m_attributes.ContainsKey("time"))
                    {
                        context.m_time = context.m_attributes["time"].As <DateTime>();
                        context.m_attributes.Remove("time");
                    }
                    else
                    {
                        throw new VariantException("Missing 'time' attribute for TimeSeries element");
                    }
                    break;
                }
            }

            m_stack.Push(context);

            // infer type from 'variant' attribute
            if (context.m_attributes.ContainsKey("variant"))
            {
                context.m_type    = Variant.StringToEnum(context.m_attributes["variant"].As <string>());
                context.m_isTyped = true;
                context.m_attributes.Remove("variant");
            }

            switch (context.m_type)
            {
            case Variant.EnumType.Any:
                if (!context.m_isTyped && !context.m_attributes.Empty)
                {
                    // untyped elements with attributes are assumed
                    // to be bags
                    context.m_type    = Variant.EnumType.Bag;
                    context.m_element = new Variant(context.m_type);
                }
                break;

            case Variant.EnumType.None:
            case Variant.EnumType.String:
            case Variant.EnumType.Int32:
            case Variant.EnumType.UInt32:
            case Variant.EnumType.Int64:
            case Variant.EnumType.UInt64:
            case Variant.EnumType.Float:
            case Variant.EnumType.Double:
            case Variant.EnumType.Boolean:
            case Variant.EnumType.Date:
            case Variant.EnumType.Time:
            case Variant.EnumType.DateTime:
            case Variant.EnumType.Buffer:
                break;

            case Variant.EnumType.List:
            case Variant.EnumType.Dictionary:
            case Variant.EnumType.Bag:
            case Variant.EnumType.TimeSeries:
                context.m_element = new Variant(context.m_type);
                break;

            case Variant.EnumType.Exception:
            case Variant.EnumType.Object:
                // Exception and Object are parsed via a dictionary for convenience.
                context.m_element = new Variant(Variant.EnumType.Dictionary);
                break;

            case Variant.EnumType.Tuple:
            {
                if (context.m_attributes.ContainsKey("size"))
                {
                    context.m_element = new Variant(Variant.EnumType.Tuple, context.m_attributes["size"].As <int>());
                    context.m_attributes.Remove("size");
                }
                else
                {
                    throw new VariantException("Missing 'size' attribute for Tuple variant");
                }
                break;
            }

            default:
                throw new VariantException("Case exhaustion: " + context.m_type.ToString());
            }
        }
Beispiel #27
0
        public override void EndElement()
        {
            if (m_stack.Count == 0)
            {
                throw new VariantException("End tag does not match start tag");
            }

            ElementInfo context = m_stack.Peek();

            if (!context.m_attributes.Empty)
            {
                if (context.m_element.Is(Variant.EnumType.Mapping))
                {
                    foreach (VariantItem item in context.m_attributes)
                    {
                        context.m_element.Add(item.Key, item.Value);
                    }
                }
                else
                {
                    throw new VariantException("No attributes allowed in XML element of " + context.m_type);
                }
            }

            switch (context.m_type)
            {
            case Variant.EnumType.None:
                context.m_element = new Variant();
                break;

            case Variant.EnumType.Any:
            case Variant.EnumType.String:
            case Variant.EnumType.Int32:
            case Variant.EnumType.UInt32:
            case Variant.EnumType.Int64:
            case Variant.EnumType.UInt64:
            case Variant.EnumType.Float:
            case Variant.EnumType.Double:
            case Variant.EnumType.Boolean:
            case Variant.EnumType.Date:
            case Variant.EnumType.Time:
            case Variant.EnumType.DateTime:
                context.m_element = new Variant(context.m_type, context.m_data);
                break;

            case Variant.EnumType.Buffer:
                context.m_element = new Variant(System.Convert.FromBase64String(context.m_data));
                break;

            case Variant.EnumType.Exception:
            {
                string typeStr = "", messageStr = "", sourceStr = "", stackStr = "";

                if (context.m_element.ContainsKey("type"))
                {
                    typeStr = context.m_element["type"].As <string>();
                }
                else
                {
                    throw new VariantException("Missing 'type' element in Exception variant");
                }

                if (context.m_element.ContainsKey("message"))
                {
                    messageStr = context.m_element["message"].As <string>();
                }
                else
                {
                    throw new VariantException("Missing 'message' element in Exception variant");
                }

                if (context.m_element.ContainsKey("source"))
                {
                    sourceStr = context.m_element["source"].As <string>();
                }

                if (context.m_element.ContainsKey("stack"))
                {
                    stackStr = context.m_element["stack"].As <string>();
                }

                context.m_element = new Variant(new VariantExceptionInfo(typeStr, messageStr, sourceStr, stackStr));

                break;
            }

            case Variant.EnumType.Object:
            {
                string  className = "";
                int     version;
                Variant param;

                if (context.m_element.ContainsKey("class"))
                {
                    className = context.m_element["class"].As <string>();
                }
                else
                {
                    throw new VariantException("Missing 'class' element in Object variant");
                }

                if (context.m_element.ContainsKey("version"))
                {
                    version = context.m_element["version"].As <int>();
                }
                else
                {
                    throw new VariantException("Missing 'version' element in Object variant");
                }

                if (context.m_element.ContainsKey("params"))
                {
                    param = context.m_element["params"];
                }
                else
                {
                    throw new VariantException("Missing 'params' element in Object variant");
                }

                IVariantObject obj = null;
                if (m_factory != null)
                {
                    obj = m_factory.Create(className);

                    if (obj == null && (m_mode & XmlMode.CreateProxy) == 0)
                    {
                        throw new VariantException("Object of class " + className + " is not regsistered in factory");
                    }
                }

                if (obj == null)
                {
                    obj = new VariantObjectProxy(className);
                }

                obj.Inflate(param, version);

                context.m_element = new Variant(obj);

                break;
            }
            }

            if (m_stack.Count > 0)
            {
                m_stack.Pop();
            }

            if (m_stack.Count == 0)
            {
                m_result = context.m_element;
            }
            else
            {
                ElementInfo parentContext = m_stack.Peek();

                switch (parentContext.m_type)
                {
                case Variant.EnumType.Exception:
                case Variant.EnumType.Object:
                case Variant.EnumType.Dictionary:
                case Variant.EnumType.Bag:
                {
                    parentContext.m_element.Add(context.m_name, context.m_element);
                    break;
                }

                case Variant.EnumType.List:
                {
                    parentContext.m_element.Add(context.m_element);
                    break;
                }

                case Variant.EnumType.Tuple:
                {
                    parentContext.m_element[parentContext.m_rowIndex++] = context.m_element;
                    break;
                }

                case Variant.EnumType.TimeSeries:
                {
                    parentContext.m_element.Add(context.m_time, context.m_element);
                    break;
                }
                }
            }
        }
Beispiel #28
0
 /// <summary>
 /// Update the mapped vertex and index buffer values using the provided element info.
 /// </summary>
 /// <param name="elementInfo">The structure containing the information about the element to draw.</param>
 /// <param name="vertexPointer">The pointer to the vertex array buffer to update.</param>
 /// <param name="indexPointer">The pointer to the index array buffer to update. This value is null if the index buffer used is static.</param>
 /// <param name="vexterStartOffset">The offset in the vertex buffer where the vertex of the element starts</param>
 protected abstract void UpdateBufferValuesFromElementInfo(ref ElementInfo elementInfo, IntPtr vertexPointer, IntPtr indexPointer, int vexterStartOffset);
Beispiel #29
0
 ObservableList <OptionalValue> IWindowExplorer.GetOptionalValuesList(ElementInfo ElementInfo, eLocateBy elementLocateBy, string elementLocateValue)
 {
     throw new NotImplementedException();
 }
Beispiel #30
0
 public ElementInfo GetMatchingElement(ElementInfo latestElement, ObservableList <ElementInfo> originalElements)
 {
     throw new NotImplementedException();
 }
Beispiel #31
0
 public bool TestElementLocators(ElementInfo EI, bool GetOutAfterFoundElement = false)
 {
     throw new NotImplementedException();
 }
Beispiel #32
0
 public override DecodedObject<object> decodeString(DecodedObject<object> decodedTag, System.Type objectClass, ElementInfo elementInfo, System.IO.Stream stream)
 {
     if (!checkTagForObject(decodedTag, TagClasses.Universal, ElementType.Primitive, CoderUtils.getStringTagForElement(elementInfo), elementInfo))
         return null;
     DecodedObject<int> len = decodeLength(stream);
     CoderUtils.checkConstraints(len.Value, elementInfo);
     byte[] byteBuf = new byte[len.Value];
     stream.Read(byteBuf, 0, byteBuf.Length);
     string result = CoderUtils.bufferToASN1String(byteBuf, elementInfo);
     return new DecodedObject<object>(result, len.Value + len.Size);
 }
Beispiel #33
0
 protected bool checkTagForObject(DecodedObject<object> decodedTag, int tagClass, int elementType, int universalTag, ElementInfo elementInfo)
 {
     if (decodedTag == null)
         return false;
     int definedTag = BERCoderUtils.getTagValueForElement(elementInfo, tagClass, elementType, universalTag).Value;
     return definedTag == (int)decodedTag.Value;
 }
Beispiel #34
0
 ObservableList <ControlProperty> IWindowExplorer.GetElementProperties(ElementInfo ElementInfo)
 {
     return(GetElementProperties(ElementInfo));
 }
Beispiel #35
0
 object IWindowExplorer.GetElementData(ElementInfo ElementInfo, eLocateBy elementLocateBy, string elementLocateValue)
 {
     throw new System.NotImplementedException();
 }
Beispiel #36
0
 ObservableList <ElementLocator> IWindowExplorer.GetElementLocators(ElementInfo ElementInfo)
 {
     return(GetElementLocators(ElementInfo));
 }
Beispiel #37
0
 public System.Collections.Generic.List <ElementInfo> GetElementChildren(ElementInfo ElementInfo)
 {
     throw new System.NotImplementedException();
 }
Beispiel #38
0
 public override DecodedObject<object> decodeChoice(DecodedObject<object> decodedTag, Type objectClass, ElementInfo elementInfo, System.IO.Stream stream)
 {
     if ( (elementInfo.hasPreparedInfo() && elementInfo.hasPreparedASN1ElementInfo() && elementInfo.PreparedASN1ElementInfo.HasTag)
         || (elementInfo.ASN1ElementInfo != null && elementInfo.ASN1ElementInfo.HasTag))
     {
         if (!checkTagForObject(decodedTag, TagClasses.ContextSpecific, ElementType.Constructed, UniversalTags.LastUniversal, elementInfo))
             return null;
         DecodedObject<int> len =  decodeLength(stream);
         DecodedObject<object> childDecodedTag = decodeTag(stream);
         DecodedObject<object> result = base.decodeChoice(childDecodedTag, objectClass, elementInfo, stream);
         result.Size += len.Size + childDecodedTag.Size;
         return result;
     }
     else
         return base.decodeChoice(decodedTag, objectClass, elementInfo, stream);
 }
Beispiel #39
0
 public ElementInfo LearnElementInfoDetails(ElementInfo EI)
 {
     return(EI);
 }
        /// <summary>
        /// Stores the <see cref="XliffElement"/> as a child of this <see cref="XliffElement"/>.
        /// </summary>
        /// <param name="child">The child to add.</param>
        /// <returns>True if the child was stored, otherwise false.</returns>
        protected override bool StoreChild(ElementInfo child)
        {
            bool result;

            result = true;
            if (child.Element is MetaGroup)
            {
                this.Groups.Add((MetaGroup)child.Element);
            }
            else
            {
                result = base.StoreChild(child);
            }

            return result;
        }
        public static SerializableAction ReadAction(ElementInfo actionInfo)
        {
            if (ActionManager.TryLoadCustomAction(actionInfo, out var customAction))
            {
                return(customAction);
            }

            switch (actionInfo.Name)
            {
            case "LoadMission":
                return(ActionDelayDecorator.Create(actionInfo, new SALoadMission()
                {
                    MissionName = actionInfo.Attributes.GetOrThrow("MissionName", "Invalid mission for LoadMission action", StringExtensions.ContentFileExists)
                }));

            case "RunFunction":
                return(new SARunFunction()
                {
                    FunctionName = actionInfo.Attributes.GetOrThrow("FunctionName", "No function given for RunFunction action"),
                    FunctionValue = actionInfo.Attributes.GetInt("FunctionValue"),
                    Delay = actionInfo.Attributes.GetFloat("Delay"),
                    DelayHost = actionInfo.Attributes.GetString("DelayHost", null)
                });

            case "AddAsset":
                return(ActionDelayDecorator.Create(actionInfo, new SAAddAsset()
                {
                    TargetComp = actionInfo.Attributes.GetString("TargetComp", null),
                    TargetFolderpath = actionInfo.Attributes.GetString("TargetFolderpath", null),
                    FileName = actionInfo.Attributes.GetString("FileName", null),
                    FileContents = actionInfo.Attributes.GetString("FileContents", null)
                }));

            case "AddMissionToHubServer":
                var tag = actionInfo.Attributes.GetString("AssignmentTag");
                if (string.IsNullOrWhiteSpace(tag))
                {
                    tag = null;
                }
                return(ActionDelayDecorator.Create(actionInfo, new SAAddMissionToHubServer()
                {
                    MissionFilepath = actionInfo.Attributes.GetOrWarn("MissionFilepath", "Invalid mission file path for AddMissionToHubServer", StringExtensions.ContentFileExists),
                    TargetComp = actionInfo.Attributes.GetOrThrow("TargetComp", "Invalid target computer for AddMissionToHubServer", StringExtensions.HasContent),
                    AssignmentTag = tag,
                    StartsComplete = actionInfo.Attributes.GetBool("StartsComplete")
                }));

            case "RemoveMissionFromHubServer":
                return(ActionDelayDecorator.Create(actionInfo, new SARemoveMissionFromHubServer()
                {
                    MissionFilepath = actionInfo.Attributes.GetOrWarn("MissionFilepath", "Invalid mission file path for RemoveMissionFromHubServer", StringExtensions.ContentFileExists),
                    TargetComp = actionInfo.Attributes.GetOrThrow("TargetComp", "Invalid target computer for RemoveMissionFromHubServer", StringExtensions.HasContent)
                }));

            case "AddThreadToMissionBoard":
                return(ActionDelayDecorator.Create(actionInfo, new SAAddThreadToMissionBoard()
                {
                    ThreadFilepath = actionInfo.Attributes.GetOrWarn("ThreadFilepath", "Invalid thread path for AddThreadToMissionBoard", StringExtensions.ContentFileExists),
                    TargetComp = actionInfo.Attributes.GetOrThrow("TargetComp", "Invalid target computer for AddThreadToMissionBoard", StringExtensions.HasContent)
                }));

            case "AddIRCMessage":
                return(new SAAddIRCMessage()
                {
                    Author = ComputerLoader.filter(actionInfo.Attributes.GetOrThrow("Author", "Invalid author for AddIRCMessage", StringExtensions.HasContent)),
                    Message = ComputerLoader.filter(string.IsNullOrEmpty(actionInfo.Content) ? throw new FormatException("Invalid message for AddIRCMessage") : actionInfo.Content),
                    Delay = actionInfo.Attributes.GetFloat("Delay"),
                    TargetComp = actionInfo.Attributes.GetOrThrow("TargetComp", "Invalid target computer for AddIRCMessage", StringExtensions.HasContent)
                });
 public override int encode(IASN1TypesEncoder encoder, object obj, Stream stream, ElementInfo elementInfo)
 {
     return encoder.encodeSequence(obj, stream, elementInfo);
 }
Beispiel #43
0
 public void HighLightElement(ElementInfo ElementInfo)
 {
     return;
 }
 public Operation_Element_ChangeRotAngle_Trans(ElementInfo e, float angleOld, float angleNew)
     : base(e, angleOld, angleNew)
 {
 }
Beispiel #45
0
        public override DecodedObject<object> decodeReal(DecodedObject<object> decodedTag, System.Type objectClass, ElementInfo elementInfo, System.IO.Stream stream)
        {
            if (!checkTagForObject(decodedTag, TagClasses.Universal, ElementType.Primitive, UniversalTags.Real, elementInfo))
                return null;
            DecodedObject<int> len = decodeLength(stream);
            int realPreamble = stream.ReadByte();

            Double result = 0.0D;
            int szResult = len.Value;
            if ((realPreamble & 0x40) == 1)
            {
                // 01000000 Value is PLUS-INFINITY
                result = Double.PositiveInfinity;
            }
            if ((realPreamble & 0x41) == 1)
            {
                // 01000001 Value is MINUS-INFINITY
                result = Double.NegativeInfinity;
                szResult += 1;
            }
            else
                if (len.Value > 0)
                {
                    int szOfExp = 1 + (realPreamble & 0x3);
                    int sign = realPreamble & 0x40;
                    int ff = (realPreamble & 0x0C) >> 2;
                    DecodedObject<object> exponentEncFrm = decodeLongValue(stream, new DecodedObject<int>(szOfExp));
                    long exponent = (long)exponentEncFrm.Value;
                    DecodedObject<object> mantissaEncFrm = decodeLongValue(stream, new DecodedObject<int>(szResult - szOfExp - 1));
                    // Unpack mantissa & decrement exponent for base 2
                    long mantissa = (long)mantissaEncFrm.Value << ff;
                    while ((mantissa & 0x000ff00000000000L) == 0x0)
                    {
                        exponent -= 8;
                        mantissa <<= 8;
                    }
                    while ((mantissa & 0x0010000000000000L) == 0x0)
                    {
                        exponent -= 1;
                        mantissa <<= 1;
                    }
                    mantissa &= 0x0FFFFFFFFFFFFFL;
                    long lValue = (exponent + 1023 + 52) << 52;
                    lValue |= mantissa;
                    if (sign == 1)
                    {
                        lValue = (long)((ulong)lValue | 0x8000000000000000L);
                    }
            #if PocketPC
                    byte[] dblValAsBytes = System.BitConverter.GetBytes(lValue);
                    result = System.BitConverter.ToDouble(dblValAsBytes, 0);
            #else
                    result = System.BitConverter.Int64BitsToDouble(lValue);
            #endif
                }
            return new DecodedObject<object>(result, len.Value + len.Size);
        }
 public Operation_Element_ChangeAlpha_Trans(ElementInfo e, float alphaOld, float alphaNew)
     : base(e, alphaOld, alphaNew)
 {
 }
Beispiel #47
0
        public override DecodedObject<object> decodeSequenceOf(DecodedObject<object> decodedTag, System.Type objectClass, ElementInfo elementInfo, System.IO.Stream stream)
        {
            if (!CoderUtils.isSequenceSetOf(elementInfo))
            {
                if (!checkTagForObject(decodedTag, TagClasses.Universal, ElementType.Constructed, UniversalTags.Sequence, elementInfo))
                    return null;
            }
            else
            {
                if (!checkTagForObject(decodedTag, TagClasses.Universal, ElementType.Constructed, UniversalTags.Set, elementInfo))
                    return null;
            }

            Type paramType = (System.Type)objectClass.GetGenericArguments()[0];
            Type collectionType = typeof(List<>);
            Type genCollectionType = collectionType.MakeGenericType(paramType);
            Object param = Activator.CreateInstance(genCollectionType);

            DecodedObject<int> len = decodeLength(stream);
            if (len.Value != 0)
            {
                int lenOfItems = 0;
                int itemsCnt = 0;
                do
                {
                    ElementInfo info = new ElementInfo();
                    info.ParentAnnotatedClass = elementInfo.AnnotatedClass;
                    info.AnnotatedClass = paramType;

                    if (elementInfo.hasPreparedInfo())
                    {
                        ASN1SequenceOfMetadata seqOfMeta = (ASN1SequenceOfMetadata)elementInfo.PreparedInfo.TypeMetadata;
                        info.PreparedInfo = (seqOfMeta.getItemClassMetadata());
                    }

                    DecodedObject<object> itemTag = decodeTag(stream);
                    DecodedObject<object> item = decodeClassType(itemTag, paramType, info, stream);
                    MethodInfo method = param.GetType().GetMethod("Add");
                    if (item != null)
                    {
                        lenOfItems += item.Size + itemTag.Size;
                        method.Invoke(param, new object[] { item.Value });
                        itemsCnt++;
                    }
                }
                while (lenOfItems < len.Value);
                CoderUtils.checkConstraints(itemsCnt, elementInfo);
            }
            return new DecodedObject<object>(param, len.Value + len.Size);
        }
 public Operation_Element_ChangeScale_Trans(ElementInfo e, SizeF scale)
     : base(e, scale)
 {
 }
 StackPanel ITreeViewItem.Header()
 {
     return(TreeViewUtils.CreateItemHeader(UIAElementInfo.ElementTitle, ElementInfo.GetElementTypeImage(eElementType.Label)));
 }
Beispiel #50
0
 StackPanel ITreeViewItem.Header()
 {
     return(TreeViewUtils.CreateItemHeader(Name, ElementInfo.GetElementTypeImage(eElementType.Browser)));
 }
Beispiel #51
0
        protected virtual DecodedObject<object> decodeSet(DecodedObject<object> decodedTag, System.Type objectClass, ElementInfo elementInfo, int len, System.IO.Stream stream)
        {
            object sequence = createInstanceForElement(objectClass,elementInfo);
            initDefaultValues(sequence);
            DecodedObject<object> fieldTag = null;
            int sizeOfSequence = 0;
            int maxSeqLen = elementInfo.MaxAvailableLen;

            if (maxSeqLen == -1 || maxSeqLen > 0)
            {
                fieldTag = decodeTag(stream);
                if (fieldTag != null)
                    sizeOfSequence += fieldTag.Size;
            }
            PropertyInfo[] fields =
                elementInfo.getProperties(objectClass);

            bool fieldEncoded = false;
            do
            {
                for (int i = 0; i < fields.Length; i++)
                {
                    PropertyInfo field = fields[i];
                    DecodedObject<object> obj = decodeSequenceField(
                        fieldTag, sequence, i, field, stream, elementInfo, false
                    );
                    if (obj != null)
                    {
                        fieldEncoded = true;
                        sizeOfSequence += obj.Size;

                        bool isAny = false;
                        if (i + 1 == fields.Length - 1)
                        {
                            ElementInfo info = new ElementInfo();
                            info.AnnotatedClass = (fields[i + 1]);
                            info.MaxAvailableLen = (elementInfo.MaxAvailableLen);
                            if (elementInfo.hasPreparedInfo())
                            {
                                info.PreparedInfo = (elementInfo.PreparedInfo.getPropertyMetadata(i + 1));
                            }
                            else
                                info.ASN1ElementInfo = CoderUtils.getAttribute<ASN1Element>(fields[i + 1]);
                            isAny = CoderUtils.isAnyField(fields[i + 1], info);
                        }

                        if (maxSeqLen != -1)
                        {
                            elementInfo.MaxAvailableLen = (maxSeqLen - sizeOfSequence);
                        }

                        if (!isAny)
                        {
                            if (i < fields.Length - 1)
                            {
                                if (maxSeqLen == -1 || elementInfo.MaxAvailableLen > 0)
                                {
                                    fieldTag = decodeTag(stream);
                                    if (fieldTag != null)
                                        sizeOfSequence += fieldTag.Size;
                                    else
                                    {
                                        break;
                                    }
                                }
                                else
                                    fieldTag = null;
                            }
                            else
                                break;
                        }
                    }
                    ;
                }
            }
            while (sizeOfSequence < len && fieldEncoded);
            return new DecodedObject<object>(sequence, sizeOfSequence);
        }
Beispiel #52
0
        public ObservableList <ControlProperty> GetElementProperties(ElementInfo ElementInfo)
        {
            return(new ObservableList <ControlProperty>());

            throw new System.NotImplementedException();
        }
Beispiel #53
0
        object IWindowExplorer.GetElementData(ElementInfo ElementInfo, eLocateBy elementLocateBy, string elementLocateValue)
        {
            UIAElementInfo EI = (UIAElementInfo)ElementInfo;

            return(mUIAutomationHelper.GetElementData(EI.ElementObject));
        }
Beispiel #54
0
 public ObservableList <ElementLocator> GetElementLocators(ElementInfo ElementInfo)
 {
     throw new System.NotImplementedException();
 }
        /// <summary>
        /// Stores the <see cref="XliffElement"/> as a child of this <see cref="XliffElement"/>.
        /// </summary>
        /// <param name="child">The child to add.</param>
        /// <returns>True if the child was stored, otherwise false.</returns>
        protected override bool StoreChild(ElementInfo child)
        {
            if (child.Element is CustomElement2)
            {
                this.Element2 = (CustomElement2)child.Element;
            }
            else if (child.Element is CustomElement1)
            {
                this.Element1 = (CustomElement1)child.Element;
            }
            else
            {
                this.children.Add(child);
            }

            return true;
        }
Beispiel #56
0
 List <ElementInfo> IWindowExplorer.GetElementChildren(ElementInfo ElementInfo)
 {
     return(GetElementChildren(ElementInfo));
 }
 public override DecodedObject<object> decode(IASN1TypesDecoder decoder, DecodedObject<object> decodedTag, Type objectClass, ElementInfo elementInfo, Stream stream)
 {
     return decoder.decodeSequence(decodedTag,objectClass,elementInfo,stream);
 }
Beispiel #58
0
 void IWindowExplorer.UpdateElementInfoFields(ElementInfo eI)
 {
 }
        /// <summary>
        /// Stores the <see cref="XliffElement"/> as a child of this <see cref="XliffElement"/>.
        /// </summary>
        /// <param name="child">The child to add.</param>
        /// <returns>True if the child was stored, otherwise false.</returns>
        protected override bool StoreChild(ElementInfo child)
        {
            bool result;

            result = true;
            if (child.Element is ResourceItemRef)
            {
                this.ResourceItemReferences.Add((ResourceItemRef)child.Element);
            }
            else if (child.Element is ResourceItem)
            {
                this.ResourceItems.Add((ResourceItem)child.Element);
            }
            else
            {
                result = base.StoreChild(child);
            }

            return result;
        }
 public async Task <ElementRects> GetMainElementRects()
 {
     return(await ElementInfo.GetElementRectsByID($"main_{IdentityKey}"));
 }