Esempio n. 1
0
            public void RemoveAdvertiser(AdvertisementWrapper advertiser)
            {
                int  index  = 0;
                bool fFound = false;

                lock (thisLock)
                {
                    // Lookup the index
                    foreach (var a in advertisers)
                    {
                        if (a.InternalId == advertiser.InternalId)
                        {
                            fFound = true;
                            break;
                        }
                        ++index;
                    }
                }

                if (fFound)
                {
                    RemoveAdvertiser(index);
                }
                else
                {
                    NotifyUser("Advertiser not found in list", NotifyType.ErrorMessage);
                }
            }
Esempio n. 2
0
            public void UnpublishService(int index)
            {
                ThrowIfDisposed();

                AdvertisementWrapper advertiser = null;

                lock (thisLock)
                {
                    if (index > advertisers.Count - 1)
                    {
                        throw new IndexOutOfRangeException("Attempted to stop service not found in list");
                    }

                    advertiser = advertisers[index];
                }

                try
                {
                    advertiser.Advertiser.Stop();
                }
                catch (Exception ex)
                {
                    RootPage.NotifyUser("Stop Advertisement Failed: " + ex.Message, NotifyType.ErrorMessage);
                }
            }
Esempio n. 3
0
 public void AddSessionRequest(WiFiDirectServiceSessionRequest request, AdvertisementWrapper advertiser)
 {
     // Update UI to add this to list
     if (scenario2 != null)
     {
         scenario2.AddSessionRequest(request, advertiser);
     }
 }
 public async void AddAdvertiser(AdvertisementWrapper advertiser)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         lock (thisLock)
         {
             Advertisements.Items.Add(advertiser);
         }
     });
 }
Esempio n. 5
0
            private void AddAdvertiser(AdvertisementWrapper advertiser)
            {
                lock (thisLock)
                {
                    advertisers.Add(advertiser);
                }

                // Update UI to add this to list
                if (scenario2 != null)
                {
                    scenario2.AddAdvertiser(advertiser);
                }
            }
Esempio n. 6
0
 public void AdvertiserStatusChanged(AdvertisementWrapper advertiser)
 {
     if (advertiser.Advertiser.AdvertisementStatus == WiFiDirectServiceAdvertisementStatus.Aborted ||
         advertiser.Advertiser.AdvertisementStatus == WiFiDirectServiceAdvertisementStatus.Stopped)
     {
         RemoveAdvertiser(advertiser);
     }
     else
     {
         if (scenario2 != null)
         {
             scenario2.UpdateAdvertiserStatus(advertiser);
         }
     }
 }
            public SessionRequestWrapper(WiFiDirectServiceSessionRequest request, AdvertisementWrapper advertisement)
            {
                this.Id = request.DeviceInformation.Id;
                this.Advertisement = advertisement;
                this.Pin = "";
                this.ProvisioningInfo = "GroupFormation? " + (request.ProvisioningInfo.IsGroupFormationNeeded ? "Yes" : "No")
                    + ", ConfigMethod: " + request.ProvisioningInfo.SelectedConfigurationMethod.ToString();

                if (request.ProvisioningInfo.SelectedConfigurationMethod == WiFiDirectServiceConfigurationMethod.PinDisplay)
                {
                    this.Pin = advertisement.Pin;
                }

                this.SessionInfo = request.SessionInfo;
            }
            public SessionRequestWrapper(WiFiDirectServiceSessionRequest request, AdvertisementWrapper advertisement)
            {
                this.Id               = request.DeviceInformation.Id;
                this.Advertisement    = advertisement;
                this.Pin              = "";
                this.ProvisioningInfo = "GroupFormation? " + (request.ProvisioningInfo.IsGroupFormationNeeded ? "Yes" : "No")
                                        + ", ConfigMethod: " + request.ProvisioningInfo.SelectedConfigurationMethod.ToString();

                if (request.ProvisioningInfo.SelectedConfigurationMethod == WiFiDirectServiceConfigurationMethod.PinDisplay)
                {
                    this.Pin = advertisement.Pin;
                }

                this.SessionInfo = request.SessionInfo;
            }
 public void UpdateAdvertiserStatus(AdvertisementWrapper advertiser)
 {
     // Update list
 }
Esempio n. 10
0
            public void StartAdvertisement(
                string serviceName,
                bool autoAccept,
                bool preferGO,
                string pin,
                IList <WiFiDirectServiceConfigurationMethod> configMethods,
                WiFiDirectServiceStatus status,
                uint customStatus,
                string serviceInfo,
                string deferredServiceInfo,
                IList <String> prefixList
                )
            {
                ThrowIfDisposed();

                // Create Advertiser object for the service
                // NOTE: service name is internally limited to up to 255 bytes in UTF-8 encoding
                // Valid characters include alpha-numeric, '.', '-', and any multi-byte character
                // characters a-z, A-Z are case-insensitive when discovering services
                WiFiDirectServiceAdvertiser advertiser = new WiFiDirectServiceAdvertiser(serviceName);

                // Auto-accept services will connect without interaction from advertiser
                // NOTE: if the config method used for a connection requires a PIN, then the advertiser will have to accept the connection
                advertiser.AutoAcceptSession = autoAccept;

                // Set the Group Owner intent to a large value so that the advertiser will try to become the group owner (GO)
                // NOTE: The GO of a P2P connection can connect to multiple clients while the client can connect to a single GO only
                advertiser.PreferGroupOwnerMode = preferGO;

                // Default status is "Available", but services may use a custom status code (value > 1) if applicable
                advertiser.ServiceStatus           = status;
                advertiser.CustomServiceStatusCode = customStatus;

                // Service information can be up to 65000 bytes.
                // Service Seeker may explicitly discover this by specifying a short buffer that is a subset of this buffer.
                // If seeker portion matches, then entire buffer is returned, otherwise, the service information is not returned to the seeker
                // This sample uses a string for the buffer but it can be any data
                if (serviceInfo != null && serviceInfo.Length > 0)
                {
                    using (var tempStream = new Windows.Storage.Streams.InMemoryRandomAccessStream())
                    {
                        using (var serviceInfoDataWriter = new Windows.Storage.Streams.DataWriter(tempStream))
                        {
                            serviceInfoDataWriter.WriteString(serviceInfo);
                            advertiser.ServiceInfo = serviceInfoDataWriter.DetachBuffer();
                        }
                    }
                }
                else
                {
                    advertiser.ServiceInfo = null;
                }

                // This is a buffer of up to 144 bytes that is sent to the seeker in case the connection is "deferred" (i.e. not auto-accepted)
                // This buffer will be sent when auto-accept is false, or if a PIN is required to complete the connection
                // For the sample, we use a string, but it can contain any data
                if (deferredServiceInfo != null && deferredServiceInfo.Length > 0)
                {
                    using (var tempStream = new Windows.Storage.Streams.InMemoryRandomAccessStream())
                    {
                        using (var deferredSessionInfoDataWriter = new Windows.Storage.Streams.DataWriter(tempStream))
                        {
                            deferredSessionInfoDataWriter.WriteString(deferredServiceInfo);
                            advertiser.DeferredSessionInfo = deferredSessionInfoDataWriter.DetachBuffer();
                        }
                    }
                }
                else
                {
                    advertiser.DeferredSessionInfo = null;
                }

                // The advertiser supported configuration methods
                // Valid values are PIN-only (either keypad entry, display, or both), or PIN (keypad entry, display, or both) and WFD Services default
                // WFD Services Default config method does not require explicit PIN entry and offers a more seamless connection experience
                // Typically, an advertiser will support PIN display (and WFD Services Default), and a seeker will connect with either PIN entry or WFD Services Default
                if (configMethods != null)
                {
                    advertiser.PreferredConfigurationMethods.Clear();
                    foreach (var configMethod in configMethods)
                    {
                        advertiser.PreferredConfigurationMethods.Add(configMethod);
                    }
                }

                // Advertiser may also be discoverable by a prefix of the service name. Must explicitly specify prefixes allowed here.
                if (prefixList != null && prefixList.Count > 0)
                {
                    advertiser.ServiceNamePrefixes.Clear();
                    foreach (var prefix in prefixList)
                    {
                        advertiser.ServiceNamePrefixes.Add(prefix);
                    }
                }

                // For this sample, we wrap the advertiser in our own object which handles the advertiser events
                AdvertisementWrapper advertiserWrapper = new AdvertisementWrapper(advertiser, this, pin);

                AddAdvertiser(advertiserWrapper);

                RootPage.NotifyUser("Starting service...", NotifyType.StatusMessage);

                try
                {
                    // This may fail if the driver is unable to handle the request or if services is not supported
                    // NOTE: this must be called from the UI thread of the app
                    advertiser.Start();
                }
                catch (Exception ex)
                {
                    RootPage.NotifyUser(String.Format(CultureInfo.InvariantCulture, "Failed to start service: {0}", ex.Message), NotifyType.ErrorMessage);
                    throw;
                }
            }
 public async void RemoveSessionRequest(WiFiDirectServiceSessionRequest request, AdvertisementWrapper advertiser)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         lock (thisLock)
         {
             foreach (SessionRequestWrapper r in SessionRequests.Items)
             {
                 if (r.Advertisement.InternalId == advertiser.InternalId &&
                     r.Id == request.DeviceInformation.Id)
                 {
                     SessionRequests.Items.Remove(r);
                     break;
                 }
             }
         }
     });
 }
Esempio n. 12
0
 public void RemoveSessionRequest(WiFiDirectServiceSessionRequest request, AdvertisementWrapper advertiser)
 {
     // Update UI to remove from list
     if (scenario2 != null)
     {
         scenario2.RemoveSessionRequest(request, advertiser);
     }
 }
 public void AdvertiserStatusChanged(AdvertisementWrapper advertiser)
 {
     if (advertiser.Advertiser.AdvertisementStatus == WiFiDirectServiceAdvertisementStatus.Aborted ||
         advertiser.Advertiser.AdvertisementStatus == WiFiDirectServiceAdvertisementStatus.Stopped)
     {
         RemoveAdvertiser(advertiser);
     }
     else
     {
         if (scenario2 != null)
         {
             scenario2.UpdateAdvertiserStatus(advertiser);
         }
     }
 }
 public async void AddSessionRequest(WiFiDirectServiceSessionRequest request, AdvertisementWrapper advertiser)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         lock (thisLock)
         {
             SessionRequestWrapper sessionRequest = new SessionRequestWrapper(request, advertiser);
             SessionRequests.Items.Add(sessionRequest);
         }
     });
 }
 public void AddSessionRequest(WiFiDirectServiceSessionRequest request, AdvertisementWrapper advertiser)
 {
     // Update UI to add this to list
     if (scenario2 != null)
     {
         scenario2.AddSessionRequest(request, advertiser);
     }
 }
 public void RemoveSessionRequest(WiFiDirectServiceSessionRequest request, AdvertisementWrapper advertiser)
 {
     // Update UI to remove from list
     if (scenario2 != null)
     {
         scenario2.RemoveSessionRequest(request, advertiser);
     }
 }
            private void AddAdvertiser(AdvertisementWrapper advertiser)
            {
                lock (thisLock)
                {
                    advertisers.Add(advertiser);
                }

                // Update UI to add this to list
                if (scenario2 != null)
                {
                    scenario2.AddAdvertiser(advertiser);
                }
            }
            public void RemoveAdvertiser(AdvertisementWrapper advertiser)
            {
                int index = 0;
                bool fFound = false;

                lock (thisLock)
                {
                    // Lookup the index
                    foreach (var a in advertisers)
                    {
                        if (a.InternalId == advertiser.InternalId)
                        {
                            fFound = true;
                            break;
                        }
                        ++index;
                    }
                }

                if (fFound)
                {
                    RemoveAdvertiser(index);
                }
                else
                {
                    NotifyUser("Advertiser not found in list", NotifyType.ErrorMessage);
                }
            }
            public void StartAdvertisement(
                string serviceName,
                bool autoAccept,
                bool preferGO,
                string pin,
                IList<WiFiDirectServiceConfigurationMethod> configMethods,
                WiFiDirectServiceStatus status,
                uint customStatus,
                string serviceInfo,
                string deferredServiceInfo,
                IList<String> prefixList
                )
            {
                ThrowIfDisposed();
                
                // Create Advertiser object for the service
                // NOTE: service name is internally limited to up to 255 bytes in UTF-8 encoding
                // Valid characters include alpha-numeric, '.', '-', and any multi-byte character
                // characters a-z, A-Z are case-insensitive when discovering services
                WiFiDirectServiceAdvertiser advertiser = new WiFiDirectServiceAdvertiser(serviceName);

                // Auto-accept services will connect without interaction from advertiser
                // NOTE: if the config method used for a connection requires a PIN, then the advertiser will have to accept the connection
                advertiser.AutoAcceptSession = autoAccept;

                // Set the Group Owner intent to a large value so that the advertiser will try to become the group owner (GO)
                // NOTE: The GO of a P2P connection can connect to multiple clients while the client can connect to a single GO only
                advertiser.PreferGroupOwnerMode = preferGO;

                // Default status is "Available", but services may use a custom status code (value > 1) if applicable
                advertiser.ServiceStatus = status;
                advertiser.CustomServiceStatusCode = customStatus;

                // Service information can be up to 65000 bytes.
                // Service Seeker may explicitly discover this by specifying a short buffer that is a subset of this buffer.
                // If seeker portion matches, then entire buffer is returned, otherwise, the service information is not returned to the seeker
                // This sample uses a string for the buffer but it can be any data
                if (serviceInfo != null && serviceInfo.Length > 0)
                {
                    using (var tempStream = new Windows.Storage.Streams.InMemoryRandomAccessStream())
                    {
                        using (var serviceInfoDataWriter = new Windows.Storage.Streams.DataWriter(tempStream))
                        {
                            serviceInfoDataWriter.WriteString(serviceInfo);
                            advertiser.ServiceInfo = serviceInfoDataWriter.DetachBuffer();
                        }
                    }
                }
                else
                {
                    advertiser.ServiceInfo = null;
                }

                // This is a buffer of up to 144 bytes that is sent to the seeker in case the connection is "deferred" (i.e. not auto-accepted)
                // This buffer will be sent when auto-accept is false, or if a PIN is required to complete the connection
                // For the sample, we use a string, but it can contain any data
                if (deferredServiceInfo != null && deferredServiceInfo.Length > 0)
                {
                    using (var tempStream = new Windows.Storage.Streams.InMemoryRandomAccessStream())
                    {
                        using (var deferredSessionInfoDataWriter = new Windows.Storage.Streams.DataWriter(tempStream))
                        {
                            deferredSessionInfoDataWriter.WriteString(deferredServiceInfo);
                            advertiser.DeferredSessionInfo = deferredSessionInfoDataWriter.DetachBuffer();
                        }
                    }
                }
                else
                {
                    advertiser.DeferredSessionInfo = null;
                }

                // The advertiser supported configuration methods
                // Valid values are PIN-only (either keypad entry, display, or both), or PIN (keypad entry, display, or both) and WFD Services default
                // WFD Services Default config method does not require explicit PIN entry and offers a more seamless connection experience
                // Typically, an advertiser will support PIN display (and WFD Services Default), and a seeker will connect with either PIN entry or WFD Services Default
                if (configMethods != null)
                {
                    advertiser.PreferredConfigurationMethods.Clear();
                    foreach (var configMethod in configMethods)
                    {
                        advertiser.PreferredConfigurationMethods.Add(configMethod);
                    }
                }

                // Advertiser may also be discoverable by a prefix of the service name. Must explicitly specify prefixes allowed here.
                if (prefixList != null && prefixList.Count > 0)
                {
                    advertiser.ServiceNamePrefixes.Clear();
                    foreach (var prefix in prefixList)
                    {
                        advertiser.ServiceNamePrefixes.Add(prefix);
                    }
                }

                // For this sample, we wrap the advertiser in our own object which handles the advertiser events
                AdvertisementWrapper advertiserWrapper = new AdvertisementWrapper(advertiser, this, pin);
                
                AddAdvertiser(advertiserWrapper);

                RootPage.NotifyUser("Starting service...", NotifyType.StatusMessage);

                try
                {
                    // This may fail if the driver is unable to handle the request or if services is not supported
                    // NOTE: this must be called from the UI thread of the app
                    advertiser.Start();
                }
                catch (Exception ex)
                {
                    RootPage.NotifyUser(String.Format(CultureInfo.InvariantCulture, "Failed to start service: {0}", ex.Message), NotifyType.ErrorMessage);
                    throw;
                }
            }
 public async void AddSessionRequest(WiFiDirectServiceSessionRequest request, AdvertisementWrapper advertiser)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         lock (thisLock)
         {
             SessionRequestWrapper sessionRequest = new SessionRequestWrapper(request, advertiser);
             SessionRequests.Items.Add(sessionRequest);
         }
     });
 }
 public void UpdateAdvertiserStatus(AdvertisementWrapper advertiser)
 {
     // Update list
 }
 public async void AddAdvertiser(AdvertisementWrapper advertiser)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         lock (thisLock)
         {
             Advertisements.Items.Add(advertiser);
         }
     });
 }
 public async void RemoveSessionRequest(WiFiDirectServiceSessionRequest request, AdvertisementWrapper advertiser)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         lock (thisLock)
         {
             foreach (SessionRequestWrapper r in SessionRequests.Items)
             {
                 if (r.Advertisement.InternalId == advertiser.InternalId &&
                     r.Id == request.DeviceInformation.Id)
                 {
                     SessionRequests.Items.Remove(r);
                     break;
                 }
             }
         }
     });
 }