Ejemplo n.º 1
0
        public async Task DisconnectAsync()
        {
            if (client != null)
            {
                log.Debug(l => l(LogMessages.Disconnecting, Host));

                Device.Disconnect();
                await disconnected.Task;

                disconnectedTokenSource.Cancel();

                try
                {
                    await processMessagesTask;
                }
                catch (Exception e)
                {
                    if (!(e is OperationCanceledException))
                    {
                        log.Warn(l => l(LogMessages.ProcessMessagesTaskFailed), e);
                    }
                }
                processMessagesTask = null;

                connected    = null;
                disconnected = null;

                Device.Dispose();
                Device = null;
                client.Dispose();
                client = null;
            }
        }
Ejemplo n.º 2
0
 internal SystemSetupPictureModifier(System.IntPtr nativePointer, MTA context) :
     base(nativePointer)
 {
     _nativePointer = nativePointer;
     _handleWrapper = context;
     _data          = (SystemSetupPictureStruct)System.Runtime.InteropServices.Marshal.PtrToStructure(nativePointer, typeof(SystemSetupPictureStruct));
 }
Ejemplo n.º 3
0
        public async Task ConnectAsync(string host, string applicationName, string userName, string password, CancellationToken cancellationToken)
        {
            if (client != null)
            {
                throw new InvalidOperationException();
            }

            log.Debug(l => l(LogMessages.Connecting, userName, host));

            connected    = new TaskCompletionSource <bool>();
            disconnected = new TaskCompletionSource <bool>();

            client = SDK.CreateSDK(applicationName);
            Device = client.CreateMTA();
            Device.NotifyConnectHandlers         = NotifyConnectHandler;
            Device.NotifyConnectionStateHandlers = NotifyConnectionStateHandler;
            Device.Connect(host, userName, password);

            disconnectedTokenSource = new CancellationTokenSource();
            var disconnectedToken = disconnectedTokenSource.Token;

            processMessagesTask = Task.Run(() => ProcessMessages(disconnectedToken), cancellationToken);

            try
            {
                await connected.Task;
            }
            catch (Exception e)
            {
                log.Error(l => l(LogMessages.ConnectFailed), e);
                disconnected.TrySetResult(true);
                DisconnectAsync();
                throw;
            }
        }
Ejemplo n.º 4
0
 internal BeaconDownloadConfigModifier(System.IntPtr nativePointer, MTA context) :
     base(nativePointer)
 {
     _nativePointer = nativePointer;
     _handleWrapper = context;
     _data          = (BeaconDownloadConfigStruct)System.Runtime.InteropServices.Marshal.PtrToStructure(nativePointer, typeof(BeaconDownloadConfigStruct));
 }
Ejemplo n.º 5
0
        public static void LoadNextPacs(string nudFileName, ModelContainer modelContainer)
        {
            // Read pacs to hide meshes.
            string pacDirectory = nudFileName.Replace("model.nud", "");

            if (!Directory.Exists(pacDirectory))
            {
                return;
            }

            string[] pacs = Directory.GetFiles(pacDirectory, "*.pac");
            foreach (string s in pacs)
            {
                PAC p = new PAC();
                p.Read(s);
                byte[] data;
                if (p.Files.TryGetValue("display", out data))
                {
                    MTA m = new MTA();
                    m.read(new FileData(data));
                    modelContainer.NUD.ApplyMta(m, 0);
                }
                if (p.Files.TryGetValue("default.mta", out data))
                {
                    MTA m = new MTA();
                    m.read(new FileData(data));
                    modelContainer.NUD.ApplyMta(m, 0);
                }
            }
        }
Ejemplo n.º 6
0
 internal TransponderModifier(System.IntPtr nativePointer, MTA context) :
     base(nativePointer)
 {
     _nativePointer = nativePointer;
     _handleWrapper = context;
     _data          = (TransponderStruct)System.Runtime.InteropServices.Marshal.PtrToStructure(nativePointer, typeof(TransponderStruct));
     _label         = MylapsSDK.Utilities.SDKHelperFunctions.UTF8ByteArrayToString(_data.label);
 }
Ejemplo n.º 7
0
        internal ChartImage(System.IntPtr nativePointer, MTA context)
        {
            _nativePointer = nativePointer;
            _data          = (ChartImageStruct)System.Runtime.InteropServices.Marshal.PtrToStructure(
                nativePointer, typeof(ChartImageStruct));

            _handleWrapper = context;
        }
Ejemplo n.º 8
0
        internal SequenceSegment(System.IntPtr nativePointer, MTA context)
        {
            _nativePointer = nativePointer;
            _data          = (SequenceSegmentStruct)System.Runtime.InteropServices.Marshal.PtrToStructure(
                nativePointer, typeof(SequenceSegmentStruct));

            _handleWrapper = context;
        }
Ejemplo n.º 9
0
        internal Timezone(System.IntPtr nativePointer, MTA context)
        {
            _nativePointer = nativePointer;
            _data          = (TimezoneStruct)System.Runtime.InteropServices.Marshal.PtrToStructure(
                nativePointer, typeof(TimezoneStruct));

            _handleWrapper = context;
            _name          = MylapsSDK.Utilities.SDKHelperFunctions.UTF8ByteArrayToString(_data.name);
        }
Ejemplo n.º 10
0
 internal SequenceModifier(System.IntPtr nativePointer, MTA context) :
     base(nativePointer)
 {
     _nativePointer = nativePointer;
     _handleWrapper = context;
     _data          = (SequenceStruct)System.Runtime.InteropServices.Marshal.PtrToStructure(nativePointer, typeof(SequenceStruct));
     _name          = MylapsSDK.Utilities.SDKHelperFunctions.UTF8ByteArrayToString(_data.name);
     _description   = MylapsSDK.Utilities.SDKHelperFunctions.UTF8ByteArrayToString(_data.description);
 }
Ejemplo n.º 11
0
        internal static System.Collections.Generic.List <Timezone> FromNativePointerArray(
            System.IntPtr pointerToNativeArray, uint count, MTA context)
        {
            var ptrArray = new System.IntPtr[count];

            System.Runtime.InteropServices.Marshal.Copy(pointerToNativeArray, ptrArray, 0, (int)count);
            return(new System.Collections.Generic.List <Timezone>(
                       System.Array.ConvertAll <System.IntPtr, Timezone>(ptrArray,
                                                                         ptr => new Timezone(ptr, context))));
        }
Ejemplo n.º 12
0
        internal DecoderPresetGroup(System.IntPtr nativePointer, MTA context)
        {
            _nativePointer = nativePointer;
            _data          = (DecoderPresetGroupStruct)System.Runtime.InteropServices.Marshal.PtrToStructure(
                nativePointer, typeof(DecoderPresetGroupStruct));

            _handleWrapper = context;
            _name          = MylapsSDK.Utilities.SDKHelperFunctions.UTF8ByteArrayToString(_data.name);
            _description   = MylapsSDK.Utilities.SDKHelperFunctions.UTF8ByteArrayToString(_data.description);
        }
        private M AddModifier(IntPtr p)
        {
            if (p == IntPtr.Zero)
            {
                throw new MylapsException("failed to create a TransponderGroupModifier");
            }
            var modifier = NewModifier(p);

            MTA.AddModifier(modifier);
            return(modifier);
        }
Ejemplo n.º 14
0
        internal ApplianceContainer(MTA mta, IntPtr mtaHandle)
        {
            _mta       = mta;
            _mtaHandle = mtaHandle;

            _connectionNotifier      = NotifyConnect;
            _connectionStateNotifier = NotifyConnectionState;

            NativeMethods.mta_notify_connect(mtaHandle, _connectionNotifier);
            NativeMethods.mta_notify_connectionstate(mtaHandle, _connectionStateNotifier);
        }
Ejemplo n.º 15
0
        internal TrackSolution(System.IntPtr nativePointer, MTA context)
        {
            _nativePointer = nativePointer;
            _data          = (TrackSolutionStruct)System.Runtime.InteropServices.Marshal.PtrToStructure(
                nativePointer, typeof(TrackSolutionStruct));

            _handleWrapper = context;
            _name          = MylapsSDK.Utilities.SDKHelperFunctions.UTF8ByteArrayToString(_data.name);
            _description   = MylapsSDK.Utilities.SDKHelperFunctions.UTF8ByteArrayToString(_data.description);
            _lapcounters   = MylapsSDK.Utilities.SDKHelperFunctions.UTF8ByteArrayToString(_data.lapcounters);
        }
Ejemplo n.º 16
0
 internal static Competitor FromNativePointer(
     System.IntPtr pointerToNativeStruct, MTA context)
 {
     if (pointerToNativeStruct == System.IntPtr.Zero)
     {
         return(null);
     }
     else
     {
         return(new Competitor(pointerToNativeStruct, context));
     }
 }
Ejemplo n.º 17
0
 internal static SystemSetupPicture FromNativePointer(
     System.IntPtr pointerToNativeStruct, MTA context)
 {
     if (pointerToNativeStruct == System.IntPtr.Zero)
     {
         return(null);
     }
     else
     {
         return(new SystemSetupPicture(pointerToNativeStruct, context));
     }
 }
Ejemplo n.º 18
0
 internal static Timezone FromNativePointer(
     System.IntPtr pointerToNativeStruct, MTA context)
 {
     if (pointerToNativeStruct == System.IntPtr.Zero)
     {
         return(null);
     }
     else
     {
         return(new Timezone(pointerToNativeStruct, context));
     }
 }
Ejemplo n.º 19
0
 internal static Segment FromNativePointer(
     System.IntPtr pointerToNativeStruct, MTA context)
 {
     if (pointerToNativeStruct == System.IntPtr.Zero)
     {
         return(null);
     }
     else
     {
         return(new Segment(pointerToNativeStruct, context));
     }
 }
Ejemplo n.º 20
0
 internal static TrackSolution FromNativePointer(
     System.IntPtr pointerToNativeStruct, MTA context)
 {
     if (pointerToNativeStruct == System.IntPtr.Zero)
     {
         return(null);
     }
     else
     {
         return(new TrackSolution(pointerToNativeStruct, context));
     }
 }
Ejemplo n.º 21
0
 internal static DecoderPresetGroup FromNativePointer(
     System.IntPtr pointerToNativeStruct, MTA context)
 {
     if (pointerToNativeStruct == System.IntPtr.Zero)
     {
         return(null);
     }
     else
     {
         return(new DecoderPresetGroup(pointerToNativeStruct, context));
     }
 }
Ejemplo n.º 22
0
 internal static TransponderGroup FromNativePointer(
     System.IntPtr pointerToNativeStruct, MTA context)
 {
     if (pointerToNativeStruct == System.IntPtr.Zero)
     {
         return(null);
     }
     else
     {
         return(new TransponderGroup(pointerToNativeStruct, context));
     }
 }
Ejemplo n.º 23
0
 internal static BeaconDownloadConfig FromNativePointer(
     System.IntPtr pointerToNativeStruct, MTA context)
 {
     if (pointerToNativeStruct == System.IntPtr.Zero)
     {
         return(null);
     }
     else
     {
         return(new BeaconDownloadConfig(pointerToNativeStruct, context));
     }
 }
Ejemplo n.º 24
0
 internal static IOTerminal FromNativePointer(
     System.IntPtr pointerToNativeStruct, MTA context)
 {
     if (pointerToNativeStruct == System.IntPtr.Zero)
     {
         return(null);
     }
     else
     {
         return(new IOTerminal(pointerToNativeStruct, context));
     }
 }
Ejemplo n.º 25
0
 internal CompetitorModifier(System.IntPtr nativePointer, MTA context) :
     base(nativePointer)
 {
     _nativePointer   = nativePointer;
     _handleWrapper   = context;
     _data            = (CompetitorStruct)System.Runtime.InteropServices.Marshal.PtrToStructure(nativePointer, typeof(CompetitorStruct));
     _number          = MylapsSDK.Utilities.SDKHelperFunctions.UTF8ByteArrayToString(_data.number);
     _firstname       = MylapsSDK.Utilities.SDKHelperFunctions.UTF8ByteArrayToString(_data.firstname);
     _lastname        = MylapsSDK.Utilities.SDKHelperFunctions.UTF8ByteArrayToString(_data.lastname);
     _competitorclass = MylapsSDK.Utilities.SDKHelperFunctions.UTF8ByteArrayToString(_data.competitorclass);
     _imagehash       = MylapsSDK.Utilities.SDKHelperFunctions.UTF8ByteArrayToString(_data.imagehash);
     _guid            = MylapsSDK.Utilities.SDKHelperFunctions.UTF8ByteArrayToString(_data.guid);
 }
Ejemplo n.º 26
0
 internal SystemSetupModifier(System.IntPtr nativePointer, MTA context) :
     base(nativePointer)
 {
     _nativePointer  = nativePointer;
     _handleWrapper  = context;
     _data           = (SystemSetupStruct)System.Runtime.InteropServices.Marshal.PtrToStructure(nativePointer, typeof(SystemSetupStruct));
     _description    = MylapsSDK.Utilities.SDKHelperFunctions.UTF8ByteArrayToString(_data.description);
     _imagehash      = MylapsSDK.Utilities.SDKHelperFunctions.UTF8ByteArrayToString(_data.imagehash);
     _reserved       = MylapsSDK.Utilities.SDKHelperFunctions.UTF8ByteArrayToString(_data.reserved);
     _timezoneid     = MylapsSDK.Utilities.SDKHelperFunctions.UTF8ByteArrayToString(_data.timezoneid);
     _masterhostname = MylapsSDK.Utilities.SDKHelperFunctions.UTF8ByteArrayToString(_data.masterhostname);
     _masterusername = MylapsSDK.Utilities.SDKHelperFunctions.UTF8ByteArrayToString(_data.masterusername);
     _masterpassword = MylapsSDK.Utilities.SDKHelperFunctions.UTF8ByteArrayToString(_data.masterpassword);
 }
Ejemplo n.º 27
0
 internal UserModifier(System.IntPtr nativePointer, MTA context) :
     base(nativePointer)
 {
     _nativePointer = nativePointer;
     _handleWrapper = context;
     _data          = (UserStruct)System.Runtime.InteropServices.Marshal.PtrToStructure(nativePointer, typeof(UserStruct));
     _username      = MylapsSDK.Utilities.SDKHelperFunctions.UTF8ByteArrayToString(_data.username);
     _password      = MylapsSDK.Utilities.SDKHelperFunctions.UTF8ByteArrayToString(_data.password);
     _firstname     = MylapsSDK.Utilities.SDKHelperFunctions.UTF8ByteArrayToString(_data.firstname);
     _lastname      = MylapsSDK.Utilities.SDKHelperFunctions.UTF8ByteArrayToString(_data.lastname);
     _companyname   = MylapsSDK.Utilities.SDKHelperFunctions.UTF8ByteArrayToString(_data.companyname);
     _role          = MylapsSDK.Utilities.SDKHelperFunctions.UTF8ByteArrayToString(_data.role);
     _imagehash     = MylapsSDK.Utilities.SDKHelperFunctions.UTF8ByteArrayToString(_data.imagehash);
     _nickname      = MylapsSDK.Utilities.SDKHelperFunctions.UTF8ByteArrayToString(_data.nickname);
 }
Ejemplo n.º 28
0
        private void NotifyConnectionStateHandler(CONNECTIONSTATE state, MTA sender)
        {
            log.Debug(l => l(LogMessages.ConnectionStateChanged, state));

            switch (state)
            {
            case CONNECTIONSTATE.csConnectFailed:
                Task.Run(() => connected.TrySetException(new X2ConnectFailedException()));
                break;

            case CONNECTIONSTATE.csAuthenticationFailed:
                Task.Run(() => connected.TrySetException(new X2ConnectFailedException(Resources.AuthenticationFailed)));
                break;
            }
        }
        internal TrackSolutionContainer(MTA mta)
        {
            _mta          = mta;
            _nativeHandle = mta.NativeHandle;

            _allTrackSolutionDataAvailable       = false;
            _allTrackSolutionGroupDataAvailable  = false;
            _allSectorDataAvailable              = false;
            _allSequenceDataAvailable            = false;
            _allSequenceSegmentDataAvailable     = false;
            _allTimingConfigurationDataAvailable = false;

            _pfTrackSolutionGroupNotifier = NotifyTrackSolutionGroup;
            _pfTrackSolutionNotifier      = NotifyTrackSolutions;
            _pfSectorNotifier             = NotifySectors;
            _pfSequenceNotifier           = NotifySequences;
            _pfSequenceSegmentNotifier    = NotifySequenceSegments;

            RegisterNotifyDelegate();
        }
Ejemplo n.º 30
0
        private void NotifyConnectHandler(bool newValue, MTA sender)
        {
            isConnected = newValue;
            if (isConnected)
            {
                log.Info(l => l(LogMessages.Connected, Host));
                OnConnected();
            }
            else
            {
                log.Info(l => l(LogMessages.Disconnected));
                OnDisconnected();
            }

            if (isConnected)
            {
                Task.Run(() => connected.TrySetResult(true));
            }
            else
            {
                Task.Run(() => disconnected.TrySetResult(true));
            }
        }