예제 #1
0
        // -------------------------------------------------------------------------

        /// <summary>
        /// makes a warmup request to the server and returns a response object in the form of RESPONSE_
        /// </summary>
        public static void make_request(CollabrifyClient c, HttpRequest__Object obj, List <string> tags)
        {
            CollabrifyRequest_PB req_pb = new CollabrifyRequest_PB();

            req_pb.request_type = CollabrifyRequestType_PB.LIST_SESSIONS_REQUEST;

            Request_ListSessions_PB cs_pb = new Request_ListSessions_PB();

            cs_pb.account_gmail = c.getAccountGmail();
            cs_pb.access_token  = c.getAccessToken();
            foreach (string s in tags)
            {
                cs_pb.session_tag.Add(s);
            }
            cs_pb.limit_query_to_organization_account = true;
            cs_pb.use_subset_query = true;
            cs_pb.account_gmail    = c.getAccountGmail();
            cs_pb.access_token     = c.getAccessToken();
            foreach (string s in tags)
            {
                cs_pb.session_tag.Add(s);
            }

            HttpWebRequest request = obj.BuildRequest(req_pb, cs_pb);

            try
            {
                request.BeginGetRequestStream(new AsyncCallback(obj.getReqStream), request);
            }
            catch (WebException e)
            {
                System.Diagnostics.Debug.WriteLine("  -- EXCEPTION THROWN \n" + e.Message);
            }
        } // make_request
예제 #2
0
        } //BuildRequest

        // -------------------------------------------------------------------------

        public void getReqStream(IAsyncResult result)
        {
            try
            {
                HttpWebRequest request    = (HttpWebRequest)result.AsyncState;
                Stream         postStream = request.EndGetRequestStream(result);

                MemoryStream ms  = new MemoryStream();
                MemoryStream ms2 = new MemoryStream();
                MemoryStream ms3 = new MemoryStream();

                Serializer.SerializeWithLengthPrefix <CollabrifyRequest_PB>(ms, collabrify_req_pb, PrefixStyle.Base128, 0);

                byte[] byteArr = ms.ToArray();
                postStream.Write(byteArr, 0, byteArr.Length);

                Debug.WriteLine(LOG_TAG + ": Beginning " + collabrify_req_pb.request_type + " request...");

                if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.ADD_EVENT_REQUEST)
                {
                    Serializer.SerializeWithLengthPrefix <Request_AddEvent_PB>(ms2, (Request_AddEvent_PB)secondary_pb, PrefixStyle.Base128, 0);
                }
                else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.ADD_PARTICIPANT_REQUEST)
                {
                    Serializer.SerializeWithLengthPrefix <Request_AddParticipant_PB>(ms2, (Request_AddParticipant_PB)secondary_pb, PrefixStyle.Base128, 0);
                }
                else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.ADD_TO_BASE_FILE_REQUEST)
                {
                    Serializer.SerializeWithLengthPrefix <Request_AddToBaseFile_PB>(ms2, (Request_AddToBaseFile_PB)secondary_pb, PrefixStyle.Base128, 0);
                }
                else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.CREATE_OR_GET_USER)
                {
                    Serializer.SerializeWithLengthPrefix <Request_CreateOrGetUser_PB>(ms2, (Request_CreateOrGetUser_PB)secondary_pb, PrefixStyle.Base128, 0);
                }
                else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.CREATE_SESSION_REQUEST)
                {
                    Serializer.SerializeWithLengthPrefix <Request_CreateSession_PB>(ms2, (Request_CreateSession_PB)secondary_pb, PrefixStyle.Base128, 0);
                }
                else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.CREATE_SESSION_WITH_BASE_FILE_REQUEST)
                {
                    Serializer.SerializeWithLengthPrefix <Request_CreateSessionWithBaseFile_PB>(ms2, (Request_CreateSessionWithBaseFile_PB)secondary_pb, PrefixStyle.Base128, 0);
                }
                else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.DELETE_ALL_SESSIONS_REQUEST)
                {
                    Serializer.SerializeWithLengthPrefix <Request_DeleteAllSessions_PB>(ms2, (Request_DeleteAllSessions_PB)secondary_pb, PrefixStyle.Base128, 0);
                }
                else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.DELETE_OLD_SESSIONS_REQUEST)
                {
                    // TODO: NO DELETE USER PB
                    // Serializer.SerializeWithLengthPrefix<Request_DeleteAllSessions_PB>(ms2, (Request_DeleteAllSessions_PB)secondary_pb, PrefixStyle.Base128, 0);
                }
                else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.DELETE_SESSION_REQUEST)
                {
                    Serializer.SerializeWithLengthPrefix <Request_DeleteSession_PB>(ms2, (Request_DeleteSession_PB)secondary_pb, PrefixStyle.Base128, 0);
                }
                else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.DELETE_USER)
                {
                    // TODO: NO DELETE USER PB
                    // Serializer.SerializeWithLengthPrefix<Request_DeleteSession_PB>(ms2, (Request_DeleteSession_PB)secondary_pb, PrefixStyle.Base128, 0);
                }
                else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.END_SESSION_REQUEST)
                {
                    Serializer.SerializeWithLengthPrefix <Request_EndSession_PB>(ms2, (Request_EndSession_PB)secondary_pb, PrefixStyle.Base128, 0);
                }
                else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.GET_BASE_FILE_REQUEST)
                {
                    Serializer.SerializeWithLengthPrefix <Request_GetBaseFile_PB>(ms2, (Request_GetBaseFile_PB)secondary_pb, PrefixStyle.Base128, 0);
                }
                else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.GET_CURRENT_ORDER_ID_REQUEST)
                {
                    Serializer.SerializeWithLengthPrefix <Request_GetCurrentOrderID_PB>(ms2, (Request_GetCurrentOrderID_PB)secondary_pb, PrefixStyle.Base128, 0);
                }
                else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.GET_EVENT_BATCH_REQUEST)
                {
                    Serializer.SerializeWithLengthPrefix <Request_GetEventBatch_PB>(ms2, (Request_GetEventBatch_PB)secondary_pb, PrefixStyle.Base128, 0);
                }
                else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.GET_EVENT_REQUEST)
                {
                    Serializer.SerializeWithLengthPrefix <Request_GetEvent_PB>(ms2, (Request_GetEvent_PB)secondary_pb, PrefixStyle.Base128, 0);
                }
                else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.GET_FROM_BASE_FILE_REQUEST)
                {
                    Serializer.SerializeWithLengthPrefix <Request_GetFromBaseFile_PB>(ms2, (Request_GetFromBaseFile_PB)secondary_pb, PrefixStyle.Base128, 0);
                }
                else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.GET_LAST_EVENT_BY_PARTICIPANT_REQUEST)
                {
                    Serializer.SerializeWithLengthPrefix <Request_GetLastEventByParticipant_PB>(ms2, (Request_GetLastEventByParticipant_PB)secondary_pb, PrefixStyle.Base128, 0);
                }
                else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.GET_NOTIFICATION_ID_REQUEST)
                {
                    Serializer.SerializeWithLengthPrefix <Request_GetNotificationID_PB>(ms2, (Request_GetNotificationID_PB)secondary_pb, PrefixStyle.Base128, 0);
                }
                else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.GET_PARTICIPANT_REQUEST)
                {
                    Serializer.SerializeWithLengthPrefix <Request_GetParticipant_PB>(ms2, (Request_GetParticipant_PB)secondary_pb, PrefixStyle.Base128, 0);
                }
                else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.GET_SESSION_REQUEST)
                {
                    Serializer.SerializeWithLengthPrefix <Request_GetSession_PB>(ms2, (Request_GetSession_PB)secondary_pb, PrefixStyle.Base128, 0);
                }
                else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.LIST_ACCOUNTS_REQUEST)
                {
                    Serializer.SerializeWithLengthPrefix <Request_ListAccounts_PB>(ms2, (Request_ListAccounts_PB)secondary_pb, PrefixStyle.Base128, 0);
                }
                else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.LIST_SESSIONS_REQUEST)
                {
                    Serializer.SerializeWithLengthPrefix <Request_ListSessions_PB>(ms2, secondary_pb as Request_ListSessions_PB, PrefixStyle.Base128, 0);
                    Request_ListSessions_PB r = secondary_pb as Request_ListSessions_PB;
                }
                else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.PREVENT_FURTHER_JOINS_REQUEST)
                {
                    Serializer.SerializeWithLengthPrefix <Request_PreventFurtherJoins_PB>(ms2, (Request_PreventFurtherJoins_PB)secondary_pb, PrefixStyle.Base128, 0);
                }
                else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.REMOVE_PARTICIPANT_REQUEST)
                {
                    Serializer.SerializeWithLengthPrefix <Request_RemoveParticipant_PB>(ms2, (Request_RemoveParticipant_PB)secondary_pb, PrefixStyle.Base128, 0);
                }
                else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.REQUEST_TYPE_NOT_SET)
                {
                }
                else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.UPDATE_NOTIFICATION_ID_REQUEST)
                {
                    Serializer.SerializeWithLengthPrefix <Request_UpdateNotificationID_PB>(ms2, (Request_UpdateNotificationID_PB)secondary_pb, PrefixStyle.Base128, 0);
                }
                else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.UPDATE_USER)
                {
                    Serializer.SerializeWithLengthPrefix <Request_UpdateUser>(ms2, (Request_UpdateUser)secondary_pb, PrefixStyle.Base128, 0);
                }
                else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.WARMUP_REQUEST)
                {
                    Serializer.SerializeWithLengthPrefix <Request_Warmup_PB>(ms2, (Request_Warmup_PB)secondary_pb, PrefixStyle.Base128, 0);
                }

                // if the second memory stream has data in it - add it to the request.
                if (ms2.Length > 0)
                {
                    byteArr = ms2.ToArray();
                    postStream.Write(byteArr, 0, byteArr.Length);
                }

                // if there is a basefile, add it to the end of the request.
                if (trail_info != null)
                {
                    postStream.Write((byte[])trail_info, 0, byteArr.Length);
                }

                // close the request stream.
                postStream.Close();

                // get our response.
                request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request);
            } // try
            catch (WebException e)
            {
                System.Diagnostics.Debug.WriteLine("  -- A WEB EXCEPTION OCCURED\n" + e.Message);
            } // catch
        }     // getReqStream