Example #1
0
 /// <summary>
 ///     Returns the corresponding PathDisplayAdapter instance
 /// </summary>
 /// <returns>An instance of PathDisplayAdapter, or null</returns>
 public PathDisplayAdapter ToPathDisplayAdapter()
 {
     return(PathDisplayAdapter.GetAdapters()
            .FirstOrDefault(adapter =>
                            adapter.DevicePath.StartsWith("\\\\?\\" + DevicePath.Replace("\\", "#"))
                            ));
 }
Example #2
0
 public UsbConnection(DeviceInformation deviceInfo)
 {
     UpdateRate = 1000;
     DevicePath = deviceInfo.Id;
     Serial     = DevicePath.Split('#')[2];
     Name       = deviceInfo.Name;
 }
Example #3
0
        public PathTarget(PathTargetInfo targetInfo, SurroundTopology surround = null)
        {
            DevicePath = targetInfo.DisplayTarget.DevicePath;
            var index = DevicePath.IndexOf("{", StringComparison.InvariantCultureIgnoreCase);

            if (index > 0)
            {
                DevicePath = DevicePath.Substring(0, index).TrimEnd('#');
            }

            FrequencyInMillihertz = targetInfo.FrequencyInMillihertz;
            Rotation         = targetInfo.Rotation.ToRotation();
            Scaling          = targetInfo.Scaling.ToScaling();
            ScanLineOrdering = targetInfo.ScanLineOrdering.ToScanLineOrdering();

            try
            {
                DisplayName = targetInfo.DisplayTarget.FriendlyName;
            }
            catch
            {
                DisplayName = null;
            }

            SurroundTopology = surround ?? SurroundTopology.FromPathTargetInfo(targetInfo);
        }
 /// <summary>
 /// The Get Dedicated Circuit Peering Routing Information operation
 /// retrieves the ARP information for specific BGP.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.ExpressRoute.IDedicatedCircuitPeeringRoutingInfoOperations.
 /// </param>
 /// <param name='serviceKey'>
 /// Required. The service key representing the circuit.
 /// </param>
 /// <param name='accessType'>
 /// Required. Whether the peering is private or public or microsoft.
 /// </param>
 /// <param name='devicePath'>
 /// Required. Whether the device is primary or secondary.
 /// </param>
 /// <returns>
 /// The Get Dedicated Circuit Peering Route Table Info operation
 /// response.
 /// </returns>
 public static DedicatedCircuitPeeringRoutingInfoGetResponse Get(this IDedicatedCircuitPeeringRoutingInfoOperations operations, string serviceKey, BgpPeeringAccessType accessType, DevicePath devicePath)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IDedicatedCircuitPeeringRoutingInfoOperations)s).GetAsync(serviceKey, accessType, devicePath);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
Example #5
0
        public override int GetHashCode()
        {
            if (DevicePath == null)
            {
                return(0);
            }

            return(DevicePath.GetHashCode());
        }
Example #6
0
        internal IEnumerable <DisplayDevice> GetDisplayDevices(bool?filterByValidity)
        {
            var device   = Native.DeviceContext.Structures.DisplayDevice.Initialize();
            var returned = new Dictionary <string, string>();

            for (uint i = 0; DeviceContextApi.EnumDisplayDevices(null, i, ref device, 0); i++)
            {
                if (DevicePath.Equals(device.DeviceId))
                {
                    DisplayDevice displayDevice = null;
                    var           display       = Native.DeviceContext.Structures.DisplayDevice.Initialize();
                    for (uint id = 0; DeviceContextApi.EnumDisplayDevices(device.DeviceName, id, ref display, 1); id++)
                    {
                        var isAttached = display.StateFlags.HasFlag(DisplayDeviceStateFlags.AttachedToDesktop);
                        if (!filterByValidity.HasValue)
                        {
                            yield return(DisplayDevice.FromDeviceInformation(this, device, display));
                        }
                        else if (filterByValidity.Value && isAttached)
                        {
                            if (!returned.ContainsKey(display.DeviceId) ||
                                !returned[display.DeviceId].Equals(display.DeviceKey))
                            {
                                returned.Add(display.DeviceId, display.DeviceKey);
                                yield return(DisplayDevice.FromDeviceInformation(this, device, display));

                                break;
                            }
                        }
                        else if (!filterByValidity.Value)
                        {
                            if (!isAttached)
                            {
                                if (!returned.ContainsKey(display.DeviceId) ||
                                    !returned[display.DeviceId].Equals(display.DeviceKey))
                                {
                                    displayDevice = DisplayDevice.FromDeviceInformation(this, device, display);
                                }
                            }
                            else
                            {
                                displayDevice = null;
                                break;
                            }
                        }
                        display = Native.DeviceContext.Structures.DisplayDevice.Initialize();
                    }
                    if (displayDevice != null)
                    {
                        returned.Add(displayDevice.DevicePath, displayDevice.DeviceKey);
                        yield return(displayDevice);
                    }
                }
                device = Native.DeviceContext.Structures.DisplayDevice.Initialize();
            }
        }
Example #7
0
        internal IEnumerable <DisplayDevice> GetDisplayDevices(bool?filterByAvailability)
        {
            var returned = new Dictionary <string, string>();

            var adapterIndex = -1;

            while (true)
            {
                adapterIndex++;
                var adapter = Native.DeviceContext.Structures.DisplayDevice.Initialize();

                if (!DeviceContextApi.EnumDisplayDevices(null, (uint)adapterIndex, ref adapter, 0))
                {
                    break;
                }

                if (!DevicePath.Equals(adapter.DeviceId))
                {
                    continue;
                }

                var displayIndex = -1;

                while (true)
                {
                    displayIndex++;
                    var display = Native.DeviceContext.Structures.DisplayDevice.Initialize();

                    if (!DeviceContextApi.EnumDisplayDevices(adapter.DeviceName, (uint)displayIndex, ref display, 1))
                    {
                        break;
                    }

                    var displayDevice = DisplayDevice.FromDeviceInformation(this, adapter, display);

                    if (!filterByAvailability.HasValue)
                    {
                        yield return(displayDevice);
                    }
                    else if (displayDevice.IsAvailable == filterByAvailability.Value)
                    {
                        if (returned.ContainsKey(display.DeviceId) &&
                            returned[display.DeviceId].Equals(display.DeviceKey)
                            )
                        {
                            continue;
                        }

                        returned.Add(display.DeviceId, display.DeviceKey);

                        yield return(displayDevice);
                    }
                }
            }
        }
Example #8
0
 /// <summary>
 /// Convert an enum of type DevicePath to a string.
 /// </summary>
 /// <param name='value'>
 /// The value to convert to a string.
 /// </param>
 /// <returns>
 /// The enum value as a string.
 /// </returns>
 internal static string DevicePathToString(DevicePath value)
 {
     if (value == DevicePath.Primary)
     {
         return("primary");
     }
     if (value == DevicePath.Secondary)
     {
         return("secondary");
     }
     throw new ArgumentOutOfRangeException("value");
 }
 /// <inheritdoc />
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = FrequencyInMillihertz.GetHashCode();
         hashCode = (hashCode * 397) ^ (int)Rotation;
         hashCode = (hashCode * 397) ^ (int)Scaling;
         hashCode = (hashCode * 397) ^ (int)ScanLineOrdering;
         hashCode = (hashCode * 397) ^ DevicePath.GetHashCode();
         hashCode = (hashCode * 397) ^ SurroundTopology?.GetHashCode() ?? 0;
         return(hashCode);
     }
 }
 /// <summary>
 /// The Get Dedicated Circuit Peering Routing Information operation
 /// retrieves the ARP information for specific BGP.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.ExpressRoute.IDedicatedCircuitPeeringRoutingInfoOperations.
 /// </param>
 /// <param name='serviceKey'>
 /// Required. The service key representing the circuit.
 /// </param>
 /// <param name='accessType'>
 /// Required. Whether the peering is private or public or microsoft.
 /// </param>
 /// <param name='devicePath'>
 /// Required. Whether the device is primary or secondary.
 /// </param>
 /// <returns>
 /// The Get Dedicated Circuit Peering Route Table Info operation
 /// response.
 /// </returns>
 public static Task<DedicatedCircuitPeeringRoutingInfoGetResponse> GetAsync(this IDedicatedCircuitPeeringRoutingInfoOperations operations, string serviceKey, BgpPeeringAccessType accessType, DevicePath devicePath)
 {
     return operations.GetAsync(serviceKey, accessType, devicePath, CancellationToken.None);
 }
        /// <summary>
        /// The Get Dedicated Circuit Peering routeTableSummary operation
        /// retrieves the ARP information for specific BGP.
        /// </summary>
        /// <param name='serviceKey'>
        /// Required. The service key representing the circuit.
        /// </param>
        /// <param name='accessType'>
        /// Required. Whether the peering is private or public or microsoft.
        /// </param>
        /// <param name='devicePath'>
        /// Required. Whether the device is primary or secondary.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// The Get Dedicated Circuit Peering Routing Summary operation
        /// response.
        /// </returns>
        public async Task <DedicatedCircuitPeeringRoutingSummaryGetResponse> GetAsync(string serviceKey, BgpPeeringAccessType accessType, DevicePath devicePath, CancellationToken cancellationToken)
        {
            // Validate
            if (serviceKey == null)
            {
                throw new ArgumentNullException("serviceKey");
            }

            // Tracing
            bool   shouldTrace  = TracingAdapter.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = TracingAdapter.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("serviceKey", serviceKey);
                tracingParameters.Add("accessType", accessType);
                tracingParameters.Add("devicePath", devicePath);
                TracingAdapter.Enter(invocationId, this, "GetAsync", tracingParameters);
            }

            // Construct URL
            string url = "";

            url = url + "/";
            if (this.Client.Credentials.SubscriptionId != null)
            {
                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
            }
            url = url + "/services/networking/dedicatedcircuits/";
            url = url + Uri.EscapeDataString(serviceKey);
            url = url + "/bgppeerings/";
            url = url + Uri.EscapeDataString(ExpressRouteManagementClient.BgpPeeringAccessTypeToString(accessType));
            url = url + "/routeTableSummary/";
            url = url + Uri.EscapeDataString(ExpressRouteManagementClient.DevicePathToString(devicePath));
            List <string> queryParameters = new List <string>();

            queryParameters.Add("api-version=1.0");
            if (queryParameters.Count > 0)
            {
                url = url + "?" + string.Join("&", queryParameters);
            }
            string baseUrl = this.Client.BaseUri.AbsoluteUri;

            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;

            try
            {
                httpRequest            = new HttpRequestMessage();
                httpRequest.Method     = HttpMethod.Get;
                httpRequest.RequestUri = new Uri(url);

                // Set Headers
                httpRequest.Headers.Add("x-ms-version", "2011-10-01");

                // Set Credentials
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                // Send Request
                HttpResponseMessage httpResponse = null;
                try
                {
                    if (shouldTrace)
                    {
                        TracingAdapter.SendRequest(invocationId, httpRequest);
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                    if (shouldTrace)
                    {
                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode != HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
                        if (shouldTrace)
                        {
                            TracingAdapter.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    DedicatedCircuitPeeringRoutingSummaryGetResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                        result = new DedicatedCircuitPeeringRoutingSummaryGetResponse();
                        XDocument responseDoc = XDocument.Parse(responseContent);

                        XElement dedicatedCircuitPeeringRoutingSummaryElement = responseDoc.Element(XName.Get("DedicatedCircuitPeeringRoutingSummary", "http://schemas.microsoft.com/windowsazure"));
                        if (dedicatedCircuitPeeringRoutingSummaryElement != null)
                        {
                            AzureDedicatedCircuitPeeringRoutingInfo dedicatedCircuitPeeringRoutingInfoInstance = new AzureDedicatedCircuitPeeringRoutingInfo();
                            result.DedicatedCircuitPeeringRoutingInfo = dedicatedCircuitPeeringRoutingInfoInstance;

                            XElement networkElement = dedicatedCircuitPeeringRoutingSummaryElement.Element(XName.Get("Network", "http://schemas.microsoft.com/windowsazure"));
                            if (networkElement != null)
                            {
                                string networkInstance = networkElement.Value;
                                dedicatedCircuitPeeringRoutingInfoInstance.Network = networkInstance;
                            }

                            XElement nextHopElement = dedicatedCircuitPeeringRoutingSummaryElement.Element(XName.Get("NextHop", "http://schemas.microsoft.com/windowsazure"));
                            if (nextHopElement != null)
                            {
                                string nextHopInstance = nextHopElement.Value;
                                dedicatedCircuitPeeringRoutingInfoInstance.NextHop = nextHopInstance;
                            }

                            XElement locPrfElement = dedicatedCircuitPeeringRoutingSummaryElement.Element(XName.Get("LocPrf", "http://schemas.microsoft.com/windowsazure"));
                            if (locPrfElement != null)
                            {
                                string locPrfInstance = locPrfElement.Value;
                                dedicatedCircuitPeeringRoutingInfoInstance.LocPrf = locPrfInstance;
                            }

                            XElement weightElement = dedicatedCircuitPeeringRoutingSummaryElement.Element(XName.Get("Weight", "http://schemas.microsoft.com/windowsazure"));
                            if (weightElement != null)
                            {
                                int weightInstance = int.Parse(weightElement.Value, CultureInfo.InvariantCulture);
                                dedicatedCircuitPeeringRoutingInfoInstance.Weight = weightInstance;
                            }

                            XElement pathElement = dedicatedCircuitPeeringRoutingSummaryElement.Element(XName.Get("Path", "http://schemas.microsoft.com/windowsazure"));
                            if (pathElement != null)
                            {
                                string pathInstance = pathElement.Value;
                                dedicatedCircuitPeeringRoutingInfoInstance.Path = pathInstance;
                            }
                        }
                    }
                    result.StatusCode = statusCode;
                    if (httpResponse.Headers.Contains("x-ms-request-id"))
                    {
                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
                    }

                    if (shouldTrace)
                    {
                        TracingAdapter.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }
 /// <summary>
 /// The Get Dedicated Circuit Peering Routing Information operation
 /// retrieves the ARP information for specific BGP.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.ExpressRoute.IDedicatedCircuitPeeringRoutingInfoOperations.
 /// </param>
 /// <param name='serviceKey'>
 /// Required. The service key representing the circuit.
 /// </param>
 /// <param name='accessType'>
 /// Required. Whether the peering is private or public or microsoft.
 /// </param>
 /// <param name='devicePath'>
 /// Required. Whether the device is primary or secondary.
 /// </param>
 /// <returns>
 /// The Get Dedicated Circuit Peering Route Table Info operation
 /// response.
 /// </returns>
 public static Task <DedicatedCircuitPeeringRoutingInfoGetResponse> GetAsync(this IDedicatedCircuitPeeringRoutingInfoOperations operations, string serviceKey, BgpPeeringAccessType accessType, DevicePath devicePath)
 {
     return(operations.GetAsync(serviceKey, accessType, devicePath, CancellationToken.None));
 }
 /// <summary>
 /// The Get DedicatedCircuitPeeringRouteTableSummary operation retrives
 /// RouteTableSummary.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.ExpressRoute.IDedicatedCircuitPeeringRouteTableSummaryOperations.
 /// </param>
 /// <param name='serviceKey'>
 /// Required. The service key representing the circuit.
 /// </param>
 /// <param name='accessType'>
 /// Required. Whether the peering is private or public or microsoft.
 /// </param>
 /// <param name='devicePath'>
 /// Required. Whether the device is primary or secondary.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static Task<ExpressRouteOperationResponse> BeginGetAsync(this IDedicatedCircuitPeeringRouteTableSummaryOperations operations, string serviceKey, BgpPeeringAccessType accessType, DevicePath devicePath)
 {
     return operations.BeginGetAsync(serviceKey, accessType, devicePath, CancellationToken.None);
 }
 /// <summary>
 /// The Get DedicatedCircuitPeeringRouteTableInfo operation retrives
 /// RouteTable.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.ExpressRoute.IDedicatedCircuitPeeringRouteTableInfoOperations.
 /// </param>
 /// <param name='serviceKey'>
 /// Required. The service key representing the circuit.
 /// </param>
 /// <param name='accessType'>
 /// Required. Whether the peering is private or public or microsoft.
 /// </param>
 /// <param name='devicePath'>
 /// Required. Whether the device is primary or secondary.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static ExpressRouteOperationResponse BeginGet(this IDedicatedCircuitPeeringRouteTableInfoOperations operations, string serviceKey, BgpPeeringAccessType accessType, DevicePath devicePath)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IDedicatedCircuitPeeringRouteTableInfoOperations)s).BeginGetAsync(serviceKey, accessType, devicePath);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
 public string GetAzureDedicatedCircuitPeeringRouteTableSummary(Guid serviceKey, BgpPeeringAccessType accessType, DevicePath devicePath)
 {
     return(Client.DedicatedCircuitPeeringRouteTableSummary.Get(serviceKey.ToString(), accessType, devicePath).Data.ToString());
 }
 /// <inheritdoc/>
 public override int GetHashCode()
 {
     return(DevicePath.GetHashCode());
 }
        /// <summary>
        /// The Get DedicatedCircuitPeeringArpInfo operation retrives ARP Table.
        /// </summary>
        /// <param name='serviceKey'>
        /// Required. The service key representing the circuit.
        /// </param>
        /// <param name='accessType'>
        /// Required. Whether the peering is private or public or microsoft.
        /// </param>
        /// <param name='devicePath'>
        /// Required. Whether the device is primary or secondary.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// The response body contains the status of the specified asynchronous
        /// operation, indicating whether it has succeeded, is inprogress, or
        /// has failed. Note that this status is distinct from the HTTP status
        /// code returned for the Get Operation Status operation itself.  If
        /// the asynchronous operation succeeded, the response body includes
        /// the HTTP status code for the successful request.  If the
        /// asynchronous operation failed, the response body includes the HTTP
        /// status code for the failed request, and also includes error
        /// information regarding the failure.
        /// </returns>
        public async Task <ExpressRouteOperationStatusResponse> GetAsync(string serviceKey, BgpPeeringAccessType accessType, DevicePath devicePath, CancellationToken cancellationToken)
        {
            ExpressRouteManagementClient client = this.Client;
            bool   shouldTrace  = TracingAdapter.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = TracingAdapter.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("serviceKey", serviceKey);
                tracingParameters.Add("accessType", accessType);
                tracingParameters.Add("devicePath", devicePath);
                TracingAdapter.Enter(invocationId, this, "GetAsync", tracingParameters);
            }

            cancellationToken.ThrowIfCancellationRequested();
            ExpressRouteOperationResponse response = await client.DedicatedCircuitPeeringArpInfo.BeginGetAsync(serviceKey, accessType, devicePath, cancellationToken).ConfigureAwait(false);

            cancellationToken.ThrowIfCancellationRequested();
            ExpressRouteOperationStatusResponse result = await client.DedicatedCircuitPeeringArpInfo.GetOperationStatusAsync(response.OperationId, cancellationToken).ConfigureAwait(false);

            int delayInSeconds = 30;

            if (client.LongRunningOperationInitialTimeout >= 0)
            {
                delayInSeconds = client.LongRunningOperationInitialTimeout;
            }
            while (result.Status == ExpressRouteOperationStatus.InProgress)
            {
                cancellationToken.ThrowIfCancellationRequested();
                await TaskEx.Delay(delayInSeconds * 1000, cancellationToken).ConfigureAwait(false);

                cancellationToken.ThrowIfCancellationRequested();
                result = await client.DedicatedCircuitPeeringArpInfo.GetOperationStatusAsync(response.OperationId, cancellationToken).ConfigureAwait(false);

                delayInSeconds = 30;
                if (client.LongRunningOperationRetryTimeout >= 0)
                {
                    delayInSeconds = client.LongRunningOperationRetryTimeout;
                }
            }

            if (shouldTrace)
            {
                TracingAdapter.Exit(invocationId, result);
            }

            if (result.Status != ExpressRouteOperationStatus.Successful)
            {
                if (result.Error != null)
                {
                    CloudException ex = new CloudException(result.Error.Code + " : " + result.Error.Message);
                    ex.Error         = new CloudError();
                    ex.Error.Code    = result.Error.Code;
                    ex.Error.Message = result.Error.Message;
                    if (shouldTrace)
                    {
                        TracingAdapter.Error(invocationId, ex);
                    }
                    throw ex;
                }
                else
                {
                    CloudException ex = new CloudException("");
                    if (shouldTrace)
                    {
                        TracingAdapter.Error(invocationId, ex);
                    }
                    throw ex;
                }
            }

            return(result);
        }
 /// <summary>
 /// The Get DedicatedCircuitPeeringRouteTableInfo operation retrives
 /// RouteTable.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.ExpressRoute.IDedicatedCircuitPeeringRouteTableInfoOperations.
 /// </param>
 /// <param name='serviceKey'>
 /// Required. The service key representing the circuit.
 /// </param>
 /// <param name='accessType'>
 /// Required. Whether the peering is private or public or microsoft.
 /// </param>
 /// <param name='devicePath'>
 /// Required. Whether the device is primary or secondary.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static Task <ExpressRouteOperationResponse> BeginGetAsync(this IDedicatedCircuitPeeringRouteTableInfoOperations operations, string serviceKey, BgpPeeringAccessType accessType, DevicePath devicePath)
 {
     return(operations.BeginGetAsync(serviceKey, accessType, devicePath, CancellationToken.None));
 }
Example #19
0
        bool TryConnectDeviceWithSN()
        {
            bool?result       = null;
            bool resultb      = false;
            int  device_count = 0;
            int  size         = 0;
            int  requiredSize = 0;

            DevicePath = string.Empty;

            // Get the GUID of the HID device Class
            myUSB.CT_HidGuid();

            // Get the device information set
            myUSB.CT_SetupDiGetClassDevs();

            // Reset the IsConnected to false
            this.IsConnected = false;

            //search the device until you have found it or no more devices in list
            while (!result.HasValue || result.Value == true)
            {
                //
                //if (result == false)
                //    break;

                //open the device
                result = myUSB.CT_SetupDiEnumDeviceInterfaces(device_count);

                //get size of device path
                resultb = myUSB.CT_SetupDiGetDeviceInterfaceBuffer(ref requiredSize, 0);

                size = requiredSize;

                //get device path
                resultb = myUSB.CT_SetupDiGetDeviceInterfaceDetail(ref requiredSize, size);

                if (resultb == false)
                {
                    int err = Marshal.GetLastWin32Error();
                }

                DevicePath = myUSB.DevicePathName;

                //is this the device i want?
                string deviceID = this.VID + "&" + this.PID;

                if (DevicePath.ToLower().IndexOf(deviceID.ToLower()) > 0)
                {
                    //create HID Device Handel
                    resultb = myUSB.CT_CreateFile(DevicePath);

                    // Check the serial Number
                    myUSB.CT_HidD_GetHIDSerialNumber(out string device_sn);

                    myUSB.CT_HidD_GetNumInputBuffers(out uint numbuffers);

                    if (SerialNumber == null || SerialNumber == string.Empty || device_sn == SerialNumber)
                    {
                        IntPtr myPtrToPreparsedData = default(IntPtr);

                        if (myUSB.CT_HidD_GetPreparsedData(myUSB.hHidFile, ref myPtrToPreparsedData))
                        {
                            if (myUSB.CT_HidP_GetCaps(myPtrToPreparsedData))
                            {
                                // we have found our device so stop searching
                                IsConnected = true;
                                break;
                            }
                        }
                        else
                        {
                            myUSB.CT_CloseFile();
                            break;
                        }
                    }
                    else
                    {
                        myUSB.CT_CloseFile();
                    }
                }

                device_count++;
            }

            myUSB.CT_SetupDiDestroyDeviceInfoList();

            //return state
            return(this.IsConnected);
        }