public static bool SaveBinaryFile <T>(T obj, string fullPath, bool isCloud, bool backupOld, JsonSerializerSettings jsonSettings) where T : class { if (backupOld && FileUtilities.Exists(fullPath, isCloud)) { FileUtilities.Copy(fullPath, fullPath + ".bak", isCloud); } string jsonStr = JsonConvert.SerializeObject(obj, obj.GetType(), jsonSettings); if (isCloud) { if (SocialAPI.Cloud != null) { return(false); } using (Stream memStream = (Stream) new MemoryStream()) { FileHelpers.ToStream(jsonStr, memStream); SocialAPI.Cloud.Write(fullPath, ((MemoryStream)memStream).ToArray()); } } else { using (Stream fileStream = (Stream) new FileStream(fullPath, FileMode.Create, FileAccess.Write)) { FileHelpers.ToStream(jsonStr, fileStream); } } return(true); }