public async Task <string> GetFileStatusStringAsync()
        {
            string outputStr = "";

            FileProtectionInfo protectionInfo = await FileProtectionManager.GetProtectionInfoAsync(m_file);

            if (protectionInfo.Status == FileProtectionStatus.Revoked)
            {
                outputStr += "\nFile " + m_file.Path + " is revoked";
            }
            else
            {
                outputStr += "\nFile protection status of: " + m_file.Path + " is " + protectionInfo.Status;
            }

            if (protectionInfo.IsRoamable)
            {
                outputStr += "\nFile " + m_file.Path + " is roamable";
            }
            else
            {
                outputStr += "\nFile " + m_file.Path + " is not roamable";
            }

            return(outputStr);
        }
        private async void CreateFileAndProtect()
        {
            string outputStr = "";

            try
            {
                FileProtectionInfo procInfo = await FileProtectionManager.GetProtectionInfoAsync(m_FileHandle);

                if (procInfo.Status != FileProtectionStatus.Protected)
                {
                    outputStr += "\nProtecting File: ";
                    await FileProtectionManager.ProtectAsync(m_FileHandle, Scenario1.m_EnterpriseIdentity);

                    procInfo = await FileProtectionManager.GetProtectionInfoAsync(m_FileHandle);

                    outputStr += "\nProtected File: " + m_FileHandle.Path + "Status:" + procInfo.Status;
                }
                else
                {
                    outputStr += "\nFile protection status is: " + procInfo.Status;
                }

                rootPage.NotifyUser(outputStr, NotifyType.StatusMessage);
            }
            catch (Exception ex)
            {
                rootPage.NotifyUser(outputStr + "\n" + "Exception thrown:" + ex.ToString(), NotifyType.ErrorMessage);
            }
        }
        public async void CopyProtectionAsync()
        {
            if (m_file != null)
            {
                StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
                StorageFile   destFile    = await localFolder.CreateFileAsync(m_FileCopyName, CreationCollisionOption.OpenIfExists);

                if (destFile != null)
                {
                    await destFile.DeleteAsync();
                }

                // Recreate file
                destFile = await localFolder.CreateFileAsync(m_FileCopyName, CreationCollisionOption.ReplaceExisting);

                string outputStr = "Copying protection from source: " + m_file.Path + "\nTo destination: " + destFile.Path;
                bool   result    = await FileProtectionManager.CopyProtectionAsync(m_file, destFile);

                if (!result)
                {
                    rootPage.NotifyUser(outputStr + " Copy protection Failed", NotifyType.ErrorMessage);
                }
                else
                {
                    FileProtectionInfo sourceInfo = await FileProtectionManager.GetProtectionInfoAsync(m_file);

                    FileProtectionInfo destInfo = await FileProtectionManager.GetProtectionInfoAsync(destFile);

                    if (sourceInfo.Status != destInfo.Status)
                    {
                        outputStr += "\nsource and destination don't have same protection source status:" +
                                     sourceInfo.Status + " Destination status:" + destInfo.Status;
                        rootPage.NotifyUser(outputStr, NotifyType.ErrorMessage);
                    }
                    else
                    {
                        outputStr += "\nCopying protection succeeded";
                        rootPage.NotifyUser(outputStr, NotifyType.StatusMessage);
                    }
                }
            }
            else
            {
                rootPage.NotifyUser("Please pick a source file", NotifyType.ErrorMessage);
            }
        }
        public async Task <StatusData> CheckFileStatus()
        {
            bool   result    = false;
            string outputStr = "";

            StatusData resultData = new StatusData();

            try
            {
                FileProtectionInfo protectionInfo =
                    await FileProtectionManager.GetProtectionInfoAsync(m_FileHandle);

                if (protectionInfo.Status == FileProtectionStatus.Revoked)
                {
                    outputStr += "\nFile " + m_FileHandle.Path + " is revoked";
                }
                else
                {
                    outputStr += "\nFile protection status of: " + m_FileHandle.Path + " is " + protectionInfo.Status;
                }

                if (protectionInfo.IsRoamable)
                {
                    outputStr += "\nFile " + m_FileHandle.Path + " is roamable";
                }
                else
                {
                    outputStr += "\nFile " + m_FileHandle.Path + " is not roamable";
                }

                result = true;
            }
            catch (Exception ex)
            {
                outputStr += "\n" + "Exception thrown:" + ex.ToString();
            }

            resultData.result    = result;
            resultData.outputStr = outputStr;


            return(resultData);
        }
        private async void CreateFileAndProtect()
        {
            string outputStr = "";

            FileProtectionInfo procInfo = await FileProtectionManager.GetProtectionInfoAsync(m_file);

            if (procInfo.Status != FileProtectionStatus.Protected)
            {
                outputStr += "\nProtecting File: ";
                await FileProtectionManager.ProtectAsync(m_file, Scenario1.m_enterpriseId);

                procInfo = await FileProtectionManager.GetProtectionInfoAsync(m_file);

                outputStr += "\nProtected File: " + m_file.Path + "Status:" + procInfo.Status;
            }
            else
            {
                outputStr += "\nFile protection status is: " + procInfo.Status;
            }

            rootPage.NotifyUser(outputStr, NotifyType.StatusMessage);
        }
예제 #6
0
        private async void ProtectFileClick(object sender, RoutedEventArgs e)
        {
            string outputStr = "";

            FileOpenPicker openPicker = new FileOpenPicker();

            openPicker.ViewMode = PickerViewMode.Thumbnail;
            openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            openPicker.FileTypeFilter.Add("*");
            var m_file = await openPicker.PickSingleFileAsync();

            if (m_file != null)
            {
                // Application now has read/write access to the picked file
                outputStr += "\nPicked file: " + m_file.Path;
            }
            else
            {
                outputStr += "\nPlease pick a file";
            }

            FileProtectionInfo procInfo = await FileProtectionManager.GetProtectionInfoAsync(m_file);

            if (procInfo.Status != FileProtectionStatus.Protected)
            {
                outputStr += "\nProtecting File: ";
                await FileProtectionManager.ProtectAsync(m_file, "microsoft.com");

                procInfo = await FileProtectionManager.GetProtectionInfoAsync(m_file);

                outputStr += "\nProtected File: " + m_file.Path + "Status:" + procInfo.Status;
            }
            else
            {
                outputStr += "\nFile protection status is: " + procInfo.Status;
            }
        }