Ejemplo n.º 1
0
 public static bool Deserialize(string s, IDictionary <string, double> dict, Deep deep)
 {
     KeyValuePair <string, string>[] keyValues;
     if (preDeserializeDict(s, out keyValues, deep))
     {
         foreach (var keyValue in keyValues)
         {
             double value;
             if (double.TryParse(keyValue.Value, out value))
             {
                 dict.Add(keyValue.Key, value);
             }
             else
             {
                 throw new ArgumentException(string.Format("String '{0}' constaint illegal values for dict<{1},{2}>.", keyValue, dict.GetType().GetGenericArguments()[0].Name, dict.GetType().GetGenericArguments()[1].Name));
             }
         }
         return(true);
     }
     else
     {
         dict = null;
         return(false);
     }
 }
Ejemplo n.º 2
0
 private static string serialize(object o, Deep deep)
 {
     if (o is String s)
     {
         return(s);
     }
     else if (o is bool b)
     {
         return(b ? "1" : "0");
     }
     else if (o is InnerSerializerV1_0 innerSerializable)
     {
         return(innerSerializable.Serialize(deep.NEXT));
     }
     else if (o is IDictionary dictionary)
     {
         return(Serialize(dictionary, deep.NEXT));
     }
     else if (o is IEnumerable enumerable)
     {
         return(Serialize(enumerable, deep.NEXT));
     }
     else if (o is double @double)
     {
         return(((ProtocolDouble)@double).ToString());
     }
     else if (o == null)
     {
         return(string.Empty);
     }
     else
     {
         return(o.ToString());
     }
 }
Ejemplo n.º 3
0
 public static bool Deserialize(string orig, Deep deep, out MineGunV1_0 deserialized)
 {
     string[] rest;
     if (ProtocolV1_0Utils.GetParams(orig, NAME, deep, out rest))
     {
         if (rest.Length == 4)
         {
             int[]    paramsInt;
             string[] zonesString;
             if (Parser.TryParse(new int[] { 0, 1, 2 }, rest, out paramsInt) &&
                 ProtocolV1_0Utils.Deserialize(rest[3], out zonesString, deep.NEXT))
             {
                 ZoneV1_0[] zones = new ZoneV1_0[zonesString.Length];
                 for (int i = 0; i < zones.Length; i++)
                 {
                     if (!ZoneV1_0.Deserialize(zonesString[i], deep.NEXT.NEXT, out zones[i]))
                     {
                         deserialized = null;
                         return(false);
                     }
                 }
                 deserialized = new MineGunV1_0(paramsInt[0], paramsInt[1], paramsInt[2], zones);
                 return(true);
             }
         }
     }
     deserialized = null;
     return(false);
 }
Ejemplo n.º 4
0
        public static string ConvertToDeeper(string serializedString, Deep toDeep)
        {
            StringBuilder sb = new StringBuilder();

            char[] serializedCharacter = serializedString.ToCharArray();

            for (int i = 0; i < serializedCharacter.Length; i++)
            {
                Deep replaceDeep  = toDeep;
                Deep replacedDeep = DEFAULT;
                while (replaceDeep != null)
                {
                    if (serializedCharacter[i] == replacedDeep.SEPARATOR)
                    {
                        sb.Append(replaceDeep.SEPARATOR);
                        goto nextCharacter;
                    }

                    replaceDeep  = replaceDeep.NEXT;
                    replacedDeep = replacedDeep.NEXT;
                }
                sb.Append(serializedCharacter[i]);
nextCharacter:
                ;
            }
            return(sb.ToString());
        }
Ejemplo n.º 5
0
        public static string ConvertToShallowly(string serializedString, int howManyTimes)
        {
            if (howManyTimes <= 0)
            {
                throw new ArgumentException(nameof(howManyTimes) + "have to be positive.");
            }
            StringBuilder sb = new StringBuilder();

            char[] serializedCharacter = serializedString.ToCharArray();

            for (int i = 0; i < serializedCharacter.Length; i++)
            {
                Deep replacedDeep = LAST;
                while (replacedDeep != DEFAULT)
                {
                    if (serializedCharacter[i] == replacedDeep.SEPARATOR)
                    {
                        Deep addedDeep = replacedDeep;
                        for (int j = 0; j < howManyTimes && addedDeep != DEFAULT; j++)
                        {
                            addedDeep = addedDeep.PREV;
                        }
                        sb.Append(addedDeep.SEPARATOR);
                        goto nextCharacter;
                    }
                    replacedDeep = replacedDeep.PREV;
                }
                sb.Append(serializedCharacter[i]);
nextCharacter:
                ;
            }
            return(sb.ToString());
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a <see cref="ParameterDefinition"/> list that represents this filter.
        /// </summary>
        public ParameterDefinition[] ToParameterDefinition()
        {
            var result = new List <ParameterDefinition>();

            if (Deep)
            {
                result.Add(ParameterDefinition.Create(DeepParamName, Deep.ToString()));
            }

            if (LimitResult >= 0)
            {
                result.Add(ParameterDefinition.Create(LimitResultParamName, LimitResult.ToString()));
            }

            if (MeasurementUuids != null && MeasurementUuids.Length > 0)
            {
                result.Add(ParameterDefinition.Create(MeasurementUuidsParamName, RestClientHelper.ConvertGuidListToString(MeasurementUuids)));
            }

            if (RequestedMeasurementAttributes != null && RequestedMeasurementAttributes.AllAttributes != AllAttributeSelection.True && RequestedMeasurementAttributes.Attributes != null)
            {
                result.Add(ParameterDefinition.Create(RequestedMeasurementAttributesParamName, RestClientHelper.ConvertUInt16ListToString(RequestedMeasurementAttributes.Attributes)));
            }

            if (OrderBy != null && OrderBy.Length > 0)
            {
                result.Add(ParameterDefinition.Create(OrderByParamName, OrderByToString(OrderBy)));
            }

            if (SearchCondition != null)
            {
                result.Add(ParameterDefinition.Create(SearchConditionParamName, SearchConditionParser.GenericConditionToString(SearchCondition)));
            }

            if (Statistics != MeasurementStatistics.None)
            {
                result.Add(ParameterDefinition.Create(StatisticsParamName, Statistics.ToString()));
            }

            if (AggregationMeasurements != AggregationMeasurementSelection.Default)
            {
                result.Add(ParameterDefinition.Create(AggregationParamName, AggregationMeasurements.ToString()));
            }

            if (FromModificationDate.HasValue)
            {
                result.Add(ParameterDefinition.Create(FromModificationDateParamName, XmlConvert.ToString(FromModificationDate.Value, XmlDateTimeSerializationMode.RoundtripKind)));
            }

            if (ToModificationDate.HasValue)
            {
                result.Add(ParameterDefinition.Create(ToModificationDateParamName, XmlConvert.ToString(ToModificationDate.Value, XmlDateTimeSerializationMode.RoundtripKind)));
            }

            return(result.ToArray());
        }
Ejemplo n.º 7
0
        // =========== DICTIONARY ========
        public static string Serialize(IDictionary dict, Deep deep)
        {
            List <string> serializeList = new List <string>();

            foreach (var key in dict.Keys)
            {
                serializeList.Add(serialize(key, deep) + DICTIONARY_KEY_VALUE_SEPARATOR + serialize(dict[key], deep));
            }
            return(SerializeArray(serializeList, deep));
        }
Ejemplo n.º 8
0
 private Deep(char separator, Deep next)
 {
     SEPARATOR        = separator;
     SEPARATOR_STRING = "" + separator;
     NEXT             = next;
     if (next != null)
     {
         next.PREV = this;
     }
 }
Ejemplo n.º 9
0
        public void PlayerFire(Player player)
        {
            var shell = new Shell {
                Id = _shellCounter++, LaunchTime = _time
            };

            shell.Origin = Deep.Clone(player.Tank.ToDto());

            // make the shell appear to come from the correct side of the tank
            shell.Origin.Point.X += Convert.ToInt32(player.Tank.Turret.Angle * Tank.Width / 180);

            player.Shells.Add(shell);
            player.Tank.IsFiring = true;
        }
Ejemplo n.º 10
0
 public static bool Deserialize(string orig, Deep deep, out ZoneV1_0 deserialized)
 {
     string[] rest;
     int[]    param;
     if (ProtocolV1_0Utils.GetParams(orig, NAME, deep, out rest))
     {
         if (rest.Length == 2 && Parser.TryParse(rest, out param))
         {
             deserialized = new ZoneV1_0(param[0], param[1]);
             return(true);
         }
     }
     deserialized = null;
     return(false);
 }
    static void Main(string[] args)
    {
        var s1 = new Shallow(new Thing(23));
        var s2 = (Shallow)s1.Clone();

        Console.WriteLine(s2.T.I); // 23
        s1.T.I = 9;
        Console.WriteLine(s2.T.I); // 9

        var d1 = new Deep(new Thing(23));
        var d2 = (Deep)d1.Clone();

        Console.WriteLine(d2.T.I); // 23
        d1.T.I = 9;
        Console.WriteLine(d2.T.I); // 23
    }
Ejemplo n.º 12
0
        private void FormStrain_VisibleChanged(object sender, EventArgs e)
        {
            if (this.Visible)
            {
                skipCrystalChangedEvent = true;
                CrystalControl.GenerateFromInterface();
                originalCrystal = Deep.Copy(CrystalControl.Crystal);

                SetStrainedCrystal();
                skipCrystalChangedEvent = false;
            }
            else
            {
                resetOriginalCrystal();
            }
        }
Ejemplo n.º 13
0
        public static string Serialize(IEnumerable enumerable, Deep deep)
        {
            StringBuilder s = new StringBuilder();

            s.Append("[");
            foreach (var item in enumerable)
            {
                s.Append(serialize(item, deep));
                s.Append(deep.SEPARATOR);
            }
            if (s.Length > 1)
            {
                s.Remove(s.Length - 1, 1);                 // remove last separator
            }
            return(s.Append("]").ToString());
        }
Ejemplo n.º 14
0
        public static string SerializeParams(string commandName, Deep deep, params object[] param)
        {
            StringBuilder s = new StringBuilder();

            s.Append(commandName);
            s.Append("(");
            for (int i = 0; i < param.Length; i++)
            {
                if (i > 0)
                {
                    s.Append(deep.SEPARATOR);
                }
                object o = param[i];
                s.Append(serialize(o, deep));
            }
            return(s.Append(")").ToString());
        }
Ejemplo n.º 15
0
 public static bool Deserialize(string s, IDictionary <string, string> dict, Deep deep)
 {
     KeyValuePair <string, string>[] keyValues;
     if (preDeserializeDict(s, out keyValues, deep))
     {
         foreach (var keyValue in keyValues)
         {
             dict.Add(keyValue);
         }
         return(true);
     }
     else
     {
         dict = null;
         return(false);
     }
 }
Ejemplo n.º 16
0
 public static bool Deserialize(String orig, Deep deep, out ArmorV1_0 deserialized)
 {
     string[] rest;
     if (ProtocolV1_0Utils.GetParams(orig, NAME, deep, out rest))
     {
         if (rest.Length == 3)
         {
             int[] paramsInt;
             if (Parser.TryParse(rest, out paramsInt))
             {
                 deserialized = new ArmorV1_0(paramsInt[0], paramsInt[1], paramsInt[2]);
                 return(true);
             }
         }
     }
     deserialized = null;
     return(false);
 }
Ejemplo n.º 17
0
        private void crystalControl_CrystalChanged(object sender, EventArgs e)
        {
            if (skipCrystalChangedEvent || !this.Visible)
            {
                return;
            }

            //ここが呼ばれるのは、crystalControl側が操作されて結晶が変更される場合のみ。
            //このformStrainがcrystalControlを変更する時は、その時だけこのイベントを無視する
            skipCrystalChangedEvent = true;
            CrystalControl.GenerateFromInterface();
            originalCrystal = Deep.Copy(CrystalControl.Crystal);

            SetStrainedCrystal();
            skipCrystalChangedEvent = false;

            numericBoxStrain_ValueChanged(new object(), new EventArgs());
        }
Ejemplo n.º 18
0
        public static bool Deserialize(string orig, Deep deep, out EndLapCommandV1_0 deserialized)
        {
            string[] rest;
            if (ProtocolV1_0Utils.GetParams(orig, COMMAND_NAME, deep, out rest))
            {
                if (rest.Length == 3)
                {
                    int      gold, score;
                    LapState lapState;

                    if (Enum.TryParse(rest[0], true, out lapState) && int.TryParse(rest[1], out gold) && int.TryParse(rest[2], out score))
                    {
                        deserialized = new EndLapCommandV1_0(lapState, gold, score);
                        return(true);
                    }
                }
            }
            deserialized = null;
            return(false);
        }
Ejemplo n.º 19
0
 public static bool Deserialize(String orig, Deep deep, out MotorV1_0 deserialized)
 {
     string[] rest;
     if (ProtocolV1_0Utils.GetParams(orig, NAME, deep, out rest))
     {
         if (rest.Length == 7)
         {
             ProtocolDouble[] paramsDouble;
             int[]            paramsInt;
             if (Parser.TryParse(new int[] { 0, 1, 2, 3, 4 }, rest, out paramsDouble) &&
                 Parser.TryParse(new int[] { 5, 6 }, rest, out paramsInt))
             {
                 deserialized = new MotorV1_0(paramsDouble[0], paramsDouble[1], paramsDouble[2], paramsDouble[3], paramsDouble[4], paramsInt[0], paramsInt[1]);
                 return(true);
             }
         }
     }
     deserialized = null;
     return(false);
 }
Ejemplo n.º 20
0
 public static bool Deserialize(string s, out int[] array, Deep deep)
 {
     string[] rest;
     if (StringUtils.GetRestOfStringSplit(s, "[", "]", out rest, deep.SEPARATOR))
     {
         array = new int[rest.Length];
         for (int i = 0; i < rest.Length; i++)
         {
             if (!int.TryParse(rest[i], out array[i]))
             {
                 return(false);
             }
         }
         return(true);
     }
     else
     {
         array = null;
         return(false);
     }
 }
        public void SetCrystal()
        {
            CrystalControl.GenerateFromInterface();
            OriginalCrystal = Deep.Copy(CrystalControl.Crystal);
            OriginalCrystal.SetAxis();

            CrystalControl.SymmetrySeriesNumber = 1;
            CrystalControl.Crystal.Atoms        = new Atoms[0];
            for (int i = 0; i < OriginalCrystal.Atoms.Length; i++)
            {
                for (int j = 0; j < OriginalCrystal.Atoms[i].Atom.Count; j++)
                {
                    var atom = Deep.Copy(OriginalCrystal.Atoms[i]);
                    atom.X = OriginalCrystal.Atoms[i].Atom[j].X;
                    atom.Y = OriginalCrystal.Atoms[i].Atom[j].Y;
                    atom.Z = OriginalCrystal.Atoms[i].Atom[j].Z;
                    CrystalControl.Crystal.AddAtoms(atom);
                }
            }
            CrystalControl.SetToInterface();
        }
Ejemplo n.º 22
0
        private void SetStrainedCrystal()
        {
            skipCrystalChangedEvent = true;

            CrystalControl.SymmetrySeriesNumber = 1;
            CrystalControl.Crystal.Atoms        = new Atoms[0];
            for (int i = 0; i < originalCrystal.Atoms.Length; i++)
            {
                for (int j = 0; j < originalCrystal.Atoms[i].Atom.Count; j++)
                {
                    var atom = Deep.Copy(originalCrystal.Atoms[i]);
                    atom.X = originalCrystal.Atoms[i].Atom[j].X;
                    atom.Y = originalCrystal.Atoms[i].Atom[j].Y;
                    atom.Z = originalCrystal.Atoms[i].Atom[j].Z;
                    CrystalControl.Crystal.AddAtoms(atom);
                }
            }
            CrystalControl.SetToInterface();
            numericBoxStrain_ValueChanged(new object(), new EventArgs());

            skipCrystalChangedEvent = false;
        }
Ejemplo n.º 23
0
        // =========== ARRAY ========
        public static string SerializeArray(IEnumerable enumerable, Deep deep)
        {
            StringBuilder s = new StringBuilder();

            s.Append("[");
            foreach (var item in enumerable)
            {
                InnerSerializerV1_0 innerSerializable = item as InnerSerializerV1_0;
                if (innerSerializable != null)
                {
                    s.Append(innerSerializable.Serialize(deep.NEXT));
                }
                else
                {
                    s.Append(item);
                }
                s.Append(deep.SEPARATOR);
            }
            if (s.Length > 1)
            {
                s.Remove(s.Length - 1, 1);                 // remove last separator
            }
            return(s.Append("]").ToString());
        }
Ejemplo n.º 24
0
		public DmConsole SetBackgroundColor(Deep.Magic.Color background)
		{
			this.BackgroundColor = background;
			return this.console;
		}
Ejemplo n.º 25
0
 public string Serialize(Deep deep)
 {
     return(ProtocolV1_0Utils.SerializeParams(NAME, deep, MAX_HP, COST, ID));
 }
Ejemplo n.º 26
0
 private static bool preDeserializeDict(string s, out KeyValuePair <string, string>[] dict, Deep deep)
 {
     string[] rest;
     if (Deserialize(s, out rest, deep))
     {
         dict = new KeyValuePair <string, string> [rest.Length];
         string[] keyValue;
         for (int i = 0; i < dict.Length; i++)
         {
             if (StringUtils.GetRestOfStringSplit(rest[i], string.Empty, string.Empty, out keyValue, DICTIONARY_KEY_VALUE_SEPARATOR))
             {
                 if (keyValue.Length == 2)
                 {
                     dict[i] = new KeyValuePair <string, string>(keyValue[0], keyValue[1]);
                 }
                 else
                 {
                     throw new ArgumentException(string.Format("S containt illegal dictionary pair '{0}'", rest[i]));
                 }
             }
         }
         return(true);
     }
     else
     {
         dict = null;
         return(false);
     }
 }
Ejemplo n.º 27
0
		public DmConsole SetColor(Deep.Magic.Color foreground, Deep.Magic.Color background)
		{
			this.ForegroundColor = foreground;
			this.BackgroundColor = background;
			return this.console;
		}
Ejemplo n.º 28
0
 public static bool GetParams(string orig, string commandName, Deep deep, out string[] rest)
 {
     return(StringUtils.GetRestOfStringSplit(orig, commandName + "(", ")", out rest, deep.SEPARATOR));
 }
Ejemplo n.º 29
0
 private void GenerateTree_Load(object sender, EventArgs e)
 {
     InputDeep.Text  = Deep.ToString();
     InputNodes.Text = NodesCount.ToString();
 }
Ejemplo n.º 30
0
		// Just wrappers, for the sake of chaining.
		public DmConsole SetForegroundColor(Deep.Magic.Color foreground)
		{
			this.ForegroundColor = foreground;
			return this.console;
		}
Ejemplo n.º 31
0
 public string Serialize(Deep deep)
 {
     return(ProtocolV1_0Utils.SerializeParams(COMMAND_NAME, deep, X, Y));
 }
Ejemplo n.º 32
0
 public static bool Deserialize(string s, out string[] array, Deep deep)
 {
     return(StringUtils.GetRestOfStringSplit(s, "[", "]", out array, deep.SEPARATOR));
 }
Ejemplo n.º 33
0
 public string Serialize(Deep deep)
 {
     return(ProtocolV1_0Utils.SerializeParams(NAME, deep, ID, COST, MAX_MINES, ZONES));
 }