public JsonResult QueuePhotoRender(ComicEffectType effect, string photoSource, int intensity) { // Generate render task PhotoTask task = new PhotoTask(); task.TaskId = Guid.NewGuid(); task.Status = TaskStatus.Queued; task.Effect = effect; task.Intensity = intensity; task.FacebookToken = this.Facebook.AccessToken; task.SourceUrl = photoSource; task.OwnerUid = this.ActiveUser.Uid; // Queue the task up using Azure Queue services. Store full task information using Blob storage. Only the task id is queued. // This is done because we need public visibility on render tasks before, during and after the task completes. // Save task to storage CloudBlobContainer container = this.BlobClient.GetContainerReference(ComicConfigSectionGroup.Blob.TaskContainer); CloudBlobDirectory directory = container.GetDirectoryReference(ComicConfigSectionGroup.Blob.PhotoTaskDirectory); CloudBlob blob = directory.GetBlobReference(task.TaskId.ToString()); blob.UploadText(task.ToXml()); // Queue up task CloudQueue queue = this.QueueClient.GetQueueReference(ComicConfigSectionGroup.Queue.PhotoTaskQueue); CloudQueueMessage message = new CloudQueueMessage(task.TaskId.ToString()); queue.AddMessage(message, TimeSpan.FromMinutes(5)); return(this.Json(new ClientPhotoTask(task, null), JsonRequestBehavior.DenyGet)); }
/// <summary> /// 部屋に参加する /// </summary> private static async Task <IResult <string, Unit> > JoinRoom(string roomName, bool createIfNoExists) { var joined = await PhotoTask.JoinRoom(roomName); if (joined.IsSuccess) { return(ToSuccess()); } if (!createIfNoExists) { return(ToFailure("No room.")); } // 部屋を作って参加する var created = await PhotoTask.CreateRoom(roomName, null, null, null); if (!created.IsSuccess) { //失敗 return(ToFailure(created.TryGetFailureValue.ToString())); } return(ToSuccess()); }
private void RemoveTask(PhotoTask task) { CloudBlobContainer container = this.BlobClient.GetContainerReference(ComicConfigSectionGroup.Blob.TaskContainer); CloudBlobDirectory directory = container.GetDirectoryReference(ComicConfigSectionGroup.Blob.PhotoTaskDirectory); CloudBlob blob = directory.GetBlobReference(task.TaskId.ToString()); blob.DeleteIfExists(); }
public ClientPhotoTask(PhotoTask source, ClientPhoto photo) { this.TaskId = source.TaskId; this.Status = source.Status; this.OwnerUid = source.OwnerUid; this.Effect = source.Effect; this.Intensity = source.Intensity; this.Photo = photo; }
public override async UniTask Initialize() { PhotonNetwork.autoJoinLobby = true; var connect = await PhotoTask.ConnectUsingSettings(RoomDefine.CONNECTING_SETTING); if (connect.IsFailure) { InstantLog.StringLogError(connect.ToFailure.Value); return; } }
/// <summary> /// Photonのサーバに接続する /// </summary> private static async Task <IResult <string, Unit> > Connect() { // サーバに接続 var connect = await PhotoTask.ConnectUsingSettings("v1"); if (connect.IsFailure) { return(ToFailure(connect.TryGetFailureValue.ToString())); } return(ToSuccess()); }
public PhotoTask Post(PhotoTask task) { try { _context.PhotoTasks.Add(task); _context.SaveChanges(); return(task); } catch (Exception ex) { throw ex; } }
private void UpdateTask(PhotoTask task) { try { CloudBlobContainer container = this.BlobClient.GetContainerReference(ComicConfigSectionGroup.Blob.TaskContainer); CloudBlobDirectory directory = container.GetDirectoryReference(ComicConfigSectionGroup.Blob.PhotoTaskDirectory); CloudBlob progressBlob = directory.GetBlobReference(task.TaskId.ToString()); progressBlob.UploadText(task.ToXml()); } catch (Exception x) { this.Log.Error("Unable to update render progress", x); } }
public async UniTask CreateRoom(string roomName, string anchorId) { if (string.IsNullOrWhiteSpace(roomName)) { return; } var option = RoomUtility.GetCloudRoomTemplate(anchorId); await FailureHandlingPhotonTask(PhotoTask.CreateRoom(roomName, option, null), _ => { RoomManager.Instance.Model.CreateRoom(roomName); RoomManager.Instance.Model.SetAnchorId(anchorId); }); }
public async UniTask CreateRoom(string roomName) { if (string.IsNullOrWhiteSpace(roomName)) { return; } var option = RoomUtility.GetCloudRoomTemplate(string.Empty); await FailureHandlingPhotonTask(PhotoTask.CreateRoom(roomName, option, null), _ => { RoomManager.Instance.Model.CreateRoom(roomName); if (option.CustomRoomProperties.TryGetValue(RoomDefine.ANCHOR_KEY, out var anchorId)) { RoomManager.Instance.Model.SetAnchorId(anchorId.ToString()); } }); }
// Use this for initialization void Start() { //Screen.sleepTimeout = SleepTimeout.NeverSleep ; DeviceInput.Init(); // setup smoothing class Smoothed.SetSmoothingStrength(Smooth); // sensor fusion needs gyroscope m_UseSensorFusion = DeviceInput.HasGyro; m_ToggleFlash.isOn = m_FlashingFocus; m_ToggleSnap.isOn = m_SnapIfAccurate; m_ToggleSensorFusion.isOn = m_UseSensorFusion; if (!DeviceInput.HasGyro) { m_ToggleSensorFusion.interactable = false; } // find parent m_PhotoTask = transform.parent.gameObject.GetComponent <PhotoTask> (); // setup label objects for (int i = 0; i < 4; i++) { // TaskPanel Panels[i] = transform.Find(PanelTitles[i]).gameObject.GetComponent <TaskPanel> (); Panels[i].Heading = 90.0f * i; Panels[i].Pitch = TaskPitch; Panels[i].Name = PanelNames [i]; } // setup frame // Panel_Frame Transform TrFrame = transform.Find("Panel_Frame"); KompassFrame = TrFrame.gameObject; TrFrame.SetParent(transform.parent, false); m_StringTakePhoto = LocalizationSupport.GetString("TakePhotoPoint"); m_StringHoldStill = LocalizationSupport.GetString("TakePhotoHoldStill"); m_StringLandscape = LocalizationSupport.GetString("TakePhotoLandscape"); m_StringFocus = LocalizationSupport.GetString("TakePhotoFocus"); }
public async UniTask ConnectRoom(string roomName = "") { if (string.IsNullOrWhiteSpace(roomName)) { await FailureHandlingPhotonTask(PhotoTask.JoinRandomRoom(), _ => RoomManager.Instance.Model.JoinRoom(PhotonNetwork.room.Name)); } else { await FailureHandlingPhotonTask(PhotoTask.JoinRoom(roomName), _ => { var roomProperty = PhotonNetwork.room.CustomProperties; RoomManager.Instance.Model.JoinRoom(roomName); if(roomProperty.TryGetValue(RoomDefine.ANCHOR_KEY, out var anchorId)) { RoomManager.Instance.Model.SetAnchorId(anchorId.ToString()); } }); } }
public JsonResult PhotoRenderProgress(string taskId) { CloudBlobContainer container = this.BlobClient.GetContainerReference(ComicConfigSectionGroup.Blob.TaskContainer); CloudBlobDirectory directory = container.GetDirectoryReference(ComicConfigSectionGroup.Blob.PhotoTaskDirectory); CloudBlob blob = directory.GetBlobReference(taskId); XmlSerializer serializer = new XmlSerializer(typeof(PhotoTask)); using (MemoryStream stream = new MemoryStream()) { blob.DownloadToStream(stream); stream.Seek(0, SeekOrigin.Begin); PhotoTask task = (PhotoTask)serializer.Deserialize(stream); if (task.OwnerUid != this.ActiveUser.Uid) { throw new Exception("Unknown task"); } ClientPhoto clientPhoto = null; if (task.PhotoId.HasValue) { // Load photo from database Photo photo = this.EntityContext.TryGetPhoto(task.PhotoId.Value); if (photo != null) { clientPhoto = new ClientPhoto(photo); } } ClientPhotoTask clientTask = new ClientPhotoTask(task, clientPhoto); return(this.Json(clientTask, JsonRequestBehavior.AllowGet)); } throw new Exception("Unknown task"); }
public PhotoTask Update(PhotoTask task) { return(_repository.Put(task)); }
public PhotoTask Create(PhotoTask task) { return(_repository.Post(task)); }
public static void Initialize(ARealmContext context) { //create db if not yet exists context.Database.EnsureCreated(); if (!context.Sessions.Any()) { var task1 = new PhotoTask() { Title = "phototask 1", Description = "this is a phototask" }; context.PhotoTasks.Add(task1); var task2 = new PhotoTask() { Title = "phototask 2", Description = "this is a phototask" }; context.PhotoTasks.Add(task2); var task3 = new PhotoTask() { Title = "puzzletask 1", Description = "this is a phto" }; context.PhotoTasks.Add(task3); var task4 = new PhotoTask() { Title = "puzzletask 2", Description = "this is a photo" }; context.PhotoTasks.Add(task4); var district1 = new District() { Title = "this is locked district 1", Task = task1 }; district1.CurrentState = new Locked(district1); context.Districts.Add(district1); var district2 = new District() { Title = "this is locked district 2", Task = task2 }; district2.CurrentState = new Locked(district2); context.Districts.Add(district2); var district3 = new District() { Title = "this is locked district 3", Task = task3 }; district3.CurrentState = new Locked(district3); context.Districts.Add(district3); var district4 = new District() { Title = "this is locked district 4", Task = task4 }; district4.CurrentState = new Locked(district4); context.Districts.Add(district4); var districtList = new LockedDistricts() { Districts = new List <District>() }; districtList.Districts.Add(district1); districtList.Districts.Add(district2); districtList.Districts.Add(district3); districtList.Districts.Add(district4); context.LockedDistricts.Add(districtList); //save changes to DB context.SaveChanges(); } }
public PhotoTask Post([FromBody] PhotoTask task) { return(_service.Create(task)); }
private void ExecuteTask(object state) { CloudQueueMessage queueMessage = (CloudQueueMessage)state; this.Log.DebugFormat("Executing image task {0}", queueMessage.AsString); string connectionString = ConfigurationManager.ConnectionStrings["ComicModelContext"].ConnectionString; ComicModelContext entityContext = new ComicModelContext(connectionString); PhotoTask task = null; try { // Read task details from storage CloudBlobContainer container = this.BlobClient.GetContainerReference(ComicConfigSectionGroup.Blob.TaskContainer); CloudBlobDirectory directory = container.GetDirectoryReference(ComicConfigSectionGroup.Blob.PhotoTaskDirectory); CloudBlob blob = directory.GetBlobReference(queueMessage.AsString); XmlSerializer serializer = new XmlSerializer(typeof(PhotoTask)); using (MemoryStream stream = new MemoryStream()) { blob.DownloadToStream(stream); stream.Seek(0, SeekOrigin.Begin); task = (PhotoTask)serializer.Deserialize(stream); task.Status = TaskStatus.Executing; this.UpdateTask(task); } User user = entityContext.TryGetUser(task.OwnerUid); FacebookClient facebook = new FacebookClient(task.FacebookToken); // Get image from web Bitmap image = this.GetImage(task.SourceUrl); if (task.Effect != ComicEffectType.None) { // Apply render effect RenderHelper effectHelper = new RenderHelper(image.Size); // Translate intensity to render parameters using min / max range Dictionary <string, object> parameters = new Dictionary <string, object>(); foreach (RenderParameter p in effectHelper.GetRenderParameters(task.Effect)) { if (task.Intensity == 0) { parameters.Add(p.Name, p.MinValue); } else if (task.Intensity == 1) { parameters.Add(p.Name, p.DefaultValue); } else if (task.Intensity == 2) { parameters.Add(p.Name, p.MaxValue); } } ImageRenderData renderResult = effectHelper.RenderEffect(image, task.Effect, parameters); image = new Bitmap(renderResult.RenderStream); } // Read raw photo into memory MemoryStream imageStream = new MemoryStream(); image.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg); imageStream.Seek(0, SeekOrigin.Begin); // Save to storage Photo photo = new Photo(); photo.CreateTime = DateTime.Now; photo.User = user; photo.StorageKey = Guid.NewGuid().ToString(); photo.Width = image.Width; photo.Height = image.Height; entityContext.AddToPhotos(photo); entityContext.SaveChanges(); CloudBlobContainer imageContainer = this.BlobClient.GetContainerReference(ComicConfigSectionGroup.Blob.RenderContainer); CloudBlobDirectory imageDirectory = imageContainer.GetDirectoryReference(ComicConfigSectionGroup.Blob.PhotoDirectory); CloudBlob imageBlob = imageDirectory.GetBlobReference(photo.StorageKey); imageBlob.Properties.ContentType = "image/jpeg"; imageBlob.UploadFromStream(imageStream); // Mark task as completed task.PhotoId = photo.PhotoId; task.Status = TaskStatus.Complete; this.UpdateTask(task); this.Log.DebugFormat("Completed image task {0}", task.TaskId); } catch (Exception x) { this.Log.Error("Unable to complete image task.", x); if (task != null) { task.Status = TaskStatus.Failed; this.UpdateTask(task); } } }
public PhotoTask Put([FromBody] PhotoTask task) { return(_service.Update(task)); }