Beispiel #1
0
 /// <summary>
 /// 添加对象到流
 /// </summary>
 /// <param name="graph">被序列化的对象</param>
 /// <param name="clazz">类型</param>
 /// <param name="writer">二进制流写入器</param>
 private static bool AddObjectToStream(object graph, Type clazz, BinaryWriter bw, AdvancedObjectMarshalAsAttribute attr)
 {
     if (TypeUnit.GetArrayElement(clazz) == null)
     {
         if (attr == null || !attr.NotNullFlags)
         {
             bw.Write(graph == null);
         }
         if (graph != null)
         {
             foreach (PropertyInfo pi in clazz.GetProperties())
             {
                 attr = AdvancedObjectMarshalAsAttribute.GetAttribute(pi);
                 if (attr != null && attr.NotSerialized) // 如果不可序列化则迭代到下一个
                 {
                     continue;
                 }
                 object value = pi.GetValue(graph, null);
                 AdvancedObjectFormatter.AddValueToStream(pi.PropertyType, value, attr, bw);
             }
         }
         return(true);
     }
     return(false);
 }
Beispiel #2
0
        /// <summary>
        /// 添加列表到流中
        /// </summary>
        private static bool AddListToStream(Type clazz, IList value, AdvancedObjectMarshalAsAttribute attr, BinaryWriter bw)
        {
            Type element = TypeUnit.GetArrayElement(clazz);

            if (element != null)
            {
                if (value == null)
                {
                    if (attr == null || attr.ArrayDoubleLength)
                    {
                        bw.Write(AdvancedObjectFormatter.As(BitConverter.GetBytes((short)-1), attr));
                    }
                    else
                    {
                        bw.Write((sbyte)-1);
                    }
                }
                else
                {
                    int size = value.Count;
                    if (attr != null && attr.SizeConst > 0)
                    {
                        size = attr.SizeConst;
                    }
                    else
                    if (attr == null || attr.ArrayDoubleLength)
                    {
                        bw.Write(AdvancedObjectFormatter.As(BitConverter.GetBytes((short)size), attr));
                    }
                    else
                    {
                        bw.Write((sbyte)size);
                    }
                    if (TypeUnit.IsBuffer(clazz))
                    {
                        bw.Write((byte[])value);
                    }
                    else
                    {
                        bool basic = ValueTypeUnit.IsBasicType(element);
                        for (int i = 0; i < size; i++)
                        {
                            object graph = value[i];
                            if (basic)
                            {
                                AdvancedObjectFormatter.AddValueToStream(element, graph, attr, bw);
                            }
                            else
                            {
                                AdvancedObjectFormatter.AddObjectToStream(graph, element, bw, attr);
                            }
                        }
                    }
                }
                return(true);
            }
            return(false);
        }
Beispiel #3
0
        public void setUnit(TypeUnitKnownValues new_value)
        {
            TypeUnit new_full_value = new TypeUnit();

            Debug.Assert(new_value != TypeUnitKnownValues.Unit__none);
            new_full_value.in_known_list = true;
            new_full_value.list_value    = new_value;
            setUnit(new_full_value);
        }
Beispiel #4
0
 public Period(String interval)
 {
     try
     {
         String[] intervalParts = interval.Split();
         this.Interval = int.Parse(intervalParts[0]);
         this.Unit = TypeUnit.Create(intervalParts[1]);
     }
     catch (IndexOutOfRangeException e)
     {
         throw new ArgumentException("Invalid period:" + interval);
     }
 }
Beispiel #5
0
        public string  getUnitAsString()
        {
            TypeUnit result = getUnit();

            if (result.in_known_list)
            {
                return(stringFromUnit(result.list_value));
            }
            else
            {
                return(result.string_value);
            }
        }
 public Period(String interval)
 {
     try
     {
         String[] intervalParts = interval.Split();
         this.Interval = int.Parse(intervalParts[0]);
         this.Unit     = TypeUnit.Create(intervalParts[1]);
     }
     catch
     {
         throw new ArgumentException($"Invalid period: {interval}");
     }
 }
Beispiel #7
0
 public Period(String interval)
 {
     try
     {
         String[] intervalParts = interval.Split();
         this.Interval = int.Parse(intervalParts[0]);
         this.Unit     = TypeUnit.Create(intervalParts[1]);
     }
     catch (IndexOutOfRangeException e)
     {
         throw new ArgumentException("Invalid period:" + interval);
     }
 }
Beispiel #8
0
        public void setUnit(string chars)
        {
            TypeUnitKnownValues known     = stringToUnit(chars);
            TypeUnit            new_value = new TypeUnit();

            if (known == TypeUnitKnownValues.Unit__none)
            {
                new_value.in_known_list = false;
                new_value.string_value  = chars;
            }
            else
            {
                new_value.in_known_list = true;
                new_value.list_value    = known;
            }
            setUnit(new_value);
        }
Beispiel #9
0
                protected override void handle_result(string result)
                {
                    TypeUnitKnownValues known     = stringToUnit(result);
                    TypeUnit            new_value = new TypeUnit();

                    if (known == TypeUnitKnownValues.Unit__none)
                    {
                        new_value.in_known_list = false;
                        new_value.string_value  = result;
                    }
                    else
                    {
                        new_value.in_known_list = true;
                        new_value.list_value    = known;
                    }
                    handle_result(new_value);
                }
Beispiel #10
0
 public PeriodWithChargeDay(String interval)
 {
     try
     {
         String[] weekdayParts = interval.Split(',');
         if (weekdayParts.Count() > 1)
         {
             this.Weekday = Weekday.Create(weekdayParts[1]);
         }
         String[] intervalParts = weekdayParts[0].Split();
         this.Interval = int.Parse(intervalParts[0]);
         this.Unit     = TypeUnit.Create(intervalParts[1]);
     }
     catch
     {
         throw new ArgumentException($"Invalid period: {interval}");
     }
 }
Beispiel #11
0
 private void Knob_ValueChanged(object sender, EventArgs e)
 {
     labelValue.Text = "";
     if (knob.Value > 17 && knob.Value <= 24)
     {
         labelValue.Text += Convert.ToString(this.Value * GlobalData.pF);
         if (knob.Value == 20)
         {
             typeUnit = TypeUnit.Picofarad;
             GlobalData.workWithElements.AddChangesValueMultimeter(this, labelValue.Text);
         }
     }
     else if (knob.Value > 11 && knob.Value <= 17)
     {
         labelValue.Text += Convert.ToString(this.Value * GlobalData.nF);
         if (knob.Value == 14)
         {
             typeUnit = TypeUnit.Nanofarad;
             GlobalData.workWithElements.AddChangesValueMultimeter(this, labelValue.Text);
         }
     }
     else if (knob.Value > 4 && knob.Value <= 11)
     {
         labelValue.Text += Convert.ToString(this.Value * GlobalData.mkF);
         if (knob.Value == 7)
         {
             typeUnit = TypeUnit.Microfarad;
             GlobalData.workWithElements.AddChangesValueMultimeter(this, labelValue.Text);
         }
     }
     else if ((knob.Value >= 0 && knob.Value <= 4) || (knob.Value <= 100 && knob.Value >= 97))
     {
         labelValue.Text += Convert.ToString(this.Value * GlobalData.mF);
         if (knob.Value == 1)
         {
             typeUnit = TypeUnit.Millifarad;
             GlobalData.workWithElements.AddChangesValueMultimeter(this, labelValue.Text);
         }
     }
     else
     {
         labelValue.Text = "-//-";
     }
 }
Beispiel #12
0
 public static IType TypeMap(Func <int, TypeVar, IType> onVar, int c, IType t)
 {
     IType Walk(int c, IType t)
     {
         return(t switch
         {
             TypeVar v => onVar(c, v),
             TypeId i => i,
             TypeString ts => ts,
             TypeUnit u => u,
             TypeRecord r => new TypeRecord(r.Variants.Select(p => (p.Item1, Walk(c, p.Item2)))),
             TypeFloat f => f,
             TypeBool b => b,
             TypeNat n => n,
             TypeArrow a => new TypeArrow(Walk(c, a.From), Walk(c, a.To)),
             TypeVariant tv => new TypeVariant(tv.Variants.Select(p => (p.Item1, Walk(c, p.Item2)))),
             _ => throw new InvalidOperationException()
         });
     }
Beispiel #13
0
        public PoolObject GetUnit(TypeUnit type, Vector3 position)
        {
            PoolObject unit = null;

            switch (type)
            {
            case TypeUnit.MoveForward:
                unit = _poolManager.InstantiateFromPool(UnitForvard, position);
                break;

            case TypeUnit.MoveForwardAndDiagonal:
                unit = _poolManager.InstantiateFromPool(UnitDiagonal, position);
                break;

            case TypeUnit.Friendly:
                unit = _poolManager.InstantiateFromPool(UnitFriend, position);
                break;
            }

            return(unit);
        }
    public static string  stringFromUnit(TypeUnit the_enum)
    {
        switch (the_enum)
        {
        case TypeUnit.Unit_Default:
            return("Default");

        case TypeUnit.Unit_Fahrenheit:
            return("Fahrenheit");

        case TypeUnit.Unit_Celsius:
            return("Celsius");

        case TypeUnit.Unit_Kelvin:
            return("Kelvin");

        default:
            Debug.Assert(false);
            return(null);
        }
    }
Beispiel #15
0
    private GameObject creatUnit2d(TypeUnit u, int unitI)
    {
        GameObject instance = Instantiate(Resources.Load("Prefabs/Unit")) as GameObject;

        //
        switch (u)
        {
        case TypeUnit.Assassin:
            instance.GetComponent <UnitController>().skin = "assassin";
            break;

        case TypeUnit.Mage:
            instance.GetComponent <UnitController>().skin = "mage";
            break;

        case TypeUnit.Protector:
            instance.GetComponent <UnitController>().skin = "protector";
            break;

        case TypeUnit.Warrior:
            instance.GetComponent <UnitController>().skin = "warrior";
            break;

        default:
            print("BUG creating unit");
            break;
        }
        instance.GetComponent <UnitController>().enabled = true;



        instance.transform.position = GameManager.instance.tileboard[(int)startPositions[unitI].x, (int)startPositions[unitI].y].transform.position + new Vector3(0, 0, -2);
        instance.gameObject.GetComponent <Renderer>().material.color = agentColor;
        instance.name = id + "_" + unitI + "_" + u.ToString();
        unitsObjects.Add(instance);


        return(instance);
    }
Beispiel #16
0
        private void  fromJSONUnit(JSONValue json_value, bool ignore_extras)
        {
            Debug.Assert(json_value != null);
            JSONStringValue json_string = json_value.string_value();

            if (json_string == null)
            {
                throw new Exception("The value for field Unit of TypeTimePointJSON is not a string.");
            }
            TypeUnit the_open_enum = new TypeUnit();

            if ((String.Compare(json_string.getData(), 0, "Months", 0, 6, false) == 0) && (json_string.getData().Length == 6))
            {
                the_open_enum.in_known_list = true;
                the_open_enum.list_value    = TypeUnitKnownValues.Unit_Months;
                goto open_enum_is_done;
            }
            the_open_enum.in_known_list = false;
            the_open_enum.string_value  = json_string.getData();
            open_enum_is_done :;
            setUnit(the_open_enum);
        }
Beispiel #17
0
 /// <summary>
 /// 添加字符串到流中
 /// </summary>
 private static bool AddStringToStream(Type clazz, string value, AdvancedObjectMarshalAsAttribute attr, BinaryWriter bw)
 {
     if (TypeUnit.IsString(clazz))
     {
         if (value == null)
         {
             if (attr == null || attr.ArrayDoubleLength)
             {
                 bw.Write(AdvancedObjectFormatter.As(BitConverter.GetBytes((short)-1), attr));
             }
             else
             {
                 bw.Write((sbyte)-1);
             }
         }
         else
         {
             byte[] buffer = AdvancedObjectFormatter.GetTextEncoding(attr).GetBytes(value);
             int    size   = buffer.Length;
             if (attr != null && attr.SizeConst > 0)
             {
                 size = attr.SizeConst;
             }
             else
             if (attr == null || attr.ArrayDoubleLength)
             {
                 bw.Write(AdvancedObjectFormatter.As(BitConverter.GetBytes((short)size), attr));
             }
             else
             {
                 bw.Write((sbyte)size);
             }
             bw.Write(buffer, 0, size);
         }
         return(true);
     }
     return(false);
 }
    GameObject InnerCreateUnit(TypeUnit type)
    {
        GameObject go    = null;
        var        units = m_Units;

        for (int i = 0; i < units.Length; i++)
        {
            if (units[i].Type == type)
            {
                go = units[i].Prefab.Instantiate();
                break;
            }
        }
        if (go == null && units.Length > 0)
        {
            go = units[0].Prefab.Instantiate();
        }
        if (go != null)
        {
            go.transform.SetParent(m_RootUnits);
        }
        return(go);
    }
    public static string  stringFromUnit(TypeUnit the_enum)
    {
        switch (the_enum)
        {
        case TypeUnit.Unit_None:
            return("None");

        case TypeUnit.Unit_Week:
            return("Week");

        case TypeUnit.Unit_Hour:
            return("Hour");

        case TypeUnit.Unit_Minute:
            return("Minute");

        case TypeUnit.Unit_Second:
            return("Second");

        default:
            Debug.Assert(false);
            return(null);
        }
    }
Beispiel #20
0
 internal PeriodWithChargeDay(int interval, TypeUnit unit, Weekday weekday)
 {
     this.Interval = interval;
     this.Unit     = unit;
     this.Weekday  = weekday;
 }
Beispiel #21
0
 protected override void handle_result(TypeUnit result)
 {
     top.value.Add(result);
 }
Beispiel #22
0
 protected override void handle_result(TypeUnit result)
 {
     //@@@        Debug.Assert(!have_value);
     have_value = true;
     value      = result;
 }
Beispiel #23
0
 protected abstract void handle_result(TypeUnit result);
 /// <summary>
 /// 是否基本类型
 /// </summary>
 /// <param name="type">类型</param>
 /// <returns></returns>
 public static bool IsBasicType(Type type)
 {
     return(type == typeof(IPAddress) || ValueTypeUnit.IsDateTime(type) ||
            ValueTypeUnit.IsNumberType(type) || TypeUnit.IsString(type) || ValueTypeUnit.IsFloatType(type));
 }
Beispiel #25
0
 public static Interval.PeriodWithChargeDay periodWithChargeDay(int interval, TypeUnit unit)
 {
     return(new Interval.PeriodWithChargeDay(interval, unit, null));
 }
Beispiel #26
0
 internal Period(int interval, TypeUnit unit)
 {
     this.Interval = interval;
     this.Unit     = unit;
 }
Beispiel #27
0
 public void setUnit(TypeUnit new_value)
 {
     flagHasUnit = true;
     storeUnit   = new_value;
 }
 public UnitContainer AddUnit(Player player, TypePlayer typePlayer, TypeUnit typeUnit)
 {
     return(AddUnit(player, typePlayer, ManagerUnits.CreateUnit(typeUnit)));
 }
Beispiel #29
0
 internal PeriodWithChargeDay(int interval, TypeUnit unit, Weekday weekday)
 {
     this.Interval = interval;
     this.Unit = unit;
     this.Weekday = weekday;
 }
Beispiel #30
0
        public Multimeter()
        {
            button = new PictureBox();
            status = new PictureBox();
            knob   = new Zeroit.Framework.Metro.ZeroitMetroKnob();

            picture.Image = Image.FromFile(@"C:\Users\Evgenij\CourseProject\ElectronVPL\pictures\multimetr\multimetr.png");

            button.Width      = 41;
            button.Height     = 18;
            button.Left       = 15;
            button.Top        = 58;
            button.Cursor     = Cursors.Hand;
            button.SizeMode   = PictureBoxSizeMode.AutoSize;
            button.BackColor  = Color.Transparent;
            button.Image      = Image.FromFile(@"C:\Users\Evgenij\CourseProject\ElectronVPL\pictures\multimetr\power1.png");
            button.Click     += Button_Click;
            button.MouseDown += Button_MouseDown;
            button.MouseUp   += Button_MouseUp;

            status.Width     = 8;
            status.Height    = 8;
            status.Left      = 80;
            status.Top       = 60;
            status.SizeMode  = PictureBoxSizeMode.AutoSize;
            status.BackColor = Color.Transparent;
            status.Image     = Image.FromFile(@"C:\Users\Evgenij\CourseProject\ElectronVPL\pictures\multimetr\status_off.png");

            //метод загрузки шрифта
            GlobalData.LoadFont(13);
            labelValue.Text      = "";
            labelValue.Font      = GlobalData.DigitalFont;
            labelValue.Left      = 22;
            labelValue.Top       = 29;
            labelValue.BackColor = Color.Black;
            labelValue.Width     = 75;
            labelValue.ForeColor = Color.Silver;
            labelValue.TextAlign = HorizontalAlignment.Right;
            labelValue.Cursor    = Cursors.Hand;

            knob.Top               = 105;
            knob.Left              = 32;
            knob.Width             = 59;
            knob.Height            = 59;
            knob.BlockedAngle      = 0;
            knob.BorderColor       = Color.DimGray;
            knob.LineColor         = Color.DimGray;
            knob.AccentColor       = Color.DimGray;
            knob.FillColor         = Color.Black;
            knob.Cursor            = Cursors.Hand;
            knob.LineWidth         = 7;
            knob.LineLength        = 100;
            knob.Value             = 20;
            knob.ValueChanged     += Knob_ValueChanged;
            knob.LinePen.EndCap    = System.Drawing.Drawing2D.LineCap.Round;
            knob.LinePen.StartCap  = System.Drawing.Drawing2D.LineCap.NoAnchor;
            knob.LinePen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
            knob.LinePen.DashCap   = System.Drawing.Drawing2D.DashCap.Flat;

            contactMinus.Width  = 33;
            contactMinus.Height = 12;
            contactMinus.Left   = 16;
            contactMinus.Top    = 192;

            contactPlus.Width  = 33;
            contactPlus.Height = 12;
            contactPlus.Left   = 49;
            contactPlus.Top    = 192;

            statusDevice       = false;
            labelValue.Visible = false;
            typeUnit           = TypeUnit.Picofarad;
            this.Value         = 0;
        }
Beispiel #31
0
 public static Interval.PeriodWithChargeDay periodWithChargeDay(int interval, TypeUnit unit)
 {
     return new Interval.PeriodWithChargeDay(interval, unit, null);
 }
Beispiel #32
0
 public static Interval.PeriodWithChargeDay periodWithChargeDay(int interval, TypeUnit unit, Weekday weekday)
 {
     return new Interval.PeriodWithChargeDay(interval, unit, weekday);
 }
Beispiel #33
0
 public static Interval.Period period(int interval, TypeUnit unit)
 {
     return new Interval.Period(interval, unit);
 }
 public static GameObject CreateUnit(TypeUnit type)
 {
     return(Can ? m_I.InnerCreateUnit(type) : null);
 }
Beispiel #35
0
 /// <summary>
 /// Creates the unit.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <returns></returns>
 /// <exception cref="System.ArgumentException">Invalid value for Interval.Unit</exception>
 private static EnumBaseType CreateUnit(String value)
 {
     return(TypeUnit.GetItemByValue(value, typeof(TypeUnit)));
 }
Beispiel #36
0
 internal Period(int interval, TypeUnit unit)
 {
     this.Interval = interval;
     this.Unit = unit;
 }