Ejemplo n.º 1
0
        private async void PasteButton_Click(object sender, TextControlPasteEventArgs e)
        {
            // Mark the event as handled first. Otherwise, the
            // default paste action will happen, then the custom paste
            // action, and the user will see the text box content change.
            e.Handled = true;

            // Get content from the clipboard.
            var dataPackageView = Windows.ApplicationModel.DataTransfer.Clipboard.GetContent();

            if (dataPackageView.Contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.Text))
            {
                var response = await dataPackageView.RequestAccessAsync();

                if (response == ProtectionPolicyEvaluationResult.Allowed)
                {
                    (sender as TextBox).Text = await dataPackageView.GetTextAsync();

                    string sourceId = dataPackageView.Properties.EnterpriseId != null ? dataPackageView.Properties.EnterpriseId : "<Personal>";
                    string targetId = ProtectionPolicyManager.GetForCurrentView().Identity != null ? dataPackageView.Properties.EnterpriseId : "<Personal>";
                    string message  = "Successfully pasted text from EnterpriseId " + sourceId + " to EnterpriseId " + targetId;
                    rootPage.NotifyUser(message, NotifyType.StatusMessage);
                }
                else
                {
                    rootPage.NotifyUser("User or policy blocked access", NotifyType.StatusMessage);
                }
            }
        }
        private async void CheckUriIdentity_Click(object sender, RoutedEventArgs e)
        {
            Uri    resourceUri;
            string resourceIdentity;
            ThreadNetworkContext context = null;

            try
            {
                if (!Uri.TryCreate(EnterpriseUri.Text.Trim(), UriKind.Absolute, out resourceUri))
                {
                    rootPage.NotifyUser("Invalid URI, please re-enter a valid URI", NotifyType.ErrorMessage);
                    return;
                }
                resourceIdentity =
                    await ProtectionPolicyManager.GetPrimaryManagedIdentityForNetworkEndpointAsync(
                        new HostName(resourceUri.Host));

                // if resourceIdentity is empty or Null, then it is considered personal

                if (!string.IsNullOrEmpty(resourceIdentity))
                {
                    context = ProtectionPolicyManager.CreateCurrentThreadNetworkContext(resourceIdentity);
                }

                // Access enterprise content

                rootPage.NotifyUser("Accessing Enterprise content.........", NotifyType.StatusMessage);

                HttpClientHandler httpHandler = new HttpClientHandler();
                if (!string.IsNullOrEmpty(UserNameBox.Text) &&
                    !string.IsNullOrEmpty(DomainBox.Text) &&
                    !string.IsNullOrEmpty(Passwordbox.Password))
                {
                    httpHandler.Credentials = new NetworkCredential(UserNameBox.Text, Passwordbox.Password, DomainBox.Text);
                }
                httpHandler.AllowAutoRedirect = true;

                using (var client = new HttpClient(httpHandler))
                {
                    var message = new HttpRequestMessage(HttpMethod.Get, resourceUri);
                    message.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1)");
                    var result = await client.SendAsync(message);
                }

                // Access to network resource was a success. If it wasn't, exception would have been thrown

                rootPage.NotifyUser("Successfully got network resource", NotifyType.StatusMessage);
            }
            catch (Exception ex)
            {
                rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage);
            }
            finally
            {
                if (context != null)
                {
                    context.Dispose();
                }
            }
        }
Ejemplo n.º 3
0
        private void Set_ClipboardSource(object sender, RoutedEventArgs e)
        {
            var protectionPolicyManager = ProtectionPolicyManager.GetForCurrentView();

            protectionPolicyManager.Identity = Scenario1.m_enterpriseId;
            rootPage.NotifyUser("Set ProtectionPolicyManager.Identity to: " + Scenario1.m_enterpriseId, NotifyType.StatusMessage);
        }
Ejemplo n.º 4
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            rootPage = MainPage.Current;
            var protectionPolicyManager = ProtectionPolicyManager.GetForCurrentView();

            protectionPolicyManager.Identity = ""; // personal context
            InputTxtBox.Text = "Copy and paste this text to a non-enterprise app such as notepad";
        }
Ejemplo n.º 5
0
        private async void ConnectUsingBackgroundTransfer(string resourceIdentity, Uri resourceUri)
        {
            ThreadNetworkContext context = null;

            try
            {
                // For demonstrational purposes, when "Use personal context" is selected,
                // the resourceIdentity is set to null to force personal context.

                // When using Windows.Networking.BackgroundTransfer, the app is responsible for disallowing connections
                // to enterprise owned URLs when in personal context.
                // Otherwise, the app may inadvertently access cached data for a different context.
                if (UsePersonalContext.IsChecked.Value && !string.IsNullOrEmpty(resourceIdentity))
                {
                    rootPage.NotifyUser("This app does not have access to the specified URL in personal context", NotifyType.ErrorMessage);
                    return;
                }

                rootPage.NotifyUser("Creating file.........", NotifyType.StatusMessage);

                StorageFile resultFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(
                    "ResultFile.txt",
                    CreationCollisionOption.GenerateUniqueName);

                if (!string.IsNullOrEmpty(resourceIdentity))
                {
                    context = ProtectionPolicyManager.CreateCurrentThreadNetworkContext(resourceIdentity);
                }

                rootPage.NotifyUser("Accessing network resource.........", NotifyType.StatusMessage);

                BackgroundDownloader downloader = new BackgroundDownloader();

                if (!string.IsNullOrEmpty(UserNameBox.Text) &&
                    !string.IsNullOrEmpty(Passwordbox.Password))
                {
                    downloader.ServerCredential = new PasswordCredential(
                        resourceUri.AbsoluteUri,
                        UserNameBox.Text,
                        Passwordbox.Password);
                }

                DownloadOperation download = downloader.CreateDownload(resourceUri, resultFile);

                await HandleDownloadAsync(download);
            }
            catch (Exception ex)
            {
                rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage);
            }
            finally
            {
                if (context != null)
                {
                    context.Dispose();
                }
            }
        }
Ejemplo n.º 6
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            rootPage = MainPage.Current;

            var protectionPolicyManager = ProtectionPolicyManager.GetForCurrentView();

            protectionPolicyManager.Identity = ""; // personal context
            InputTxtBox.PlaceholderText      = "Copy Text here from a non-enterprise app";
        }
Ejemplo n.º 7
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            rootPage = MainPage.Current;

            var protectionPolicyManager = ProtectionPolicyManager.GetForCurrentView();

            protectionPolicyManager.Identity = ""; // personal
            InputTxtBox.PlaceholderText      = "Paste any text here";
        }
Ejemplo n.º 8
0
 static T UsingNetworkContext <T>(string identity, Func <T> lambda)
 {
     // The "using" statement will Dispose the object when control leaves the block.
     using (ThreadNetworkContext context = string.IsNullOrEmpty(identity)
         ? null
         : ProtectionPolicyManager.CreateCurrentThreadNetworkContext(identity))
     {
         return(lambda());
     }
 }
Ejemplo n.º 9
0
 private void IsIdentityManaged_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         bool isIdentityManaged = ProtectionPolicyManager.IsIdentityManaged(Scenario1.m_EnterpriseIdentity);
         rootPage.NotifyUser("IsIdentityManaged: " + isIdentityManaged, NotifyType.StatusMessage);
     }
     catch (Exception ex)
     {
         rootPage.NotifyUser("Exception thrown:" + ex.ToString(), NotifyType.ErrorMessage);
     }
 }
 private void TryApplyProcessUIPolicy_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         bool result = ProtectionPolicyManager.TryApplyProcessUIPolicy(Scenario1.m_EnterpriseIdentity);
         rootPage.NotifyUser("TryApplyProcessUIPolicy returned " + result, NotifyType.ErrorMessage);
     }
     catch (Exception ex)
     {
         rootPage.NotifyUser("Exception thrown:" + ex.ToString(), NotifyType.ErrorMessage);
     }
 }
 private void ClearProcessUIPolicy_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         ProtectionPolicyManager.ClearProcessUIPolicy();
         rootPage.NotifyUser("Copy+Paste from this app should now succeed", NotifyType.ErrorMessage);
     }
     catch (Exception ex)
     {
         rootPage.NotifyUser("Exception thrown:" + ex.ToString(), NotifyType.ErrorMessage);
     }
 }
 private void Revoke_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         ProtectionPolicyManager.RevokeContent(Scenario1.m_EnterpriseIdentity);
         rootPage.NotifyUser("RevokeContent executed", NotifyType.StatusMessage);
     }
     catch (Exception ex)
     {
         rootPage.NotifyUser("Exception thrown:" + ex.ToString(), NotifyType.ErrorMessage);
     }
 }
 private void Set_ClipboardSource(object sender, RoutedEventArgs e)
 {
     try
     {
         ProtectionPolicyManager ppManager = ProtectionPolicyManager.GetForCurrentView();
         ppManager.Identity = Scenario1.m_EnterpriseIdentity;
         rootPage.NotifyUser("Set ProtectionPolicyManager.Identity to: " + Scenario1.m_EnterpriseIdentity, NotifyType.StatusMessage);
     }
     catch (Exception ex)
     {
         rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage);
     }
 }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            rootPage = MainPage.Current;

            try
            {
                // Set protectionPolicyManager.Identity to "" so that current view is personal

                ProtectionPolicyManager protectionPolicyManager = ProtectionPolicyManager.GetForCurrentView();
                protectionPolicyManager.Identity = "";
                InputTxtBox.PlaceholderText      = "Copy Text here from a non-enterprise app";
            }
            catch (Exception ex)
            {
                rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage);
            }
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            rootPage = MainPage.Current;

            try
            {
                // Set view as personal

                ProtectionPolicyManager protectionPolicyManager = ProtectionPolicyManager.GetForCurrentView();
                protectionPolicyManager.Identity = "";
                InputTxtBox.PlaceholderText      = "Paste any text here";
            }
            catch (Exception ex)
            {
                rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage);
            }
        }
Ejemplo n.º 16
0
        bool IsClipboardPeekAllowedAsync()
        {
            var result          = ProtectionPolicyEvaluationResult.Blocked;
            var dataPackageView = Clipboard.GetContent();

            if (dataPackageView.Contains("text"))
            {
                var protectionPolicyManager = ProtectionPolicyManager.GetForCurrentView();
                result = ProtectionPolicyManager.CheckAccess(dataPackageView.Properties.EnterpriseId,
                                                             protectionPolicyManager.Identity);
            }

            // Since this is a convenience feature to allow a peek of clipboard content,
            // if state is Blocked or ConsentRequired, do not show peek.

            return(result == ProtectionPolicyEvaluationResult.Allowed);
        }
Ejemplo n.º 17
0
        private async void ConnectToUri()
        {
            Uri resourceUri;

            if (!Uri.TryCreate(ResourceUriText.Text, UriKind.Absolute, out resourceUri))
            {
                rootPage.NotifyUser("Invalid URI", NotifyType.ErrorMessage);
                return;
            }

            var hostName = new HostName(resourceUri.Host);

            try
            {
                string resourceIdentity = await ProtectionPolicyManager.GetPrimaryManagedIdentityForNetworkEndpointAsync(hostName);

                // if there is no resourceIdentity, then the resource is considered personal, and no thread network context is needed.
                // Otherwise, it requires the enterprise context.
                DisplayNetworkIdentity(resourceIdentity);

                rootPage.NotifyUser("Accessing network resource...", NotifyType.StatusMessage);

                if (UseSystemNetHttpClient.IsChecked.Value)
                {
                    ConnectUsingNetHttpClient(resourceIdentity, resourceUri);
                }
                else if (UseWindowsWebHttpClient.IsChecked.Value)
                {
                    ConnectUsingWebHttpClient(resourceIdentity, resourceUri);
                }
                else if (UseBackgroundTransferButton.IsChecked.Value)
                {
                    ConnectUsingBackgroundTransfer(resourceIdentity, resourceUri);
                }
                else
                {
                    rootPage.NotifyUser("Please select a method to connect.", NotifyType.ErrorMessage);
                }
            }
            catch (Exception ex)
            {
                // Access to the network resource was not successful.
                rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage);
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Initializes the singleton application object.  This is the first line of authored code
        /// executed, and as such is the logical equivalent of main() or WinMain().
        /// </summary>
        public App()
        {
            this.InitializeComponent();
            this.Suspending += OnSuspending;

            bool use_WIP_APIs = false;

            var enterpriseId      = "microsoft.com1";
            var isIdentityManaged = ProtectionPolicyManager.IsIdentityManaged(enterpriseId);

            if ((ApiInformation.IsApiContractPresent
                     ("Windows.Security.EnterpriseData.EnterpriseDataContract", 3) &&
                 ProtectionPolicyManager.IsProtectionEnabled))
            {
                use_WIP_APIs = true;
            }
            else
            {
                use_WIP_APIs = false;
            }
        }
Ejemplo n.º 19
0
        private async void CheckUriIdentity_Click(object sender, RoutedEventArgs e)
        {
            Uri    resourceUri;
            string resourceIdentity;

            try
            {
                if (!Uri.TryCreate(ResourceUriText.Text.Trim(), UriKind.Absolute, out resourceUri))
                {
                    rootPage.NotifyUser("Invalid URI, please re-enter a valid URI", NotifyType.ErrorMessage);
                    return;
                }
                resourceIdentity = await ProtectionPolicyManager.GetPrimaryManagedIdentityForNetworkEndpointAsync(
                    new HostName(resourceUri.Host));

                DisplayNetworkIdentity(resourceIdentity);
            }
            catch (Exception ex)
            {
                rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage);
            }
        }
Ejemplo n.º 20
0
 private void Revoke_Click(object sender, RoutedEventArgs e)
 {
     ProtectionPolicyManager.RevokeContent(Scenario1.m_enterpriseId);
     rootPage.NotifyUser("RevokeContent executed", NotifyType.StatusMessage);
 }
        private async void CheckUriIdentity_Click(object sender, RoutedEventArgs e)
        {
            Uri    resourceUri;
            string resourceIdentity;
            ThreadNetworkContext context = null;

            IdentityBox.Text = String.Empty;

            try
            {
                rootPage.NotifyUser("Creating file.........", NotifyType.StatusMessage);

                StorageFile resultFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(
                    "ResultFile.txt",
                    CreationCollisionOption.GenerateUniqueName);

                if (!Uri.TryCreate(EnterpriseUri.Text.Trim(), UriKind.Absolute, out resourceUri))
                {
                    rootPage.NotifyUser("Invalid URI, please re-enter a valid URI", NotifyType.ErrorMessage);
                    return;
                }
                resourceIdentity = await ProtectionPolicyManager.GetPrimaryManagedIdentityForNetworkEndpointAsync(
                    new HostName(resourceUri.Host));

                // if resourceIdentity is empty or Null, then it is considered personal
                IdentityBox.Text = resourceIdentity;

                if (!string.IsNullOrEmpty(resourceIdentity))
                {
                    context = ProtectionPolicyManager.CreateCurrentThreadNetworkContext(resourceIdentity);
                }

                // Access enterprise content

                rootPage.NotifyUser("Accessing network resource.........", NotifyType.StatusMessage);

                BackgroundDownloader downloader = new BackgroundDownloader();

                if (!string.IsNullOrEmpty(UserNameBox.Text) &&
                    !string.IsNullOrEmpty(Passwordbox.Password))
                {
                    downloader.ServerCredential = new PasswordCredential(
                        resourceUri.AbsoluteUri,
                        UserNameBox.Text,
                        Passwordbox.Password);
                }

                DownloadOperation download = downloader.CreateDownload(resourceUri, resultFile);

                await HandleDownloadAsync(download);
            }
            catch (Exception ex)
            {
                rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage);
            }
            finally
            {
                if (context != null)
                {
                    context.Dispose();
                }
            }
        }
        private void TryApplyProcessUIPolicy_Click(object sender, RoutedEventArgs e)
        {
            bool result = ProtectionPolicyManager.TryApplyProcessUIPolicy(Scenario1.m_enterpriseId);

            rootPage.NotifyUser("TryApplyProcessUIPolicy returned " + result, NotifyType.StatusMessage);
        }
 private void ClearProcessUIPolicy_Click(object sender, RoutedEventArgs e)
 {
     ProtectionPolicyManager.ClearProcessUIPolicy();
     rootPage.NotifyUser("Copy+Paste from this app should now succeed", NotifyType.ErrorMessage);
 }
Ejemplo n.º 24
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            rootPage = MainPage.Current;

            // It is recommended to only retrieve the m_shareOperation object in the activation handler, return as
            // quickly as possible, and retrieve all data from the share target asynchronously.

            m_shareOperation = (ShareOperation)e.Parameter;

            var result = await ProtectionPolicyManager.RequestAccessAsync(Scenario1.m_enterpriseId,
                                                                          m_shareOperation.Data.Properties.EnterpriseId);

            if (result == ProtectionPolicyEvaluationResult.Blocked)
            {
                rootPage.NotifyUser("\nSharing is blocked by policy from your Enterprise", NotifyType.ErrorMessage);
            }

            await Task.Factory.StartNew(async() =>
            {
                // Retrieve the data package properties.
                m_sharedDataTitle                        = m_shareOperation.Data.Properties.Title;
                m_sharedDataDescription                  = m_shareOperation.Data.Properties.Description;
                m_sharedDataPackageFamilyName            = m_shareOperation.Data.Properties.PackageFamilyName;
                m_sharedDataContentSourceWebLink         = m_shareOperation.Data.Properties.ContentSourceWebLink;
                m_sharedDataContentSourceApplicationLink = m_shareOperation.Data.Properties.ContentSourceApplicationLink;
                m_sharedDataLogoBackgroundColor          = m_shareOperation.Data.Properties.LogoBackgroundColor;
                m_sharedDataSquare30x30Logo              = m_shareOperation.Data.Properties.Square30x30Logo;
                m_sharedThumbnailStreamRef               = m_shareOperation.Data.Properties.Thumbnail;
                shareQuickLinkId = m_shareOperation.QuickLinkId;

                // Retrieve the data package content.
                // The GetWebLinkAsync(), GetTextAsync(), GetStorageItemsAsync(), etc. APIs will throw if there was an error retrieving the data from the source app.
                // In this sample, we just display the error. It is recommended that a share target app handles these in a way appropriate for that particular app.
                if (m_shareOperation.Data.Contains(StandardDataFormats.WebLink))
                {
                    try
                    {
                        m_sharedWebLink = await m_shareOperation.Data.GetWebLinkAsync();
                    }
                    catch (Exception ex)
                    {
                        NotifyUserBackgroundThread("Failed GetWebLinkAsync - " + ex.Message, NotifyType.ErrorMessage);
                    }
                }
                if (m_shareOperation.Data.Contains(StandardDataFormats.ApplicationLink))
                {
                    try
                    {
                        m_sharedApplicationLink = await m_shareOperation.Data.GetApplicationLinkAsync();
                    }
                    catch (Exception ex)
                    {
                        NotifyUserBackgroundThread("Failed GetApplicationLinkAsync - " + ex.Message, NotifyType.ErrorMessage);
                    }
                }
                if (m_shareOperation.Data.Contains(StandardDataFormats.Text))
                {
                    try
                    {
                        m_sharedText = await m_shareOperation.Data.GetTextAsync();
                    }
                    catch (Exception ex)
                    {
                        NotifyUserBackgroundThread("Failed GetTextAsync - " + ex.Message, NotifyType.ErrorMessage);
                    }
                }
                if (m_shareOperation.Data.Contains(StandardDataFormats.StorageItems))
                {
                    try
                    {
                        m_sharedStorageItems = await m_shareOperation.Data.GetStorageItemsAsync();
                    }
                    catch (Exception ex)
                    {
                        NotifyUserBackgroundThread("Failed GetStorageItemsAsync - " + ex.Message, NotifyType.ErrorMessage);
                    }
                }
                if (m_shareOperation.Data.Contains(dataFormatName))
                {
                    try
                    {
                        m_sharedCustomData = await m_shareOperation.Data.GetTextAsync(dataFormatName);
                    }
                    catch (Exception ex)
                    {
                        NotifyUserBackgroundThread("Failed GetTextAsync(" + dataFormatName + ") - " + ex.Message, NotifyType.ErrorMessage);
                    }
                }
                if (m_shareOperation.Data.Contains(StandardDataFormats.Html))
                {
                    try
                    {
                        m_sharedHtmlFormat = await m_shareOperation.Data.GetHtmlFormatAsync();
                    }
                    catch (Exception ex)
                    {
                        NotifyUserBackgroundThread("Failed GetHtmlFormatAsync - " + ex.Message, NotifyType.ErrorMessage);
                    }

                    try
                    {
                        m_sharedResourceMap = await m_shareOperation.Data.GetResourceMapAsync();
                    }
                    catch (Exception ex)
                    {
                        NotifyUserBackgroundThread("Failed GetResourceMapAsync - " + ex.Message, NotifyType.ErrorMessage);
                    }
                }
                if (m_shareOperation.Data.Contains(StandardDataFormats.Bitmap))
                {
                    try
                    {
                        m_sharedBitmapStreamRef = await m_shareOperation.Data.GetBitmapAsync();
                    }
                    catch (Exception ex)
                    {
                        NotifyUserBackgroundThread("Failed GetBitmapAsync - " + ex.Message, NotifyType.ErrorMessage);
                    }
                }

                // In this sample, we just display the m_shared data content.

                // Get back to the UI thread using the dispatcher.
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                {
                    DataPackageTitle.Text             = m_sharedDataTitle;
                    DataPackageDescription.Text       = m_sharedDataDescription;
                    DataPackagePackageFamilyName.Text = m_sharedDataPackageFamilyName;
                    if (m_sharedDataContentSourceWebLink != null)
                    {
                        DataPackageContentSourceWebLink.Text = m_sharedDataContentSourceWebLink.AbsoluteUri;
                    }
                    if (m_sharedDataContentSourceApplicationLink != null)
                    {
                        DataPackageContentSourceApplicationLink.Text = m_sharedDataContentSourceApplicationLink.AbsoluteUri;
                    }

                    if (m_sharedDataSquare30x30Logo != null)
                    {
                        IRandomAccessStreamWithContentType logoStream = await m_sharedDataSquare30x30Logo.OpenReadAsync();
                        BitmapImage bitmapImage = new BitmapImage();
                        bitmapImage.SetSource(logoStream);
                        LogoHolder.Source         = bitmapImage;
                        LogoBackground.Background = new SolidColorBrush(m_sharedDataLogoBackgroundColor);
                        LogoArea.Visibility       = Visibility.Visible;
                    }

                    if (!String.IsNullOrEmpty(m_shareOperation.QuickLinkId))
                    {
                        SelectedQuickLinkId.Text = shareQuickLinkId;
                    }

                    if (m_sharedThumbnailStreamRef != null)
                    {
                        IRandomAccessStreamWithContentType thumbnailStream = await m_sharedThumbnailStreamRef.OpenReadAsync();
                        BitmapImage bitmapImage = new BitmapImage();
                        bitmapImage.SetSource(thumbnailStream);
                        ThumbnailHolder.Source   = bitmapImage;
                        ThumbnailArea.Visibility = Visibility.Visible;
                    }

                    if (m_sharedWebLink != null)
                    {
                        AddContentValue("WebLink: ", m_sharedWebLink.AbsoluteUri);
                    }
                    if (m_sharedApplicationLink != null)
                    {
                        AddContentValue("ApplicationLink: ", m_sharedApplicationLink.AbsoluteUri);
                    }
                    if (m_sharedText != null)
                    {
                        AddContentValue("Text: ", m_sharedText);
                    }
                    if (m_sharedStorageItems != null)
                    {
                        // Display the name of the files being m_shared.
                        StringBuilder fileNames = new StringBuilder();
                        for (int index = 0; index < m_sharedStorageItems.Count; index++)
                        {
                            fileNames.Append(m_sharedStorageItems[index].Name);
                            if (index < m_sharedStorageItems.Count - 1)
                            {
                                fileNames.Append(", ");
                            }
                        }
                        fileNames.Append(".");

                        AddContentValue("StorageItems: ", fileNames.ToString());
                    }
                    if (m_sharedCustomData != null)
                    {
                        // This is an area to be especially careful parsing data from the source app to avoid buffer overruns.
                        // This sample doesn't perform data validation but will catch any exceptions thrown.
                        try
                        {
                            StringBuilder receivedStrings = new StringBuilder();
                            JsonObject customObject       = JsonObject.Parse(m_sharedCustomData);
                            if (customObject.ContainsKey("type"))
                            {
                                if (customObject["type"].GetString() == "http://schema.org/Book")
                                {
                                    // This sample expects the custom format to be of type http://schema.org/Book
                                    receivedStrings.AppendLine("Type: " + customObject["type"].Stringify());
                                    JsonObject properties = customObject["properties"].GetObject();
                                    receivedStrings.AppendLine("Image: " + properties["image"].Stringify());
                                    receivedStrings.AppendLine("Name: " + properties["name"].Stringify());
                                    receivedStrings.AppendLine("Book Format: " + properties["bookFormat"].Stringify());
                                    receivedStrings.AppendLine("Author: " + properties["author"].Stringify());
                                    receivedStrings.AppendLine("Number of Pages: " + properties["numberOfPages"].Stringify());
                                    receivedStrings.AppendLine("Publisher: " + properties["publisher"].Stringify());
                                    receivedStrings.AppendLine("Date Published: " + properties["datePublished"].Stringify());
                                    receivedStrings.AppendLine("In Language: " + properties["inLanguage"].Stringify());
                                    receivedStrings.Append("ISBN: " + properties["isbn"].Stringify());

                                    AddContentValue("Custom format data:" + Environment.NewLine, receivedStrings.ToString());
                                }
                                else
                                {
                                    rootPage.NotifyUser("The custom format from the source app is not of type http://schema.org/Book", NotifyType.ErrorMessage);
                                }
                            }
                            else
                            {
                                rootPage.NotifyUser("The custom format from the source app doesn't contain a type", NotifyType.ErrorMessage);
                            }
                        }
                        catch (Exception ex)
                        {
                            rootPage.NotifyUser("Failed to parse the custom data - " + ex.Message, NotifyType.ErrorMessage);
                        }
                    }
                    if (m_sharedHtmlFormat != null)
                    {
                        string htmlFragment = HtmlFormatHelper.GetStaticFragment(m_sharedHtmlFormat);
                        if (!String.IsNullOrEmpty(htmlFragment))
                        {
                            AddContentValue("HTML: ");
                            ShareWebView.Visibility = Visibility.Visible;
                            ShareWebView.NavigateToString("<html><body>" + htmlFragment + "</body></html>");
                        }
                        else
                        {
                            rootPage.NotifyUser("GetStaticFragment failed to parse the HTML from the source app", NotifyType.ErrorMessage);
                        }

                        // Check if there are any local images in the resource map.
                        if (m_sharedResourceMap.Count > 0)
                        {
                            //ResourceMapValue.Text = "";
                            foreach (KeyValuePair <string, RandomAccessStreamReference> item in m_sharedResourceMap)
                            {
                                ResourceMapValue.Text += "\nKey: " + item.Key;
                            }
                            ResourceMapArea.Visibility = Visibility.Visible;
                        }
                    }
                    if (m_sharedBitmapStreamRef != null)
                    {
                        IRandomAccessStreamWithContentType bitmapStream = await m_sharedBitmapStreamRef.OpenReadAsync();
                        BitmapImage bitmapImage = new BitmapImage();
                        bitmapImage.SetSource(bitmapStream);
                        ImageHolder.Source   = bitmapImage;
                        ImageArea.Visibility = Visibility.Visible;
                    }
                });
            });
        }
Ejemplo n.º 25
0
        private void IsIdentityManaged_Click(object sender, RoutedEventArgs e)
        {
            bool isIdentityManaged = ProtectionPolicyManager.IsIdentityManaged(Scenario1.m_enterpriseId);

            rootPage.NotifyUser("IsIdentityManaged: " + isIdentityManaged, NotifyType.StatusMessage);
        }