public void Context_Id_Is_Not_Updated_When_Calling_ToString()
        {
            var request = new QueryRequest("SELECT * FROM default;");

            var contextId = request.CurrentContextId;
            var json      = JsonConvert.DeserializeObject <dynamic>(request.ToString());

            Assert.AreEqual(contextId, json[0].client_context_id.ToString());
        }
        /// <summary>
        /// This will make a search request and bind the search results to the
        /// table.  In theory the search request could be done in chunks
        /// starting at the given startAt variable, however we're just going to
        /// fetch the entire result set when we do the query since we don't have
        /// 100k+ resulting matches.
        /// </summary>
        /// <param name="startAt"></param>
        private void BindData(int startAt)
        {
            dgSearchResults.PageSize = Convert.ToInt32(ReturnResultsPageSizeSetting);

            try
            {
                string       keywordString = txtSearch.Text;
                QueryRequest queryRequest  = BuildQueryRequest(keywordString, true, startAt, null);
                QueryService queryService  = new QueryService
                {
                    Url         = SearchServerURLSetting,
                    Credentials = new NetworkCredential(WebServiceUserNameSetting, WebServicePasswordSetting, WebServiceDomainSetting)
                };

                //queryService.Credentials = System.Net.CredentialCache.DefaultCredentials;
                queryResults = queryService.QueryEx(queryRequest.ToString());
                _endTime     = DateTime.Now;
                if (queryResults.Tables[0].Rows.Count > 0)
                {
                    dgSearchResults.Visible = true;
                    divNoResults.Visible    = false;
                    DisplayHeader(queryResults.Tables[0].Rows.Count);
                    dgSearchResults.DataSource = queryResults.Tables[0];
                    dgSearchResults.DataBind();
                }
                else
                {
                    dgSearchResults.Visible = false;
                    divHeader.Visible       = false;
                    divNoResults.Visible    = true;
                }
                divErrorMessage.Visible = false;
            }
            catch
            {
                dgSearchResults.DataSource = null;
                dgSearchResults.DataBind();
                divHeader.Visible       = false;
                dgSearchResults.Visible = false;
                divErrorMessage.Visible = true;
            }
        }
Пример #3
0
 public override void Query(IRpcController controller, QueryRequest request, Action<QueryResponse> done)
 {
     ProtoOutputBuffer.Write(request.GetType(), request.ToString());
 }
Пример #4
0
        public override void CallServerMethod(uint token, uint methodId, CodedInputStream stream)
        {
            switch (methodId)
            {
            case 1:
            {
                SubscribeRequest request = new SubscribeRequest();
                request.MergeFrom(stream);


                NoData response = new NoData();
                BattlenetRpcErrorCode status = HandleSubscribe(request, response);
                Log.outDebug(LogFilter.ServiceProtobuf, "{0} Client called server method PresenceService.Subscribe(bgs.protocol.presence.v1.SubscribeRequest: {1}) returned bgs.protocol.NoData: {2} status: {3}.",
                             GetCallerInfo(), request.ToString(), response.ToString(), status);
                if (status == 0)
                {
                    SendResponse(token, response);
                }
                else
                {
                    SendResponse(token, status);
                }
                break;
            }

            case 2:
            {
                UnsubscribeRequest request = new UnsubscribeRequest();
                request.MergeFrom(stream);


                NoData response = new NoData();
                BattlenetRpcErrorCode status = HandleUnsubscribe(request, response);
                Log.outDebug(LogFilter.ServiceProtobuf, "{0} Client called server method PresenceService.Unsubscribe(bgs.protocol.presence.v1.UnsubscribeRequest: {1}) returned bgs.protocol.NoData: {2} status: {3}.",
                             GetCallerInfo(), request.ToString(), response.ToString(), status);
                if (status == 0)
                {
                    SendResponse(token, response);
                }
                else
                {
                    SendResponse(token, status);
                }
                break;
            }

            case 3:
            {
                UpdateRequest request = new UpdateRequest();
                request.MergeFrom(stream);


                NoData response = new NoData();
                BattlenetRpcErrorCode status = HandleUpdate(request, response);
                Log.outDebug(LogFilter.ServiceProtobuf, "{0} Client called server method PresenceService.Update(bgs.protocol.presence.v1.UpdateRequest: {1}) returned bgs.protocol.NoData: {2} status: {3}.",
                             GetCallerInfo(), request.ToString(), response.ToString(), status);
                if (status == 0)
                {
                    SendResponse(token, response);
                }
                else
                {
                    SendResponse(token, status);
                }
                break;
            }

            case 4:
            {
                QueryRequest request = new QueryRequest();
                request.MergeFrom(stream);


                QueryResponse         response = new QueryResponse();
                BattlenetRpcErrorCode status   = HandleQuery(request, response);
                Log.outDebug(LogFilter.ServiceProtobuf, "{0} Client called server method PresenceService.Query(bgs.protocol.presence.v1.QueryRequest: {1}) returned bgs.protocol.presence.v1.QueryResponse: {2} status: {3}.",
                             GetCallerInfo(), request.ToString(), response.ToString(), status);
                if (status == 0)
                {
                    SendResponse(token, response);
                }
                else
                {
                    SendResponse(token, status);
                }
                break;
            }

            case 5:
            {
                OwnershipRequest request = new OwnershipRequest();
                request.MergeFrom(stream);


                NoData response = new NoData();
                BattlenetRpcErrorCode status = HandleOwnership(request, response);
                Log.outDebug(LogFilter.ServiceProtobuf, "{0} Client called server method PresenceService.Ownership(bgs.protocol.presence.v1.OwnershipRequest: {1}) returned bgs.protocol.NoData: {2} status: {3}.",
                             GetCallerInfo(), request.ToString(), response.ToString(), status);
                if (status == 0)
                {
                    SendResponse(token, response);
                }
                else
                {
                    SendResponse(token, status);
                }
                break;
            }

            case 7:
            {
                SubscribeNotificationRequest request = new SubscribeNotificationRequest();
                request.MergeFrom(stream);


                NoData response = new NoData();
                BattlenetRpcErrorCode status = HandleSubscribeNotification(request, response);
                Log.outDebug(LogFilter.ServiceProtobuf, "{0} Client called server method PresenceService.SubscribeNotification(bgs.protocol.presence.v1.SubscribeNotificationRequest: {1}) returned bgs.protocol.NoData: {2} status: {3}.",
                             GetCallerInfo(), request.ToString(), response.ToString(), status);
                if (status == 0)
                {
                    SendResponse(token, response);
                }
                else
                {
                    SendResponse(token, status);
                }
                break;
            }

            /*case 8:
             *  {
             *      MigrateOlympusCustomMessageRequest request = new MigrateOlympusCustomMessageRequest();
             *      request.MergeFrom(stream);
             *
             *
             *      MigrateOlympusCustomMessageResponse response = new MigrateOlympusCustomMessageResponse();
             *      BattlenetRpcErrorCode status = HandleMigrateOlympusCustomMessage(request, response);
             *      Log.outDebug(LogFilter.ServiceProtobuf, "{0} Client called server method PresenceService.MigrateOlympusCustomMessage(bgs.protocol.presence.v1.MigrateOlympusCustomMessageRequest: {1}) returned bgs.protocol.presence.v1.MigrateOlympusCustomMessageResponse: {2} status: {3}.",
             *        GetCallerInfo(), request.ToString(), response.ToString(), status);
             *      if (status == 0)
             *          SendResponse(token, response);
             *      else
             *          SendResponse(token, status);
             *      break;
             *  }*/
            default:
                Log.outError(LogFilter.ServiceProtobuf, "Bad method id {0}.", methodId);
                SendResponse(token, BattlenetRpcErrorCode.RpcInvalidMethod);
                break;
            }
        }
Пример #5
0
 BattlenetRpcErrorCode HandleQuery(QueryRequest request, QueryResponse response)
 {
     Log.outError(LogFilter.ServiceProtobuf, "{0} Client tried to call not implemented method PresenceService.Query: {1}",
                  GetCallerInfo(), request.ToString());
     return(BattlenetRpcErrorCode.RpcNotImplemented);
 }
Пример #6
0
 public override void Query(IRpcController controller, QueryRequest request, Action <QueryResponse> done)
 {
     ProtoOutputBuffer.Write(request.GetType(), request.ToString());
 }
Пример #7
0
        public BulkDeleteResponse BulkDelete(QueryRequest request)
        {
            var url         = string.Format("{0}/{1}/_delete_by_query", _baseUrl, _index);
            var requestText = request.GenerateQuery();

            if (logger.IsDebugEnabled)
            {
                logger.Debug("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+");
                logger.Debug(string.Format("Delete Request {0} Started:{1}Query:{2}", request.UniqueIdentifer, DateTime.Now.ToShortTimeString(), request.ToString()));
            }
            try
            {
                var responseJson            = PostAsync(url, requestText).Result;
                BulkDeleteResponse response = JsonConvert.DeserializeObject <BulkDeleteResponse>(responseJson);
                response.RequestIdentifier = request.UniqueIdentifer;

                if (logger.IsDebugEnabled)
                {
                    logger.Debug(string.Format("Delete Request {0} completed: {1}; {2} Records deleted", request.UniqueIdentifer, DateTime.Now.ToShortTimeString(), response.Deleted));
                    logger.Debug("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+");
                }
                return(response);
            }
            catch (Exception ex)
            {
                logger.Error(string.Format("{0} -{1}- Failed. {2}", "DoSearch", request.UniqueIdentifer, ex.Message));
                throw;
            }
        }
Пример #8
0
        public SearchResult DoSearch(QueryRequest request)
        {
            var searchresult = new SearchResult(request.UniqueIdentifer);
            var requestText  = request.GenerateQuery();
            var url          = string.Format("{0}/{1}/_search", _baseUrl, _index);

            if (logger.IsDebugEnabled)
            {
                logger.Debug(string.Format("Search Request Started - {0} -Time:{1} {2}", request.UniqueIdentifer, DateTime.Now.ToShortTimeString(), request.ToString()));
            }

            string responseJson;

            try
            {
                responseJson = PostAsync(url, requestText).Result;
            }
            catch (Exception ex)
            {
                logger.Error(string.Format("{0} -{1}- Failed. {2}", "DoSearch", request.UniqueIdentifer, ex.Message));
                throw;
            }
            JObject awsSearch = JObject.Parse(responseJson);

            searchresult.Took       = (int)awsSearch["took"];
            searchresult.TimedOut   = (bool)awsSearch["timed_out"];
            searchresult.MatchCount = (int)awsSearch["hits"]["total"];

            List <JToken> hits       = awsSearch["hits"]["hits"].Children().ToList();
            var           properties = typeof(SearchResultItem).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.CanWrite);

            foreach (var token in hits)
            {
                var           resultItem = token.ToObject <SearchResultItem>();
                List <JToken> fields     = token["_source"].Children().ToList();
                foreach (JToken s in fields)
                {
                    JValue jValue = ((JProperty)s).Value as JValue;
                    var    name   = ((JProperty)s).Name;
                    object value  = jValue != null ? jValue.Value : null;
                    resultItem.AddSource(new SearchItem()
                    {
                        Name = name, Value = value
                    });

                    //if has a value then set the property (if present)
                    if (value != null)
                    {
                        //set the result items property
                        var prop = properties.FirstOrDefault(p => p.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
                        if (prop != null)
                        {
                            Type propType = prop.PropertyType;
                            if (propType.IsGenericType && propType.GetGenericTypeDefinition().Equals(typeof(Nullable <>)))
                            {  //get underyling type
                                propType = Nullable.GetUnderlyingType(propType);
                            }
                            prop.SetValue(resultItem, Convert.ChangeType(value, propType), null);
                        }
                    }
                }
                searchresult.AddSearchResultItem(resultItem);
            }
            if (logger.IsDebugEnabled)
            {
                logger.Debug(string.Format("Search {0} Complete: Time: {1})", searchresult.UniqueIdentifier, DateTime.Now.ToShortTimeString()));
            }



            return(searchresult);
        }