public void ShouldUnbindOnFlushException()
        {
            IServiceLocator serviceLocator = NewServiceLocator();

            RegisterAsTransient <ISillyCrudModel, SillyCrudModel>(serviceLocator);
            var convFactory = new ConversationFactoryStub(delegate(string id)
            {
                IConversation result = new ExceptionOnFlushConversationStub(id);
                result.OnException  += ((sender, args) => args.ReThrow = false);
                return(result);
            });

            RegisterInstanceForService <IConversationFactory>(serviceLocator, convFactory);

            var   scm = serviceLocator.GetInstance <ISillyCrudModel>();
            Silly e   = scm.GetIfAvailable(Guid.NewGuid());
            var   conversationContainer =
                (ThreadLocalConversationContainerStub)serviceLocator.GetInstance <IConversationContainer>();

            Assert.That(conversationContainer.BindedConversationCount, Is.EqualTo(1),
                        "Don't start and bind the conversation inmediately");
            scm.ImmediateDelete(e);
            Assert.That(conversationContainer.BindedConversationCount, Is.EqualTo(0),
                        "Don't unbind the conversation with exception catch by custom event handler");

            conversationContainer.Reset();
        }
Beispiel #2
0
        public static async Task MainAsync(Configuration configuration, CancellationToken cancel)
        {
            var persistence      = new JsonFileKeyValueStore(new FileInfo(configuration.Get("db-file-location")));
            var gamesPersistence = new JsonFileKeyValueStore(new FileInfo(configuration.Get("games-db-location")));

            var slackApi = new SlackApi(configuration.Get("slack-api-key"));

            var slackRtm = await(ReconnectingSlackRealTimeMessaging.CreateAsync(
                                     async() => await slackApi.StartRtm()));
            var aliasList = GetAliasList(slackRtm.InstanceInfo.Users);

            var commandParser = new SlackCommandParser("scbot", slackRtm.InstanceInfo.BotId);

            var webClient = new WebClient();

            var features = new FeatureMessageProcessor(commandParser,
                                                       NoteProcessor.Create(commandParser, persistence),
                                                       //ZendeskTicketTracker.Create(commandParser, persistence, configuration),
                                                       RecordReplayTraceManagement.Create(commandParser),
                                                       SeatingPlans.Create(commandParser, webClient),
                                                       Webcams.Create(commandParser, configuration),
                                                       Silly.Create(commandParser, webClient),
                                                       Installers.Create(commandParser, webClient),
                                                       Polls.Create(commandParser),
                                                       RollBuildNumbers.Create(commandParser, configuration),
                                                       ReviewFactory.Create(commandParser, webClient, configuration),
                                                       LabelPrinting.Create(commandParser, webClient, configuration),
                                                       Jira.Create(commandParser),
                                                       CompareTeamEmails.Create(commandParser, configuration),
                                                       GamesProcessor.Create(commandParser, gamesPersistence, aliasList)
                                                       );

            var pasteBin = new HasteServerPasteBin(webClient, configuration.Get("haste-server-url"));

            var newChannelNotificationsChannel = configuration.GetWithDefault("new-channels-notification-channel", null);
            var newChannelProcessor            = GetNewChannelProcessor(newChannelNotificationsChannel);

            var bot = new Bot(
                new ErrorReportingMessageProcessor(
                    new ConcattingMessageProcessor(features),
                    pasteBin),
                newChannelProcessor);

            var handler = new SlackMessageHandler(bot, slackRtm.InstanceInfo.BotId);

            MainLoop(slackRtm, handler, slackApi, cancel);
        }
        T AskInner <T>(string question, params string[] options)
        {
            Console.WriteLine(question);
            bool unanswered = true;


            for (int i = 0; i < options.Length; i++)
            {
                Console.WriteLine("{0}. {1}", i, options[i]);
            }


            Console.Write("Answer:");

            Silly <T> silly = null;

            do
            {
                try
                {
                    string result = Console.ReadLine();

                    var dict = new Dictionary <string, object>()
                    {
                        { "answer", result }
                    };
                    var fmd = new FastModelBinder();
                    var cxt = new AskContext(dict);
                    silly = fmd.Bind <Silly <T> >(cxt);

                    unanswered = false;
                }
                catch (Exception)
                {
                    Console.WriteLine("Whoops. Looks like something went wrong.");
                }
            } while (unanswered);

            return(silly.answer);
        }
        public void ConversationAbort()
        {
            var scm1 = ServiceLocator.Current.GetInstance <ISillyCrudModel>();

            IList <Silly> l1 = scm1.GetEntirelyList();

            Assert.That(l1.Count, Is.EqualTo(0));

            var s = new Silly {
                Name = "fiamma"
            };

            scm1.Save(s);
            Assert.That(s.Id, Is.Not.EqualTo(0), "The entity didn't receive the hilo id!?!");
            Guid savedId = s.Id;

            scm1.Abort();

            var scm2 = ServiceLocator.Current.GetInstance <ISillyCrudModel>();

            Assert.That(scm2.GetIfAvailable(savedId), Is.Null, "If it was aborted then it is not present in another conversation");
            scm2.AcceptAll();
        }
        public void ConversationCommitAndContinue()
        {
            var scm1 = ServiceLocator.Current.GetInstance <ISillyCrudModel>();

            IList <Silly> l1 = scm1.GetEntirelyList();

            Assert.That(l1.Count, Is.EqualTo(0));

            var s = new Silly {
                Name = "fiamma"
            };

            scm1.Save(s);
            Assert.That(s.Id, Is.Not.EqualTo(0), "The entity didn't receive the hilo id!?!");
            scm1.AcceptAll();
            Guid savedId = s.Id;

            scm1.ImmediateDelete(s);

            var   scm2  = ServiceLocator.Current.GetInstance <ISillyCrudModel>();
            Silly silly = scm2.GetIfAvailable(savedId);

            Assert.That(silly, Is.Null, "Silly was supposed to be removed immediately");
        }
        public void SimultaneousConversationExample()
        {
            // This test shows what happens using something else than identity
            var scm1 = ServiceLocator.Current.GetInstance <ISillyCrudModel>();
            var scm2 = ServiceLocator.Current.GetInstance <ISillyCrudModel>();

            Assert.That(scm1, Is.Not.SameAs(scm2),
                        "The model is expected to be configured to return a new instance for every ISillyCrudModel.");

            IList <Silly> l1 = scm1.GetEntirelyList();

            Assert.That(l1.Count, Is.EqualTo(0));

            // We save in a conversation, and then retrieve the results from a different one.
            var s = new Silly {
                Name = "fiamma"
            };

            scm1.Save(s);
            Assert.That(s.Id, Is.Not.EqualTo(0));
            Guid savedId = s.Id;

            scm1.AcceptAll();             // <== To have a result available to other conversation you must end yours

            IList <Silly> l2 = scm2.GetEntirelyList();

            Assert.That(l2.Count, Is.EqualTo(1));
            Assert.That("fiamma", Is.EqualTo(l2[0].Name));
            Assert.That(l2[0], Is.Not.SameAs(s), "the two instances of Silly should be of a different session");
            scm2.Delete(l2[0]);
            scm2.AcceptAll();

            // the conversation should resume and the entity should not be associated to the current session
            Assert.That(scm1.GetIfAvailable(savedId), Is.Null);
            scm1.AcceptAll();
        }
Beispiel #7
0
 public void MakeTransient(Silly entity)
 {
 }
Beispiel #8
0
 public Silly MakePersistent(Silly entity)
 {
     return(entity);
 }
Beispiel #9
0
 public virtual void ImmediateDelete(Silly entity)
 {
     EntityDao.MakeTransient(entity);
 }
Beispiel #10
0
 public virtual Silly Save(Silly entity)
 {
     return(EntityDao.MakePersistent(entity));
 }
 public void MakeTransient(Silly entity)
 {
     factory.GetCurrentSession().Delete(entity);
 }
 public Silly MakePersistent(Silly entity)
 {
     factory.GetCurrentSession().SaveOrUpdate(entity);
     return(entity);
 }