private void CreateWzProp(IPropertyContainer parent, WzPropertyType propType, string propName, object value)
 {
     IWzImageProperty addedProp;
     switch (propType)
     {
         case WzPropertyType.ByteFloat:
             addedProp = new WzByteFloatProperty(propName);
             break;
         case WzPropertyType.Canvas:
             addedProp = new WzCanvasProperty(propName);
             ((WzCanvasProperty)addedProp).PngProperty = new WzPngProperty();
             break;
         case WzPropertyType.CompressedInt:
             addedProp = new WzCompressedIntProperty(propName);
             break;
         case WzPropertyType.Double:
             addedProp = new WzDoubleProperty(propName);
             break;
         /*case WzPropertyType.Sound:
             addedProp = new WzSoundProperty(propName);
             break;*/
         case WzPropertyType.String:
             addedProp = new WzStringProperty(propName);
             break;
         case WzPropertyType.UnsignedShort:
             addedProp = new WzUnsignedShortProperty(propName);
             break;
         case WzPropertyType.Vector:
             addedProp = new WzVectorProperty(propName);
             ((WzVectorProperty)addedProp).X = new WzCompressedIntProperty("X");
             ((WzVectorProperty)addedProp).Y = new WzCompressedIntProperty("Y");
             break;
         default:
             throw new NotSupportedException("not supported type");
     }
     addedProp.SetValue(value);
     parent.AddProperty(addedProp);
 }
        internal IWzImageProperty ParsePropertyFromXMLElement(XmlElement element)
        {
            switch (element.Name)
            {
                case "imgdir":
                    WzSubProperty sub = new WzSubProperty(element.GetAttribute("name"));
                    foreach (XmlElement subelement in element)
                        sub.AddProperty(ParsePropertyFromXMLElement(subelement));
                    return sub;

                case "canvas":
                    WzCanvasProperty canvas = new WzCanvasProperty(element.GetAttribute("name"));
                    if (!element.HasAttribute("basedata")) throw new NoBase64DataException("no base64 data in canvas element with name " + canvas.Name);
                    canvas.PngProperty = new WzPngProperty();
                    MemoryStream pngstream = new MemoryStream(Convert.FromBase64String(element.GetAttribute("basedata")));
                    canvas.PngProperty.SetPNG((Bitmap)Image.FromStream(pngstream, true, true));
                    foreach (XmlElement subelement in element)
                        canvas.AddProperty(ParsePropertyFromXMLElement(subelement));
                    return canvas;

                case "int":
                    WzCompressedIntProperty compressedInt = new WzCompressedIntProperty(element.GetAttribute("name"), int.Parse(element.GetAttribute("value"), formattingInfo));
                    return compressedInt;

                case "double":
                    WzDoubleProperty doubleProp = new WzDoubleProperty(element.GetAttribute("name"), double.Parse(element.GetAttribute("value"), formattingInfo));
                    return doubleProp;

                case "null":
                    WzNullProperty nullProp = new WzNullProperty(element.GetAttribute("name"));
                    return nullProp;

                case "sound":
                    if (!element.HasAttribute("basedata") || !element.HasAttribute("basehead") || !element.HasAttribute("length")) throw new NoBase64DataException("no base64 data in sound element with name " + element.GetAttribute("name"));
                    WzSoundProperty sound = new WzSoundProperty(element.GetAttribute("name"),
                        int.Parse(element.GetAttribute("length")),
                        Convert.FromBase64String(element.GetAttribute("basehead")),
                        Convert.FromBase64String(element.GetAttribute("basedata")));
                    return sound;

                case "string":
                    WzStringProperty stringProp = new WzStringProperty(element.GetAttribute("name"), element.GetAttribute("value"));
                    return stringProp;

                case "short":
                    WzUnsignedShortProperty shortProp = new WzUnsignedShortProperty(element.GetAttribute("name"), ushort.Parse(element.GetAttribute("value"), formattingInfo));
                    return shortProp;

                case "uol":
                    WzUOLProperty uol = new WzUOLProperty(element.GetAttribute("name"), element.GetAttribute("value"));
                    return uol;

                case "vector":
                    WzVectorProperty vector = new WzVectorProperty(element.GetAttribute("name"), new WzCompressedIntProperty("x", Convert.ToInt32(element.GetAttribute("x"))), new WzCompressedIntProperty("y", Convert.ToInt32(element.GetAttribute("y"))));
                    return vector;

                case "float":
                    WzByteFloatProperty floatProp = new WzByteFloatProperty(element.GetAttribute("name"), float.Parse(element.GetAttribute("value"), formattingInfo));
                    return floatProp;

                case "extended":
                    WzConvexProperty convex = new WzConvexProperty(element.GetAttribute("name"));
                    foreach (XmlElement subelement in element)
                        convex.AddProperty(ParsePropertyFromXMLElement(subelement));
                    return convex;
            }
            throw new InvalidDataException("unknown XML prop " + element.Name);
        }
Beispiel #3
0
        public override IWzImageProperty DeepClone()
        {
            WzDoubleProperty clone = (WzDoubleProperty)MemberwiseClone();

            return(clone);
        }
Beispiel #4
0
        public override WzImageProperty DeepClone()
        {
            WzDoubleProperty clone = new WzDoubleProperty(name, val);

            return(clone);
        }
Beispiel #5
0
 private static void ParseXML(XmlElement element, IPropertyContainer wo)
 {
     foreach (XmlNode node in element)
     {
         if (!(node is XmlElement)) continue;
         XmlElement childElement = (XmlElement)node;
         if (childElement.Name == "imgdir")
         {
             WzSubProperty sub = new WzSubProperty(childElement.GetAttribute("name"));
             wo.AddProperty(sub);
             ParseXML(childElement, (IPropertyContainer)sub);
         }
         else if (childElement.Name == "canvas")
         {
             WzCanvasProperty canvas = new WzCanvasProperty(childElement.GetAttribute("name"));
             canvas.PngProperty = new WzPngProperty();
             MemoryStream pngstream = new MemoryStream(Convert.FromBase64String(childElement.GetAttribute("basedata")));
             canvas.PngProperty.SetPNG((Bitmap)Image.FromStream(pngstream, true, true));
             wo.AddProperty(canvas);
             ParseXML(childElement, (IPropertyContainer)canvas);
         }
         if (childElement.Name == "int")
         {
             WzCompressedIntProperty compressedInt = new WzCompressedIntProperty(childElement.GetAttribute("name"), int.Parse(childElement.GetAttribute("value"), formattingInfo));
             wo.AddProperty(compressedInt);
         }
         if (childElement.Name == "double")
         {
             WzDoubleProperty doubleProp = new WzDoubleProperty(childElement.GetAttribute("name"), double.Parse(childElement.GetAttribute("value"), formattingInfo));
             wo.AddProperty(doubleProp);
         }
         if (childElement.Name == "null")
         {
             WzNullProperty nullProp = new WzNullProperty(childElement.GetAttribute("name"));
             wo.AddProperty(nullProp);
         }
         if (childElement.Name == "sound")
         {
             WzSoundProperty sound = new WzSoundProperty(childElement.GetAttribute("name"));
             sound.SetDataUnsafe(Convert.FromBase64String(childElement.GetAttribute("basedata")));
             wo.AddProperty(sound);
         }
         if (childElement.Name == "string")
         {
             string str = childElement.GetAttribute("value").Replace("&lt;", "<").Replace("&amp;", "&").Replace("&gt;", ">").Replace("&apos;", "'").Replace("&quot;", "\"");
             WzStringProperty stringProp = new WzStringProperty(childElement.GetAttribute("name"), str);
             wo.AddProperty(stringProp);
         }
         if (childElement.Name == "short")
         {
             WzUnsignedShortProperty shortProp = new WzUnsignedShortProperty(childElement.GetAttribute("name"), ushort.Parse(childElement.GetAttribute("value"), formattingInfo));
             wo.AddProperty(shortProp);
         }
         if (childElement.Name == "uol")
         {
             WzUOLProperty uol = new WzUOLProperty(childElement.GetAttribute("name"), childElement.GetAttribute("value"));
             wo.AddProperty(uol);
         }
         if (childElement.Name == "vector")
         {
             WzVectorProperty vector = new WzVectorProperty(childElement.GetAttribute("name"), new WzCompressedIntProperty("x", Convert.ToInt32(childElement.GetAttribute("x"))), new WzCompressedIntProperty("y", Convert.ToInt32(childElement.GetAttribute("y"))));
             wo.AddProperty(vector);
         }
         if (childElement.Name == "float")
         {
             WzByteFloatProperty floatProp = new WzByteFloatProperty(childElement.GetAttribute("name"), float.Parse(childElement.GetAttribute("value"), formattingInfo));
             wo.AddProperty(floatProp);
         }
         if (childElement.Name == "extended")
         {
             WzConvexProperty convex = new WzConvexProperty(childElement.GetAttribute("name"));
             wo.AddProperty(convex);
             ParseXML(childElement, (IPropertyContainer)convex);
         }
     }
 }
Beispiel #6
0
 public override WzImageProperty DeepClone()
 {
     WzDoubleProperty clone = new WzDoubleProperty(name, val);
     return clone;
 }