示例#1
0
        /// <summary>
        /// Get a FlashCardFileInfo
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public FlashCardFileInfo GetFile(string name)
        {
            FlashCardFileInfo res = null;

            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }

            var tableServiceContext = GetFilesContext();

            try
            {
                res = tableServiceContext.CreateQuery <FlashCardFileInfo>("Files").Where(fi => fi.Name == name).FirstOrDefault();
            }
            catch (Exception) { }


            return(res);
        }
示例#2
0
        /// <summary>
        /// Add a FlashCardFileInfo to the Files table
        /// </summary>
        /// <param name="name"></param>
        /// <param name="container"></param>
        /// <param name="blobUri"></param>
        /// <returns>The token to be used to access the file</returns>
        public Guid AddFile(string name, string container, string blobUri)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("Blob name can't be null or empty");
            }

            var validator = new Regex(RegularExpressions.Uri);

            if (!validator.IsMatch(blobUri))
            {
                throw new ArgumentException("Blob uri is invalid");
            }

            //The blob already exist
            var existingFile = GetFile(name);

            if (existingFile != null)
            {
                return(existingFile.Token);
            }

            var tableServiceContext = GetFilesContext();

            FlashCardFileInfo newFile = new FlashCardFileInfo()
            {
                Name = name, BlobUri = blobUri, Container = container
            };

            newFile.Token = Guid.NewGuid();

            tableServiceContext.AddObject("Files", newFile);
            tableServiceContext.SaveChangesWithRetries();

            return(newFile.Token);
        }
        /// <summary>
        /// Add a FlashCardFileInfo to the Files table
        /// </summary>
        /// <param name="name"></param>
        /// <param name="container"></param>
        /// <param name="blobUri"></param>
        /// <returns>The token to be used to access the file</returns>
        public Guid AddFile(string name, string container, string blobUri)
        {
            if (string.IsNullOrEmpty(name))
               throw new ArgumentException("Blob name can't be null or empty");

            var validator = new Regex(RegularExpressions.Uri);
            if (!validator.IsMatch(blobUri))
                throw new ArgumentException("Blob uri is invalid");

            //The blob already exist
            var existingFile = GetFile(name);
            if (existingFile != null)
                return existingFile.Token;

            var tableServiceContext = GetFilesContext();

            FlashCardFileInfo newFile = new FlashCardFileInfo() { Name = name, BlobUri = blobUri, Container = container };
            newFile.Token = Guid.NewGuid();

            tableServiceContext.AddObject("Files", newFile);
            tableServiceContext.SaveChangesWithRetries();

            return newFile.Token;
        }