Ejemplo n.º 1
0
        public async Task <IHttpActionResult> ProvisionDevice(string deviceId)
        {
            var info = await _registry.FindAsync(deviceId);

            if (info == null)
            {
                return(NotFound());
            }

            // If the device was revoked, restore it.
            if (info.Status.Equals(DeviceStateConstants.RevokedState, StringComparison.Ordinal))
            {
                await _provisioner.RestoreDeviceAsync(deviceId);
            }

            var token = await _provisioner.GetTokenAsync(deviceId);

            var endpoint = new DeviceEndpoint
            {
                Uri          = _provisioner.EndpointUri.AbsoluteUri,
                EventHubName = _provisioner.EventHubName,
                AccessToken  = token
            };

            // Update registry with new provisioning state.
            info.Status = DeviceStateConstants.ProvisionedState;
            await _registry.AddOrUpdateAsync(info);

            return(Ok(endpoint));
        }
 private static ICommunicationChannel GetChannelFromEndpoint(DeviceEndpoint endpoint)
 {
     if (endpoint is SerialDeviceEndpoint)
     {
         return(new SerialCommunicationChannel(endpoint));
     }
     throw new NotSupportedException("The requested communications method is not supported by the device");
 }
        public static DeviceLayer GetDeviceLayer()
        {
            Log.Info("Composing device layer from connection string: {0}", Settings.Default.ConnectionString);
            var endpoint = DeviceEndpoint.FromConnectionString(Settings.Default.ConnectionString);
            var channel  = GetChannelFromEndpoint(endpoint);
            var device   = new DeviceLayer(channel);

            return(device);
        }
 public static ICommunicationChannel BuildChannel(DeviceEndpoint endpoint)
 {
     if (endpoint is SerialDeviceEndpoint)
     {
         return(new SerialCommunicationChannel(endpoint));
     }
     throw new NotSupportedException($"There is no supported channel type for the endpoint: {endpoint}")
           {
               Data = { ["endpoint"] = endpoint }
           };
 }
 /// <summary>
 ///     Creates the transaction processor ready for use. Also creates and initialises the
 ///     device endpoint and the communications channel and opens the channel.
 /// </summary>
 /// <returns>ITransactionProcessor.</returns>
 public ITransactionProcessor CreateTransactionProcessor()
 {
     Endpoint  = DeviceEndpoint.FromConnectionString(ConnectionString);
     Channel   = CommunicationsStackBuilder.BuildChannel(Endpoint);
     observer  = new TransactionObserver(Channel);
     processor = new ReactiveTransactionProcessor();
     processor.SubscribeTransactionObserver(observer, TimeSpan.FromMilliseconds(100));
     Channel.Open();
     //Task.Delay(TimeSpan.FromSeconds(2)).Wait(); // Arduino needs 2 seconds to initialize
     Thread.Sleep(TimeSpan.FromSeconds(3));
     return(processor);
 }
Ejemplo n.º 6
0
 private void InitializeEndpoints()
 {
     Cards = new CardEndpoint(this);
     CustomerStatements   = new CustomerStatementEndpoint(this);
     Devices              = new DeviceEndpoint(this);
     DeviceServers        = new DeviceServerEndpoint(this);
     Installations        = new InstallationEndpoint(this);
     Invoices             = new InvoiceEndpoint(this);
     MonetaryAccountBanks = new MonetaryAccountBankEndpoint(this);
     Payments             = new PaymentEndpoint(this);
     Sessions             = new SessionEndpoint(this);
 }
 public ReactiveTransactionProcessorFactory(string connectionString)
 {
     this.ConnectionString = connectionString;
     // Endpoint will be InvalidEndpoint if the connection string is invalid.
     Endpoint = DeviceEndpoint.FromConnectionString(connectionString);
 }
Ejemplo n.º 8
0
 public UnitTestChannel(DeviceEndpoint endpoint)
 {
     Endpoint = endpoint;
 }
Ejemplo n.º 9
0
        private string TalkWithAxis(AXISID axis, char cmd, string cmdDataStr)
        {
            string         response = string.Empty;
            DeviceEndpoint endPoint = SerialDeviceEndpoint.FromConnectionString(ConnectionString);

            const int     BufferSize = 20;
            StringBuilder sb         = new StringBuilder(BufferSize);

            sb.Append(cStartChar_Out);           // 0: Leading char
            sb.Append(cmd);                      // 1: Length of command( Source, distination, command char, data )

            // Target Device
            sb.Append(((int)axis + 1).ToString()); // 2: Target Axis
                                                   // Copy command data to buffer
            sb.Append(cmdDataStr);

            sb.Append(cEndChar); // CR Character

            string cmdString = sb.ToString();


            var cmdTransaction = new EQTransaction(cmdString)
            {
                Timeout = TimeSpan.FromSeconds(TimeOut)
            };


            using (ICommunicationChannel channel = new SerialCommunicationChannel(endPoint))
                using (var processor = new ReactiveTransactionProcessor())
                {
                    var transactionObserver = new TransactionObserver(channel);
                    processor.SubscribeTransactionObserver(transactionObserver);
                    try
                    {
                        channel.Open();

                        // prepare to communicate
                        for (int i = 0; i < Retry; i++)
                        {
                            Task.Run(() => processor.CommitTransaction(cmdTransaction));
                            cmdTransaction.WaitForCompletionOrTimeout();
                            if (!cmdTransaction.Failed)
                            {
                                response = cmdTransaction.Value;
                                break;
                            }
                            else
                            {
                                Trace.TraceError(cmdTransaction.ErrorMessage.Single());
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError("Connnection Lost");
                        throw new Exception("AstroEQ not responding", ex);
                    }
                    finally
                    {
                        // To clean up, we just need to dispose the TransactionObserver and the channel is closed automatically.
                        // Not strictly necessary, but good practice.
                        transactionObserver.OnCompleted(); // There will be no more transactions.
                        transactionObserver = null;        // not necessary, but good practice.
                        endPoint            = null;
                    }
                }
            return(response);
        }
Ejemplo n.º 10
0
 public void AddEndpoint(DeviceEndpoint endpoint)
 {
     Endpoints.Add(endpoint);
     ShowNoResultsMessage = false;
 }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            // Uncomment this line of code to allow for debugging
            while (!System.Diagnostics.Debugger.IsAttached)
            {
                System.Threading.Thread.Sleep(100);
            }

            // Test Bed
            //SpeakerMode.SpeakerModeExternal; //Possibly SPDIF out?
            //SpeakerMode.SpeakerModeHeadPhone; //Possible headset out?


            ManagementObjectSearcher objSearcher = new ManagementObjectSearcher(
                "SELECT * FROM Win32_SoundDevice");

            ManagementObjectCollection objCollection = objSearcher.Get();

            ManagementObject soundblaster = null;

            foreach (ManagementObject obj in objCollection)
            {
                foreach (PropertyData property in obj.Properties)
                {
                    Console.Out.WriteLine(String.Format("{0}:{1}", property.Name, property.Value));

                    if (property.Name.Equals("Name") && property.Value.ToString().Contains("Sound Blaster"))
                    {
                        soundblaster = obj;
                    }
                }
            }

            Creative.Platform.Devices.Models.DeviceManager dm = DeviceManager.Instance;
            //.Collections.Concurrent.ConcurrentDictionary<string, DeviceEndpoint> des = dm.MixerDiscoveredDeviceEndpoints;
            //DeviceEndpoint mixerDevice = dm.GetMixerDeviceEndpoints(new Device {d });

            //  Define an IMM Device
            Creative.Platform.CoreAudio.Interfaces.IMMDeviceEnumerator imde = (Creative.Platform.CoreAudio.Interfaces.IMMDeviceEnumerator) new Creative.Platform.CoreAudio.Classes.MMDeviceEnumerator();

            IMMDevice imd = null;

            foreach (DeviceEndpoint de in dm.MixerDiscoveredDeviceEndpoints.Values)
            {
                int device_id = imde.GetDevice(de.DeviceEndpointId, out imd);
                if (imd != null)
                {
                    break;
                }
            }


            //  Generate a DeviceEndpoint
            DefaultDeviceEndpointFactory ddef = new Creative.Platform.Devices.Models.DefaultDeviceEndpointFactory();
            DeviceEndpoint dep = ddef.CreateDeviceEndPoint(imd);

            List <IDeviceRepository> dev_reps = dep.GetDeviceRepositories();

            //  Create the SoundCore
            //Creative.Platform.Devices.Features.SoundCore.SoundCoreRepository scr =
            Creative.Platform.Devices.Features.Apo.ApoInfoWrapper      aiw = new Creative.Platform.Devices.Features.Apo.ApoInfoWrapper(dep);
            Creative.Platform.Devices.Features.Apo.ApoFeatureChecker   apc = new Creative.Platform.Devices.Features.Apo.ApoFeatureChecker(aiw);
            Creative.Platform.Devices.Features.Apo.PropStoreRepository psr = new Creative.Platform.Devices.Features.Apo.PropStoreRepository(dep.DeviceEndpointId, apc);

            IPropertyStore properties;

            imd.OpenPropertyStore(0u, out properties);
            CDCDeviceRepositoryInitializer cdcri = new CDCDeviceRepositoryInitializer();

            cdcri.Initialize(dep, properties);

            psr.GetSpeakerConfig();

            //Creative.Platform.Devices.Features.SpeakerConfigs.SpeakerConfigService scs = new SpeakerConfigService(dep);
            //Creative.Platform.Devices.Features.SpeakerConfigs.SoundCoreSpeakerConfigFeature scsrf = new SoundCoreSpeakerConfigFeature(dep,,, scs);

            //Creative.Platform.Devices.Features.SoundCore.SoundCoreRepository scr = new Creative.Platform.Devices.Features.SoundCore.SoundCoreRepository()

            try
            {
                psr.SetSpeakerConfig((int)SpeakerMode.SpeakerModeHeadPhone);
            }
            catch (Exception e)
            {
            }
            //scr.SetSpeakerConfig((int)SpeakerMode.SpeakerModeHeadPhone);

            //SDWrapper.Run(args);
        }