Пример #1
0
        public ItemImage Save(ItemRequestImageInput image)
        {
            var id          = Guid.NewGuid();
            var virtualPath = string.Format("request/{0}_{1}.jpg", id, "{0}");
            var sproc       = new GoodsSaveItemRequestImage()
            {
                Identifier            = id,
                ContentType           = image.ContentType,
                FileName              = image.FileName,
                FileSize              = image.FileSize,
                ItemRequestIdentifier = image.ItemRequestIdentifier,
                UserIdentifier        = image.UserIdentifier,
                Path = string.Format("/user/{0}", virtualPath),
            };

            var storedImage = sproc.CallObject <ItemRequestImageInput>();

            var container = new BinaryContainer("user");

            container.Save(string.Format(virtualPath, OriginalName), image.Contents, image.ContentType);

            var thumbnail = this.Thumbnail(image.Contents, ImageFormat.Jpeg);

            var thumbnailPath = string.Format(virtualPath, ImageCore.ThumbnailName);

            container.Save(thumbnailPath, thumbnail, contentType);

            var large = this.Large(image.Contents, ImageFormat.Jpeg);

            var largePath = string.Format(virtualPath, ImageCore.LargeName);

            container.Save(largePath, large, contentType);

            var activity = new ActivityCore();

            activity.NewItemRequestImage(storedImage);

            return(new ItemImage()
            {
                VirtualPathFormat = string.Format("/user/{0}", thumbnailPath),
            });
        }
        public void GetBytesExtension()
        {
            var    bytes  = new byte[256];
            Random random = new Random();

            random.NextBytes(bytes);
            var containerName = Guid.NewGuid().ToString().Replace("-", string.Empty);
            var container     = new BinaryContainer(CloudStorageAccount.DevelopmentStorageAccount, containerName);

            container.EnsureExist();

            var id       = string.Format("{0}.jpeg", Guid.NewGuid());
            var uri      = container.Save(id, bytes, "na");
            var returned = container.GetBytes(id);

            Assert.IsTrue(bytes.ContentEquals(returned));
        }
Пример #3
0
        public void SaveWithTimeOut()
        {
            var    bytes  = new byte[256];
            Random random = new Random();

            random.NextBytes(bytes);
            var containerName = "aslasdasdkdjh";
            var container     = new BinaryContainer(CloudStorageAccount.DevelopmentStorageAccount, containerName);

            container.EnsureExist();

            var id       = Guid.NewGuid().ToString();
            var uri      = container.Save(id, bytes, "na", new TimeSpan(0, 1, 0));
            var returned = container.GetBytes(id);

            Assert.IsTrue(bytes.ContentEquals(returned));
        }
        public void GetStream()
        {
            var    bytes  = new byte[256];
            Random random = new Random();

            random.NextBytes(bytes);
            var containerName = Guid.NewGuid().ToString().Replace("-", string.Empty);
            var container     = new BinaryContainer(CloudStorageAccount.DevelopmentStorageAccount, containerName);

            container.EnsureExist();

            var id  = Guid.NewGuid().ToString();
            var uri = container.Save(id, bytes, "na");

            using (var stream = container.GetStream(id) as MemoryStream)
            {
                var returned = stream.ToArray();
                Assert.IsTrue(bytes.ContentEquals(returned));
            }
        }
Пример #5
0
        public void RoundTrip()
        {
            var data   = new byte[64];
            var random = new Random();

            random.NextBytes(data);
            var objId     = "a" + Guid.NewGuid().ToString();
            var container = new BinaryContainer("test");

            container.Create().Wait();

            container.Save(objId, data);

            var result = container.Get(objId);

            Assert.IsNotNull(result);
            Assert.AreEqual <int>(data.Length, result.Length);
            for (var i = 0; i < data.Length; i++)
            {
                Assert.AreEqual <byte>(data[i], result[i]);
            }
        }
Пример #6
0
        /// <summary>
        /// Store Locations
        /// </summary>
        public async void StoreLocations()
        {
            var locations  = this.Locations();
            var dictionary = new Dictionary <long, IList <SearchLocationIp> >();

            foreach (var location in locations)
            {
                var keys = new long[] { this.Floor(location.StartIp), this.Floor(location.EndIp) };

                if (keys[0] == keys[1])
                {
                    keys = new long[] { keys[0] };
                }

                foreach (var key in keys)
                {
                    if (dictionary.ContainsKey(key))
                    {
                        dictionary[key].Add(location);
                    }
                    else
                    {
                        var locs = new List <SearchLocationIp>();
                        locs.Add(location);
                        dictionary.Add(key, locs);
                    }
                }
            }

            var container = new BinaryContainer(spatialIpContainer);

            foreach (var key in dictionary.Keys)
            {
                container.Save(string.Format(spatialIpFileFormat, key), dictionary[key].Serialize());
            }
        }
Пример #7
0
        public void SaveWithTimeSpanMaxTimeSpan()
        {
            var container = new BinaryContainer(CloudStorageAccount.DevelopmentStorageAccount, "asdasdfa");

            container.Save(StringHelper.ValidString(), null, StringHelper.NullEmptyWhiteSpace(), TimeSpan.MaxValue);
        }
Пример #8
0
        public void SaveWithTimeSpanInvalidContentType()
        {
            var container = new BinaryContainer(CloudStorageAccount.DevelopmentStorageAccount, "asdasdfa");

            container.Save(StringHelper.ValidString(), null, StringHelper.NullEmptyWhiteSpace(), new TimeSpan(0, 0, 45));
        }
Пример #9
0
        public void SaveInvalidId()
        {
            var container = new BinaryContainer(CloudStorageAccount.DevelopmentStorageAccount, "asdasdfa");

            container.Save(StringHelper.NullEmptyWhiteSpace(), null, StringHelper.ValidString());
        }