예제 #1
0
        public static IList <byte[]> BuildResponse(QueryResultSet resultSet, int commandVersion, string RequestId, IList <byte[]> _serializedResponse)
        {
            long requestId = Convert.ToInt64(RequestId);

            try
            {
                switch (commandVersion)
                {
                case 0:     //Version from NCache 3.8 to NCache 3.8 SP3
                {
                    Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response();
                    Alachisoft.NCache.Common.Protobuf.SearchEntriesResponse searchEntriesResponse = new Alachisoft.NCache.Common.Protobuf.SearchEntriesResponse();
                    response.requestId = requestId;
                    searchEntriesResponse.keyValuePackage = Alachisoft.NCache.SocketServer.Util.KeyPackageBuilder.PackageKeysValues(resultSet.SearchEntriesResult, searchEntriesResponse.keyValuePackage);
                    response.responseType  = Alachisoft.NCache.Common.Protobuf.Response.Type.SEARCH_ENTRIES;
                    response.searchEntries = searchEntriesResponse;
                    _serializedResponse.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
                }
                break;

                case 1:     //From Version 3.8 SP4 onwards //Offically announcing support in 4.1// So not supporting 3.8 SP4 clients in case of aggregate functions with 4.1 Cache Server Decision taken by Kashif Butt
                case 2:     //NCache 4.1 SP1
                {
                    switch (resultSet.Type)
                    {
                    case QueryType.AggregateFunction:
                    {
                        Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response();
                        Alachisoft.NCache.Common.Protobuf.SearchEntriesResponse searchEntriesResponse = new Alachisoft.NCache.Common.Protobuf.SearchEntriesResponse();
                        searchEntriesResponse.queryResultSet = new Alachisoft.NCache.Common.Protobuf.QueryResultSet();
                        response.requestId = requestId;
                        searchEntriesResponse.queryResultSet.queryType                     = Alachisoft.NCache.Common.Protobuf.QueryType.AGGREGATE_FUNCTIONS;
                        searchEntriesResponse.queryResultSet.aggregateFunctionType         = (Alachisoft.NCache.Common.Protobuf.AggregateFunctionType)(int) resultSet.AggregateFunctionType;
                        searchEntriesResponse.queryResultSet.aggregateFunctionResult       = new Alachisoft.NCache.Common.Protobuf.DictionaryItem();
                        searchEntriesResponse.queryResultSet.aggregateFunctionResult.key   = resultSet.AggregateFunctionResult.Key.ToString();
                        searchEntriesResponse.queryResultSet.aggregateFunctionResult.value = resultSet.AggregateFunctionResult.Value != null?CompactBinaryFormatter.ToByteBuffer(resultSet.AggregateFunctionResult.Value, null) : null;

                        response.responseType  = Alachisoft.NCache.Common.Protobuf.Response.Type.SEARCH_ENTRIES;
                        response.searchEntries = searchEntriesResponse;
                        _serializedResponse.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
                    }
                    break;

                    case QueryType.SearchEntries:
                    {
                        int sequenceId = 1;
                        List <Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse> keyValuesPackageChuncks = Alachisoft.NCache.SocketServer.Util.KeyPackageBuilder.PackageKeysValues(resultSet.SearchEntriesResult);
                        Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response();
                        Alachisoft.NCache.Common.Protobuf.SearchEntriesResponse searchEntriesResponse = new Alachisoft.NCache.Common.Protobuf.SearchEntriesResponse();
                        searchEntriesResponse.queryResultSet = new Alachisoft.NCache.Common.Protobuf.QueryResultSet();
                        response.requestId = requestId;
                        searchEntriesResponse.queryResultSet.queryType = Alachisoft.NCache.Common.Protobuf.QueryType.SEARCH_ENTRIES;
                        response.numberOfChuncks = keyValuesPackageChuncks.Count;
                        response.responseType    = Alachisoft.NCache.Common.Protobuf.Response.Type.SEARCH_ENTRIES;

                        foreach (Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse package in keyValuesPackageChuncks)
                        {
                            response.sequenceId = sequenceId++;
                            searchEntriesResponse.queryResultSet.searchKeyEnteriesResult = package;
                            response.searchEntries = searchEntriesResponse;
                            _serializedResponse.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
                        }
                    }
                    break;
                    }
                }
                break;

                default:
                {
                    throw new Exception("Unsupported Command Version");
                }
                }
            }
            catch (Exception ex)
            {
                if (SocketServer.Logger.IsErrorLogsEnabled)
                {
                    SocketServer.Logger.NCacheLog.Error(ex.ToString());
                    if (resultSet == null)
                    {
                        SocketServer.Logger.NCacheLog.Error("QueryResultSet is null");
                    }
                    else if (resultSet.AggregateFunctionResult.Key == null)
                    {
                        SocketServer.Logger.NCacheLog.Error("QueryResultSet.AggregateFunctionResult.Key is null");
                    }
                    else if (resultSet.AggregateFunctionResult.Value == null)
                    {
                        SocketServer.Logger.NCacheLog.Error("QueryResultSet.AggregateFunctionResult.Value is null");
                    }
                }
            }

            return(_serializedResponse);
        }
        public static IList<byte[]> BuildResponse(QueryResultSet resultSet, int commandVersion, string RequestId, IList<byte[]> _serializedResponse)
        {
            long requestId = Convert.ToInt64(RequestId);
            try
            {
                switch (commandVersion)
                {
                    case 0: //Version from NCache 3.8 to NCache 3.8 SP3
                        {
                            Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response();
                            Alachisoft.NCache.Common.Protobuf.SearchEntriesResponse searchEntriesResponse = new Alachisoft.NCache.Common.Protobuf.SearchEntriesResponse();
                            response.requestId = requestId;
                            searchEntriesResponse.keyValuePackage = Alachisoft.NCache.SocketServer.Util.KeyPackageBuilder.PackageKeysValues(resultSet.SearchEntriesResult, searchEntriesResponse.keyValuePackage);
                            response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.SEARCH_ENTRIES;
                            response.searchEntries = searchEntriesResponse;
                            _serializedResponse.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
                        }
                        break;
                    case 1: //From Version 3.8 SP4 onwards //Offically announcing support in 4.1// So not supporting 3.8 SP4 clients in case of aggregate functions with 4.1 Cache Server Decision taken by Kashif Butt
                    case 2: //NCache 4.1 SP1
                        {
                            switch (resultSet.Type)
                            {
                                case QueryType.AggregateFunction:
                                {
                                        Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response();
                                        Alachisoft.NCache.Common.Protobuf.SearchEntriesResponse searchEntriesResponse = new Alachisoft.NCache.Common.Protobuf.SearchEntriesResponse();
                                        searchEntriesResponse.queryResultSet = new Alachisoft.NCache.Common.Protobuf.QueryResultSet();
                                        response.requestId = requestId;
                                        searchEntriesResponse.queryResultSet.queryType = Alachisoft.NCache.Common.Protobuf.QueryType.AGGREGATE_FUNCTIONS;
                                        searchEntriesResponse.queryResultSet.aggregateFunctionType = (Alachisoft.NCache.Common.Protobuf.AggregateFunctionType)(int)resultSet.AggregateFunctionType;
                                        searchEntriesResponse.queryResultSet.aggregateFunctionResult =  new Alachisoft.NCache.Common.Protobuf.DictionaryItem();
                                        searchEntriesResponse.queryResultSet.aggregateFunctionResult.key = resultSet.AggregateFunctionResult.Key.ToString();
                                        searchEntriesResponse.queryResultSet.aggregateFunctionResult.value = resultSet.AggregateFunctionResult.Value != null ? CompactBinaryFormatter.ToByteBuffer(resultSet.AggregateFunctionResult.Value, null) : null;
                                        response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.SEARCH_ENTRIES;
                                        response.searchEntries = searchEntriesResponse;
                                        _serializedResponse.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
                                }
                                break;

                                case QueryType.SearchEntries:
                                {
                                        int sequenceId = 1;
                                        List<Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse> keyValuesPackageChuncks = Alachisoft.NCache.SocketServer.Util.KeyPackageBuilder.PackageKeysValues(resultSet.SearchEntriesResult);
                                        Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response();
                                        Alachisoft.NCache.Common.Protobuf.SearchEntriesResponse searchEntriesResponse = new Alachisoft.NCache.Common.Protobuf.SearchEntriesResponse();
                                        searchEntriesResponse.queryResultSet = new Alachisoft.NCache.Common.Protobuf.QueryResultSet();
                                        response.requestId = requestId;
                                        searchEntriesResponse.queryResultSet.queryType = Alachisoft.NCache.Common.Protobuf.QueryType.SEARCH_ENTRIES;
                                        response.numberOfChuncks = keyValuesPackageChuncks.Count;
                                        response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.SEARCH_ENTRIES;

                                        foreach (Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse package in keyValuesPackageChuncks)
                                        {
                                            response.sequenceId = sequenceId++;
                                            searchEntriesResponse.queryResultSet.searchKeyEnteriesResult = package;
                                            response.searchEntries = searchEntriesResponse;
                                            _serializedResponse.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
                                        }
                                }
                                break;
                            }
                        }
                        break;
                    default:
                        {
                            throw new Exception("Unsupported Command Version");
                        }
                }
            }
            catch (Exception ex)
            {
                if (SocketServer.Logger.IsErrorLogsEnabled)
                {
                    SocketServer.Logger.NCacheLog.Error(ex.ToString());
                    if (resultSet == null)
                    {
                        SocketServer.Logger.NCacheLog.Error("QueryResultSet is null");
                    }
                    else if (resultSet.AggregateFunctionResult.Key == null)
                    {
                        SocketServer.Logger.NCacheLog.Error("QueryResultSet.AggregateFunctionResult.Key is null");
                    }
                    else if (resultSet.AggregateFunctionResult.Value == null)
                    {
                        SocketServer.Logger.NCacheLog.Error("QueryResultSet.AggregateFunctionResult.Value is null");
                    }
                }
            }

            return _serializedResponse;
        }