private string CopyIfFileReference(string source)
        {
            FileReference sourceReference = FileReference.Parse(source);

            if (sourceReference == null)
            {
                return(source);
            }

            string destinationPath = CreateUniqueFilename(Path.GetExtension(sourceReference.Path));

            using (IsolatedStorageFile userStore = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream outputStream = new IsolatedStorageFileStream(destinationPath, FileMode.CreateNew, userStore))
                {
                    using (IsolatedStorageFileStream inputStream = new IsolatedStorageFileStream(sourceReference.Path, FileMode.Open, userStore))
                    {
                        inputStream.CopyTo(outputStream);
                    }
                }
            }

            FileReference destinationReference = new FileReference(destinationPath, sourceReference.Context);

            logger.TraceFormat("Copied {0} to {1}", sourceReference, destinationReference);

            return(destinationReference.ToString());
        }
        private void AddIfFileReference(string source, IList <FileReference> references)
        {
            FileReference fileReference = FileReference.Parse(source);

            if (fileReference != null)
            {
                references.Add(fileReference);
            }
        }
        public FileReference FindFirstFileReference(JToken source)
        {
            FileReference fileReference = null;

            Satisfies(s =>
            {
                fileReference = FileReference.Parse(s);

                return(fileReference != null);
            }, source);

            return(fileReference);
        }
        private string ExpandFileReferences(string source)
        {
            FileReference fileReference = FileReference.Parse(source);

            if (fileReference == null)
            {
                return(source);
            }

            FileData fileData = FileData.Load(fileReference.Path);

            logger.TraceFormat("Expanded {0} to data of {1} bytes", source, fileData.Data.Length);

            return(fileData.ToString());
        }
        private void DeleteFiles(string source)
        {
            try
            {
                FileReference fileReference = FileReference.Parse(source);

                if (fileReference != null)
                {
                    logger.TraceFormat("Deleting file referrered to by {0}", source);

                    using (IsolatedStorageFile userStore = IsolatedStorageFile.GetUserStoreForApplication())
                    {
                        userStore.DeleteFile(fileReference.Path);
                    }

                    return;
                }

                ContentReference contentReference = ContentReference.Parse(source);

                if (contentReference != null)
                {
                    logger.TraceFormat("Deleting file referrered to by {0}", source);

                    using (IsolatedStorageFile userStore = IsolatedStorageFile.GetUserStoreForApplication())
                    {
                        userStore.DeleteFile(contentReference.Path);
                    }

                    return;
                }
            }
            catch (Exception e)
            {
                logger.WarnFormat("Cannot delete file referrered to by {0}: {1}", source, e.Message);
            }
        }
        private string ReplaceReference(string source, FileReference sourceReference, AzureStorageBlobReference blobReference)
        {
            FileReference fileReference = FileReference.Parse(source);

            return(fileReference == sourceReference?blobReference.ToString() : source);
        }