Пример #1
0
        private void httpReturned(CollabrifyEventArgs e)
        {
            /* Handles the response from the server within the CollabrifyClient object */
            if (e.response.success_flag)
            {
                Debug.WriteLine(LOG_TAG + ": " + e.type.ToString() + " was successful.\n");

                List <CollabrifySession> sessionList = new List <CollabrifySession>();

                switch (e.type)
                {
                case CollabrifyRequestType_PB.ADD_EVENT_REQUEST:
                    break;

                case CollabrifyRequestType_PB.ADD_PARTICIPANT_REQUEST:
                    this.session        = new CollabrifySession((e.specificResponsePB as Response_AddParticipant_PB).session);
                    this.participant    = new CollabrifyParticipant((e.specificResponsePB as Response_AddParticipant_PB).participant);
                    this.notificationID = (e.specificResponsePB as Response_AddParticipant_PB).participant.notification_id;
                    channelAPI.connect(notificationID);
                    break;

                case CollabrifyRequestType_PB.ADD_TO_BASE_FILE_REQUEST:
                    break;

                case CollabrifyRequestType_PB.CREATE_OR_GET_USER:
                    break;

                case CollabrifyRequestType_PB.CREATE_SESSION_REQUEST:
                    this.session        = new CollabrifySession((e.specificResponsePB as Response_CreateSession_PB).session);
                    this.participant    = session.getOwner();
                    this.notificationID = (e.specificResponsePB as Response_CreateSession_PB).owner.notification_id;
                    channelAPI.connect(this.notificationID);
                    break;

                case CollabrifyRequestType_PB.CREATE_SESSION_WITH_BASE_FILE_REQUEST:
                    this.session        = new CollabrifySession((e.specificResponsePB as Response_CreateSessionWithBaseFile_PB).session);
                    this.participant    = session.getOwner();
                    this.notificationID = (e.specificResponsePB as Response_CreateSessionWithBaseFile_PB).owner.notification_id;
                    try { channelAPI.connect((e.specificResponsePB as Response_CreateSessionWithBaseFile_PB).owner.notification_id); }
                    catch (Exception ex) { Debug.WriteLine(LOG_TAG + ":\n" + ex.Message); }
                    break;

                case CollabrifyRequestType_PB.DELETE_SESSION_REQUEST:
                    break;

                case CollabrifyRequestType_PB.DELETE_ALL_SESSIONS_REQUEST:
                    break;

                case CollabrifyRequestType_PB.DELETE_OLD_SESSIONS_REQUEST:
                    break;

                case CollabrifyRequestType_PB.DELETE_USER:
                    break;

                case CollabrifyRequestType_PB.END_SESSION_REQUEST:
                    this.channelAPI.disconnect();
                    break;

                case CollabrifyRequestType_PB.GET_BASE_FILE_REQUEST:
                    break;

                case CollabrifyRequestType_PB.GET_CURRENT_ORDER_ID_REQUEST:
                    break;

                case CollabrifyRequestType_PB.GET_EVENT_BATCH_REQUEST:
                    break;

                case CollabrifyRequestType_PB.GET_EVENT_REQUEST:
                    break;

                case CollabrifyRequestType_PB.GET_FROM_BASE_FILE_REQUEST:
                    break;

                case CollabrifyRequestType_PB.GET_LAST_EVENT_BY_PARTICIPANT_REQUEST:
                    break;

                case CollabrifyRequestType_PB.GET_NOTIFICATION_ID_REQUEST:
                    break;

                case CollabrifyRequestType_PB.GET_PARTICIPANT_REQUEST:
                    break;

                case CollabrifyRequestType_PB.GET_SESSION_REQUEST:
                    break;

                case CollabrifyRequestType_PB.LIST_ACCOUNTS_REQUEST:
                    break;

                case CollabrifyRequestType_PB.LIST_SESSIONS_REQUEST:
                    foreach (Session_PB s in (e.specificResponsePB as Response_ListSessions_PB).session)
                    {
                        sessionList.Add(new CollabrifySession(s));
                    }
                    break;

                case CollabrifyRequestType_PB.PREVENT_FURTHER_JOINS_REQUEST:
                    break;

                case CollabrifyRequestType_PB.REMOVE_PARTICIPANT_REQUEST:
                    channelAPI.disconnect();
                    break;

                case CollabrifyRequestType_PB.REQUEST_TYPE_NOT_SET:
                    Debug.WriteLine(LOG_TAG + ":\n\tError:\n\tRequest Type Was Not Set");
                    break;

                case CollabrifyRequestType_PB.UPDATE_NOTIFICATION_ID_REQUEST:
                    this.participant = new CollabrifyParticipant((e.specificResponsePB as Response_UpdateNotificationID_PB).participant);
                    this.session     = new CollabrifySession((e.specificResponsePB as Response_UpdateNotificationID_PB).session);
                    break;

                case CollabrifyRequestType_PB.UPDATE_USER:
                    break;

                case CollabrifyRequestType_PB.WARMUP_REQUEST:
                    //HttpRequest_CreateOrGetUser.make_request(this, http_object);
                    break;
                } // switch

                if (mCompletionHandler != null)
                {
                    Deployment.Current.Dispatcher.BeginInvoke(delegate {
                        mListSessionsCompletionHandler += delegate { mListSessionsCompletionHandler = null; };
                        mCompletionHandler.Invoke(this);
                    });
                }
                if (mListSessionsCompletionHandler != null)
                {
                    Deployment.Current.Dispatcher.BeginInvoke(delegate
                    {
                        mListSessionsCompletionHandler += delegate { mListSessionsCompletionHandler = null; };
                        mListSessionsCompletionHandler.Invoke(sessionList);
                    });
                }
            } // if
            else
            {
                Debug.WriteLine(LOG_TAG + ":\n\t" + e.type.ToString() + " Failed:");
                Debug.WriteLine("\tException Type: " + e.response.exception.exception_type.ToString());
                Debug.WriteLine("\tException Cause: " + e.response.exception.cause.ToString() + "\n");
            }
        } // httpReturned
 protected virtual void OnChanged(CollabrifyEventArgs e)
 {
     try
       {
     if (HttpRequestDone != null) HttpRequestDone.Invoke(e);
     else Debug.WriteLine("Changed event is null");
       }
       catch { Debug.WriteLine("OnChanged exception..."); }
 }
        // -------------------------------------------------------------------------
        private void GetResponseCallback(IAsyncResult asynchronousResult)
        {
            try
              {
            HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
            HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);

            //to read server response
            Stream streamResponse = response.GetResponseStream();
            try
            {
              collabrify_resp_pb = Serializer.DeserializeWithLengthPrefix<CollabrifyResponse_PB>(streamResponse, PrefixStyle.Base128, 0);

              returned_secondary_pb = null;
              if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.ADD_EVENT_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_AddEvent_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.ADD_PARTICIPANT_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_AddParticipant_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.ADD_TO_BASE_FILE_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_AddToBaseFile_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.CREATE_OR_GET_USER)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_CreateOrGetUser_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.CREATE_SESSION_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_CreateSession_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.CREATE_SESSION_WITH_BASE_FILE_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_CreateSessionWithBaseFile_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.DELETE_ALL_SESSIONS_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_DeleteAllSessions_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.DELETE_OLD_SESSIONS_REQUEST)
              {
            // TODO: DELETE OLD SESSIONS??
            // returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_DeleteAllSessions_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.DELETE_SESSION_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_DeleteSession_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.DELETE_USER)
              {
            // TODO: DELETE USER??
            // returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_DeleteSession_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.END_SESSION_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_EndSession_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.GET_BASE_FILE_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_GetBaseFile_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.GET_CURRENT_ORDER_ID_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_GetCurrentOrderID_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.GET_EVENT_BATCH_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_GetEventBatch_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.GET_EVENT_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_GetEvent_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.GET_FROM_BASE_FILE_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_GetFromBaseFile_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.GET_LAST_EVENT_BY_PARTICIPANT_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_GetLastEventByParticipant_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.GET_NOTIFICATION_ID_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_GetNotificationID_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.GET_PARTICIPANT_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_GetParticipant_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.GET_SESSION_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_GetSession_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.LIST_ACCOUNTS_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_ListAccounts_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.LIST_SESSIONS_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_ListSessions_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.PREVENT_FURTHER_JOINS_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_PreventFurtherJoins_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.REMOVE_PARTICIPANT_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_RemoveParticipant_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.REQUEST_TYPE_NOT_SET)
              {
            // TODO
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.UPDATE_NOTIFICATION_ID_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_UpdateNotificationID_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.UPDATE_USER)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_UpdateUser>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.WARMUP_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_Warmup_PB>(streamResponse, PrefixStyle.Base128, 0);
              }

              // invokes an event that is returned to the cliend object.
              CollabrifyEventArgs e = new CollabrifyEventArgs(collabrify_resp_pb, returned_secondary_pb, collabrify_req_pb.request_type);

              try
              {
            if (HttpRequestDone != null) HttpRequestDone.Invoke(e);
            else Debug.WriteLine("Changed event is null");
              } // try
              catch
              {
            Debug.WriteLine("OnChanged exception...");
              } // catch

            } // try
            catch (Exception e)
            {
              System.Diagnostics.Debug.WriteLine(LOG_TAG + " Error:\nMessage: " + e.Message.ToString() + "\ndata: " + e.Data.ToString() + "\n -- \n" + e.StackTrace.ToString());
            } // catch

            // Close the stream object
            streamResponse.Close();

            // Release the HttpWebResponse
            response.Close();

              } // try
              catch (WebException e)
              {
            System.Diagnostics.Debug.WriteLine(LOG_TAG + " Error:\nMessage: " + e.Message.ToString() + "\ndata: " + e.Data.ToString() + "\n -- \n" + e.StackTrace.ToString());
              } // catch
        }
Пример #4
0
        private void httpReturned(CollabrifyEventArgs e)
        {
            /* Handles the response from the server within the CollabrifyClient object */
              if (e.response.success_flag)
              {
              Debug.WriteLine(LOG_TAG + ": " + e.type.ToString() + " was successful.\n");

              List<CollabrifySession> sessionList = new List<CollabrifySession>();

              switch (e.type)
              {
              case CollabrifyRequestType_PB.ADD_EVENT_REQUEST:
                  break;
              case CollabrifyRequestType_PB.ADD_PARTICIPANT_REQUEST:
                  this.session = new CollabrifySession((e.specificResponsePB as Response_AddParticipant_PB).session);
                  this.participant = new CollabrifyParticipant((e.specificResponsePB as Response_AddParticipant_PB).participant);
                  this.notificationID = (e.specificResponsePB as Response_AddParticipant_PB).participant.notification_id;
                  channelAPI.connect( notificationID );
                  break;
              case CollabrifyRequestType_PB.ADD_TO_BASE_FILE_REQUEST:
                  break;
              case CollabrifyRequestType_PB.CREATE_OR_GET_USER:
                  break;
              case CollabrifyRequestType_PB.CREATE_SESSION_REQUEST:
                    this.session = new CollabrifySession((e.specificResponsePB as Response_CreateSession_PB).session);
                    this.participant = session.getOwner();
                    this.notificationID = (e.specificResponsePB as Response_CreateSession_PB).owner.notification_id;
                    channelAPI.connect(this.notificationID);
                  break;
              case CollabrifyRequestType_PB.CREATE_SESSION_WITH_BASE_FILE_REQUEST:
                  this.session = new CollabrifySession((e.specificResponsePB as Response_CreateSessionWithBaseFile_PB).session);
                  this.participant = session.getOwner();
                  this.notificationID = (e.specificResponsePB as Response_CreateSessionWithBaseFile_PB).owner.notification_id;
                  try { channelAPI.connect((e.specificResponsePB as Response_CreateSessionWithBaseFile_PB).owner.notification_id); }
                  catch (Exception ex) { Debug.WriteLine(LOG_TAG + ":\n" + ex.Message); }
                  break;
              case CollabrifyRequestType_PB.DELETE_SESSION_REQUEST:
                  break;
              case CollabrifyRequestType_PB.DELETE_ALL_SESSIONS_REQUEST:
                  break;
              case CollabrifyRequestType_PB.DELETE_OLD_SESSIONS_REQUEST:
                  break;
              case CollabrifyRequestType_PB.DELETE_USER:
                  break;
              case CollabrifyRequestType_PB.END_SESSION_REQUEST:
                  this.channelAPI.disconnect();
                  break;
              case CollabrifyRequestType_PB.GET_BASE_FILE_REQUEST:
                  break;
              case CollabrifyRequestType_PB.GET_CURRENT_ORDER_ID_REQUEST:
                  break;
              case CollabrifyRequestType_PB.GET_EVENT_BATCH_REQUEST:
                  break;
              case CollabrifyRequestType_PB.GET_EVENT_REQUEST:
                  break;
              case CollabrifyRequestType_PB.GET_FROM_BASE_FILE_REQUEST:
                  break;
              case CollabrifyRequestType_PB.GET_LAST_EVENT_BY_PARTICIPANT_REQUEST:
                  break;
              case CollabrifyRequestType_PB.GET_NOTIFICATION_ID_REQUEST:
                  break;
              case CollabrifyRequestType_PB.GET_PARTICIPANT_REQUEST:
                  break;
              case CollabrifyRequestType_PB.GET_SESSION_REQUEST:
                  break;
              case CollabrifyRequestType_PB.LIST_ACCOUNTS_REQUEST:
                  break;
              case CollabrifyRequestType_PB.LIST_SESSIONS_REQUEST:
                  foreach(Session_PB s in (e.specificResponsePB as Response_ListSessions_PB).session)
                  {
                    sessionList.Add( new CollabrifySession(s) );
                  }
                  break;
              case CollabrifyRequestType_PB.PREVENT_FURTHER_JOINS_REQUEST:
                  break;
              case CollabrifyRequestType_PB.REMOVE_PARTICIPANT_REQUEST:
                  channelAPI.disconnect();
                  break;
              case CollabrifyRequestType_PB.REQUEST_TYPE_NOT_SET:
                  Debug.WriteLine(LOG_TAG + ":\n\tError:\n\tRequest Type Was Not Set");
                  break;
              case CollabrifyRequestType_PB.UPDATE_NOTIFICATION_ID_REQUEST:
                  this.participant = new CollabrifyParticipant((e.specificResponsePB as Response_UpdateNotificationID_PB).participant);
                  this.session = new CollabrifySession((e.specificResponsePB as Response_UpdateNotificationID_PB).session);
                  break;
              case CollabrifyRequestType_PB.UPDATE_USER:
                  break;
              case CollabrifyRequestType_PB.WARMUP_REQUEST:
                  //HttpRequest_CreateOrGetUser.make_request(this, http_object);
                  break;
              } // switch

              if (mCompletionHandler != null)
              {
            Deployment.Current.Dispatcher.BeginInvoke(delegate {
              mListSessionsCompletionHandler += delegate { mListSessionsCompletionHandler = null; };
              mCompletionHandler.Invoke(this);
            });
              }
              if(mListSessionsCompletionHandler != null)
              {
            Deployment.Current.Dispatcher.BeginInvoke(delegate
            {
              mListSessionsCompletionHandler += delegate { mListSessionsCompletionHandler = null; };
              mListSessionsCompletionHandler.Invoke(sessionList);
            });
              }
              } // if
              else
              {
              Debug.WriteLine(LOG_TAG + ":\n\t" + e.type.ToString() + " Failed:");
              Debug.WriteLine("\tException Type: " + e.response.exception.exception_type.ToString());
              Debug.WriteLine("\tException Cause: " + e.response.exception.cause.ToString() + "\n");
              }
        }