map improvement

user picture
image crop
This commit is contained in:
2011-03-31 06:24:59 +03:00
parent 833083ca0e
commit c0d31a8652
65 changed files with 3128 additions and 41 deletions
@@ -3,14 +3,28 @@ using System.Collections.Generic;
using System.Data.Objects;
using System.Data.SqlTypes;
using System.Linq;
using System.Net;
using System.Text;
using Microsoft.SqlServer.Types;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;
using MyFriendsAround.Common.Entities;
using System.IO;
using System.Configuration;
namespace MyFriendsAround.Data.BLL
{
public static class FriendsRepository
{
private static string profilesContainerName = string.Empty;
private static string profileImageFormat = string.Empty;
static FriendsRepository()
{
profilesContainerName = ConfigurationManager.AppSettings["azureProfilesContainer"];
profileImageFormat = ConfigurationManager.AppSettings["profileImageFormat"];
}
public static List<Friend> GetFriends()
{
return GetFriends(0, 50);
@@ -32,6 +46,11 @@ namespace MyFriendsAround.Data.BLL
}
}
/// <summary>
/// Publish user info
/// </summary>
/// <param name="friend">friend obj</param>
/// <returns>true if success</returns>
public static bool PublishLocation(Friend friend)
{
using (MyFriendsModelContainer ctx = new MyFriendsModelContainer())
@@ -55,7 +74,7 @@ namespace MyFriendsAround.Data.BLL
bool success = ctx.SaveChanges() > 0;
if (success)
{
//update gegraphy field
//update geography field
ctx.ExecuteFunction("UpdateFriendLocationById", new ObjectParameter[]
{
new ObjectParameter("FriendID", friend.Id),
@@ -65,10 +84,78 @@ namespace MyFriendsAround.Data.BLL
}
}
private static bool storageInitialized = false;
private static object gate = new Object();
private static CloudBlobClient blobStorage;
public static bool UpdatePicture(string userId, byte[] userPicture)
{
bool success = false;
try
{
InitializeStorage();
return false;
// upload the image to blob storage
CloudBlobContainer container = blobStorage.GetContainerReference(profilesContainerName);
string uniqueBlobName = string.Format(profileImageFormat, userId);
CloudBlockBlob blob = container.GetBlockBlobReference(uniqueBlobName);
blob.DeleteIfExists();
blob.Properties.ContentType = "image/jpeg";
using (MemoryStream ms = new MemoryStream(userPicture))
{
blob.UploadFromStream(ms);
}
//
System.Diagnostics.Trace.TraceInformation("Uploaded image '{0}' to blob storage as '{1}'", userId, uniqueBlobName);
//
success = true;
}
catch (Exception)
{
throw;
}
return success;
}
private static void InitializeStorage()
{
if (storageInitialized)
{
return;
}
lock (gate)
{
if (storageInitialized)
{
return;
}
try
{
// read account configuration settings
var storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
// create blob container for images
blobStorage = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobStorage.GetContainerReference(profilesContainerName);
container.CreateIfNotExist();
// configure container for public access
var permissions = container.GetPermissions();
permissions.PublicAccess = BlobContainerPublicAccessType.Container;
container.SetPermissions(permissions);
}
catch (WebException)
{
throw new WebException("Storage services initialization failure. "
+ "Check your storage account configuration settings. If running locally, "
+ "ensure that the Development Storage service is running.");
}
storageInitialized = true;
}
}
}
@@ -49,7 +49,9 @@
<HintPath>..\Libs\Sql\Microsoft.SqlServer.Types.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.WindowsAzure.StorageClient, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Data.Entity" />
<Reference Include="System.Xml.Linq" />