Exemple #1
0
		static void Main(string[] args)
		{
			var context = ServiceUtil.GetContextProvider<ISampleContextProvider>().GetCurrentContext();

			var consoleProvider = ServiceUtil.GetService<IConsoleProvider>(context);
			
			// test output string provider with string transformers
			var outputStr = Strings.GetTransformedString(context, "MyResourceKey");
			consoleProvider.WriteLine(outputStr);

			outputStr = Strings.GetHtmlEncodedString("<span>aaa</span>");
			consoleProvider.WriteLine(outputStr);

			consoleProvider.WriteLine("================================================");
			
			// test service provider
			var userTokenProvider = ServiceUtil.GetService<IUserTokenProvider>(context);
			var loginData = (SampleUserToken)userTokenProvider.GetUserToken(context, new UserTokenRequestWithCredentials("aaa", "bbb"));
			consoleProvider.WriteLine(loginData.UserId.ToString());
			consoleProvider.WriteLine("================================================");

			// test error handling
			try
			{
				throw ServiceUtil.GetService<ISampleTypeSetProvider>(context).GetSampleTypeInstanceByName(context, "First name").GetTestErrorException(context);
			}
			catch (EntityException<SampleType, TestError> exc)
			{
				consoleProvider.WriteLine(Strings.GetHtmlEncodedTransformedString(context, exc.Info.GetDescription(context)), exc.Entity);
				consoleProvider.WriteLine(exc.ContextSnapshot.UTCTime + " " + exc.ContextSnapshot.LocalTimeOffset + " " + exc.ContextSnapshot.UICulture.LCID);
				consoleProvider.WriteLine(context.GetCurrentTimeUTC() + " " + context.GetLocalTimeOffset() + " " + context.GetCurrentUICulture().LCID);
			}
			catch (EntityException<SampleType> exc)
			{
				if (exc.GetInfoEntityType() == typeof(TestError))
				{
					consoleProvider.WriteLine(exc.GetInfo<TestError>().GetDescription(context), exc.Entity);
				}
				else
				{
					throw;
				}
			}
			catch (EntityException exc)
			{
				if (exc.GetEntityType() != typeof(SampleType) && exc.GetInfoEntityType() == typeof(TestError))
				{
					consoleProvider.WriteLine(exc.GetInfo<TestError>().GetDescription(context), exc.GetEntity<SampleType>());
				}
				else
				{
					consoleProvider.WriteLine(exc.GetInfo().GetObjectDescription(context), exc.GetEntity().GetObjectDescription(context));
					throw;
				}
			}

			consoleProvider.WriteLine("================================================");

			// test configuration provider
			var authCookieProperties = ServiceUtil.GetService<IAuthCookiePropertiesProvider>(context).GetAuthCookieProperties();
			consoleProvider.WriteLine("Auth cookie name: {0}", authCookieProperties != null ? authCookieProperties.Name : "!!!DEFAULT!!!");
			consoleProvider.WriteLine("================================================");

			// test structured entity providers
			var sampleTypes = ServiceUtil.GetService<ISampleTypeStructuredDataProvider>(context).ListSampleTypes(context);
			foreach (var sampleType in sampleTypes)
			{
				consoleProvider.WriteLine(sampleType.GetObjectDescription(context));
			}

			consoleProvider.WriteLine("================================================");

			var treeDisplayer = new TreeDisplayer(consoleProvider);

			var anotherTypesTree = ServiceUtil.GetService<IAnotherTypeStructuredDataProvider>(context).GetAnotherTypeStructuredData(context);
			anotherTypesTree.GetSidebarLikeTreeWithSeparators().TraverseDepth(treeDisplayer.DisplayTree);
			consoleProvider.WriteLine("================================================");

			var yetAnotherTypesTree = ServiceUtil.GetService<IYetAnotherTypeStructuredDataProvider>(context).GetYetAnotherTypeStructuredData(context);
			yetAnotherTypesTree.GetSidebarLikeTreeWithSeparators().TraverseDepth(treeDisplayer.DisplayTree);
			consoleProvider.WriteLine("================================================");

			var controller = new SampleController(
				ServiceUtil.GetService<ISampleContextProvider>(context),
				ServiceUtil.GetService<ICurrentUserTokenProvider>(context),
				ServiceUtil.GetService<ISampleUserTokenFactory>(context),
				ServiceUtil.GetService<IConsoleProvider>(context));

			controller.OperationWithEnvironmentContext();
			controller.OperationWithUserContext();
			controller.OperationWithUserContext(100);
			controller.OperationWithMeetingContext(100, 2, "NEW MEETING NAME");
			consoleProvider.WriteLine("================================================");

			consoleProvider.ReadKey();
		}
Exemple #2
0
        static void Main(string[] args)
        {
            var context = ServiceUtil.GetContextProvider <ISampleContextProvider>().GetCurrentContext();

            var consoleProvider = ServiceUtil.GetService <IConsoleProvider>(context);

            // test output string provider with string transformers
            var outputStr = Strings.GetTransformedString(context, "MyResourceKey");

            consoleProvider.WriteLine(outputStr);

            outputStr = Strings.GetHtmlEncodedString("<span>aaa</span>");
            consoleProvider.WriteLine(outputStr);

            consoleProvider.WriteLine("================================================");

            // test service provider
            var userTokenProvider = ServiceUtil.GetService <IUserTokenProvider>(context);
            var loginData         = (SampleUserToken)userTokenProvider.GetUserToken(context, new UserTokenRequestWithCredentials("aaa", "bbb"));

            consoleProvider.WriteLine(loginData.UserId.ToString());
            consoleProvider.WriteLine("================================================");

            // test error handling
            try
            {
                throw ServiceUtil.GetService <ISampleTypeSetProvider>(context).GetSampleTypeInstanceByName(context, "First name").GetTestErrorException(context);
            }
            catch (EntityException <SampleType, TestError> exc)
            {
                consoleProvider.WriteLine(Strings.GetHtmlEncodedTransformedString(context, exc.Info.GetDescription(context)), exc.Entity);
                consoleProvider.WriteLine(exc.ContextSnapshot.UTCTime + " " + exc.ContextSnapshot.LocalTimeOffset + " " + exc.ContextSnapshot.UICulture.LCID);
                consoleProvider.WriteLine(context.GetCurrentTimeUTC() + " " + context.GetLocalTimeOffset() + " " + context.GetCurrentUICulture().LCID);
            }
            catch (EntityException <SampleType> exc)
            {
                if (exc.GetInfoEntityType() == typeof(TestError))
                {
                    consoleProvider.WriteLine(exc.GetInfo <TestError>().GetDescription(context), exc.Entity);
                }
                else
                {
                    throw;
                }
            }
            catch (EntityException exc)
            {
                if (exc.GetEntityType() != typeof(SampleType) && exc.GetInfoEntityType() == typeof(TestError))
                {
                    consoleProvider.WriteLine(exc.GetInfo <TestError>().GetDescription(context), exc.GetEntity <SampleType>());
                }
                else
                {
                    consoleProvider.WriteLine(exc.GetInfo().GetObjectDescription(context), exc.GetEntity().GetObjectDescription(context));
                    throw;
                }
            }

            consoleProvider.WriteLine("================================================");

            // test configuration provider
            var authCookieProperties = ServiceUtil.GetService <IAuthCookiePropertiesProvider>(context).GetAuthCookieProperties();

            consoleProvider.WriteLine("Auth cookie name: {0}", authCookieProperties != null ? authCookieProperties.Name : "!!!DEFAULT!!!");
            consoleProvider.WriteLine("================================================");

            // test structured entity providers
            var sampleTypes = ServiceUtil.GetService <ISampleTypeStructuredDataProvider>(context).ListSampleTypes(context);

            foreach (var sampleType in sampleTypes)
            {
                consoleProvider.WriteLine(sampleType.GetObjectDescription(context));
            }

            consoleProvider.WriteLine("================================================");

            var treeDisplayer = new TreeDisplayer(consoleProvider);

            var anotherTypesTree = ServiceUtil.GetService <IAnotherTypeStructuredDataProvider>(context).GetAnotherTypeStructuredData(context);

            anotherTypesTree.GetSidebarLikeTreeWithSeparators().TraverseDepth(treeDisplayer.DisplayTree);
            consoleProvider.WriteLine("================================================");

            var yetAnotherTypesTree = ServiceUtil.GetService <IYetAnotherTypeStructuredDataProvider>(context).GetYetAnotherTypeStructuredData(context);

            yetAnotherTypesTree.GetSidebarLikeTreeWithSeparators().TraverseDepth(treeDisplayer.DisplayTree);
            consoleProvider.WriteLine("================================================");

            var controller = new SampleController(
                ServiceUtil.GetService <ISampleContextProvider>(context),
                ServiceUtil.GetService <ICurrentUserTokenProvider>(context),
                ServiceUtil.GetService <ISampleUserTokenFactory>(context),
                ServiceUtil.GetService <IConsoleProvider>(context));

            controller.OperationWithEnvironmentContext();
            controller.OperationWithUserContext();
            controller.OperationWithUserContext(100);
            controller.OperationWithMeetingContext(100, 2, "NEW MEETING NAME");
            consoleProvider.WriteLine("================================================");

            consoleProvider.ReadKey();
        }