예제 #1
0
        public static async Task <ReferenceFile> GetFile(StorageFile referenceFile, ReferenceFileData referenceFileData)
        {
            if (referenceFileData == null || string.IsNullOrEmpty(referenceFileData.path))
            {
                return(new ReferenceFile(referenceFile, null)
                {
                    LastError = new SafeWrapperResult(OperationErrorCode.InvalidArgument, new ArgumentNullException(), "The Reference File data is corrupt.")
                });
            }

            SafeWrapper <StorageFile> file = await StorageHelpers.ToStorageItemWithError <StorageFile>(referenceFileData.path);

            if (!file)
            {
                if (file == OperationErrorCode.NotFound)
                {
                    // If NotFound, use custom exception for LoadCanvasFromCollection()
                    return(new ReferenceFile(referenceFile, null)
                    {
                        LastError = new SafeWrapperResult(OperationErrorCode.NotFound, new ReferencedFileNotFoundException(), "The file referenced could not be found.")
                    });
                }
                else
                {
                    return(new ReferenceFile(referenceFile, null)
                    {
                        LastError = (SafeWrapperResult)file
                    });
                }
            }

            return(new ReferenceFile(referenceFile, file));
        }
예제 #2
0
        internal static async Task <ReferenceFileData> ReadData(StorageFile referenceFile)
        {
            string data = await FileIO.ReadTextAsync(referenceFile);

            ReferenceFileData referenceFileData = JsonConvert.DeserializeObject <ReferenceFileData>(data);

            return(referenceFileData);
        }
예제 #3
0
        public static async Task <ReferenceFile> GetFile(StorageFile referenceFile)
        {
            // The file is not a Reference File
            if (!IsReferenceFile(referenceFile))
            {
                return(null);
            }
            // The file does not exist
            if (!StorageHelpers.Exists(referenceFile.Path))
            {
                return(new ReferenceFile(referenceFile, null)
                {
                    LastError = new SafeWrapperResult(OperationErrorCode.NotFound, new FileNotFoundException(), "Couldn't resolve item associated with path.")
                });
            }

            ReferenceFileData referenceFileData = await ReadData(referenceFile);

            return(await GetFile(referenceFile, referenceFileData));
        }
예제 #4
0
 public async Task UpdateReferenceFile(ReferenceFileData referenceFileData)
 {
     string serialized = JsonConvert.SerializeObject(referenceFileData, Formatting.Indented);
     await FileIO.WriteTextAsync(_innerFile, serialized);
 }