private static void SendMessages(MessengerFactory factory, string[] messages, Identity identity, string to, string messengerType) { IMessenger messenger = null; try { messenger = factory.GetMessenger(messengerType, identity); foreach (var message in messages) { try { messenger.Send(new SendParamater(to: to, message: message)); } catch (Exceptions.ConnectionException exception) { Logger.Error(exception: exception); } } } catch (Exceptions.ConnectionException exception) { Logger.Error(exception: exception); } finally { if (messenger != null) { messenger.Dispose(); } } }
private static MessengerFactory InitFactory() { var factory = new MessengerFactory(); factory.Registry(Constants.Skype, identity => new SkypeMessenger(identity, new SkypeClient())); factory.Registry(Constants.Viber, identity => new ViberMessenger(identity, new ViberClient())); return(factory); }
private void speak() { if (voiceReady && timeDone) { // Occurs when the speech engine is initialized System.Diagnostics.Debug.Assert(currentMessenger == null); currentMessenger = MessengerFactory.CreateMessenger(speechEngine, DateTime.Now, this); currentMessenger.OnCompleted += CurrentMessenger_OnCompleted; currentMessenger.Start(); } }
static void Main(string[] args) { MessengerFactory factory = InitFactory(); var messages = new string[3] { "hello my dier friend!", "how are you doing", "bye!" }; var skypeIdentity = new Identity(username: "******", password: "******"); var viberIdentity = new Identity(username: "******", password: "******"); SendMessages( factory: factory, messages: new [] { "hello my dier friend!", "how are you doing", "bye!" }, identity: skypeIdentity, to: "Andrew", messengerType: Constants.Skype); SendMessages( factory: factory, messages: new [] { "hi Nina! Will you go to the party on friday?" }, identity: skypeIdentity, to: "Nina", messengerType: Constants.Viber); SendMessages( factory: factory, messages: new [] { "hi Nina! Will you go to the party on friday?" }, identity: skypeIdentity, to: "Nina", messengerType: Constants.Viber); SendMessages( factory: factory, messages: new [] { "hi Nina! Will you go to the party on friday?" }, identity: skypeIdentity, to: "Nina", messengerType: Constants.Viber); }
private static void Main() { var productCategory = ShowMenu(); #region Naive implementation Product product; switch (productCategory) { case ProductCategory.Insurance: product = new InsuranceProduct(); break; case ProductCategory.Messenger: product = new GhasedakProduct(); break; case ProductCategory.IaaS: product = new ArvanCloudProduct(); break; case ProductCategory.CreditCalculation: product = new AbaciProduct(); break; case ProductCategory.Security: product = new SejelProduct(); break; default: throw new ArgumentOutOfRangeException(); } Report("Naive Method", product); #endregion #region Using SimpleFactory var productViaSimpleFactory = SimpleFactory.CreateProduct(productCategory); Report("Using SimpleFactory", productViaSimpleFactory); #endregion #region Using factory method Product productViaFactoryMethod; switch (productCategory) { case ProductCategory.Insurance: productViaFactoryMethod = new InsuranceFactory().CreateProduct(); break; case ProductCategory.Messenger: productViaFactoryMethod = new MessengerFactory().CreateProduct(); break; case ProductCategory.IaaS: productViaFactoryMethod = new IaaSFactory().CreateProduct(); break; case ProductCategory.CreditCalculation: productViaFactoryMethod = new CreditCalculationFactory().CreateProduct(); break; case ProductCategory.Security: productViaFactoryMethod = new SecurityFactory().CreateProduct(); break; default: throw new ArgumentOutOfRangeException(); } Report("Using FactoryMethod", productViaFactoryMethod); #endregion #region Using abstract factory var apf2 = new AbstractProductFactory2(new IaaSFactory()); var p2 = apf2.CreateProductInstance(); Report("Using apf2:", p2); var apf = new MessengerAbstractProductFactory(); var productViaApf = apf.CreateProductInstance(); Report("Using Abstract Factory", productViaApf); #endregion //CreateAndReportProduct(productCategory); }
public void Setup() { this.factory = new MessengerFactory(); }