コード例 #1
0
ファイル: Note.cs プロジェクト: shakurocom/xamarin-sample-app
 public static DBNote FromNoteData(string UUID, NoteData data)
 {
     return(new DBNote
     {
         UUID = UUID,
         CreationDate = data.creationDate,
         Name = data.name,
         Text = data.text,
         ImageURLString = data.imageURLstring
     });
 }
コード例 #2
0
        internal async Task AddNoteAsync(DateTime time,
                                         string name,
                                         System.IO.Stream imageStream,
                                         string text,
                                         Action <DBNote, Error> completionHandler)
        {
            DBNote newNote = null;
            Error  error   = null;

            // get user ID
            if (_currentUserProvider() == null)
            {
                await _loginSequence();
            }
            string userID = _currentUserProvider().UUID;

            // upload image to firebase storage
            string uploadedImageURL = null;

            if (error == null && imageStream != null)
            {
                try
                {
                    string imageUUID  = Guid.NewGuid().ToString() + ".jpg";
                    var    uploadTask = _firebaseStorage
                                        .Child("user")
                                        .Child(userID)
                                        .Child(imageUUID)
                                        .PutAsync(imageStream);
                    uploadedImageURL = await uploadTask;
                }
                catch (Exception e)
                {
                    error = ErrorFromFibaseException(e);
                }
            }

            // create note entity in database
            if (error == null)
            {
                try
                {
                    NoteData noteData = new NoteData();
                    noteData.creationDate   = time;
                    noteData.name           = name;
                    noteData.imageURLstring = uploadedImageURL;
                    noteData.text           = text;

                    var postedNoteData = await _firebaseClient
                                         .Child("notes")
                                         .Child(userID)
                                         .PostAsync(noteData, false);

                    newNote = DBNote.FromNoteData(postedNoteData.Key, postedNoteData.Object);
                }
                catch (Exception e)
                {
                    error = ErrorFromFibaseException(e);
                }
            }

            // done
            completionHandler(newNote, error);
        }