예제 #1
0
        public BrokerResult CreateEventChannel(IEvent theEvent, IUser eventCreator)
        {
            string tableName = ConvertEventToTableName(theEvent);
            string data      = RTStringBuilder.MakeCreateString(tableName);

            try
            {
                var              CreateUrl = Properties.Settings.Default.RTFCreateURL;
                string           response  = MessageConnect.SendRequest(CreateUrl, data);
                CreationResponse creation  = JsonConvert.DeserializeObject <CreationResponse>(response);
                try
                {
                    if (tableName.Equals(creation.data.table))
                    {
                        return(BrokerResult.newSuccess());
                    }
                    throw new Exception("RTF returned table name " + creation.data.table);
                }
                catch (NullReferenceException e)
                {
                    throw new Exception("RTF returned an error Message during table creation: " + creation.error.code + creation.error.message);
                }
            }
            catch (WebException e)
            {
                return(new BrokerResult {
                    type = ResultType.createError, reason = ErrorReason.remoteCreateFailure, Message = e.Message
                });
            }
        }
예제 #2
0
        public BrokerResult CreateEventChannel(Guid eventID, IUser eventCreator)
        {
            string tableName = EIDToEtableName(eventID);
            string data      = RTStringBuilder.MakeCreateString(tableName);

            try
            {
                var CreateUrl = Properties.Settings.Default.RTFCreateURL;

                string creationResult = MessageConnect.SendRequest(CreateUrl, data);
            }
            catch (WebException e)
            {
                return(new BrokerResult {
                    type = ResultType.createError, reason = ErrorReason.remoteCreateFailure, Message = e.Message
                });
            }

            bool creatorOK = AuthenticateAndUpdateUser(eventCreator, tableName);

            if (creatorOK)
            {
                return(BrokerResult.newSuccess());
            }
            else
            {
                return new BrokerResult {
                           type = ResultType.createError, reason = ErrorReason.remoteAuthFailure
                }
            };
        }
예제 #3
0
        //Does not evaluate JSON response for errors in table creation!
        //doesn't invite!
        public BrokerResult InviteUsers(IEnumerable <IUser> invitees, string inviter, string tableName)
        {
            BrokerResult invitesResult = BrokerResult.newInviteResult();

            foreach (IUser invitee in invitees)
            {
                bool success = AuthenticateAndUpdateUser(invitee, tableName);

                if (success)
                {
                    PutInvite(invitee, tableName, inviter);
                    invitesResult.validUsers.Add(invitee);
                }
                else
                {
                    invitesResult.invalidUsers.Add(invitee);
                }
            }

            if (invitesResult.invalidUsers.Count > 0)
            {
                invitesResult.type = ResultType.sufficientSuccess;
                if (invitesResult.validUsers.Count == 0)
                {
                    invitesResult.type   = ResultType.inviteError;
                    invitesResult.reason = ErrorReason.remoteAuthFailure;
                }
            }
            return(invitesResult);
        }
예제 #4
0
        public BrokerResult CreateAuthAndInvite(Guid eventID, IUser eventCreator, IEnumerable <IUser> invitees)
        {
            string       tableName   = EIDToEtableName(eventID);
            BrokerResult creationRes = CreateEventChannel(eventID, eventCreator);

            if (creationRes.ok())
            {
                return(InviteUsers(invitees, eventCreator.Name, tableName));
            }
            else
            {
                return(creationRes);
            }
        }
예제 #5
0
        private bool AuthenticateAndUpdateUser(IUser user, string tableName)
        {
            List <string> tableNames = user.AuthenticatedChannels;

            tableNames.Add(tableName);
            string       userToken = user.Token;
            BrokerResult result    = AuthUser(tableNames, userToken);

            if (result.ok())
            {
                user.AuthenticatedChannels.Add(tableName);
            }
            return(result.ok());
        }
예제 #6
0
        /*TODO:
         * 1)DONE
         * 2)write unit tests --sorta done
         * 3)exception handling
         * 4)DONE
         * 5)implement wait for resource busy "creating" state
         */
        private BrokerResult AuthUser(List <string> tableNames, string userToken)
        {
            try
            {
                //bool busy = true;
                string data = RTStringBuilder.MakeAuthString(tableNames, userToken);

                var    AuthUrl = Properties.Settings.Default.RTFAuthURL;
                string result  = MessageConnect.SendRequest(AuthUrl, data);

                return(BrokerResult.newSuccess());
            }
            catch (WebException e)
            {
                return(new BrokerResult {
                    type = ResultType.authError, Message = e.Message
                });
            }
        }
예제 #7
0
        //Current implementation only allows for all users to have the same (RU) policy on table.
        //Otherwise we have to store each policy in DB.
        public BrokerResult RespondToInvite(IUser user, Guid eventID, bool accept)
        {
            bool success = true;

            if (accept)
            {
                string tablename = EIDToEtableName(eventID);
                success = AuthenticateAndUpdateUser(user, tablename);
            }
            if (success)
            {
                return(BrokerResult.newSuccess());
            }
            else
            {
                return new BrokerResult {
                           type = ResultType.respondError, reason = ErrorReason.remoteAuthFailure
                }
            };
        }
예제 #8
0
        public BrokerResult AuthUser(List <string> tableNames, string userToken)
        {
            try
            {
                //bool busy = true;
                string data = RTStringBuilder.MakeAuthString(tableNames, userToken);

                var    AuthUrl = Properties.Settings.Default.RTFAuthURL;
                string result  = MessageConnect.SendRequest(AuthUrl, data);
                Debug.Print(result);
                BooleanResponse response = JsonConvert.DeserializeObject <BooleanResponse>(result);
                if (response.data)
                {
                    return(BrokerResult.newSuccess());
                }
                throw new Exception("RTF returned error " + response.error.message);
            }
            catch (WebException e)
            {
                return(new BrokerResult {
                    type = ResultType.authError, Message = e.Message
                });
            }
        }
예제 #9
0
 public BrokerResult AddToChannel(IUser user, Guid eventId)
 {
     AuthenticateAndUpdateUser(user, EIDToEtableName(eventId));
     return(BrokerResult.newSuccess());
 }