Example #1
0
        private object GetValueObject(string value, bool dotNetClient)
        {
            object retVal = null;

            try
            {
                // Now we move data-type along with the value.So extract them here.
                string[] vals    = value.Split(Delimitor);
                object   valObj  = (object)vals[0];
                string   typeStr = vals[1];
                // Assuming that its otherwise java client only

                if (!dotNetClient)
                {
                    string type = JavaClrTypeMapping.JavaToClr(typeStr);
                    if (type != null) // Only if it is not null, otherwise let it go...
                    {
                        typeStr = type;
                    }
                }

                Type objType = System.Type.GetType(typeStr);
                retVal = Convert.ChangeType(valObj, objType);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(retVal);
        }
Example #2
0
 public static Hashtable GetHashtableFromNamedTagInfoObjFromJava(NamedTagInfo tagInfo)
 {
     if (tagInfo == null)
     {
         return(null);
     }
     for (int i = 0; i < tagInfo.names.Count; i++)
     {
         tagInfo.types[i] = JavaClrTypeMapping.JavaToClr(tagInfo.types[i]);
     }
     return(GetHashtableFromNamedTagInfoObj(tagInfo));
 }
        private CommandInfo ParseCommand(Alachisoft.NCache.Common.Protobuf.Command command, ClientManager clientManager)
        {
            CommandInfo commandInfo = new CommandInfo();

            Alachisoft.NCache.Common.Protobuf.ExecuteReaderCQCommand executeReaderCQCommand = command.executeReaderCQCommand;
            commandInfo.Query            = executeReaderCQCommand.query;
            commandInfo.getData          = executeReaderCQCommand.getData;
            commandInfo.chunkSize        = (int)executeReaderCQCommand.chunkSize;
            commandInfo.RequestId        = executeReaderCQCommand.requestId.ToString();
            commandInfo.notifyAdd        = executeReaderCQCommand.notifyAdd;
            commandInfo.notifyRemove     = executeReaderCQCommand.notifyRemove;
            commandInfo.notifyUpdate     = executeReaderCQCommand.notifyUpdate;
            commandInfo.clientUniqueId   = executeReaderCQCommand.clientUniqueId;
            commandInfo.ClientLastViewId = command.clientLastViewId.ToString();
            commandInfo.addDF            = executeReaderCQCommand.addDataFilter;
            commandInfo.removeDF         = executeReaderCQCommand.remvoeDataFilter;
            commandInfo.updateDF         = executeReaderCQCommand.updateDataFilter;

            commandInfo.CommandVersion = command.commandVersion;
            commandInfo.Values         = new Hashtable();
            foreach (Alachisoft.NCache.Common.Protobuf.KeyValue keyValuePair in executeReaderCQCommand.values)
            {
                string key = keyValuePair.key;
                List <Alachisoft.NCache.Common.Protobuf.ValueWithType> valueWithTypes = keyValuePair.value;
                Type   type  = null;
                object value = null;
                foreach (Alachisoft.NCache.Common.Protobuf.ValueWithType valueWithType in valueWithTypes)
                {
                    string typeString = valueWithType.type;
                    if (!clientManager.IsDotNetClient)
                    {
                        typeString = JavaClrTypeMapping.JavaToClr(valueWithType.type);
                    }
                    type = Type.GetType(typeString, true, true);

                    if (valueWithType.value != null)
                    {
                        try
                        {
                            if (type == typeof(System.DateTime))
                            {
                                // For client we would be sending ticks instead
                                // of string representation of Date.
                                value = new DateTime(Convert.ToInt64(valueWithType.value));
                            }
                            else
                            {
                                value = Convert.ChangeType(valueWithType.value, type);
                            }
                        }
                        catch (Exception)
                        {
                            throw new System.FormatException("Cannot convert '" + valueWithType.value + "' to " + type.ToString());
                        }
                    }

                    if (!commandInfo.Values.Contains(key))
                    {
                        commandInfo.Values.Add(key, value);
                    }
                    else
                    {
                        ArrayList list = commandInfo.Values[key] as ArrayList; // the value is not array list
                        if (list == null)
                        {
                            list = new ArrayList();
                            list.Add(commandInfo.Values[key]); // add the already present value in the list
                            commandInfo.Values.Remove(key);    // remove the key from hashtable to avoid key already exists exception
                            list.Add(value);                   // add the new value in the list
                            commandInfo.Values.Add(key, list);
                        }
                        else
                        {
                            list.Add(value);
                        }
                    }
                }
            }
            return(commandInfo);
        }
Example #4
0
        //PROTOBUF
        private CommandInfo ParseCommand(Alachisoft.NCache.Common.Protobuf.Command command, ClientManager clientManager)
        {
            CommandInfo cmdInfo = new CommandInfo();

            Alachisoft.NCache.Common.Protobuf.DeleteQueryCommand deleteQueryCommand = command.deleteQueryCommand;
            cmdInfo.RequestId        = deleteQueryCommand.requestId.ToString();
            cmdInfo.ClientLastViewId = command.clientLastViewId;
            cmdInfo.CommandVersion   = command.commandVersion;
            cmdInfo.Query            = deleteQueryCommand.query;

            {
                cmdInfo.Values = new Hashtable();
                foreach (Alachisoft.NCache.Common.Protobuf.KeyValue searchValue in deleteQueryCommand.values)
                {
                    string key = searchValue.key;
                    List <Alachisoft.NCache.Common.Protobuf.ValueWithType> valueWithTypes = searchValue.value;
                    Type   type  = null;
                    object value = null;

                    foreach (Alachisoft.NCache.Common.Protobuf.ValueWithType valueWithType in valueWithTypes)
                    {
                        string typeStr = valueWithType.type;
                        if (!clientManager.IsDotNetClient)
                        {
                            typeStr = JavaClrTypeMapping.JavaToClr(valueWithType.type);
                        }
                        type = Type.GetType(typeStr, true, true);

                        if (valueWithType.value != null)
                        {
                            try
                            {
                                if (type == typeof(System.DateTime))
                                {
                                    // For client we would be sending ticks instead
                                    // of string representation of Date.
                                    value = new DateTime(Convert.ToInt64(valueWithType.value));
                                }
                                else
                                {
                                    value = Convert.ChangeType(valueWithType.value, type);
                                }
                            }
                            catch (Exception)
                            {
                                throw new System.FormatException("Cannot convert '" + valueWithType.value + "' to " + type.ToString());
                            }
                        }

                        if (!cmdInfo.Values.Contains(key))
                        {
                            cmdInfo.Values.Add(key, value);
                        }
                        else
                        {
                            ArrayList list = cmdInfo.Values[key] as ArrayList; // the value is not array list
                            if (list == null)
                            {
                                list = new ArrayList();
                                list.Add(cmdInfo.Values[key]); // add the already present value in the list
                                cmdInfo.Values.Remove(key);    // remove the key from hashtable to avoid key already exists exception
                                list.Add(value);               // add the new value in the list
                                cmdInfo.Values.Add(key, list);
                            }
                            else
                            {
                                list.Add(value);
                            }
                        }
                    }
                }
            }

            return(cmdInfo);
        }
Example #5
0
        private CommandInfo ParseCommand(Alachisoft.NCache.Common.Protobuf.Command command, ClientManager clientManager)
        {
            CommandInfo cmdInfo = new CommandInfo();

            Alachisoft.NCache.Common.Protobuf.RegisterCQCommand registerCQCommand = command.registerCQCommand;
            cmdInfo.Query            = registerCQCommand.query;
            cmdInfo.RequestId        = registerCQCommand.requestId.ToString();
            cmdInfo.notifyAdd        = registerCQCommand.notifyAdd;
            cmdInfo.notifyUpdate     = registerCQCommand.notifyUpdate;
            cmdInfo.notifyRemove     = registerCQCommand.notifyRemove;
            cmdInfo.clientUniqueId   = registerCQCommand.clientUniqueId;
            cmdInfo.addDataFilter    = registerCQCommand.addDataFilter;
            cmdInfo.removeDataFilter = registerCQCommand.remvoeDataFilter;
            cmdInfo.updateDataFilter = registerCQCommand.updateDataFilter;

            {
                cmdInfo.Values = new Hashtable();
                foreach (Alachisoft.NCache.Common.Protobuf.KeyValue searchValue in registerCQCommand.values)
                {
                    string key = searchValue.key;
                    List <Alachisoft.NCache.Common.Protobuf.ValueWithType> valueWithTypes = searchValue.value;
                    Type   type  = null;
                    object value = null;

                    foreach (Alachisoft.NCache.Common.Protobuf.ValueWithType valueWithType in valueWithTypes)
                    {
                        string typeStr = valueWithType.type;
                        if (!clientManager.IsDotNetClient)
                        {
                            typeStr = JavaClrTypeMapping.JavaToClr(valueWithType.type);
                        }
                        type = Type.GetType(typeStr, true, true);

                        if (valueWithType.value != null)
                        {
                            try
                            {
                                if (type == typeof(System.DateTime))
                                {
                                    if (clientManager.IsDotNetClient)
                                    {
                                        System.Globalization.CultureInfo enUs = new System.Globalization.CultureInfo("en-US");
                                        value = Convert.ChangeType(valueWithType.value, type, enUs);
                                    }
                                    else
                                    {
                                        // For java client we would be sending ticks instead
                                        // of string representation of Date.
                                        long ticks = long.Parse(valueWithType.value);
                                        value = new DateTime(ticks);
                                    }
                                }
                                else
                                {
                                    value = Convert.ChangeType(valueWithType.value, type);
                                }
                            }
                            catch (Exception)
                            {
                                throw new System.FormatException("Cannot convert '" + valueWithType.value + "' to " + type.ToString());
                            }
                        }

                        if (!cmdInfo.Values.Contains(key))
                        {
                            cmdInfo.Values.Add(key, value);
                        }
                        else
                        {
                            ArrayList list = cmdInfo.Values[key] as ArrayList; // the value is not array list
                            if (list == null)
                            {
                                list = new ArrayList();
                                list.Add(cmdInfo.Values[key]); // add the already present value in the list
                                cmdInfo.Values.Remove(key);    // remove the key from hashtable to avoid key already exists exception
                                list.Add(value);               // add the new value in the list
                                cmdInfo.Values.Add(key, list);
                            }
                            else
                            {
                                list.Add(value);
                            }
                        }
                    }
                }
            }

            return(cmdInfo);
        }