Esempio n. 1
0
 private void SetGroupPriorities(SimConnectzmo sc)
 {
     foreach (GROUP?group in Enum.GetValues(typeof(GROUP)))
     {
         var attr = group !.GetAttribute <GroupAttribute>();
         sc.SetNotificationGroupPriority(group, attr.Priority);
     }
 }
Esempio n. 2
0
        private void OnRecvOpen(SimConnect simConnect, SIMCONNECT_RECV_OPEN data)
        {
            SimConnectzmo sc = (simConnect as SimConnectzmo) !;

            RegisterDataStructs(sc);
            MapClientEvents(sc);
            SetGroupPriorities(sc);

            foreach (IRequestDataOnOpen request in sc.typeToRequest !.Keys
                     .Where(candidate => candidate is IRequestDataOnOpen)
                     .Select(data => (IRequestDataOnOpen)data))
            {
                simConnect.RequestDataOnSimObject(request as IDataListener, request.GetInitialRequestPeriod());
            }
        }
Esempio n. 3
0
        private void MapClientEvents(SimConnectzmo sc)
        {
            foreach (var e in Enum.GetValues(typeof(EVENT)).OfType <EVENT>())
            {
                sc.MapClientEventToSimEvent(e, e.GetAttribute <EventAttribute>().ClientEvent);
            }
            foreach (var eventToEnum in sc.eventToEnum !)
            {
                sc.MapClientEventToSimEvent(eventToEnum.Value, eventToEnum.Key.SimEvent());
            }

            foreach (var notificationToEvent in sc.notificationsToEvent !)
            {
                sc.AddClientEventToNotificationGroup(notificationToEvent.Key.GetGroup(), notificationToEvent.Value, true);
            }
        }
Esempio n. 4
0
 private void RegisterDataStructs(SimConnectzmo sc)
 {
     foreach (var type2Struct in sc.typeToStruct !)
     {
         foreach (FieldInfo field in type2Struct.Key.GetFields())
         {
             var dataField = field.GetCustomAttribute <SCStructFieldAttribute>();
             if (dataField == null)
             {
                 throw new NullReferenceException($"No DataField for {type2Struct.Key}.{field.Name}");
             }
             sc.AddToDataDefinition(type2Struct.Value, dataField.Variable, dataField.Units,
                                    dataField.Type, dataField.Epsilon, SimConnect.SIMCONNECT_UNUSED);
         }
         sc.GetType().GetMethod("RegisterDataDefineStruct") !.MakeGenericMethod(type2Struct.Key)
         .Invoke(scHolder.SimConnect, new object[] { type2Struct.Value });
     }
 }
Esempio n. 5
0
        private void AssignIds(SimConnectzmo simConnect)
        {
            simConnect.typeToStruct = serviceProvider.GetServices <IData>()
                                      .Select(candidate => candidate.GetStructType())
                                      .Distinct()
                                      .Select((structType, index) => new ValueTuple <Type, STRUCT>(structType, (STRUCT)(index + 1)))
                                      .ToDictionary(tuple => tuple.Item1, tuple => tuple.Item2);

            simConnect.typeToRequest = serviceProvider.GetServices <IDataListener>()
                                       .Select((request, index) => new ValueTuple <IDataListener, REQUEST>(request, (REQUEST)(index + 1)))
                                       .ToDictionary(tuple => tuple.Item1, tuple => tuple.Item2);
            //TODO: check that the struct is also registered

            int maxEvent = Enum.GetValues(typeof(EVENT)).Cast <int>().Max();

            simConnect.eventToEnum = serviceProvider.GetServices <IEvent>()
                                     .Select((e, index) => new ValueTuple <IEvent, EVENT>(e, (EVENT)(index + maxEvent + 1)))
                                     .ToDictionary(tuple => tuple.Item1, tuple => tuple.Item2);

            simConnect.notificationsToEvent = serviceProvider.GetServices <IEventNotification>()
                                              .ToDictionary(en => en, en => simConnect.eventToEnum[en.GetEvent()]);
        }