public static CultureInfo GetConfigLang()
 {
     if (Settings.Instance["language"] == null)
     {
         return(CultureInfo.CurrentUICulture);
     }
     else
     {
         return(CultureInfoEx.GetCultureInfo(Settings.Instance["language"]));
     }
 }
예제 #2
0
        /// <summary>
        /// Returns a culture based on its identifier.
        /// </summary>
        /// <param name="culture">The culture identifier, or null for the invariant culture.</param>
        /// <returns>The requested culture.</returns>
        private static CultureInfo GetCulture(string culture)
        {
            if (culture == null)
            {
                return(CultureInfo.InvariantCulture);
            }
#if (!DESKTOP && SHAMAN) || CORECLR
            else
            {
                return(CultureInfoEx.GetCultureInfo(culture));
            }
예제 #3
0
        public static CultureInfo GetConfigLang()
        {
            CultureInfo ci = CultureInfoEx.GetCultureInfo((string)MainV2.config["language"]);

            if (ci != null)
            {
                return(ci);
            }
            else
            {
                return(CultureInfo.GetCultureInfo("en-US"));
            }
        }
예제 #4
0
        public static CultureInfo GetConfigLang()
        {
            CultureInfo ci = CultureInfoEx.GetCultureInfo(Settings.Instance["language"]);

            if (ci != null)
            {
                return(ci);
            }
            else
            {
                return(System.Globalization.CultureInfo.CurrentUICulture);
            }
        }
예제 #5
0
        public static CultureInfo GetConfigLang()
        {
            CultureInfo ci = CultureInfoEx.GetCultureInfo(MainV2.getConfig("language"));

            if (ci != null)
            {
                return(ci);
            }
            else
            {
                return(System.Globalization.CultureInfo.CurrentUICulture);
            }
        }
예제 #6
0
        /// <summary>
        /// Detects APM board version
        /// </summary>
        /// <param name="port"></param>
        /// <returns> (1280/2560/2560-2/px4)</returns>
        public static string DetectBoard(string port)
        {
            SerialPort serialPort = new SerialPort();

            serialPort.PortName = port;

            if (!MainV2.MONO)
            {
                ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_SerialPort"); // Win32_USBControllerDevice
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
                foreach (ManagementObject obj2 in searcher.Get())
                {
                    Console.WriteLine("PNPID: " + obj2.Properties["PNPDeviceID"].Value.ToString());

                    // check vid and pid
                    if (obj2.Properties["PNPDeviceID"].Value.ToString().Contains(@"USB\VID_2341&PID_0010"))
                    {
                        // check port name as well
                        if (obj2.Properties["Name"].Value.ToString().ToUpper().Contains(serialPort.PortName.ToUpper()))
                        {
                            log.Info("is a 2560-2");
                            return("2560-2");
                        }
                    }

                    if (obj2.Properties["PNPDeviceID"].Value.ToString().Contains(@"USB\VID_26AC&PID_0010") || obj2.Properties["PNPDeviceID"].Value.ToString().Contains(@"USB\VID_26AC&PID_0011") || obj2.Properties["PNPDeviceID"].Value.ToString().Contains(@"USB\VID_26AC&PID_0012") || obj2.Properties["PNPDeviceID"].Value.ToString().Contains(@"USB\VID_26AC&PID_0013") || obj2.Properties["PNPDeviceID"].Value.ToString().Contains(@"USB\VID_26AC&PID_0014") || obj2.Properties["PNPDeviceID"].Value.ToString().Contains(@"USB\VID_26AC&PID_0015") || obj2.Properties["PNPDeviceID"].Value.ToString().Contains(@"USB\VID_26AC&PID_0016"))
                    {
                        // check port name as well
                        //if (obj2.Properties["Name"].Value.ToString().ToUpper().Contains(serialPort.PortName.ToUpper()))
                        {
                            log.Info("is a px4");
                            return("px4");
                        }
                    }
                }
            }

            if (serialPort.IsOpen)
            {
                serialPort.Close();
            }

            serialPort.DtrEnable = true;
            serialPort.BaudRate  = 57600;
            serialPort.Open();

            Thread.Sleep(100);

            int a = 0;

            while (a < 20) // 20 * 50 = 1 sec
            {
                //Console.WriteLine("write " + DateTime.Now.Millisecond);
                serialPort.DiscardInBuffer();
                serialPort.Write(new byte[] { (byte)'0', (byte)' ' }, 0, 2);
                a++;
                Thread.Sleep(50);

                //Console.WriteLine("btr {0}", serialPort.BytesToRead);
                if (serialPort.BytesToRead >= 2)
                {
                    byte b1 = (byte)serialPort.ReadByte();
                    byte b2 = (byte)serialPort.ReadByte();
                    if (b1 == 0x14 && b2 == 0x10)
                    {
                        serialPort.Close();
                        log.Info("is a 1280");
                        return("1280");
                    }
                }
            }

            serialPort.Close();

            log.Warn("Not a 1280");

            Thread.Sleep(500);

            serialPort.DtrEnable = true;
            serialPort.BaudRate  = 115200;
            serialPort.Open();

            Thread.Sleep(100);

            a = 0;
            while (a < 4)
            {
                byte[] temp = new byte[] { 0x6, 0, 0, 0, 0 };
                temp = ArduinoDetect.genstkv2packet(serialPort, temp);
                a++;
                Thread.Sleep(50);

                try
                {
                    if (temp[0] == 6 && temp[1] == 0 && temp.Length == 2)
                    {
                        serialPort.Close();
                        //HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_2341&PID_0010\640333439373519060F0\Device Parameters
                        if (!MainV2.MONO && !Thread.CurrentThread.CurrentCulture.IsChildOf(CultureInfoEx.GetCultureInfo("zh-Hans")))
                        {
                            ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_SerialPort"); // Win32_USBControllerDevice
                            ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
                            foreach (ManagementObject obj2 in searcher.Get())
                            {
                                //Console.WriteLine("Dependant : " + obj2["Dependent"]);

                                // all apm 1-1.4 use a ftdi on the imu board.

                                /*    obj2.Properties.ForEach(x =>
                                 *  {
                                 *      try
                                 *      {
                                 *          log.Info(((PropertyData)x).Name.ToString() + " = " + ((PropertyData)x).Value.ToString());
                                 *      }
                                 *      catch { }
                                 *  });
                                 */
                                // check vid and pid
                                if (obj2.Properties["PNPDeviceID"].Value.ToString().Contains(@"USB\VID_2341&PID_0010"))
                                {
                                    // check port name as well
                                    if (obj2.Properties["Name"].Value.ToString().ToUpper().Contains(serialPort.PortName.ToUpper()))
                                    {
                                        log.Info("is a 2560-2");
                                        return("2560-2");
                                    }
                                }

                                if (obj2.Properties["PNPDeviceID"].Value.ToString().Contains(@"USB\VID_26AC&PID_0010"))
                                {
                                    // check port name as well
                                    if (obj2.Properties["Name"].Value.ToString().ToUpper().Contains(serialPort.PortName.ToUpper()))
                                    {
                                        log.Info("is a px4");
                                        return("px4");
                                    }
                                }
                            }

                            log.Info("is a 2560");
                            return("2560");
                        }
                        else
                        {
                            if (DialogResult.Yes == CustomMessageBox.Show("Is this a APM 2+?", "APM 2+", MessageBoxButtons.YesNo))
                            {
                                return("2560-2");
                            }
                            else
                            {
                                if (DialogResult.Yes == CustomMessageBox.Show("Is this a PX4?", "PX4", MessageBoxButtons.YesNo))
                                {
                                    return("px4");
                                }
                                else
                                {
                                    return("2560");
                                }
                            }
                        }
                    }
                }
                catch { }
            }

            serialPort.Close();
            log.Warn("Not a 2560");



            return("");
        }
예제 #7
0
        private void Configuration_Load(object sender, EventArgs e)
        {
            startup = true;

            // read tooltips
            if (tooltips.Count == 0)
            {
                readToolTips();
            }

            // ensure the fields are populated before setting them
            CH7_OPT.DataSource = Enum.GetNames(typeof(Common.ac2ch7modes));
            TUNE.DataSource    = Enum.GetNames(typeof(Common.ac2ch6modes));

            // prefill all fields
            param = MainV2.comPort.param;
            processToScreen();



            // setup up camera button states
            if (MainV2.cam != null)
            {
                BUT_videostart.Enabled = false;
                CHK_hudshow.Checked    = GCSViews.FlightData.myhud.hudon;
            }
            else
            {
                BUT_videostart.Enabled = true;
            }

            // setup speech states
            if (MainV2.config["speechenable"] != null)
            {
                CHK_enablespeech.Checked = bool.Parse(MainV2.config["speechenable"].ToString());
            }
            if (MainV2.config["speechwaypointenabled"] != null)
            {
                CHK_speechwaypoint.Checked = bool.Parse(MainV2.config["speechwaypointenabled"].ToString());
            }
            if (MainV2.config["speechmodeenabled"] != null)
            {
                CHK_speechmode.Checked = bool.Parse(MainV2.config["speechmodeenabled"].ToString());
            }
            if (MainV2.config["speechcustomenabled"] != null)
            {
                CHK_speechcustom.Checked = bool.Parse(MainV2.config["speechcustomenabled"].ToString());
            }
            if (MainV2.config["speechbatteryenabled"] != null)
            {
                CHK_speechbattery.Checked = bool.Parse(MainV2.config["speechbatteryenabled"].ToString());
            }
            if (MainV2.config["speechaltenabled"] != null)
            {
                CHK_speechaltwarning.Checked = bool.Parse(MainV2.config["speechaltenabled"].ToString());
            }

            // this can't fail because it set at startup
            NUM_tracklength.Value = int.Parse(MainV2.config["NUM_tracklength"].ToString());

            // get wps on connect
            if (MainV2.config["loadwpsonconnect"] != null)
            {
                CHK_loadwponconnect.Checked = bool.Parse(MainV2.config["loadwpsonconnect"].ToString());
            }

            // setup other config state
            if (MainV2.config["CHK_resetapmonconnect"] != null)
            {
                CHK_resetapmonconnect.Checked = bool.Parse(MainV2.config["CHK_resetapmonconnect"].ToString());
            }

            CMB_rateattitude.Text = MainV2.cs.rateattitude.ToString();
            CMB_rateposition.Text = MainV2.cs.rateposition.ToString();
            CMB_raterc.Text       = MainV2.cs.raterc.ToString();
            CMB_ratestatus.Text   = MainV2.cs.ratestatus.ToString();
            CMB_ratesensors.Text  = MainV2.cs.ratesensors.ToString();


            if (MainV2.config["CHK_GDIPlus"] != null)
            {
                CHK_GDIPlus.Checked = bool.Parse(MainV2.config["CHK_GDIPlus"].ToString());
            }

            //set hud color state
            string hudcolor = (string)MainV2.config["hudcolor"];

            CMB_osdcolor.DataSource = Enum.GetNames(typeof(KnownColor));
            if (hudcolor != null)
            {
                int index = CMB_osdcolor.Items.IndexOf(hudcolor);
                CMB_osdcolor.SelectedIndex = index;
            }
            else
            {
                int index = CMB_osdcolor.Items.IndexOf("White");
                CMB_osdcolor.SelectedIndex = index;
            }

            // set distance/speed unit states
            CMB_distunits.DataSource  = Enum.GetNames(typeof(Common.distances));
            CMB_speedunits.DataSource = Enum.GetNames(typeof(Common.speeds));

            if (MainV2.config["distunits"] != null)
            {
                CMB_distunits.Text = MainV2.config["distunits"].ToString();
            }
            if (MainV2.config["speedunits"] != null)
            {
                CMB_speedunits.Text = MainV2.config["speedunits"].ToString();
            }

            // setup language selection
            CultureInfo ci = null;

            foreach (string name in new string[] { "en-US", "zh-Hans", "zh-TW", "ru-RU", "Fr", "Pl", "it-IT", "es-ES" })
            {
                ci = CultureInfoEx.GetCultureInfo(name);
                if (ci != null)
                {
                    languages.Add(ci);
                }
            }

            CMB_language.DisplayMember = "DisplayName";
            CMB_language.DataSource    = languages;
            ci = Thread.CurrentThread.CurrentUICulture;
            for (int i = 0; i < languages.Count; i++)
            {
                if (ci.IsChildOf(languages[i]))
                {
                    CMB_language.SelectedIndex = i;
                    break;
                }
            }
            CMB_language.SelectedIndexChanged += CMB_language_SelectedIndexChanged;

            startup = false;
        }
예제 #8
0
        private static void SetUpCustomSerializations()
        {
            SetUpCustomSerialization <Assembly>((ser, x) =>
            {
                ser.WriteObjectInternal(x.FullName);
            }, des =>
            {
                var name = des.ReadObjectInternal <string>();
                return(AppDomain.CurrentDomain.GetAssemblies().Single(x => x.FullName == name));
            }, RuntimeAssemblyType);

            SetUpCustomSerialization <Type>((ser, x) =>
            {
                ser.WriteObjectInternal(x.Assembly());
                ser.WriteObjectInternal(x.FullName);
            }, des =>
            {
                var asm  = des.ReadObjectInternal <Assembly>();
                var name = des.ReadObjectInternal <string>();
                return(asm.GetType(name, true, false));
            }, RuntimeTypeType);

            SetUpCustomSerialization <EventInfo>((ser, x) =>
            {
                ser.WriteObjectInternal(x.DeclaringType);
                ser.WriteObjectInternal(x.Name);
            }, des =>
            {
                var t    = des.ReadObjectInternal <Type>();
                var name = des.ReadObjectInternal <string>();
                return(t.GetEvent(name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static));
            }, RuntimeEventInfoType);
            SetUpCustomSerialization <MultiValueStringBuilder>((ser, x) =>
            {
                ser.WriteObjectInternal(x.BlockSize, typeof(object));
            }, des =>
            {
                return(new MultiValueStringBuilder(des.ReadObjectInternal <int>()));
            });
            SetUpCustomSerialization <PropertyInfo>((ser, x) =>
            {
                ser.WriteObjectInternal(x.DeclaringType);
                ser.WriteObjectInternal(x.Name);
            }, des =>
            {
                var t    = des.ReadObjectInternal <Type>();
                var name = des.ReadObjectInternal <string>();
                return(t.GetProperty(name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static));
            }, RuntimePropertyInfoType);

            SetUpCustomSerialization <FieldInfo>((ser, x) =>
            {
                ser.WriteObjectInternal(x.DeclaringType);
                ser.WriteObjectInternal(x.Name);
            }, des =>
            {
                var t    = des.ReadObjectInternal <Type>();
                var name = des.ReadObjectInternal <string>();
                return(t.GetField(name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static));
            }, RuntimeFieldInfoType);

            var MonoGenericMethodType = Compatibility.IsMono ? typeof(MethodInfo).Assembly().GetType("System.Reflection.MonoGenericMethod") : null;

            SetUpCustomSerialization <MethodInfo>((ser, m) =>
            {
                ser.WriteObjectInternal(m.DeclaringType);
                ser.WriteObjectInternal(m.Name);
                ser.WriteObjectInternal(m.GetParameters().Select(x => x.ParameterType).ToArray());
                ser.WriteObjectInternal(m.ReturnType);
            }, (des, t) =>
            {
                var declaringType = des.ReadObjectInternal <Type>();
                var name          = des.ReadObjectInternal <string>();
                var parameters    = des.ReadObjectInternal <Type[]>();
                var retval        = des.ReadObjectInternal <Type>();
                var method        = declaringType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance)
                                    .Single(x => x.Name == name && x.ReturnType == retval && x.GetParameters().Select(y => y.ParameterType).SequenceEqual(parameters));
                return(method);
            }, new[] { RuntimeMethodInfoType, MonoGenericMethodType });

#if !STANDALONE
            SetUpCustomSerialization <EntityType>((ser, x) =>
            {
                if (x.NativeType == null)
                {
                    throw new ArgumentException("Only reflected entity types can be serialized.");
                }
                ser.WriteObjectInternal(x.NativeType);
            }, des =>
            {
                var t = des.ReadObjectInternal <Type>();
                return(EntityType.FromNativeType(t));
            });


            SetUpCustomSerialization <Field>((ser, x) =>
            {
                ser.WriteObjectInternal(x.DeclaringType);
                ser.WriteObjectInternal(x.Name);
            }, des =>
            {
                var t    = des.ReadObjectInternal <EntityType>();
                var name = des.ReadObjectInternal <string>();
                return(t.GetFieldByName(name));
            });
#endif

            SetUpCustomSerialization <CultureInfo>((ser, x) =>
            {
                ser.WriteObjectInternal(x.Name);
            }, des =>
            {
                var name = des.ReadObjectInternal <string>();
#if CORECLR
                return(CultureInfoEx.GetCultureInfo(name));
#else
                return(CultureInfo.GetCultureInfo(name));
#endif
            });

            SetUpCustomSerialization <CompareInfo>((ser, x) =>
            {
                ser.WriteObjectInternal(x.Name);
            }, des =>
            {
                var name = des.ReadObjectInternal <string>();
                return(CompareInfo.GetCompareInfo(name));
            });



            SetUpCustomSerialization <Uri>((ser, x) =>
            {
                ser.WriteObjectInternal(x.AbsoluteUri);
            }, des =>
            {
#if STANDALONE
                return(new Uri(des.ReadObjectInternal <string>()));
#else
                return(des.ReadObjectInternal <string>().AsUri());
#endif
            });

            SetUpCustomSerialization <System.Collections.IList>((ser, x) =>
            {
                var elemType = x.GetType().GetGenericArguments()[0];
                ser.WriteObjectInternal(x.Count, typeof(int));
                foreach (var item in x)
                {
                    ser.WriteObjectInternal(item, elemType);
                }
            }, (des, type) =>
            {
                var elemType = type.GetGenericArguments()[0];

                var count = des.ReadObjectInternal <int>();
                var list  = (System.Collections.IList)Activator.CreateInstance(type, new object[] { count });
                for (int i = 0; i < count; i++)
                {
                    list.Add(des.ReadObjectInternal(elemType));
                }
                return(list);
            }, typeof(List <>));



            SetUpCustomSerialization <System.Collections.IDictionary>((ser, x) =>
            {
                var gen       = x.GetType().GetGenericArguments();
                var keyType   = gen[0];
                var valueType = gen[1];
                ser.WriteObjectInternal(x.Count, typeof(int));
                object comparer;
                if (x.GetType().GetGenericTypeDefinition() == typeof(Dictionary <,>))
                {
                    comparer = x.GetFieldOrProperty("Comparer");
                }
                else
                {
                    comparer = x.GetFieldOrProperty("m_comparer");
                }
                var defComparer = typeof(EqualityComparer <>).MakeGenericTypeFast(keyType).GetFieldOrProperty("Default");
                ser.WriteObjectInternal(comparer == defComparer ? null : comparer);

                foreach (System.Collections.DictionaryEntry item in x)
                {
                    ser.WriteObjectInternal(item.Key, keyType);
                    ser.WriteObjectInternal(item.Value, valueType);
                }
            }, (des, type) =>
            {
                var gen       = type.GetGenericArguments();
                var keyType   = gen[0];
                var valueType = gen[1];

                var count    = des.ReadObjectInternal <int>();
                var comparer = des.ReadObjectInternal <object>();

                var defComparer = typeof(EqualityComparer <>).MakeGenericTypeFast(keyType).GetFieldOrProperty("Default");


                var dict = (System.Collections.IDictionary)(type.GetGenericTypeDefinition() == typeof(ConcurrentDictionary <,>)
                    ? type.InvokeFunction(".ctor", 4 * Environment.ProcessorCount, count, comparer ?? defComparer)
                    : type.InvokeFunction(".ctor", count, comparer ?? defComparer)
                                                            );
                for (int i = 0; i < count; i++)
                {
                    var key   = des.ReadObjectInternal(keyType);
                    var value = des.ReadObjectInternal(valueType);
                    dict.Add(key, value);
                }
                return(dict);
            }, new[] { typeof(Dictionary <,>), typeof(ConcurrentDictionary <,>) });



            SetUpCustomSerialization <System.Collections.IEnumerable>((ser, x) =>
            {
                var elemType = x.GetType().GetGenericArguments()[0];
                var count    = (int)x.GetType().GetProperty("Count").GetValue(x);
                ser.WriteObjectInternal(count, typeof(int));

                var comparer    = x.GetType().GetProperty("Comparer").GetValue(x);
                var defComparer = typeof(EqualityComparer <>).MakeGenericTypeFast(elemType).GetProperty("Default", BindingFlags.Public | BindingFlags.Static).GetValue(null);
                ser.WriteObjectInternal(comparer == defComparer ? null : comparer);

                foreach (var item in x)
                {
                    ser.WriteObjectInternal(item, elemType);
                }
            }, (des, type) =>
            {
                var elemType = type.GetGenericArguments()[0];

                var count    = des.ReadObjectInternal <int>();
                var comparer = des.ReadObjectInternal <object>();
                var add      = count != 0 ? type.GetMethod("Add") : null;
                var set      = Activator.CreateInstance(type, comparer != null ? new object[] { comparer } : null);
                for (int i = 0; i < count; i++)
                {
                    var item = des.ReadObjectInternal(elemType);
                    add.Invoke(set, new[] { item });
                }
                return((System.Collections.IEnumerable)set);
            }, typeof(HashSet <>));

#if !STANDALONE
            SetUpCustomSerialization <ListExtractionAttribute>((ser, attr) =>
            {
                ser.WriteObjectInternal(attr.OwnerField);
                ser.WriteObjectInternal(attr.OwnerType);
                ser.WriteObjectInternal(attr.SortOrder, typeof(SortOrder));
                var idx = attr.OwnerField != null ? attr.OwnerField.ListDefinition.IndexOf(attr) : attr.OwnerType.ListDefinition.IndexOf(attr);
                if (idx == -1)
                {
                    throw new Exception("Attribute not found.");
                }
                ser.WriteObjectInternal(idx, typeof(int));
            }, des =>
            {
                var field     = des.ReadObjectInternal <Field>();
                var type      = des.ReadObjectInternal <EntityType>();
                var sortOrder = des.ReadObjectInternal <SortOrder>();
                var idx       = des.ReadObjectInternal <int>();
                var attr      = field != null ? field.ListDefinition.ElementAt(idx) : type.ListDefinition.ElementAt(idx);
                if (attr.SortOrder != sortOrder)
                {
                    throw new Exception("Mismatching attribute during deserialization.");
                }
                return(attr);
            });
#endif

            var CancellationTokenSource_timer = typeof(CancellationTokenSource).GetFields(BindingFlags.Instance | BindingFlags.NonPublic).First(x => x.Name == "timer" || x.Name == "m_timer");

            /*var Timer_due_time_ms = typeof(System.Threading.Timer).GetFields(BindingFlags.NonPublic | BindingFlags.Instance).FirstOrDefault(x => x.Name == "due_time_ms");
             * var Timer_m_timer = typeof(System.Threading.Timer).GetFields(BindingFlags.NonPublic | BindingFlags.Instance).FirstOrDefault(x => x.Name == "m_timer");
             * FieldInfo TimerHolder_h_holder;
             * FieldInfo TimerQueueTimer_m_dueTime;
             * if (Timer_m_timer != null) {
             *  TimerHolder_h_holder = Timer_m_timer.FieldType.
             * }*/

#if !STANDALONE
            SetUpCustomSerialization <SingleThreadSynchronizationContext>((a, b) =>
            {
                Sanity.ShouldntHaveHappened();
            }, b => null);
#endif
            SetUpCustomSerialization <SynchronizationContext>((a, b) =>
            {
                Sanity.ShouldntHaveHappened();
            }, b => null);
            SetUpCustomSerialization <CancellationTokenSource>((ser, x) =>
            {
                var timer         = CancellationTokenSource_timer.GetValue(x);
                var cancRequested = x.IsCancellationRequested;

                ser.WriteObjectInternal(timer != null ? true : cancRequested, typeof(bool));
                if (!cancRequested)
                {
                    if (Compatibility.IsMono)
                    {
                        var callbacks = GetFieldValue <ConcurrentDictionary <CancellationTokenRegistration, Action> >(x, "callbacks");
                        ser.WriteObjectInternal(callbacks != null && callbacks.Count > 0 ? callbacks.Select(y => y.Value).ToList() : null);
                    }
                    else
                    {
                        var callbacks   = GetFieldValue <Array>(x, "m_registeredCallbacksLists");
                        List <Action> l = null;
                        if (callbacks != null)
                        {
                            l = new List <Action>();
                            foreach (var sparse in callbacks)
                            {
                                if (sparse != null)
                                {
                                    var head = GetFieldValue(sparse, "m_head");
                                    foreach (var k in head.RecursiveEnumeration(y => GetFieldValue(y, "m_next")))
                                    {
                                        var elements = GetFieldValue <Array>(k, "m_elements");
                                        if (elements != null)
                                        {
                                            foreach (var el in elements)
                                            {
                                                if (el != null)
                                                {
                                                    var state    = GetFieldValue(el, "StateForCallback");
                                                    var callback = GetFieldValue <Action <object> >(el, "Callback");
                                                    var syncCtx  = GetFieldValue <SynchronizationContext>(el, "TargetSyncContext");
                                                    l.Add(MakeDelegate(callback, state, syncCtx));
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        ser.WriteObjectInternal(l != null && l.Count != 0 ? l : null);
                    }
                }
                else
                {
                    ser.WriteObjectInternal <object>(null);
                }
            }, des =>
            {
                var cancelled     = des.ReadObjectInternal <bool>();
                var registrations = des.ReadObjectInternal <List <Action> >();
                var k             = new CancellationTokenSource();
                if (cancelled)
                {
                    k.Cancel();
                }
                if (registrations != null)
                {
                    foreach (var item in registrations)
                    {
                        item();
                    }
                }
                return(k);
            });
#if !STANDALONE
            SetUpCustomSerialization <EntitySet>((ser, x) =>
            {
                ser.WriteObjectInternal(x.Url.AbsoluteUri);
            }, des =>
            {
                return((EntitySet)AwdeeUrlParser.Parse(des.ReadObjectInternal <string>().AsUri()));
            }, typeof(EntitySet <>));

            SetUpForbiddenType <Shaman.Runtime.DetailSource>();
#endif
        }