Esempio n. 1
0
 public RatHatchBrush(Struct.Pattern pattern)
 {
     this.pattern=pattern;
     this.pen = null;
     this.color = pattern.ForeColor;
     this.opacity = ((float) this.color.A) / 255f;
 }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the PlanePosition class.
 /// </summary>
 public SurfacesPosition(Struct pos)
 {
     Throttle = pos.throttle;
     Rudder = pos.rudder;
     Elevator = pos.elevator;
     Aileron = pos.aileron;
 }
    public static List<Struct.DoubleIndex> Dfs(char [,] map, Struct.DoubleIndex current, Struct.DoubleIndex target, char wall, bool isNew = true)
    {
        if (isNew) {
            currentPath.Clear ();
            bestPath = null;
        }

        currentPath.Insert (0, current.Clone());

        if (current.Equals (target) && (bestPath == null || bestPath.Count > currentPath.Count))
            bestPath = new List<Struct.DoubleIndex> (currentPath);

        if (bestPath != null && bestPath.Count <= currentPath.Count)
            return bestPath;

        for (int i = 0; i < directionsX.Length; i++) {
            current.first  += directionsY[i];
            current.second += directionsX[i];

            if(!currentPath.Contains(current) && CanMove(map, current, wall))
                Dfs (map, current, target, wall, false);

            current.first  -= directionsY[i];
            current.second -= directionsX[i];
        }

        currentPath.RemoveAt (0);

        return bestPath;
    }
    Vector3 GetPosition(Struct.DoubleIndex index)
    {
        Vector3 worldPosition = new Vector3(field.position.x + index.first, 0, field.position.z + index.second);
        worldPosition += wallSize / 2;

        return worldPosition;
    }
 public static int Main()
 {
     object
     o
     =
     new
     Struct
     (1);
     Struct
     s
     =
     new
     Struct
     (2);
     if
     (s.a
     !=
     2)
     return
     1;
     if
     (((Struct)o).a
     !=
     1)
     return
     2;
     return
     0;
 }
        public void GetPrivateValueField()
        {
            Struct instance = new Struct(privateValueField: 1);

            GetMethod result = sut.GetFieldGetter(privateValueField);

            Assert.AreEqual(1, result(instance));
        }
        public void GetPrivateValueProperty()
        {
            Struct instance = new Struct(privateValueProperty: 1);

            GetMethod result = sut.GetPropertyGetter(privateValueProperty);

            Assert.AreEqual(1, result(instance));
        }
        public void GetPublicClassField()
        {
            object expected = new object();
            Struct instance = new Struct { PublicClassField = expected };

            GetMethod result = sut.GetFieldGetter(publicClassField);

            Assert.AreSame(expected, result(instance));
        }
        public void GetPrivateClassField()
        {
            object expected = new object();
            Struct instance = new Struct(privateClassField: expected);

            GetMethod result = sut.GetFieldGetter(privateClassField);

            Assert.AreSame(expected, result(instance));
        }
Esempio n. 10
0
            private WeakRefTracker _tracker;        // storage for weak proxy's

            private void Initialize(Struct s) {
                _formatString = s._formatString;
                _formats = s._formats;
                _isStandardized = s._isStandardized;
                _isLittleEndian = s._isLittleEndian;
                _encodingCount = s._encodingCount;
                _encodingSize = s._encodingSize;
                _tracker = s._tracker;
            }
    public static void Main()
    {
        Struct s  = pointer_reference.get();
        if (s.value != 10) throw new Exception("get test failed");

        Struct ss = new Struct(20);
        pointer_reference.set(ss);
        if (Struct.instance.value != 20) throw new Exception("set test failed");
    }
        public void GetPublicClassProperty()
        {
            object expected = new object();
            Struct instance = new Struct { PublicClassProperty = expected };

            GetMethod result = sut.GetPropertyGetter(publicClassProperty);

            Assert.AreSame(expected, result(instance));
        }
Esempio n. 13
0
    public static void Main(string[] args)
    {
        object foo = new Foo();
        NullRefTest containsnullref = new NullRefTest();

        Struct s = new Struct(1);
        Outer();
        GC.KeepAlive(foo);
        GC.KeepAlive(containsnullref);
    }
Esempio n. 14
0
 public Struct Get(Struct klass)
 {
     foreach (Struct st in _mystructs)
     {
         if (Equals(st.GetType(), klass.GetType()))
         {
             return st;
         }
     }
     return null;
 }
Esempio n. 15
0
        /// <summary>
        /// Initializes a new instance of the PlaneControl class.
        /// </summary>
        public PlaneControl(Struct pkt)
        {
            double ScaleFactor = 1.0;

            Roll = (pkt.roll / ScaleFactor) * 100.0;
            Pitch = (pkt.pitch / ScaleFactor) * 100.0;
            Rudder = (pkt.rudder / ScaleFactor) * 100.0;

            // Throttle must be reversed
            Throttle = (pkt.throttle / ScaleFactor) * 100.0;
        }
Esempio n. 16
0
    public static void Main (string[] args) {
        var a = new Struct[10];

        for (var i = 0; i < a.Length; i++)
            a[i] = new Struct {
                I = i
            };

        foreach (var s in a)
            Console.WriteLine(s);
    }
Esempio n. 17
0
	public static void Main() {
		
		Struct s = new Struct();
		
		s.x = 1;
		s.y = 2;
		
		System.Console.WriteLine("{0} {1} {2}", s.x, s.y, s.z);
		
		TestS(ref s);
	}	
  public static void Main() {
    Struct s  = pointer_reference.get();
    if (s.value != 10) throw new Exception("get test failed");

    Struct ss = new Struct(20);
    pointer_reference.set(ss);
    if (Struct.instance.value != 20) throw new Exception("set test failed");

    if (pointer_reference.overloading(1) != 111) throw new Exception("overload test 1 failed");
    if (pointer_reference.overloading(ss) != 222) throw new Exception("overload test 2 failed");
  }
Esempio n. 19
0
 private static void Inner(object i)
 {
     bool b = true;
     char c = 'c';
     object d = 43.0;
     Struct st = new Struct(1);
     if (b)
     {
         string s = "hello world";
         throw new Exception();
     }
 }
Esempio n. 20
0
	public static int Main ()
	{
		Struct s = new Struct ("1");
		var t = s.AsyncMethod ();
		if (!Task.WaitAll (new[] { t }, 2000))
			return 1;
		
		if (!t.Result)
			return 2;
		
		return 0;
	}
Esempio n. 21
0
        private StackArray<Struct, S005<Struct>> InitArray(StackArray<Struct, S005<Struct>> array)
        {
            for (var i = 0; i < 5; i++)
            {
                var s = new Struct();
                s.Number = i;

                var gcMemory = GC.GetTotalMemory(false);
                array[i] = s;
                Assert.AreEqual(gcMemory, GC.GetTotalMemory(false), "Set index is allocating on heap.");
            }

            return array;
        }
Esempio n. 22
0
        /// <summary>
        /// Initializes a new instance of the PlanePosition class.
        /// </summary>
        public PlanePosition(Struct pos)
        {
            this.Latitude = pos.latitude;
            this.Longitude = pos.longitude;
            this.Altitude = pos.altitude;

            this.Roll = pos.phi;
            this.Pitch = pos.theta;
            this.Yaw = pos.heading;
            this.MagneticHeading = pos.magheading;

            this.Airspeed = pos.vcas;
            this.VerticalSpeed = pos.climb_rate;
        }
Esempio n. 23
0
 static Struct()
 {
     Default = new Struct()
     {
         ShowShadowCascadeSplits = false,
         UpdateCascadesEveryFrame = false,
         EnableShadowBlur = true,
         ShadowCascadeMaxDistance = 300.0f,
         ShadowCascadeMaxDistanceMultiplierMedium = 2f,
         ShadowCascadeMaxDistanceMultiplierHigh = 3.5f,
         ShadowCascadeSpreadFactor = 0.5f,
         ShadowCascadeZOffset = 400,
         DisplayFrozenShadowCascade = false,
     };
 }
Esempio n. 24
0
        public static void Main()
        {
            {
                TestLogger.Log("Testing cpobj...");
                var s = new Struct();
                TestLogger.Log(s.ToString());
                s.a = 3;
                s.b = true;
                s.c = 'x';
                s.d = 4;
                s.e = 2.5f;
                s.f = 9.4;
                s.g.x = 10;
                s.g.y = 12;
                s.h = "test";
                TestLogger.Log(s.ToString());
                var t = new Struct();
                TestLogger.Log(t.ToString());
                CopyStruct(ref s, ref t);
                TestLogger.Log(t.ToString());
            }

            {
                TestLogger.Log("Testing ldflda...");
                var s = new Struct();
                s.a = 3;
                s.g.x = 10;
                LogInt(ref s.a);
                LogInt(ref s.g.x);
            }

            {
                TestLogger.Log("Testing indexer...");
                Arr arr = new Arr();
                for (var i = 0; i < arr.Count; i++)
                    arr[i] = i * 37 % 11;
                for (var i = 0; i < arr.Count; i++)
                    TestLogger.Log(arr[i]);
            }

            {
                TestLogger.Log("Testing parameters...");
                var p = new Params(1, 2, 3, 4, 5);
                TestLogger.Log(p.ToString());
            }

        }
Esempio n. 25
0
    public static void Main (string[] args) {
        // [y, x], not [x, y]!
        var a = new Struct[4, 6];
        var h = a.GetLength(0);
        var w = a.GetLength(1);
        var y = 0;

        for (; y < h / 2; y++)
            for (var x = 0; x < w; x++)
                a[y, x] = new Struct {
                    X = x,
                    Y = y
                };

        for (; y < h; y++)
            for (var x = 0; x < w; x++)
                a[y, x] = new Struct(x, y);

        foreach (var s in a)
            Console.WriteLine(s);
    }
Esempio n. 26
0
		public async Task<MediaObjectInfo> NewMediaObjectAsync(string name, string type, byte[] bits)
		{
			Service service = new Service(this.BlogConnectionInfo.MetaWeblogURL);
			Struct @struct = new Struct();
			@struct["name"] = new StringValue(name);
			@struct["type"] = new StringValue(type);
			@struct["bits"] = new Base64Data(bits);
			MethodCall methodCall = new MethodCall("metaWeblog.newMediaObject");
			methodCall.Parameters.Add(this.BlogConnectionInfo.BlogID);
			methodCall.Parameters.Add(this.BlogConnectionInfo.Username);
			methodCall.Parameters.Add(this.BlogConnectionInfo.Password);
			methodCall.Parameters.Add(@struct);
			service.Cookies = this.BlogConnectionInfo.Cookies;
			MethodResponse methodResponse = await service.ExecuteAsync(methodCall);
			Value value = methodResponse.Parameters[0];
			Struct struct2 = (Struct)value;
			return new MediaObjectInfo
			{
				URL = struct2.Get<StringValue>("url", StringValue.NullString).String
			};
		}
        static void Main(string[] args)
        {
            TestEnv.TestEnv te= new TestEnv.TestEnv();

               te.CheckComplainAndAdjustExpected( 0);

               Struct s = new Struct();

               dlgt_vv aDlgt0 = s.foo;
               dlgt_vv aDlgt = s.foo;

               te.Test( 0== ( (Struct)aDlgt.Target).i);

               Struct sCopy1= (Struct) aDlgt.Target;

               te.Test( s.Equals( sCopy1)); // bb86f83d6448458db598c5fa849441c8
               te.Test( aDlgt.Target.Equals( ( (dlgt_vv) s.foo).Target)); // 6494647464964967a30d5f91c399c818

               te.Test( ! aDlgt.Equals( ( (dlgt_vv) s.foo)));
               te.Test( ! aDlgt0.Equals( aDlgt));

               aDlgt();
               //s.foo(); // not the same Result

               Struct sCopy2= (Struct) aDlgt.Target; // 109ea2c9d5584c15854be335d0b81884

               te.Test( ! s.Equals( sCopy2)); // bb86f83d6448458db598c5fa849441c8
               te.Test( ! aDlgt.Target.Equals( ( (dlgt_vv) s.foo).Target)); // 6494647464964967a30d5f91c399c818

               te.Test( 0 == s.i);

               te.Test( 0 == sCopy1.i);

               te.Test( 1 == sCopy2.i); // 109ea2c9d5584c15854be335d0b81884

               te.CheckComplainAndAdjustExpected( 10);

               System.Console.WriteLine( te.Result());
        }
Esempio n. 28
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="type"></param>
        /// <param name="bits"></param>
        /// <returns></returns>
        public async Task<MediaObjectInfo> NewMediaObject(string name, string type, byte[] bits)
        {
            var service = new Service(BlogConnectionInfo.MetaWeblogUrl);

            var inputStruct = new Struct();
            inputStruct["name"] = new StringValue(name);
            inputStruct["type"] = new StringValue(type);
            inputStruct["bits"] = new Base64Data(bits);

            var method = new MethodCall("metaWeblog.newMediaObject");
            method.Parameters.Add(BlogConnectionInfo.BlogId);
            method.Parameters.Add(BlogConnectionInfo.Username);
            method.Parameters.Add(BlogConnectionInfo.Password);
            method.Parameters.Add(inputStruct);

            var response = await service.Execute(method);
            var param = response.Parameters[0];
            var _struct = (Struct)param;

            var mediaobject = new MediaObjectInfo { Url = _struct.Get("url", StringValue.NullString).String };

            return mediaobject;
        }
Esempio n. 29
0
 internal static extern void GValueSetString(ref Struct value, IntPtr vString);
Esempio n. 30
0
 public FieldGetter(Struct structure, Field field)
 {
     mStruct = structure;
     mField = field;
 }
Esempio n. 31
0
 internal static extern void GValueSetEnum(ref Struct value, int vEnum);
Esempio n. 32
0
 internal static extern uint GValueGetFlags(ref Struct value);
Esempio n. 33
0
 internal static extern IntPtr GValueGetString(ref Struct value);
Esempio n. 34
0
    public static void Main()
    {
        // Set up an int int map
        StringIntMap simap = new StringIntMap();

        for (int i = 0; i < collectionSize; i++)
        {
            int val = i * 18;
            simap.Add(i.ToString(), val);
        }

        // Count property test
        if (simap.Count != collectionSize)
        {
            throw new Exception("Count test failed");
        }

        // IsReadOnly property test
        if (simap.IsReadOnly)
        {
            throw new Exception("IsReadOnly test failed");
        }

        // Item indexing test
        simap["0"] = 200;
        if (simap["0"] != 200)
        {
            throw new Exception("Item property test failed");
        }
        simap["0"] = 0 * 18;

        // ContainsKey() test
        for (int i = 0; i < collectionSize; i++)
        {
            if (!simap.ContainsKey(i.ToString()))
            {
                throw new Exception("ContainsKey test " + i + " failed");
            }
        }

        // ContainsKey() test
        for (int i = 0; i < collectionSize; i++)
        {
            if (!simap.Contains(new KeyValuePair <string, int>(i.ToString(), i * 18)))
            {
                throw new Exception("Contains test " + i + " failed");
            }
        }

        // TryGetValue() test
        int  value;
        bool rc = simap.TryGetValue("3", out value);

        if (rc != true || value != (3 * 18))
        {
            throw new Exception("TryGetValue test 1 failed");
        }

        rc = simap.TryGetValue("-1", out value);
        if (rc != false)
        {
            throw new Exception("TryGetValue test 2 failed");
        }

        // Keys and Values test
        {
            IList <string> keys   = new List <string>(simap.Keys);
            IList <int>    values = new List <int>(simap.Values);
            if (keys.Count != collectionSize)
            {
                throw new Exception("Keys count test failed");
            }

            if (values.Count != collectionSize)
            {
                throw new Exception("Values count test failed");
            }

            for (int i = 0; i < keys.Count; i++)
            {
                if (simap[keys[i]] != values[i])
                {
                    throw new Exception("Keys and values test failed for index " + i);
                }
            }
        }

        // Add and Remove test
        for (int i = 100; i < 103; i++)
        {
            simap.Add(i.ToString(), i * 18);
            if (!simap.ContainsKey(i.ToString()) || simap[i.ToString()] != (i * 18))
            {
                throw new Exception("Add test failed for index " + i);
            }

            simap.Remove(i.ToString());
            if (simap.ContainsKey(i.ToString()))
            {
                throw new Exception("Remove test failed for index " + i);
            }
        }

        for (int i = 200; i < 203; i++)
        {
            simap.Add(new KeyValuePair <string, int>(i.ToString(), i * 18));
            if (!simap.ContainsKey(i.ToString()) || simap[i.ToString()] != (i * 18))
            {
                throw new Exception("Add explicit test failed for index " + i);
            }

            simap.Remove(new KeyValuePair <string, int>(i.ToString(), i * 18));
            if (simap.ContainsKey(i.ToString()))
            {
                throw new Exception("Remove explicit test failed for index " + i);
            }
        }

        // Duplicate key test
        try
        {
            simap.Add("3", 0);
            throw new Exception("Adding duplicate key test failed");
        }
        catch (ArgumentException)
        {
        }

        // CopyTo() test
        {
            KeyValuePair <string, int>[] outputarray = new KeyValuePair <string, int> [collectionSize];
            simap.CopyTo(outputarray);
            foreach (KeyValuePair <string, int> val in outputarray)
            {
                if (simap[val.Key] != val.Value)
                {
                    throw new Exception("CopyTo (1) test failed, index:" + val.Key);
                }
            }
        }
        {
            KeyValuePair <string, int>[] outputarray = new KeyValuePair <string, int> [midCollection + collectionSize];
            simap.CopyTo(outputarray, midCollection);
            for (int i = midCollection; i < midCollection + collectionSize; i++)
            {
                KeyValuePair <string, int> val = outputarray[i];
                if (simap[val.Key] != val.Value)
                {
                    throw new Exception("CopyTo (2) test failed, index:" + val.Key);
                }
            }
        }
        {
            KeyValuePair <string, int>[] outputarray = new KeyValuePair <string, int> [collectionSize - 1];
            try
            {
                simap.CopyTo(outputarray);
                throw new Exception("CopyTo (4) test failed");
            }
            catch (ArgumentException)
            {
            }
        }

        // Clear test
        simap.Clear();
        if (simap.Count != 0)
        {
            throw new Exception("Clear test failed");
        }

        // Test wrapped methods
        for (int i = 1; i <= 5; i++)
        {
            simap[i.ToString()] = i;
        }
        double avg = li_std_map.valueAverage(simap);

        if (avg != 3.0)
        {
            throw new Exception("Wrapped method valueAverage test failed. Got " + avg);
        }

        string keyStringified = li_std_map.stringifyKeys(simap);

        if (keyStringified != " 1 2 3 4 5")
        {
            throw new Exception("Wrapped method stringifyKeys test failed. Got " + keyStringified);
        }

        // Test a map with a new complex type (Struct)
        {
            IntStructMap ismap = new IntStructMap();
            for (int i = 0; i < 10; i++)
            {
                ismap.Add(i, new Struct(i * 10.1));
            }

            if (ismap.Count != 10)
            {
                throw new Exception("Count test on complex type map failed");
            }

            foreach (KeyValuePair <int, Struct> p in ismap)
            {
                if ((p.Key * 10.1) != p.Value.num)
                {
                    throw new Exception("Iteration test on complex type map failed for index " + p.Key);
                }
            }
        }

        // Test a map of pointers
        {
            IntStructPtrMap ispmap = new IntStructPtrMap();
            for (int i = 0; i < 10; i++)
            {
                ispmap.Add(i, new Struct(i * 10.1));
            }

            if (ispmap.Count != 10)
            {
                throw new Exception("Count test on complex type pointer map failed");
            }

            foreach (KeyValuePair <int, Struct> p in ispmap)
            {
                if ((p.Key * 10.1) != p.Value.num)
                {
                    throw new Exception("Iteration test on complex type pointer map failed for index " + p.Key);
                }
            }
        }
        {
            IntStructConstPtrMap iscpmap = new IntStructConstPtrMap();
            for (int i = 0; i < 10; i++)
            {
                iscpmap.Add(i, new Struct(i * 10.1));
            }

            if (iscpmap.Count != 10)
            {
                throw new Exception("Count test on complex type const pointer map failed");
            }

            foreach (KeyValuePair <int, Struct> p in iscpmap)
            {
                if ((p.Key * 10.1) != p.Value.num)
                {
                    throw new Exception("Iteration test on complex type const pointer map failed for index " + p.Key);
                }
            }
        }

        // Test complex type as key (Struct)
        {
            StructIntMap limap = new StructIntMap();
            Struct       s7    = new Struct(7);
            Struct       s8    = new Struct(8);
            limap[s7] = 8;
            if (limap[s7] != 8)
            {
                throw new Exception("Assignment test on complex key map failed");
            }

            if (!limap.ContainsKey(s7))
            {
                throw new Exception("Key test (1) on complex key map failed");
            }

            if (limap.ContainsKey(s8))
            {
                throw new Exception("Key test (2) on complex key map failed");
            }
        }

        // All done
    }
    public static void Main()
    {
        // Setup a list of int
        IntList list = new IntList();

        IntList.IntListNode node;

        for (int i = 0; i < 20; i++)
        {
            int nb = i * 10;
            list.Add(nb);
        }

        // Count property test
        if (list.Count != collectionSize)
        {
            throw new Exception("Count test failed");
        }

        // IsReadOnly property test
        if (list.IsReadOnly)
        {
            throw new Exception("IsReadOnly test failed");
        }

        // Contains method test
        if (!list.Contains(0))
        {
            throw new Exception("Contains method test 1 failed");
        }
        if (!list.Contains(2 * 10))
        {
            throw new Exception("Contains method test 2 failed");
        }
        if (!list.Contains(19 * 10))
        {
            throw new Exception("Contains method test 3 failed");
        }
        if (list.Contains(20 * 10))
        {
            throw new Exception("Contains method test 4 failed");
        }

        // Nodes comparison method overload
        {
            IntList.IntListNode temp = new IntList.IntListNode(3);
            if (list.First == temp)
            {
                throw new Exception("== overload method test (1) failed");
            }
            temp = new IntList.IntListNode(0);
            if (list.First == temp)
            {
                throw new Exception("== overload method test (2) failed");
            }
            IntList.IntListNode temp2 = new IntList.IntListNode(0);
            if (temp == temp2)
            {
                throw new Exception("== overload method test (3) failed");
            }
            if (!(list.First == list.First))
            {
                throw new Exception("== overload method test (4) failed");
            }
            if (list.First != list.First)
            {
                throw new Exception("!= overload method test (1) failed");
            }
            if (!(temp != temp2))
            {
                throw new Exception("!= overload method test (2) failed");
            }
            if (list.First.Equals(temp))
            {
                throw new Exception("Equals method test failed");
            }
            if (list.First.GetHashCode() == temp.GetHashCode())
            {
                throw new Exception("GetHashCode method test (1) failed");
            }
            if (list.First.GetHashCode() == list.First.GetHashCode())
            {
                throw new Exception("GetHashCode method test (2) failed");
            }
        }

        // Getter test
        {
            if (list.First == null)
            {
                throw new Exception("First getter test (1) failed");
            }
            if (list.Last == null)
            {
                throw new Exception("Last getter test (1) failed");
            }
            if (list.Last.Next != null)
            {
                throw new Exception("Next getter test (1) failed");
            }
            if (list.First.Next == null)
            {
                throw new Exception("Next getter test (2) failed");
            }
            if (list.First.Previous != null)
            {
                throw new Exception("Previous getter test (1) failed");
            }
            if (list.Last.Previous == null)
            {
                throw new Exception("Previous getter test (2) failed");
            }
        }

        // AddFirst method test
        node = list.AddFirst(34);
        if (list.First.Value != 34 || node.Value != 34 || node != list.First)
        {
            throw new Exception("AddFirst method test failed");
        }
        try {
            list.AddFirst(null);
        } catch (ArgumentNullException) {
            try {
                list.AddFirst(list.First);
            } catch (InvalidOperationException) {
            }
        }

        // RemoveFirst method test
        int tmp = list.First.Value;

        list.RemoveFirst();
        if (list.First.Value == tmp || list.First.Value != 0 * 10)
        {
            throw new Exception("RemoveFirst method test failed");
        }

        // AddLast method test
        node = list.AddLast(8);
        if (list.Last.Value != 8 || node.Value != 8 || node != list.Last)
        {
            throw new Exception("AddLast method test failed");
        }
        try {
            list.AddLast(null);
        } catch (ArgumentNullException) {
            try {
                list.AddLast(list.First);
            } catch (InvalidOperationException) {
            }
        }

        // RemoveLast method test
        int tmp2 = list.Last.Value;

        list.RemoveLast();
        if (list.Last.Value == tmp2 || list.Last.Value != (list.Count - 1) * 10)
        {
            throw new Exception("RemoveLast method test failed");
        }

        // AddBefore method test
        node = list.AddBefore(list.Last, 17);
        if (list.Last.Previous.Value != 17 || node.Value != 17 || node != list.Last.Previous)
        {
            throw new Exception("AddBefore method test (1) failed");
        }
        try {
            node = null;
            list.AddBefore(list.Last, node);
            throw new Exception("AddBefore method test (2) failed");
        } catch (ArgumentNullException) {
            try {
                node = new IntList.IntListNode(1);
                list.AddBefore(null, node);
                throw new Exception("AddBefore method test (3) failed");
            } catch (ArgumentNullException) {
                try {
                    list.AddBefore(list.Last, list.First);
                } catch (InvalidOperationException) {
                }
            }
        }

        // AddAfter method test
        node = list.AddAfter(list.First, 47);
        if (list.First.Next.Value != 47 || node.Value != 47 || node != list.First.Next)
        {
            throw new Exception("AddAfter method test (1) failed");
        }
        try {
            node = null;
            list.AddAfter(list.First.Next, node);
            throw new Exception("AddAfter method test (2) failed");
        } catch (ArgumentNullException) {
            try {
                list.AddAfter(list.First, list.Last);
            } catch (InvalidOperationException) {
            }
        }

        // Find method test
        node = list.Find(0);
        if (node == null || node.Value != 0)
        {
            throw new Exception("Find method test (1) failed");
        }
        node = list.Find(47);
        if (node == null || node.Value != 47)
        {
            throw new Exception("Find method test (2) failed");
        }
        node = list.Find(190);
        if (node == null || node.Value != 190)
        {
            throw new Exception("Find method test (3) failed");
        }
        node = list.Find(-3);
        if (node != null)
        {
            throw new Exception("Find method test (4) failed");
        }

        // Remove method test
        if (!list.Remove(17) || list.Contains(17) || list.Last.Previous.Value == 17)
        {
            throw new Exception("Remove method test (1) failed");
        }
        if (!list.Remove(47) || list.Contains(47) || list.First.Next.Value == 47)
        {
            throw new Exception("Remove method test (2) failed");
        }
        if (!list.Remove(0) || list.Contains(0) || list.First.Value == 0)
        {
            throw new Exception("Remove method test (3) failed");
        }
        if (!list.Remove(190) || list.Contains(190) || list.Last.Value == 190)
        {
            throw new Exception("Remove method test (4) failed");
        }
        try {
            node = null;
            list.Remove(node);
            throw new Exception("Remove method test (5) failed");
        } catch (ArgumentNullException) {
            try {
                node = new IntList.IntListNode(4);
                list.Remove(node);
                throw new Exception("Remove method test (5) failed");
            } catch (InvalidOperationException) {
            }
        }

        // ICollection constructor test
        {
            int[]   intArray = new int[] { 0, 11, 22, 33, 44, 55, 33 };
            IntList il       = new IntList(intArray);
            if (intArray.Length != il.Count)
            {
                throw new Exception("ICollection constructor length check failed: " + intArray.Length + "-" + il.Count);
            }
            node = il.First;
            for (int i = 0; i < intArray.Length; i++)
            {
                if (intArray[i] != node.Value)
                {
                    throw new Exception("ICollection constructor failed, index:" + i);
                }
                node = node.Next;
            }
            try {
                new IntList((System.Collections.ICollection)null);
                throw new Exception("ICollection constructor null test failed");
            } catch (ArgumentNullException) {
            }
        }

        // Enumerator test
        {
            node = list.First;
            System.Collections.IEnumerator myEnumerator = list.GetEnumerator();
            while (myEnumerator.MoveNext())
            {
                if ((int)myEnumerator.Current != node.Value)
                {
                    throw new Exception("Enumerator (1) test failed");
                }
                node = node.Next;
            }
        }
        {
            node = list.First;
            System.Collections.Generic.IEnumerator <int> myEnumerator = list.GetEnumerator();
            while (myEnumerator.MoveNext())
            {
                if (myEnumerator.Current != node.Value)
                {
                    throw new Exception("Enumerator (2) test failed");
                }
                node = node.Next;
            }
        }
        {
            node = list.First;
            IntList.IntListEnumerator myEnumerator = list.GetEnumerator();
            while (myEnumerator.MoveNext())
            {
                if (myEnumerator.Current != node.Value)
                {
                    throw new Exception("Enumerator (3) test failed");
                }
                node = node.Next;
            }
        }
        {
            node = list.First;
            foreach (var elem in list)
            {
                if (elem != node.Value)
                {
                    throw new Exception("Enumerator (4) test failed");
                }
                node = node.Next;
            }
        }

        // CopyTo method test
        {
            int[] outputarray = new int[collectionSize - 2];
            list.CopyTo(outputarray, 0);
            int index = 0;
            IntList.IntListNode temp = list.First;
            foreach (int val in outputarray)
            {
                if (temp.Value != val)
                {
                    throw new Exception("CopyTo method test (1) failed, index:" + index);
                }
                index++;
                temp = temp.Next;
            }
        }
        {
            DoubleList inputlist = new DoubleList();
            int        arrayLen  = 10;
            for (int i = 0; i < arrayLen; i++)
            {
                double num = i * 10.1;
                inputlist.Add(num);
            }
            double[] outputarray = new double[arrayLen];
            inputlist.CopyTo(outputarray, 0);
            DoubleList.DoubleListNode temp = inputlist.First;
            for (int i = 0; i < arrayLen; i++)
            {
                if (outputarray[i] != temp.Value)
                {
                    throw new Exception("CopyTo method test (2) failed, index:" + i);
                }
                temp = temp.Next;
            }
        }
        {
            StructList inputlist = new StructList();
            int        arrayLen  = 10;
            for (int i = 0; i < arrayLen; i++)
            {
                inputlist.Add(new Struct(i / 10.0));
            }
            Struct[] outputarray = new Struct[arrayLen];
            inputlist.CopyTo(outputarray, 0);
            StructList.StructListNode temp = inputlist.First;
            for (int i = 0; i < arrayLen; i++)
            {
                if (outputarray[i].num != temp.Value.num)
                {
                    throw new Exception("CopyTo method test (3) failed, index:" + i);
                }
                temp = temp.Next;
            }
            foreach (Struct s in inputlist)
            {
                s.num += 20.0;
            }
            temp = inputlist.First;
            for (int i = 0; i < arrayLen; i++)
            {
                if (outputarray[i].num != temp.Value.num)
                {
                    throw new Exception("CopyTo method test (4) failed, index:" + i);
                }
                temp = temp.Next;
            }
        }
        try {
            list.CopyTo(null, 0);
            throw new Exception("CopyTo method test (5) failed");
        } catch (ArgumentNullException) {
        }

        // Clear() test
        list.Clear();
        if (list.Count != 0)
        {
            throw new Exception("Clear method failed");
        }

        // Finally test the methods being wrapped
        {
            IntList il = new IntList();
            for (int i = 0; i < 4; i++)
            {
                il.Add(i);
            }

            double x = li_std_list.average(il);
            x += li_std_list.average(new IntList(new int[] { 1, 2, 3, 4 }));

            DoubleList dlist = new DoubleList();
            for (int i = 0; i < 10; i++)
            {
                dlist.Add(i / 2.0);
            }
            li_std_list.halve_in_place(dlist);
        }

        // Dispose()
        {
            using (StructList ls = new StructList(new Struct[] { new Struct(0.0), new Struct(11.1) }))
                using (DoubleList ld = new DoubleList(new double[] { 0.0, 11.1 })) {  }
        }

        // More wrapped methods
        {
            FloatList l0  = li_std_list.listreal(new FloatList());
            float     flo = 123.456f;
            l0.Add(flo);
            flo = l0.First.Value;

            IntList         l1 = li_std_list.listint(new IntList());
            IntPtrList      l2 = li_std_list.listintptr(new IntPtrList());
            IntConstPtrList l3 = li_std_list.listintconstptr(new IntConstPtrList());

            l1.Add(123);
            l2.Clear();
            l3.Clear();

            StructList         l4 = li_std_list.liststruct(new StructList());
            StructPtrList      l5 = li_std_list.liststructptr(new StructPtrList());
            StructConstPtrList l6 = li_std_list.liststructconstptr(new StructConstPtrList());

            l4.Add(new Struct(123));
            l5.Add(new Struct(123));
            l6.Add(new Struct(123));
        }

        // Test lists of pointers
        {
            StructPtrList inputlist = new StructPtrList();
            int           arrayLen  = 10;
            for (int i = 0; i < arrayLen; i++)
            {
                inputlist.Add(new Struct(i / 10.0));
            }
            Struct[] outputarray = new Struct[arrayLen];
            inputlist.CopyTo(outputarray, 0);
            StructPtrList.StructPtrListNode temp = inputlist.First;
            for (int i = 0; i < arrayLen; i++)
            {
                if (outputarray[i].num != temp.Value.num)
                {
                    throw new Exception("StructPtrList test (1) failed, i:" + i);
                }
                temp = temp.Next;
            }
            foreach (Struct s in inputlist)
            {
                s.num += 20.0;
            }
            for (int i = 0; i < arrayLen; i++)
            {
                if (outputarray[i].num != 20.0 + i / 10.0)
                {
                    throw new Exception("StructPtrList test (2) failed (a deep copy was incorrectly made), i:" + i);
                }
            }
        }

        // Test lists of const pointers
        {
            StructConstPtrList inputlist = new StructConstPtrList();
            int arrayLen = 10;
            for (int i = 0; i < arrayLen; i++)
            {
                inputlist.Add(new Struct(i / 10.0));
            }
            Struct[] outputarray = new Struct[arrayLen];
            inputlist.CopyTo(outputarray, 0);
            StructConstPtrList.StructConstPtrListNode temp = inputlist.First;
            for (int i = 0; i < arrayLen; i++)
            {
                if (outputarray[i].num != temp.Value.num)
                {
                    throw new Exception("StructConstPtrList test (1) failed, i:" + i);
                }
                temp = temp.Next;
            }
            foreach (Struct s in inputlist)
            {
                s.num += 20.0;
            }
            for (int i = 0; i < arrayLen; i++)
            {
                if (outputarray[i].num != 20.0 + i / 10.0)
                {
                    throw new Exception("StructConstPtrList test (2) failed (a deep copy was incorrectly made), i:" + i);
                }
            }
        }
    }
Esempio n. 36
0
 internal static extern void GValueSetInt(ref Struct value, int vInt);
Esempio n. 37
0
 internal static extern int GValueGetBoolean(ref Struct value);
Esempio n. 38
0
 internal static extern void GValueSetBoolean(ref Struct value, int vBoolean);
Esempio n. 39
0
 internal static extern void GValueUnset(ref Struct value);
Esempio n. 40
0
 internal static extern void GValueSetDouble(ref Struct value, double vDouble);
Esempio n. 41
0
 internal static extern IntPtr GParamSpecGetBlurb(ref Struct pspec);
Esempio n. 42
0
        private void PacketListView_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (PacketListView.SelectedIndex == -1)
            {
                return;
            }

            var item = (PacketEntry)PacketListView.Items[PacketListView.SelectedIndex];

            var data = item.Data;

            if (Properties.Settings.Default.HideHexBoxActorId)
            {
                byte[] noIdData = new byte[data.Length];
                Array.Copy(data, 0, noIdData, 0, 3);
                Array.Copy(data, 12, noIdData, 12, data.Length - 12);
                data = noIdData;
            }

            _currentPacketStream = new MemoryStream(data);
            try
            {
                HexEditor.ByteProvider = new DynamicByteProvider(data);
            }
            catch (Exception exception)
            {
                new ExtendedErrorView("Failed to load packet.", exception.ToString(), "Error").ShowDialog();
            }


            StructListView.Items.Clear();

            try
            {
                string structText = null;
                structText = item.Direction == "S" ? _db.GetServerZoneStruct(int.Parse(item.Message, NumberStyles.HexNumber)) : _db.GetClientZoneStruct(int.Parse(item.Message, NumberStyles.HexNumber));

                if (structText == null)
                {
                    StructListItem infoItem = new StructListItem {
                        NameCol = "No Struct found"
                    };
                    StructListView.Items.Add(infoItem);
                    return;
                }

                var structProvider = new Struct();
                var structEntries  = structProvider.Parse(structText, item.Data);

                var colours = Struct.TypeColours;
                int i       = 0;


                // Highlight the IPC header lightly grey
                HexEditor.HighlightBytes(0, 0x20, System.Drawing.Color.Black, System.Drawing.Color.LightGray);

                foreach (var entry in structEntries.Item1)
                {
                    System.Drawing.Color colour = Struct.TypeColours.ElementAt(i).Value;
                    StructListView.Items.Add(entry);
                    HexEditor.HighlightBytes(entry.offset, entry.typeLength, System.Drawing.Color.Black, colour);
                    ++i;
                    if (i == colours.Count)
                    {
                        i = 1;
                    }
                }

                if (_mainWindow.ShowObjectMapCheckBox.IsChecked)
                {
                    new ExtendedErrorView("Object map for " + item.Name, structEntries.Item2.Print(), "FFXIVMon Reborn").ShowDialog();
                }
            }
            catch (Exception exc)
            {
#if !DEBUG
                if (_erroredOpcodes.Contains(item.Message))
                {
#endif
                new ExtendedErrorView($"Struct error! Could not get struct for {item.Name} - {item.Message}", exc.ToString(), "Error").ShowDialog();
#if !DEBUG
                _erroredOpcodes.Add(item.Message);
            }
#endif

                StructListItem infoItem = new StructListItem {
                    NameCol = "Parsing failed"
                }
                ;
                StructListView.Items.Add(infoItem);
                return;
            }

            UpdateInfoLabel();
        }
Esempio n. 43
0
        public void AddPacketToListView(PacketEntry item, bool silent = false)
        {
            if (_mainWindow.IsPausedCheckBox.IsChecked && !silent)
            {
                return;
            }

            if (_encryptionProvider != null && !item.IsDecrypted && item.Data[0x0C] != 0x09 && item.Data[0x0C] != 0x07 && item.Connection == FFXIVNetworkMonitor.ConnectionType.Lobby)
            {
                var data = item.Data;
                _encryptionProvider.DecryptPacket(ref data);
                item.Data = data;

                item.Message = BitConverter.ToUInt16(item.Data, 0x12).ToString("X4");

                item.IsDecrypted = true;
            }

            if (item.Direction == "S")
            {
                item.Name    = _db.GetServerZoneOpName(int.Parse(item.Message, NumberStyles.HexNumber));
                item.Comment = _db.GetServerZoneOpComment(int.Parse(item.Message, NumberStyles.HexNumber));

                switch (item.Message)
                {
                case "0142":
                case "0143":
                case "0144":
                    int cat = BitConverter.ToUInt16(item.Data, 0x20);
                    item.ActorControl = cat;
                    item.Name         = _db.GetActorControlTypeName(cat);
                    break;
                }

                if (_mainWindow.ExEnabledCheckbox.IsChecked)
                {
                    try
                    {
                        var structText = _db.GetServerZoneStruct(int.Parse(item.Message, NumberStyles.HexNumber));

                        if (structText != null && structText.Length != 0)
                        {
                            switch (item.Name)
                            {
                            case "NpcSpawn":
                            {
                                Struct  structProvider = new Struct();
                                dynamic obj            = structProvider.Parse(structText, item.Data).Item2;

                                item.Comment =
                                    $"Name: {_mainWindow.ExdProvider.GetBnpcName((int)obj.bNPCName)}({obj.bNPCName}) - Base: {obj.bNPCBase}";
                            }
                            break;

                            case "ActorCast":
                            {
                                Struct  structProvider = new Struct();
                                dynamic obj            = structProvider.Parse(structText, item.Data).Item2;

                                item.Comment = $"Action: {_mainWindow.ExdProvider.GetActionName(obj.action_id)}({obj.action_id}) - Type {obj.skillType} - Cast Time: {obj.cast_time}";
                            }
                            break;
                            }

                            if (item.Name.Contains("ActorControl"))
                            {
                                switch (item.ActorControl)
                                {
                                case 3:     //CastStart
                                {
                                    var ctrl = Util.FastParseActorControl(item.Data);

                                    item.Comment = $"Action: {_mainWindow.ExdProvider.GetActionName((int)ctrl.Param2)}({ctrl.Param2}) - Type {ctrl.Param1}";
                                }
                                break;

                                case 17:     //ActionStart
                                {
                                    var ctrl = Util.FastParseActorControl(item.Data);

                                    item.Comment = $"Action: {_mainWindow.ExdProvider.GetActionName((int)ctrl.Param2)}({ctrl.Param2}) - Type {ctrl.Param1}";
                                }
                                break;
                                }
                            }
                        }
                    }
                    catch (Exception exc)
                    {
                        new ExtendedErrorView(
                            $"EXD Error for {item.Message} - {item.Name}. Turning off EXD features.", exc.ToString(), "Error").ShowDialog();
                        _mainWindow.ExEnabledCheckbox.IsChecked = false;
                    }
                }
            }
            else
            {
                item.Name    = _db.GetClientZoneOpName(int.Parse(item.Message, NumberStyles.HexNumber));
                item.Comment = _db.GetClientZoneOpComment(int.Parse(item.Message, NumberStyles.HexNumber));

                if (item.Data[0x0C] == 0x09 && item.Message == "0000" && item.Connection == FFXIVNetworkMonitor.ConnectionType.Lobby)
                {
                    _encryptionProvider = new LobbyEncryptionProvider(item.Data);

                    item.Comment = "Lobby Encryption INIT: " + Util.ByteArrayToString(_encryptionProvider.EncKey);
                }
            }

            item.IsForSelf = BitConverter.ToUInt32(item.Data, 0x04) == BitConverter.ToUInt32(item.Data, 0x08);
            item.Category  = item.Set.ToString();

            if (_mainWindow.RunScriptsOnNewCheckBox.IsChecked)
            {
                if (_mainWindow.ScriptProvider == null)
                {
                    MessageBox.Show("No scripts were loaded.", "Error", MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                    _mainWindow.RunScriptsOnNewCheckBox.IsChecked = false;
                }
                else
                {
                    try
                    {
                        Scripting_RunOnPacket(item, _mainWindow.ScriptProvider);
                    }
                    catch (Exception exc)
                    {
                        new ExtendedErrorView(
                            $"Scripting exception thrown for {item.Message} - {item.Name}. Turning off auto script running.", exc.ToString(), "Error").ShowDialog();
                        _mainWindow.RunScriptsOnNewCheckBox.IsChecked = false;
                    }
                }
            }

            if (_filters != null && _filters.Length > 0)
            {
                foreach (var filterEntry in _filters)
                {
                    if (!filterEntry.IsApplicableForFilterSet(item))
                    {
                        return;
                    }
                }
            }

            PacketListView.Items.Add(item);

            if (!silent)
            {
                UpdateInfoLabel();
            }
        }
Esempio n. 44
0
 internal static extern int GValueGetInt(ref Struct value);
Esempio n. 45
0
 public override void visit_struct(Struct st)
 {
     check_unused_attr(st);
     st.accept_children(this);
 }
Esempio n. 46
0
 internal static extern int GValueGetEnum(ref Struct value);
Esempio n. 47
0
        private StackItem DeserializeStackItem(BinaryReader reader, ExecutionEngine engine, uint maxItemSize)
        {
            Stack <StackItem> deserialized = new Stack <StackItem>();
            int undeserialized             = 1;

            while (undeserialized-- > 0)
            {
                StackItemType type = (StackItemType)reader.ReadByte();
                switch (type)
                {
                case StackItemType.ByteArray:
                    deserialized.Push(new ByteArray(reader.ReadVarBytes((int)maxItemSize)));
                    break;

                case StackItemType.Boolean:
                    deserialized.Push(new VMBoolean(reader.ReadBoolean()));
                    break;

                case StackItemType.Integer:
                    deserialized.Push(new Integer(new BigInteger(reader.ReadVarBytes(ExecutionEngine.MaxSizeForBigInteger))));
                    break;

                case StackItemType.Array:
                case StackItemType.Struct:
                {
                    int count = (int)reader.ReadVarInt(engine.MaxArraySize);
                    deserialized.Push(new ContainerPlaceholder
                        {
                            Type         = type,
                            ElementCount = count
                        });
                    undeserialized += count;
                }
                break;

                case StackItemType.Map:
                {
                    int count = (int)reader.ReadVarInt(engine.MaxArraySize);
                    deserialized.Push(new ContainerPlaceholder
                        {
                            Type         = type,
                            ElementCount = count
                        });
                    undeserialized += count * 2;
                }
                break;

                default:
                    throw new FormatException();
                }
            }
            Stack <StackItem> stack_temp = new Stack <StackItem>();

            while (deserialized.Count > 0)
            {
                StackItem item = deserialized.Pop();
                if (item is ContainerPlaceholder placeholder)
                {
                    switch (placeholder.Type)
                    {
                    case StackItemType.Array:
                        VMArray array = new VMArray();
                        for (int i = 0; i < placeholder.ElementCount; i++)
                        {
                            array.Add(stack_temp.Pop());
                        }
                        item = array;
                        break;

                    case StackItemType.Struct:
                        Struct @struct = new Struct();
                        for (int i = 0; i < placeholder.ElementCount; i++)
                        {
                            @struct.Add(stack_temp.Pop());
                        }
                        item = @struct;
                        break;

                    case StackItemType.Map:
                        Map map = new Map();
                        for (int i = 0; i < placeholder.ElementCount; i++)
                        {
                            StackItem key   = stack_temp.Pop();
                            StackItem value = stack_temp.Pop();
                            map.Add(key, value);
                        }
                        item = map;
                        break;
                    }
                }
                stack_temp.Push(item);
            }
            return(stack_temp.Peek());
        }
Esempio n. 48
0
        /// <summary>
        /// Writes event properties as a JSON object for a GCP log entry.
        /// </summary>
        private void WritePropertyAsJson(LogEntry log, Struct jsonStruct, string propertyKey, LogEventPropertyValue propertyValue)
        {
            switch (propertyValue)
            {
            case ScalarValue scalarValue when scalarValue.Value is null:
            {
                jsonStruct.Fields.Add(propertyKey, Value.ForNull());

                break;
            }

            case ScalarValue scalarValue when scalarValue.Value is bool:
            {
                jsonStruct.Fields.Add(propertyKey, Value.ForBool(Convert.ToBoolean(scalarValue.Value)));

                break;
            }

            case ScalarValue scalarValue when Double.TryParse(scalarValue.Value?.ToString(), out var doubleValue):
            {
                jsonStruct.Fields.Add(propertyKey, Value.ForNumber(doubleValue));

                break;
            }

            case ScalarValue scalarValue:
            {
                var stringValue = scalarValue.Value.ToString();
                jsonStruct.Fields.Add(propertyKey, Value.ForString(stringValue));

                if (_sinkOptions.UseSourceContextAsLogName && propertyKey.Equals("SourceContext", StringComparison.OrdinalIgnoreCase))
                {
                    log.LogName = new LogName(_sinkOptions.ProjectId, stringValue).ToString();
                }

                break;
            }

            case SequenceValue sequenceValue:
            {
                var childStruct = new Struct();
                for (int i = 0; i < sequenceValue.Elements.Count; i++)
                {
                    WritePropertyAsJson(log, childStruct, i.ToString(), sequenceValue.Elements[i]);
                }

                jsonStruct.Fields.Add(propertyKey, Value.ForList(childStruct.Fields.Values.ToArray()));

                break;
            }

            case StructureValue structureValue:
            {
                var childStruct = new Struct();
                foreach (var childProperty in structureValue.Properties)
                {
                    WritePropertyAsJson(log, childStruct, childProperty.Name, childProperty.Value);
                }

                jsonStruct.Fields.Add(propertyKey, Value.ForStruct(childStruct));

                break;
            }

            case DictionaryValue dictionaryValue:
            {
                var childStruct = new Struct();
                foreach (var childProperty in dictionaryValue.Elements)
                {
                    WritePropertyAsJson(log, childStruct, childProperty.Key.Value?.ToString(), childProperty.Value);
                }

                jsonStruct.Fields.Add(propertyKey, Value.ForStruct(childStruct));

                break;
            }
            }
        }
Esempio n. 49
0
 protected virtual void FromStruct(Struct @struct)
 {
     Balance = @struct[0].GetBigInteger();
 }
Esempio n. 50
0
 internal static extern void GValueSetFlags(ref Struct value, uint vFlags);
Esempio n. 51
0
        /// <inheritdoc />
        public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
        {
            GaxPreconditions.CheckNotNull(formatter, nameof(formatter));

            if (!IsEnabled(logLevel))
            {
                return;
            }

            string message = formatter(state, exception);

            if (string.IsNullOrEmpty(message))
            {
                return;
            }

            var jsonStruct = new Struct();

            jsonStruct.Fields.Add("message", Value.ForString(message));
            jsonStruct.Fields.Add("log_name", Value.ForString(_logName));

            if (GoogleLoggerScope.Current != null)
            {
                jsonStruct.Fields.Add("scope", Value.ForString(GoogleLoggerScope.Current.ToString()));
            }

            if (eventId.Id != 0 || eventId.Name != null)
            {
                var eventStruct = new Struct();
                if (eventId.Id != 0)
                {
                    eventStruct.Fields.Add("id", Value.ForNumber(eventId.Id));
                }
                if (!string.IsNullOrWhiteSpace(eventId.Name))
                {
                    eventStruct.Fields.Add("name", Value.ForString(eventId.Name));
                }
                jsonStruct.Fields.Add("event_id", Value.ForStruct(eventStruct));
            }

            // If we have format params and its more than just the original message add them.
            if (state is IEnumerable <KeyValuePair <string, object> > formatParams &&
                !(formatParams.Count() == 1 && formatParams.Single().Key.Equals("{OriginalFormat}")))
            {
                var paramStruct = new Struct();
                foreach (var pair in formatParams)
                {
                    // Consider adding formatting support for values that are IFormattable.
                    paramStruct.Fields.Add(pair.Key, Value.ForString(pair.Value?.ToString() ?? ""));
                }

                if (paramStruct.Fields.Count > 0)
                {
                    jsonStruct.Fields.Add("format_parameters", Value.ForStruct(paramStruct));
                }
            }

            LogEntry entry = new LogEntry
            {
                Resource    = _loggerOptions.MonitoredResource,
                LogName     = _fullLogName,
                Severity    = logLevel.ToLogSeverity(),
                Timestamp   = Timestamp.FromDateTime(_clock.GetCurrentDateTimeUtc()),
                JsonPayload = jsonStruct,
                Labels      = { _loggerOptions.Labels },
                Trace       = GetTraceName() ?? "",
            };

            _consumer.Receive(new[] { entry });
        }
Esempio n. 52
0
 public static void writeInfo(SendPacket s, Struct info)
 {
     s.writeC(info._hitEffects);
     s.writeC(info._hitPart);
 }
Esempio n. 53
0
        public static List <Definition> BuildDefinitions(ParseTreeNodeList definitionNodes)
        {
            var definitions = new List <Definition>();

            foreach (var definitionNode in definitionNodes)
            {
                var definitionChildNode = definitionNode.ChildNodes[0];

                if (definitionChildNode.Term.Name == IdlGrammar.CNAME_DOC_STRING)
                {
                    continue;
                }

                string[]           docStringLines = null;
                IList <Annotation> annotations    = null;
                var docStringNode = definitionChildNode.ChildNodes[0];
                if (docStringNode.ChildNodes.Count != 0)
                {
                    docStringLines = ParseDocStringLines(docStringNode.ChildNodes[0].Token.Text);
                }
                var annotationsNode = definitionChildNode.ChildNodes[1];
                if (annotationsNode.ChildNodes.Count != 0)
                {
                    annotations = BuildAnnotations(annotationsNode.ChildNodes);
                }

                if (definitionChildNode.Term.Name == IdlGrammar.NTNAME_TENUM)
                {
                    var enumId               = definitionChildNode.ChildNodes[2].Token.Text;
                    var enumFields           = new List <IntegerEnumField>();
                    int nextDefaultEnumValue = 0; // enumerations start at zero by default
                    foreach (var enumFieldNode in definitionChildNode.ChildNodes[3].ChildNodes)
                    {
                        string[] fieldDocStringLines = null;
                        var      fieldDocStringNode  = enumFieldNode.ChildNodes[0];
                        if (fieldDocStringNode.ChildNodes.Count != 0)
                        {
                            fieldDocStringLines = ParseDocStringLines(fieldDocStringNode.ChildNodes[0].Token.Text);
                        }
                        var enumFieldId = enumFieldNode.ChildNodes[1].Token.Text;
                        IntegerEnumField enumField;
                        if (enumFieldNode.ChildNodes.Count > 1 &&
                            enumFieldNode.ChildNodes[2].ChildNodes != null &&
                            enumFieldNode.ChildNodes[2].ChildNodes.Count > 0) // has enum value
                        {
                            var valueText = enumFieldNode.ChildNodes[2].ChildNodes[0].Token.Text;
                            int enumValue = int.Parse(valueText);
                            enumField = new IntegerEnumField(fieldDocStringLines, enumFieldId, enumValue,
                                                             nextDefaultEnumValue);
                            nextDefaultEnumValue = ++enumValue;
                        }
                        else
                        {
                            enumField = new IntegerEnumField(fieldDocStringLines, enumFieldId, null,
                                                             nextDefaultEnumValue);
                            ++nextDefaultEnumValue;
                        }
                        enumFields.Add(enumField);
                    }
                    var integerEnum = new IntegerEnum(docStringLines, enumId, enumFields, annotations);
                    definitions.Add(integerEnum);
                }
                else if (definitionChildNode.Term.Name == IdlGrammar.NTNAME_TSTRUCT)
                {
                    var name    = definitionChildNode.ChildNodes[2].Token.Text;
                    var fFields = BuildFields(definitionChildNode.ChildNodes[3], name);
                    var @struct = new Struct(docStringLines, name, fFields, annotations);
                    definitions.Add(@struct);
                }
                else if (definitionChildNode.Term.Name == IdlGrammar.NTNAME_TSERVICE)
                {
                    var name = definitionChildNode.ChildNodes[2].Token.Text;
                    IList <BaijiMethod> methods = new List <BaijiMethod>();

                    var functionsChild = definitionChildNode.ChildNodes[3];
                    if (functionsChild.Term.Name == IdlGrammar.NTNAME_FUNCTIONS)
                    {
                        methods = BuildMethods(functionsChild);
                    }

                    var service = new Service(docStringLines, name, methods, annotations);
                    definitions.Add(service);
                }
            }

            // Mark all locally referenced response struct types.
            var structs = definitions.OfType <Struct>().ToList();

            foreach (var service in definitions.OfType <Service>())
            {
                foreach (var method in service.Methods)
                {
                    var responseStruct = structs.FirstOrDefault(s => s.Name == method.ReturnType.Name);
                    if (responseStruct != null)
                    {
                        responseStruct.IsServiceResponse = true;
                    }
                }
            }

            return(definitions);
        }
 private long NextRandom(long minimum, long maximum)
 {
     _random.NextBytes(_randomBuffer);
     Struct.FromArray(_randomBuffer, out long longRand, 0);
     return(Math.Abs(longRand % (maximum - minimum)) + minimum);
 }
 private ulong NextRandom(ulong minimum, ulong maximum)
 {
     _random.NextBytes(_randomBuffer);
     Struct.FromArray(_randomBuffer, out ulong longRand, 0);
     return((longRand % (maximum - minimum)) + minimum);
 }
 private double NextRandom(double minimum, double maximum)
 {
     _random.NextBytes(_randomBuffer);
     Struct.FromArray(_randomBuffer, out long longRand, 0);
     return((double)(Math.Abs(longRand % (maximum - minimum)) + minimum));
 }
        public void SourceIsStruct_ItIsReplicated()
        {
            var source = new Struct { field1 = "some string", field2 = new Class() };

            Struct result = objectReplicator.Replicate(source);

            Assert.That(result.field1, Is.SameAs(source.field1));
            Assert.That(result.field2, Is.Not.SameAs(source.field2));
        }
Esempio n. 58
0
 public void __init(int _i, ByteBuffer _bb)
 {
     __p = new Struct(_i, _bb);
 }
Esempio n. 59
0
 internal static extern IntPtr GValueInit(ref Struct value, IntPtr gType);
Esempio n. 60
0
 internal static extern double GValueGetDouble(ref Struct value);