Beispiel #1
0
        public void SetCapabilities(Dictionary <string, object> clientCapabilities)
        {
            if (clientCapabilities == null || clientCapabilities.Count == 0)
            {
                return;
            }

            var builder      = new CapabilitiesSet();
            var capabilities = new Capabilities();

            foreach (var cap in clientCapabilities)
            {
                var value = new Any();

                if (cap.Key == "tls")
                {
                    value = ExprUtil.BuildAny(cap.Value);
                }
                else if (cap.Key == "session_connect_attrs" || cap.Key == "compression")
                {
                    var obj = new Mysqlx.Datatypes.Object();

                    if (cap.Key == "session_connect_attrs")
                    {
                        foreach (var pair in (Dictionary <string, string>)cap.Value)
                        {
                            obj.Fld.Add(new ObjectField {
                                Key = pair.Key, Value = ExprUtil.BuildAny(pair.Value)
                            });
                        }
                    }
                    else if (cap.Key == "compression")
                    {
                        foreach (var pair in (Dictionary <string, object>)cap.Value)
                        {
                            obj.Fld.Add(new ObjectField {
                                Key = pair.Key, Value = ExprUtil.BuildAny(pair.Value)
                            });
                        }
                    }

                    value = new Any {
                        Type = Any.Types.Type.Object, Obj = obj
                    };
                }

                var capabilityMsg = new Capability()
                {
                    Name = cap.Key, Value = value
                };
                capabilities.Capabilities_.Add(capabilityMsg);
            }

            builder.Capabilities = capabilities;
            _writer.Write(ClientMessageId.CON_CAPABILITIES_SET, builder);
            ReadOk();
        }
Beispiel #2
0
 private Any CreateAny(object o)
 {
     if (o is string)
     {
         return(ExprUtil.BuildAny((string)o));
     }
     if (o is bool)
     {
         return(ExprUtil.BuildAny((bool)o));
     }
     return(ExprUtil.BuildAny(o));
 }
Beispiel #3
0
        /// <summary>
        /// Build the message to be sent to MySQL Server to execute statement "Create" or "Modify" collection with schema options
        /// </summary>
        /// <param name="ns">The namespace</param>
        /// <param name="stmt">The name of the command to be executed on MySql Server</param>
        /// <param name="args">Array of KeyValuePairs with the parameters required to build the message</param>
        /// <returns>void.</returns>
        public void SendExecuteStatementOptions(string ns, string stmt, params KeyValuePair <string, object>[] args)
        {
            StmtExecute stmtExecute = new StmtExecute();

            stmtExecute.Namespace       = ns;
            stmtExecute.Stmt            = ByteString.CopyFromUtf8(stmt);
            stmtExecute.CompactMetadata = false;
            if (args != null)
            {
                var options    = new ObjectField();
                var validation = new ObjectField();
                var reuse_obj  = new ObjectField();
                var optionsAny = ExprUtil.BuildEmptyAny(Any.Types.Type.Object);
                var any        = ExprUtil.BuildEmptyAny(Any.Types.Type.Object);
                var innerAny   = ExprUtil.BuildEmptyAny(Any.Types.Type.Object);
                var reuse_any  = ExprUtil.BuildEmptyAny(Any.Types.Type.Object);
                foreach (var arg in args)
                {
                    if (arg.Value is Dictionary <string, object> && arg.Key == "options")
                    {
                        foreach (var field in arg.Value as Dictionary <string, object> )
                        {
                            innerAny.Obj.Fld.Add(CreateObject(field.Key, field.Value));
                        }
                    }
                    else if (arg.Key == "reuse_existing")
                    {
                        reuse_any = ExprUtil.BuildAny(arg.Value);
                    }
                    else
                    {
                        any.Obj.Fld.Add(CreateObject(arg.Key, arg.Value));
                    }
                }
                options.Key      = "options";
                validation.Key   = "validation";
                validation.Value = innerAny;
                reuse_obj.Key    = "reuse_existing";
                reuse_obj.Value  = reuse_any;
                optionsAny.Obj.Fld.Add(validation);
                if (stmt == "create_collection")
                {
                    optionsAny.Obj.Fld.Add(reuse_obj);
                }
                options.Value = optionsAny;
                any.Obj.Fld.Add(options);
                stmtExecute.Args.Add(any);
            }

            _writer.Write(ClientMessageId.SQL_STMT_EXECUTE, stmtExecute);
        }
Beispiel #4
0
 public void AddArgs(Action <Any> addFunction, IEnumerable args)
 {
     foreach (var arg in args)
     {
         if (arg.GetType().IsArray)
         {
             AddArgs(addFunction, (System.Array)arg);
         }
         else
         {
             addFunction(ExprUtil.BuildAny(arg));
         }
     }
 }
Beispiel #5
0
        public void SetCapabilities(Dictionary <string, object> clientCapabilities)
        {
            if (clientCapabilities == null || clientCapabilities.Count == 0)
            {
                return;
            }

            var builder      = new CapabilitiesSet();
            var capabilities = new Capabilities();

            foreach (var cap in clientCapabilities)
            {
                var capabilityMsg = new Capability()
                {
                    Name = (cap.Key), Value = ExprUtil.BuildAny(cap.Value)
                };
                capabilities.Capabilities_.Add(capabilityMsg);
            }
            builder.Capabilities = capabilities;
            _writer.Write(ClientMessageId.CON_CAPABILITIES_SET, builder);
            ReadOk();
        }