示例#1
0
        private OccupantInviteResponse GetFirebaseUserByEmail(string userId)
        {
            try
            {
                this.logger.Information("get the node js firebase admin Bundle");
                var    apiDirectory         = Directory.GetParent(Assembly.GetEntryAssembly().Location);
                string firebaseAdminConsole = String.Concat(apiDirectory.FullName, "\\FirebaseAdmin\\firebaseAdminBundle.js");
                this.logger.Information($"Firebase Admin console looking for at path: {firebaseAdminConsole}");

                if (!File.Exists(firebaseAdminConsole))
                {
                    this.logger.Error($"Firebase Admin console not found at path: {firebaseAdminConsole}");
                    throw new Exception($"Firebase Admin console not found at path: {firebaseAdminConsole}");
                }

                string commandName = "getFirebaseUserByEmail";
                string args        = string.Concat(firebaseAdminConsole, " ", commandName, " ", userId);

                this.logger.Information("Firebase Admin console args: {args}", args);

                //Run the command
                Process process = new Process()
                {
                    StartInfo = new ProcessStartInfo
                    {
                        RedirectStandardOutput = true,
                        RedirectStandardError  = true,
                        FileName  = "C:\\Program Files\\nodejs\\node.exe",
                        Arguments = args
                    }
                };
                process.Start();

                string jsonOccupantInviteResponse = process.StandardOutput.ReadToEnd();
                string err = process.StandardError.ReadToEnd();
                if (err != null)
                {
                    this.logger.Error("Firebase Admin console error: {err}", err);
                }
                process.WaitForExit();
                this.logger.Information("Firebase Admin console response: {response}", jsonOccupantInviteResponse);
                OccupantInviteResponse occupant = JsonConvert.DeserializeObject <OccupantInviteResponse>(jsonOccupantInviteResponse);

                return(occupant);
            }
            catch (Exception ex)
            {
                this.logger.Error("Exception calling firebase admin console: {ex}", ex.Message);
                throw ex;
            }
        }
示例#2
0
        public async Task <OccupantInviteResponse> GetFirebaseUserByEmail(OccupantInviteRequest invitee)
        {
            OccupantInviteResponse msg = new OccupantInviteResponse();

            try
            {
                // msg = await nodeServices.InvokeAsync<OccupantInviteResponse>("node_services/myHouseFirebaseAdmin.js", $"getFirebaseUserByEmail \"{invitee.Email}\"");
                msg = await nodeServices.InvokeAsync <OccupantInviteResponse>("build/actions/getFirebaseUserByEmail.js", $"{invitee.Email}");
            }
            catch (Exception ex)
            {
                logger.Error(ex, ex.Message);
            }

            return(msg);
        }
示例#3
0
        public async Task <bool> InviteOccupant(OccupantInviteRequest invite)
        {
            // TODO: Send invite email!
            return(await asyncConnection(invite.InvitedByUserId, invite.InvitedByOccupantId, async db =>
            {
                bool occupantInvited = false;
                OccupantInviteResponse existingOccupant = GetFirebaseUserByEmail(invite.Email);
                if (existingOccupant != null)
                {
                    this.logger.Information($"Creating Occupant from invite: {invite.ToString()}");
                    OccupantInsertRequest createOccupant = new OccupantInsertRequest
                    {
                        InviteAccepted = false,
                        UserId = existingOccupant.Uid,
                        DisplayName = existingOccupant.DisplayName,
                        EnteredBy = invite.InvitedByUserId,
                        InvitedByOccupantId = invite.InvitedByOccupantId
                    };
                    this.logger.Information($"Creating Occupant: {createOccupant.ToString()}");
                    OccupantResponse newOccupant = await this.InsertOccupantQuery(db, createOccupant);

                    this.logger.Information($"Created Occupant: {newOccupant.ToString()}");

                    NewsFeedInsertRequest householdInviteNewsItem = new NewsFeedInsertRequest
                    {
                        EnteredBy = invite.InvitedByUserId,
                        OccupantId = invite.InvitedByOccupantId,
                        Headline = "Invited to a new household",
                        SubHeadline = "Congrats",
                        Story = "You have been invited to a new household! Go to households to accept the invite.",
                        Author = invite.InvitedByUserId,
                        Recipient = newOccupant.UserId,
                    };
                    this.logger.Information($"Creating News Feed Invite: {invite.ToString()}");
                    await newsFeedsRepository.InsertNewsFeedQuery(db, householdInviteNewsItem);
                    occupantInvited = true;
                }
                else
                {
                    // TODO: Improve functionality here!
                    this.logger.Error("Existing occupant: {existingOccupant}, not found for email {invite}", existingOccupant, invite.Email);
                    throw new Exception($"The email address {invite.Email} must sign up to myHouse first");
                }

                return occupantInvited;
            }));
        }