public void CreateModifyDeleteMessageType() { if (!Settings.ModifyTests) { return; } string name = "Test message type"; string icon = "t"; string name2 = "Altered message type"; string icon2 = "a"; ApiList <MessageType> messages = RunTest(MessageType.GetMessageTypes(Api, Settings.TestProject)); List <MessageType> all = messages.All(Api).ToList(); MessageType d = all.FirstOrDefault(x => x.name == name); if (d != null) { d.Destroy(Api, Settings.TestProject).Wait(); } d = all.FirstOrDefault(x => x.name == name2); if (d != null) { d.Destroy(Api, Settings.TestProject).Wait(); } MessageType m = MessageType.Create(Api, Settings.TestProject, name, icon).Result; Assert.AreEqual(name, m.name); Assert.AreEqual(icon, m.icon); MessageType changed = m.Update(Api, Settings.TestProject, name2, icon2).Result; Assert.AreEqual(name2, changed.name); Assert.AreEqual(icon2, changed.icon); changed.Destroy(Api, Settings.TestProject).Wait(); }
public void Create() { if (!this.ServiceBroker.MessageTypes.Contains(this.FullName)) { // Create message types MessageType msgType = new MessageType( this.ServiceBroker, this.FullName); msgType.MessageTypeValidation = this.MessageTypeValidation; if (msgType.MessageTypeValidation == MessageTypeValidation.XmlSchemaCollection) { if (!this.ServiceBroker.Parent.XmlSchemaCollections.Contains (this.ValidationXmlSchemaCollection) && !String.IsNullOrEmpty(this.ValidationXmlSchemaCollectionSchema)) { XmlSchemaCollection schema = new XmlSchemaCollection (this.ServiceBroker.Parent, this.ValidationXmlSchemaCollection); schema.Text = this.ValidationXmlSchemaCollectionSchema; schema.Create(); } msgType.ValidationXmlSchemaCollection = this.ValidationXmlSchemaCollection; } msgType.Create(); } }
public void TestFactory() { foreach (var id in new [] { "coffee", "cof$fee", "cof|fee", "cof/fee" }) { var message = MessageType.Create(new MessageSnapshot { Id = id, Title = "Get coffee" }); Assert.NotNull(message); } }
public static void Main() { byte[] buffer = new byte[10 * 1024 * 1024]; int id = 0; int encode_size = 0; // encode message to buffer { MsgTest msg = new MsgTest(); msg.a1 = 0x7f; msg.a2 = 0xff; msg.a3 = 0x7fff; msg.a4 = 0xffff; msg.a5 = 0x7fffffff; msg.a6 = 0xffffffff; msg.a7 = 0x7fffffffffffffff; msg.a8 = 0xffffffffffffffff; msg.a9 = "hello, world!"; msg.a10 = true; msg.a11 = AttrType.STR; msg.a12 = Encoding.ASCII.GetBytes("hello, world!"); msg.a13 = 0x7fff; msg.a14 = 0xffff; msg.a15 = 0x7fffffff; msg.a16 = 0xffffffff; msg.a17 = 0x7fffffffffffffff; msg.a18 = 0xffffffffffffffff; for (int i = 0; i < 254; ++i) { msg.b5.Add(i); } for (int i = 0; i < 10; ++i) { msg.b7.Add(msg.a7); } for (int i = 0; i < 10; ++i) { msg.b8.Add(msg.a8); } for (int i = 0; i < 254; ++i) { msg.b15.Add(i); } for (int i = 0; i < 10; ++i) { msg.b17.Add(msg.a17); } for (int i = 0; i < 10; ++i) { msg.b18.Add(msg.a18); } msg.set_c1(1); msg.set_c2(1); msg.clear_has_c1(); msg.set_has_c3(); for (int i = 0; i < 65536; ++i) { msg.c3.Add(i); } // do encode encode_size = msg.Encode(buffer); if (-1 == encode_size) { Console.WriteLine("buffer is too small"); return; } // get message id from type id = MessageType.GetId <MsgTest>(); } // decode message from buffer { BaseStruct msg_decoded = MessageType.Create(id); msg_decoded.Decode(buffer, 0, encode_size); MsgTest msg = (MsgTest)msg_decoded; StringBuilder s = new StringBuilder(); s.AppendFormat("encode_size = {0}\n", encode_size); s.AppendFormat("a1 = {0}\n", msg.a1); s.AppendFormat("a2 = {0}\n", msg.a2); s.AppendFormat("a3 = {0}\n", msg.a3); s.AppendFormat("a4 = {0}\n", msg.a4); s.AppendFormat("a5 = {0}\n", msg.a5); s.AppendFormat("a6 = {0}\n", msg.a6); s.AppendFormat("a7 = {0}\n", msg.a7); s.AppendFormat("a8 = {0}\n", msg.a8); s.AppendFormat("a9 = {0}\n", msg.a9); s.AppendFormat("a10 = {0}\n", msg.a10 ? 1 : 0); s.AppendFormat("a11 = {0}\n", (int)msg.a11); s.AppendFormat("a12 = {0}\n", Encoding.ASCII.GetString(msg.a12)); s.AppendFormat("a13 = {0}\n", msg.a13); s.AppendFormat("a14 = {0}\n", msg.a14); s.AppendFormat("a15 = {0}\n", msg.a15); s.AppendFormat("a16 = {0}\n", msg.a16); s.AppendFormat("a17 = {0}\n", msg.a17); s.AppendFormat("a18 = {0}\n", msg.a18); s.AppendFormat("b5 size = {0}\n", msg.b5.Count); s.AppendFormat("b5[253] = {0}\n", msg.b5[253]); s.AppendFormat("b7 size = {0}\n", msg.b7.Count); s.AppendFormat("b7[0] = {0}\n", msg.b7[0]); s.AppendFormat("b8 size = {0}\n", msg.b8.Count); s.AppendFormat("b8[0] = {0}\n", msg.b8[0]); s.AppendFormat("has c1 = {0}\n", msg.has_c1() ? 1 : 0); s.AppendFormat("c1 = {0}\n", msg.c1); s.AppendFormat("has c2 = {0}\n", msg.has_c2() ? 1 : 0); s.AppendFormat("c2 = {0}\n", msg.c2); s.AppendFormat("has c3 = {0}\n", msg.has_c3() ? 1 : 0); s.AppendFormat("c3 size = {0}\n", msg.c3.Count); s.AppendFormat("c3[65535] = {0}\n", msg.c3[65535]); Console.Write(s); } }
static void Main(string[] args) { Server svr = new Server("localhost"); Console.WriteLine("Language: " + svr.Information.Language); Console.WriteLine("OS version: " + svr.Information.OSVersion); Console.WriteLine("Edition: " + svr.Information.Edition); Console.WriteLine("Root directory: " + svr.Information.RootDirectory); // Create a new database Database db = new Database(svr, "Chapter12_SMOSample"); db.Create(); // Create the required message types MessageType requestMessage = new MessageType(db.ServiceBroker, "RequestMessage"); MessageType responseMessage = new MessageType(db.ServiceBroker, "ResponseMessage"); requestMessage.Create(); responseMessage.Create(); // Create the service contract ServiceContract contract = new ServiceContract(db.ServiceBroker, "SampleContract"); contract.MessageTypeMappings.Add(new MessageTypeMapping(contract, "RequestMessage", Microsoft.SqlServer.Management.Smo.Broker.MessageSource.Initiator)); contract.MessageTypeMappings.Add(new MessageTypeMapping(contract, "ResponseMessage", Microsoft.SqlServer.Management.Smo.Broker.MessageSource.Target)); contract.Create(); // Create the queue ServiceQueue queue = new ServiceQueue(db.ServiceBroker, "SampleQueue"); queue.Create(); // Create the Service Broker service BrokerService service = new BrokerService(db.ServiceBroker, "SampleService"); service.QueueName = "SampleQueue"; service.ServiceContractMappings.Add(new ServiceContractMapping(service, "SampleContract")); service.Create(); // Retrieve Service Broker information through SMO foreach (MessageType messageType in db.ServiceBroker.MessageTypes) { Console.WriteLine(messageType.Name); } foreach (ServiceContract serviceContract in db.ServiceBroker.ServiceContracts) { Console.WriteLine(serviceContract.Name); } foreach (ServiceQueue serviceQueue in db.ServiceBroker.Queues) { Console.WriteLine(serviceQueue.Name); Console.WriteLine("\tActivation enabled:" + serviceQueue.IsActivationEnabled); Console.WriteLine("\tMax Queue Readers: " + serviceQueue.MaxReaders); Console.WriteLine("\tProcedure name: " + serviceQueue.ProcedureName); } foreach (BrokerService brokerService in db.ServiceBroker.Services) { Console.WriteLine(brokerService.Name); Console.WriteLine("\tQueue name: " + brokerService.QueueName); } Console.ReadLine(); }
internal static void DeploySsbObj(object obj, string svrName, string dbName, SsbEnum ssbType, bool isEdit) { Server svr = CreateServer(svrName, null, null); Database db = svr.Databases[dbName]; ServiceBroker sb = db.ServiceBroker; MessageType mt = null; ServiceContract sc = null; ServiceQueue q = null; BrokerService serv = null; ServiceRoute rt = null; RemoteServiceBinding bind = null; try { switch (ssbType) { case SsbEnum.MessageType: MessageType mtNew = new MessageType(); mtNew.Parent = sb; mt = (MessageType)obj; mtNew.Name = mt.Name; mtNew.MessageTypeValidation = mt.MessageTypeValidation; if (mt.MessageTypeValidation == MessageTypeValidation.XmlSchemaCollection) { mtNew.ValidationXmlSchemaCollection = mt.ValidationXmlSchemaCollection; } if (isEdit) { mtNew.Alter(); } else { mtNew.Create(); } break; case SsbEnum.Contract: ServiceContract scNew = new ServiceContract(); sc = (ServiceContract)obj; scNew.Parent = sb; scNew.Name = sc.Name; foreach (MessageTypeMapping mtm in sc.MessageTypeMappings) { if (!sb.MessageTypes.Contains(mtm.Name)) { ServiceBroker sbParent = sc.Parent; MessageType mtp = sbParent.MessageTypes[mtm.Name]; DeploySsbObj(mtp, svrName, dbName, SsbEnum.MessageType, false); } MessageTypeMapping mtmNew = new MessageTypeMapping(); mtmNew.Name = mtm.Name; mtmNew.Parent = scNew; mtmNew.MessageSource = mtm.MessageSource; scNew.MessageTypeMappings.Add(mtmNew); } if (isEdit) { scNew.Alter(); } else { scNew.Create(); } break; case SsbEnum.Queu: q = (ServiceQueue)obj; q.Parent = sb; if (isEdit) { q.Alter(); } else { q.Create(); } break; case SsbEnum.Service: serv = (BrokerService)obj; serv.Parent = sb; if (isEdit) { serv.Alter(); } else { serv.Create(); } break; case SsbEnum.Route: rt = (ServiceRoute)obj; rt.Parent = sb; if (isEdit) { rt.Alter(); } else { rt.Create(); } break; case SsbEnum.RemoteBinding: bind = (RemoteServiceBinding)obj; bind.Parent = sb; if (isEdit) { bind.Alter(); } else { bind.Create(); } break; } } catch (FailedOperationException e) { string err = string.Format("{0}", e.InnerException); //throw; } catch (Exception ex) { string errx = string.Format("{0}", ex.InnerException); } finally { svr.ConnectionContext.Disconnect(); } }
internal static void DeploySsbObj(object obj, string svrName, string dbName, SsbEnum ssbType, bool isEdit) { Server svr = CreateServer(svrName, null, null); Database db = svr.Databases[dbName]; ServiceBroker sb = db.ServiceBroker; MessageType mt = null; ServiceContract sc = null; ServiceQueue q = null; BrokerService serv = null; ServiceRoute rt = null; RemoteServiceBinding bind = null; try { switch (ssbType) { case SsbEnum.MessageType: MessageType mtNew = new MessageType(); mtNew.Parent = sb; mt = (MessageType)obj; mtNew.Name = mt.Name; mtNew.MessageTypeValidation = mt.MessageTypeValidation; if (mt.MessageTypeValidation == MessageTypeValidation.XmlSchemaCollection) mtNew.ValidationXmlSchemaCollection = mt.ValidationXmlSchemaCollection; if (isEdit) mtNew.Alter(); else mtNew.Create(); break; case SsbEnum.Contract: ServiceContract scNew = new ServiceContract(); sc = (ServiceContract)obj; scNew.Parent = sb; scNew.Name = sc.Name; foreach (MessageTypeMapping mtm in sc.MessageTypeMappings) { if (!sb.MessageTypes.Contains(mtm.Name)) { ServiceBroker sbParent = sc.Parent; MessageType mtp = sbParent.MessageTypes[mtm.Name]; DeploySsbObj(mtp, svrName, dbName, SsbEnum.MessageType, false); } MessageTypeMapping mtmNew = new MessageTypeMapping(); mtmNew.Name = mtm.Name; mtmNew.Parent = scNew; mtmNew.MessageSource = mtm.MessageSource; scNew.MessageTypeMappings.Add(mtmNew); } if (isEdit) scNew.Alter(); else scNew.Create(); break; case SsbEnum.Queu: q = (ServiceQueue)obj; q.Parent = sb; if (isEdit) q.Alter(); else q.Create(); break; case SsbEnum.Service: serv = (BrokerService)obj; serv.Parent = sb; if (isEdit) serv.Alter(); else serv.Create(); break; case SsbEnum.Route: rt = (ServiceRoute)obj; rt.Parent = sb; if (isEdit) rt.Alter(); else rt.Create(); break; case SsbEnum.RemoteBinding: bind = (RemoteServiceBinding)obj; bind.Parent = sb; if (isEdit) bind.Alter(); else bind.Create(); break; } } catch (FailedOperationException e) { string err = string.Format("{0}", e.InnerException); //throw; } catch (Exception ex) { string errx = string.Format("{0}", ex.InnerException); } finally { svr.ConnectionContext.Disconnect(); } }
public void Create() { if (!this.ServiceBroker.MessageTypes.Contains(this.FullName)) { // Create message types MessageType msgType = new MessageType( this.ServiceBroker, this.FullName); msgType.MessageTypeValidation = this.MessageTypeValidation; if (msgType.MessageTypeValidation == MessageTypeValidation.XmlSchemaCollection) { if(!this.ServiceBroker.Parent.XmlSchemaCollections.Contains (this.ValidationXmlSchemaCollection) && ! String.IsNullOrEmpty(this.ValidationXmlSchemaCollectionSchema)) { XmlSchemaCollection schema = new XmlSchemaCollection (this.ServiceBroker.Parent, this.ValidationXmlSchemaCollection); schema.Text = this.ValidationXmlSchemaCollectionSchema; schema.Create(); } msgType.ValidationXmlSchemaCollection = this.ValidationXmlSchemaCollection; } msgType.Create(); } }