TMCN tech-cafe Vol.01 Day3資料

289 views

Published on

Published in: Education
  • Be the first to comment

  • Be the first to like this

TMCN tech-cafe Vol.01 Day3資料

  1. 1. TMCN tech-cafe Vol.01 「Leap in the Cloud」 LeapMotionの可能性は雲の中に 2014/4/23 初音玲
  2. 2. 資料:MSDN http://msdn.microsoft.com/ja-jp/ library/azure/ jj554228.aspx
  3. 3. .NET(VB/C#) http://azure.microsoft.com/en-us/ documentation/articles/ mobile-services-windows-dotnet-how-to-use- client-library/
  4. 4. JavaScript:... http://azure.microsoft.com/en-us/ documentation/articles/ mobile-services-html-how-to-use-client- library/
  5. 5. 準備:VB.NET / C# 1. プロジェクトを右クリックし、[NuGet パッケージの管理] を選択 2. WindowsAzure.MobileServices パッケージを検索して追加 3. "using Microsoft.WindowsAzure.MobileServices;" を追加 4. 次のコードを追加 public static MobileServiceClient MobileService = new MobileServiceClient( "https://leapcloud.azure-mobile.net/");
  6. 6. ユーザ登録:VB.NET/C# public class UserItem { public string Id { get; set; } public string UserId { get; set; } public string UserName { get; set; }} private IMobileServiceTable<UserItem> userTable =App.MobileService.GetTable<UserItem>(); await userTable.InsertAsync(new UserItem {UserName = “hatsune_"}); var query = userTable.CreateQuery(); query.Parameters.Add("UserName","hatsune_"); var response = await query.ToListAsync();
  7. 7. じゃんけん:VB.NET/C#
  8. 8. 準備:JS 1. HTML部分へ追加 <script src="http://ajax.aspnetcdn.com/ajax/mobileservices/MobileSe rvices.Web-1.1.3.min.js"></script> 2. JavaScriptコードに追加 var client = new WindowsAzure.MobileServiceClient( "https://leapcloud.azure- mobile.net/");
  9. 9. ユーザ登録:JS var item = { UserName: “hatsune_” }; client.getTable(“UserItem").insert(item); userItemTable = client.getTable(‘UserItem'); var query = userItemTable.where({UserName: “hatsune_”}); query.read().then(function(userItems){ var listItems = $.map(userItems, function(item) { item.UserId }); };
  10. 10. 参考:UserItem-insert.js function insert(item, user, request) { var userDeviceTable = tables.getTable('UserItem'); userDeviceTable.where({ UserName: item.UserName }).read({ success: function(results) { if (results.length > 0) { console.log('User %s is duplicate.', item.UserId); request.respond(statusCodes.BAD_REQUEST, 'ユーザ名が重複しています。'); } else { request.execute(); } } }); }
  11. 11. 参考:UserItem-read.js function read(query, user, request) { var param = request.parameters.UserName; if (param) { var sql = "SELECT Id,Id AS UserId,UserName “ + “FROM [LeapCloud].UserItem WHERE UserName = ?"; mssql.query(sql, param, { success: function (results) { request.respond(statusCodes.OK, results); } }); } else { request.respond(statusCodes.BAD_REQUEST, 'ユーザ名が登録されていません。'); } }

×