Exemplo n.º 1
0
 public static string ChangeProfileImage(Image gotImg)
 {
     using (Bitmap roundedBmp = new Bitmap(GraphicsStudio.ClipToCircle(gotImg), new Size(200, 200)))
     {
         JObject profileImgIdJson = null;
         byte[]  imgByteArray     = Universal.ImageToByteArray(roundedBmp, gotImg.RawFormat);
         ServerHub.WorkingInstance.ServerHubProxy.Invoke <JObject>("ChangeProfileImage", Consumer.LoggedIn.Id, imgByteArray).ContinueWith(task =>
         {
             if (!task.IsFaulted)
             {
                 profileImgIdJson = task.Result;
             }
         }).Wait();
         if (profileImgIdJson == null)
         {
             return(null);
         }
         try
         {
             string oldProfileImgId = profileImgIdJson["old_image_id"].ToString();
             if (oldProfileImgId != null && oldProfileImgId.Length > 5)
             {
                 LocalDataFileAccess.EraseOldProfileImageFromLocalData(oldProfileImgId);
             }
             string newImgId = profileImgIdJson["new_image_id"].ToString();
             LocalDataFileAccess.SaveProfileImageToLocal(roundedBmp, newImgId);
             return(newImgId);
         }
         catch (Exception e)
         {
             Console.WriteLine("Error occured in ChangeProfileImage() => " + e.Message);
             return(null);
         }
     }
 }
Exemplo n.º 2
0
        //testing methods
        public static void SendFileToServer()
        {
            bool?result = null;

            ServerHub.WorkingInstance.ServerHubProxy.Invoke <bool>("ReceiveFile", Universal.ImageToByteArray(FileResources.NullProfileImage, ImageFormat.Png)).ContinueWith(task =>
            {
                if (!task.IsFaulted)
                {
                    result = task.Result;
                }
            }).Wait();
            if (result == null)
            {
                Console.WriteLine("File sending failed");
            }
            else
            {
                Console.WriteLine("File sending success");
            }
        }