Esempio n. 1
0
            private static void FinaliseTexture(string url, ulong codedURL, Texture2D tex, Action <ServerImage> successCallback, string cancelKey)
            {
                Debugger.Log("FinaliseTexture key: " + cancelKey + " url: " + url, (int)SharedSystems.Systems.WEB_IMAGE);
                CacheImage    newCacheImage = new CacheImage();
                WeakReference weakReference = new WeakReference(tex);

                newCacheImage.weakReference = weakReference;
                newCacheImage.isCached      = false;
                newCacheImage.timeStamp     = System.DateTime.UtcNow;
                if (RemoveRequest(cancelKey, codedURL))
                {
                    try
                    {
                        ServerImage image = new ServerImage();

                        image.texture  = newCacheImage.weakReference.Target as Texture2D;
                        image.isCached = false;

                        Debugger.Log("FinaliseTexture successCallback key: " + cancelKey + " url: " + url, (int)SharedSystems.Systems.WEB_IMAGE);
                        successCallback(image);
                    }
                    catch (Exception ex)
                    {
                        Debugger.Error("FinaliseTexture Error in success callback (" + cancelKey + "): " + ex.Message, (int)SharedSystems.Systems.WEB_IMAGE);
                    }
                }
                else
                {
                    Debugger.Log("FinaliseTexture RemoveRequestFailed url: " + url, (int)SharedSystems.Systems.WEB_IMAGE);
                }

                AddImageToCache(newCacheImage, codedURL);
            }
        public void TestGetImage()
        {
            IComputeProvider          provider = new CloudServersProvider(Bootstrapper.Settings.TestIdentity);
            IEnumerable <ServerImage> images   = ListAllImagesWithDetails(provider);

            Assert.IsNotNull(images);
            if (!images.Any())
            {
                Assert.Inconclusive("The test could not proceed because the specified account and/or region does not appear to contain any images.");
            }

            foreach (ServerImage image in images)
            {
                Assert.IsNotNull(image);
                ServerImage details = provider.GetImage(image.Id);
                Assert.AreEqual(image.Created, details.Created);
                Assert.AreEqual(image.DiskConfig, details.DiskConfig);
                Assert.AreEqual(image.Id, details.Id);
                //Assert.AreEqual(image.Links, details.Links);
                Assert.AreEqual(image.MinDisk, details.MinDisk);
                Assert.AreEqual(image.MinRAM, details.MinRAM);
                Assert.AreEqual(image.Name, details.Name);
                //Assert.AreEqual(image.Progress, details.Progress);
                Assert.AreEqual(image.Server, details.Server);
                //Assert.AreEqual(image.Status, details.Status);
                Assert.AreEqual(image.Updated, details.Updated);
            }
        }
Esempio n. 3
0
        public void Should_Retrieve_Image_By_Name()
        {
            var provider = new CloudServersProvider(_testIdentity);
            var images   = provider.ListImagesWithDetails();

            _testImage = images.First(i => i.Name == _testImageName);

            Assert.IsNotNull(_testImage);
        }
Esempio n. 4
0
        /// <summary>
        /// 从内存字典中获取服务缓冲区图片文件
        /// </summary>
        /// <param name="MD5">图片MD5值</param>
        /// <returns></returns>
        private ServerImage getServerImage(string MD5)
        {
            ServerImage image = null;

            if (Images.ContainsKey(MD5)) //如果文件存在
            {
                Images.TryGetValue(MD5, out image);
            }
            return(image);
        }
Esempio n. 5
0
        public void Add()
        {
            var image = new ServerImage {
                Id = "123", Path = "MyPath"
            };
            var autoMocker = new AutoMocker();
            var testee     = autoMocker.CreateInstance <ImageController>();

            testee.Post(image);

            autoMocker.GetMock <IServerImageRepository>().Verify(x => x.Add(image), Times.Once);
        }
Esempio n. 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            m_serverImg = (ServerImage)Session["serverImg"];

            if (!Page.IsPostBack)
            {
                imgNameLbl.Text = m_serverImg.m_imgName;
                userName.Text   = Session["userName"].ToString();

                imgPreview.ImageUrl = ImagePath.IMAGE_STORAGE_PATH + m_serverImg.m_imgID;

                UpdateImgTags();

                renameText.Text = m_serverImg.m_imgName;
            }
        }
Esempio n. 7
0
        internal DetailImage (ServerImage _image, CustomNotification _notice)
		{
			InitializeComponent ();
            currentImage = _image;
            notice = _notice;

            if(currentImage != null)
            {
                im_current.Source = currentImage.UriImage;
            }

            bt_back.Text = "Back";
            bt_del.Text = "X";

            bt_back.Clicked += async (x, y) => { await Navigation.PopModalAsync(true); };
            bt_del.Clicked += Bt_del_Clicked;
		}
Esempio n. 8
0
        public void TestGetImage()
        {
            IComputeProvider          provider = Bootstrapper.CreateComputeProvider();
            IEnumerable <ServerImage> images   = ListAllImagesWithDetails(provider);

            Assert.IsNotNull(images);
            if (!images.Any())
            {
                Assert.Inconclusive("The test could not proceed because the specified account and/or region does not appear to contain any images.");
            }

            foreach (ServerImage image in images)
            {
                Assert.IsNotNull(image);
                ServerImage details = provider.GetImage(image.Id);
                Assert.AreEqual(image.Created, details.Created);
                Assert.AreEqual(image.DiskConfig, details.DiskConfig);
                Assert.AreEqual(image.Id, details.Id);

                Assert.IsNotNull(details.Links);
                Assert.AreEqual(image.Links.Length, details.Links.Length);
                for (int i = 0; i < image.Links.Length; i++)
                {
                    // this could start to fail if the server reorders links; if that occurs the test should be rewritten to allow it
                    Assert.AreEqual(image.Links[i].Href, details.Links[i].Href);
                    Assert.AreEqual(image.Links[i].Rel, details.Links[i].Rel);
                }

                Assert.AreEqual(image.MinDisk, details.MinDisk);
                Assert.AreEqual(image.MinRAM, details.MinRAM);
                Assert.AreEqual(image.Name, details.Name);

                Assert.IsTrue(details.Progress >= 0 && details.Progress <= 100);

                if (image.Server != null)
                {
                    Assert.IsNotNull(details.Server);
                    Assert.AreEqual(image.Server.Id, details.Server.Id);
                }

                Assert.IsNotNull(details.Status);

                Assert.AreEqual(image.Updated, details.Updated);
            }
        }
Esempio n. 9
0
        public IActionResult Upload()
        {
            var formFile = Request.Form.Files.FirstOrDefault();

            if (formFile != null)
            {
                var virtualFilePath = ImageUploader.Upload(_HostingEnvironment, formFile);

                var image = new ServerImage
                {
                    Name            = formFile.FileName,
                    VirtualFilePath = virtualFilePath
                };

                _ServerImageRepository.Create(image);
            }

            return(Ok(ServiceResponse.Ok()));
        }
Esempio n. 10
0
        public static IEnumerable <ServerImage> ListAllImagesWithDetails(IComputeProvider provider, int?blockSize = null, string server = null, string imageName = null, ImageState imageStatus = null, DateTimeOffset?changesSince = null, ImageType imageType = null, string region = null, CloudIdentity identity = null)
        {
            if (blockSize <= 0)
            {
                throw new ArgumentOutOfRangeException("blockSize");
            }

            ServerImage lastImage = null;

            do
            {
                string marker = lastImage != null ? lastImage.Id : null;
                IEnumerable <ServerImage> images = provider.ListImagesWithDetails(server, imageName, imageStatus, changesSince, marker, blockSize, imageType, region, identity);
                lastImage = null;
                foreach (ServerImage image in images)
                {
                    lastImage = image;
                    yield return(image);
                }
            } while (lastImage != null);
        }
        public void TestCreateImage()
        {
            IComputeProvider provider = Bootstrapper.CreateComputeProvider();

            /* Create the image
             */
            string imageName = UserComputeTests.UnitTestImagePrefix + Path.GetRandomFileName();
            bool   imaged    = provider.CreateImage(_server.Id, imageName);

            Assert.IsTrue(imaged);
            ServerImage[] images = provider.ListImagesWithDetails(server: _server.Id, imageName: imageName).ToArray();
            Assert.IsNotNull(images);
            Assert.AreEqual(1, images.Length);

            ServerImage image = images[0];

            Assert.AreEqual(imageName, image.Name);
            Assert.IsFalse(string.IsNullOrEmpty(image.Id));

            Assert.AreEqual(ImageState.Active, provider.WaitForImageActive(image.Id).Status);

            /* Test metadata operations on the image
             */
            Assert.IsTrue(provider.SetImageMetadataItem(image.Id, "Item 1", "Value"));
            Assert.AreEqual("Value", provider.GetImageMetadataItem(image.Id, "Item 1"));
            Assert.IsTrue(provider.SetImageMetadataItem(image.Id, "Item 2", "Value ²"));
            Assert.AreEqual("Value ²", provider.GetImageMetadataItem(image.Id, "Item 2"));

            // setting the same key overwrites the previous value
            Assert.IsTrue(provider.SetImageMetadataItem(image.Id, "Item 1", "Value 1"));
            Assert.AreEqual("Value 1", provider.GetImageMetadataItem(image.Id, "Item 1"));

            Assert.IsTrue(provider.DeleteImageMetadataItem(image.Id, "Item 1"));
            Assert.IsFalse(provider.ListImageMetadata(image.Id).ContainsKey("Item 1"));

            Metadata metadata = new Metadata()
            {
                { "Different", "Variables" },
            };

            Assert.IsTrue(provider.UpdateImageMetadata(image.Id, metadata));
            Metadata actual = provider.ListImageMetadata(image.Id);

            Assert.IsNotNull(actual);
            Assert.AreEqual("Value ²", actual["Item 2"]);
            Assert.AreEqual("Variables", actual["Different"]);

            // a slight tweak
            metadata["Different"] = "Values";
            Assert.IsTrue(provider.SetImageMetadata(image.Id, metadata));
            actual = provider.ListImageMetadata(image.Id);
            Assert.IsNotNull(actual);
            Assert.AreEqual(1, actual.Count);
            Assert.AreEqual("Values", actual["Different"]);

            Assert.IsTrue(provider.SetImageMetadata(image.Id, new Metadata()));
            Assert.AreEqual(0, provider.ListImageMetadata(image.Id).Count);

            /* Cleanup
             */
            bool deleted = provider.DeleteImage(images[0].Id);

            Assert.IsTrue(deleted);
            provider.WaitForImageDeleted(images[0].Id);
        }
 /*!
  *  \brief 通过调用这个方法来显示设置这个图片模板的数据。
  *  \param showImg 被显示的图片信息,包括图片的ID、名称、所属用户。
  */
 public void Initialize(ServerImage showImg)
 {
     m_serverImg = showImg;
     UpdateImg();
 }
Esempio n. 13
0
            public static void Request(string url, Action <ServerImage> successCallback, Action <string> failedCallback = null, Action <ProgressResponse> progressCallback = null, string cancelKey = DEFAULT_URL_CANCEL_KEY, float cacheTimeOutInSecs = DEFAULT_CACHE_TIMEOUT, float requestTimeout = -1)
            {
                if (m_prefixURL != null && !url.Contains("http"))
                {
                    url = m_prefixURL + url;
                }

                CacheImage cacheImage;
                bool       useMemoryCache = false;
                bool       imageOnDisk    = false;
                ulong      codedURL       = GetHashCodeInt64(url);

                Debugger.Log("WebImage::Request key: " + cancelKey + " url: " + url, (int)SharedSystems.Systems.WEB_IMAGE);
                Debugger.Assert(!string.IsNullOrEmpty(cancelKey), "WebImage:;Request() called with no cancel key, ignoring request");
                if (string.IsNullOrEmpty(cancelKey))
                {
                    return;
                }

                if (s_cachedImages.TryGetValue(codedURL, out cacheImage))
                {
                    useMemoryCache = ((cacheImage.weakReference.Target as Texture2D) != null);
                }

                Debugger.Log("WebImage::Request useMemoryCache: " + useMemoryCache, (int)SharedSystems.Systems.WEB_IMAGE);
                if (useMemoryCache)
                {
                    cacheImage.isCached  = true;
                    cacheImage.timeStamp = System.DateTime.UtcNow;

                    if (progressCallback != null)
                    {
                        ProgressResponse progress = new ProgressResponse();
                        progress.isDone   = true;
                        progress.progress = (float)1.0;
                        progressCallback(progress);
                    }

                    if (successCallback != null)
                    {
                        ServerImage image = new ServerImage();

                        image.texture  = cacheImage.weakReference.Target as Texture2D;
                        image.isCached = true;

                        Debugger.Log("WebImage::Request successCallback key: " + cancelKey + " url: " + url, (int)SharedSystems.Systems.WEB_IMAGE);
                        successCallback(image);
                    }
                }
                else
                {
                    bool doRequest = true;

                    string filePath = Application.temporaryCachePath + "/CACHE" + codedURL.ToString();

                    if (System.IO.File.Exists(filePath))
                    {
                        //check how old
                        System.DateTime written      = File.GetLastWriteTimeUtc(filePath);
                        System.DateTime now          = System.DateTime.UtcNow;
                        double          totalSeconds = now.Subtract(written).TotalSeconds;

                        if (totalSeconds < cacheTimeOutInSecs)
                        {
                            doRequest = false;

                            CoroutineHelper.Instance.Run(LoadImageFromDiskInternal(filePath, codedURL, successCallback, cancelKey));
                        }
                    }

                    if (doRequest)
                    {
                        CoroutineHelper.Instance.Run(GetImage(url, codedURL, successCallback, progressCallback, failedCallback, cancelKey, imageOnDisk, requestTimeout));
                    }
                }
            }
Esempio n. 14
0
        /// <summary>
        /// 文件传送
        /// </summary>
        /// <param name="FileTransmit"></param>
        /// <param name="session"></param>
        private void onFileTransmit(ImageFileMsg FileMsg, TCPServerSession session)
        {
            if (FileMsg.Length > 1024000 || FileMsg.Length < 0)
            {
                return;                                                //如果所传输的文件大于1M或无大小则为非法请求退出
            }
            ServerImage image        = getServerImage(FileMsg.MD5);
            string      fullFileName = System.Windows.Forms.Application.StartupPath + "\\Images\\" + FileMsg.MD5 + FileMsg.Extension;//标记文件路径

            #region 在内存中为文件创建空间
            if (FileMsg.type == type.New)                               //上传文件请求
            {
                if (image == null)                                      //如果服务器内存中无此文件
                {
                    image = new ServerImage(FileMsg.MD5);               //创建内存文件
                    Images.Add(image.MD5, image);                       //将内存文件添加到文件下载服务区
                    if (File.Exists(fullFileName))                      //如果文件已在服务器硬盘中
                    {
                        image.Data         = OpFile.Read(fullFileName); //将文件数据全部读取到内存
                        image.Length       = image.Data.Length;         //设置准确的文件长度
                        image.uploadLength = image.Length;              //标记文件已经全部上传完成
                        FileMsg.type       = type.over;                 //标识文件已经传输完成,通知客户端停止上传
                        sendFileMsg(FileMsg, session);                  //通知客户端文件已经上传完成
                        session.Disconnect();                           //断开客户端的TCP连接
                    }
                    else
                    {
                        image.Extension = FileMsg.Extension;
                        image.Length    = FileMsg.Length;
                        image.Name      = FileMsg.Name;
                        image.userID    = FileMsg.from;
                        image.Data      = new byte[image.Length]; //创建内存空间

                        FileMsg.type       = type.set;            //通知客户端上传
                        FileMsg.LastLength = 0;                   //上传位置从零开始
                        sendFileMsg(FileMsg, session);            //通知客户端可以上传文件
                    }
                }
                else//如果服务器内存中有此文件
                {
                    FileMsg.type = type.over;//标识文件已经传输完成,通知客户端停止上传
                    sendFileMsg(FileMsg, session); //通知客户端文件已经上传完成
                    session.Disconnect();          //断开客户端的TCP连接
                }
            }
            #endregion

            #region  载文件
            if (FileMsg.type == type.get)                                  //下载文件请求
            {
                if (image == null)                                         //如果内存中无文件
                {
                    if (File.Exists(fullFileName))                         //如果文件已在服务器硬盘中
                    {
                        image              = new ServerImage(FileMsg.MD5); //创建内存文件
                        image.MD5          = FileMsg.MD5;
                        image.Data         = OpFile.Read(fullFileName);    //将文件数据全部读取到内存
                        image.Length       = image.Data.Length;            //设置准确的文件长度
                        image.uploadLength = image.Length;                 //标记文件已经全部上传完成
                        Images.Add(image.MD5, image);                      //将内存文件添加到文件下载服务区
                    }
                }

                if (image != null && FileMsg.LastLength < image.Data.Length) //如果内存中有文件
                {
                    if (FileMsg.LastLength + 10240 > image.Data.Length)
                    {
                        FileMsg.fileBlock = new byte[image.Data.Length - FileMsg.LastLength];//要发送的缓冲区
                    }
                    else
                    {
                        FileMsg.fileBlock = new byte[10240];                                                               //要发送的缓冲区
                    }
                    Buffer.BlockCopy(image.Data, (int)FileMsg.LastLength, FileMsg.fileBlock, 0, FileMsg.fileBlock.Length); //将其保存于Buffer字节数组

                    FileMsg.type        = type.get;                                                                        //下载标记
                    FileMsg.LastLength += FileMsg.fileBlock.Length;
                    sendFileMsg(FileMsg, session);

                    if (FileMsg.LastLength == image.Data.Length)
                    {
                        FileMsg.type      = type.over;//标记下载完成
                        FileMsg.fileBlock = null;
                        sendFileMsg(FileMsg, session);
                        session.Disconnect();
                    }
                }
            }
            #endregion

            #region   文件
            if (FileMsg.type == type.set)//上传文件内容
            {
                if (image.uploadLength + FileMsg.fileBlock.Length > image.Length)
                {
                    return;
                }

                Buffer.BlockCopy(FileMsg.fileBlock, 0, image.Data, (int)image.uploadLength, FileMsg.fileBlock.Length); //将收到的数据保存于Buffer字节数组

                image.uploadLength += FileMsg.fileBlock.Length;                                                        //设置最后一次上传文件的末尾长度

                FileMsg.LastLength = image.uploadLength;                                                               //告诉客户端已上传的文件位置
                FileMsg.fileBlock  = null;

                if (image.uploadLength == image.Length)//如果文件上传完成
                {
                    OpFile.Write(image.Data, fullFileName);
                    FileMsg.type = type.over;      //标识文件已经传输完成,通知客户端停止上传
                    sendFileMsg(FileMsg, session); //通知客户端文件已经上传完成
                    session.Disconnect();          //断开客户端的TCP连接
                }
                else
                {
                    sendFileMsg(FileMsg, session);//通知客户端上传文件下一数据包
                }
            }
            #endregion
        }
Esempio n. 15
0
 public void Post([FromBody] ServerImage entry)
 {
     ServerImageRepository.Add(entry);
 }