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);
            }
        }
Beispiel #3
0
        private async void DoFileWork(IBackgroundTaskInstance taskInstance)
        {
            string textBody     = "\nHello World";
            string fileName     = "EdpSample.txt";
            string fileCopyName = "EdpSampleCopy.txt";
            string logFileName  = "Filelog.txt";

            StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;

            StorageFile logFile = await localFolder.CreateFileAsync(logFileName, CreationCollisionOption.OpenIfExists);

            // Create a protected file allows the creation of new files even after keys are dropped so that application
            // can create and continue writing to files under lock

            var result = await FileProtectionManager.CreateProtectedAndOpenAsync(localFolder,
                                                                                 fileName,
                                                                                 m_EnterpriseID,
                                                                                 CreationCollisionOption.ReplaceExisting
                                                                                 );

            using (var stream = result.Stream)
            {
                m_fileProtStatus = result.ProtectionInfo.Status.ToString();

                // Write to File

                using (IOutputStream outputStream = result.Stream.GetOutputStreamAt(0))
                {
                    DataWriter writer = new DataWriter(outputStream);
                    for (int i = 0; i < 100; i++)
                    {
                        writer.WriteString(textBody);
                        await writer.StoreAsync();
                    }
                }
            }

            // Check and if Keys are not dropped, read and write to another file.
            // Read from a protected file and copy it to another one

            if (!m_areKeysDropped)
            {
                StorageFile edpFileSource = await localFolder.CreateFileAsync(fileName, CreationCollisionOption.OpenIfExists);

                StorageFile edpFileCopy = await localFolder.CreateFileAsync(fileCopyName, CreationCollisionOption.ReplaceExisting);

                string sourceContent = await FileIO.ReadTextAsync(edpFileSource);

                await FileIO.WriteTextAsync(edpFileCopy, sourceContent);
            }
            else
            {
                await FileIO.AppendTextAsync(logFile, "\r\n" + DateTime.Now + ":" + " keys are dropped. Skip reading");
            }
        }
        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);
        }
Beispiel #7
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;
            }
        }