Beispiel #1
0
        protected override void InitialiseInternal(TinyIoC.TinyIoCContainer container)
        {
            base.InitialiseInternal(container);
            var formsAuthConfiguration =
                new FormsAuthenticationConfiguration()
            {
                Passphrase     = "SuperSecretPass",
                Salt           = "AndVinegarCrisps",
                HmacPassphrase = "UberSuperSecure",
                RedirectUrl    = "/authentication/login",
                UsernameMapper = container.Resolve <IUsernameMapper>(),
            };

            FormsAuthentication.Enable(this, formsAuthConfiguration);

            BeforeRequest += ctx =>
            {
                var rootPathProvider =
                    container.Resolve <IRootPathProvider>();

                var staticFileExtensions =
                    new Dictionary <string, string>
                {
                    { "jpg", "image/jpg" },
                    { "png", "image/png" },
                    { "gif", "image/gif" },
                    { "css", "text/css" },
                    { "js", "text/javascript" }
                };

                var requestedExtension =
                    Path.GetExtension(ctx.Request.Uri);

                if (!string.IsNullOrEmpty(requestedExtension))
                {
                    var extensionWithoutDot =
                        requestedExtension.Substring(1);

                    if (staticFileExtensions.Keys.Any(x => x.Equals(extensionWithoutDot, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        var fileName =
                            Path.GetFileName(ctx.Request.Uri);

                        if (fileName == null)
                        {
                            return(null);
                        }

                        var filePath =
                            Path.Combine(rootPathProvider.GetRootPath(), "content", fileName);

                        return(!File.Exists(filePath) ? null : new StaticFileResponse(filePath, staticFileExtensions[extensionWithoutDot]));
                    }
                }

                return(null);
            };
        }
Beispiel #2
0
 public RegisterType Resolve <RegisterType>() where RegisterType : class
 {
     try
     {
         return(_container.Resolve <RegisterType>());
     }
     catch (TinyIoC.TinyIoCResolutionException e)
     {
         throw new DIException(typeof(RegisterType), e);
     }
 }
Beispiel #3
0
        async public override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            HasOptionsMenu = true;
            container      = TinyIoC.TinyIoCContainer.Current;
            //TODO: Add TinyIOC and move these to app start
            webService = container.Resolve <WlcWebService> ();
            var parser = new WlcHtmlParse();

            var prefs = Activity.GetSharedPreferences("wlcPrefs", FileCreationMode.Private);

            myStatsUrl = prefs.GetString("statsUrl", "");
            csrfToken  = prefs.GetString("csrfToken", "");
            var challengeProfile = prefs.GetString("challengeProfile", "");

            adapter = new StatsBarAdapter(this.Activity);

            fadeinAnimation  = AnimationUtils.LoadAnimation(this.Activity, Resource.Animation.abc_fade_in);
            fadeoutAnimation = AnimationUtils.LoadAnimation(this.Activity, Resource.Animation.abc_fade_out);

            // Get the data here
            try {
                profile = Newtonsoft.Json.JsonConvert.DeserializeObject <ChallengeProfile> (challengeProfile, new Newtonsoft.Json.JsonSerializerSettings()
                {
                    NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
                });
                today = await webService.GetRecord(StoredCookies, "today.json", csrfToken);

                yesterday = await webService.GetRecord(StoredCookies, "yesterday.json", csrfToken);

                var contentStr = await webService.GetStats(StoredCookies, "/profiles/" + profile.id.ToString() + "/stats_calendar");

                myStats = parser.GetStats(contentStr);

                if (today != null)
                {
                    byte[] imageBytes = await webService.GetProfileImage(profile.user.photo);

                    // IBitmap is a type that provides basic image information such as dimensions
                    profileImage = await BitmapLoader.Current.Load(new MemoryStream(imageBytes), null /* Use original width */, null /* Use original height */);
                }

                ((StatsBarAdapter)adapter).Stats = myStats.OrderByDescending(x => x.StatDate).ToList();
                if (!Activity.IsFinishing)
                {
                    updateView();
                    if (loading != null)
                    {
                        loading.Visibility  = ViewStates.Gone;
                        listView.Visibility = ViewStates.Visible;
                    }
                }
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }

            actionBarBackgroundDrawable = new Android.Graphics.Drawables.ColorDrawable(Android.Graphics.Color.MediumAquamarine);
            actionBarBackgroundDrawable.SetAlpha(0);
            Activity.ActionBar.SetBackgroundDrawable(actionBarBackgroundDrawable);
        }
 protected override void ApplicationStartup(TinyIoC.TinyIoCContainer container, IPipelines pipelines)
 {
     base.ApplicationStartup(container, pipelines);
     pipelines.EnableBasicAuthentication(new BasicAuthenticationConfiguration(
                                             container.Resolve <IUserValidator>(),
                                             "NancyFx"));
 }
        protected override void ApplicationStartup(TinyIoC.TinyIoCContainer container, Nancy.Bootstrapper.IPipelines pipelines)
        {
            base.ApplicationStartup(container, pipelines);

            StaticConfiguration.DisableErrorTraces = false;

            SassAndCoffee.Hooks.Enable(pipelines, new InMemoryCache(), container.Resolve <IRootPathProvider>());
        }
        protected override void InitialiseInternal(TinyIoC.TinyIoCContainer container)
        {
            base.InitialiseInternal(container);

            this.EnableBasicAuthentication(new BasicAuthenticationConfiguration(
                                               container.Resolve <IUserValidator>(),
                                               "MyRealm"));
        }
        protected override void ConfigureApplicationContainer(TinyIoC.TinyIoCContainer container)
        {
            container.Register <IPersistentStore, PersistentStore>().AsSingleton();

            var bus = StickABusInIt(container.Resolve <IPersistentStore>());

            container.Register <ICommandSender, FakeBus>(bus);
            container.Register <IEventPublisher, FakeBus>(bus);
        }
Beispiel #8
0
    static int Main(string[] args)
    {
      TinyIoC.TinyIoCContainer container = new TinyIoC.TinyIoCContainer();
      container.Register<ArgumentsModel>(new ArgumentsModel(args));
      container.RegisterInterfaceImplementations("MFilesImporter.Service", TinyIoCExtensions.RegisterOptions.AsSingleton, TinyIoCExtensions.RegisterTypes.AsInterfaceTypes);
      container.RegisterInterfaceImplementations("MFilesImporter.Factory", TinyIoCExtensions.RegisterOptions.AsSingleton, TinyIoCExtensions.RegisterTypes.AsInterfaceTypes);

      var program = container.Resolve<Program>();
      return program.Run();
    }
Beispiel #9
0
 public object GetService(Type serviceType)
 {
     try
     {
         return(_container.Resolve(serviceType));
     }
     catch (Exception)
     {
         return(null);
     }
 }
 public void TinyIoCSimpleDITest()
 {
     var container = new TinyIoC.TinyIoCContainer();
     container.Register<MockObject, MockObjectTiny>().AsMultiInstance();
     var start = DateTime.Now;
     for (int i = 0; i < _iterations; i++)
     {
         var t = container.Resolve<MockObject>();
     }
     var end = DateTime.Now;
     Console.WriteLine(string.Format("{0} Simple DI, Total milliseconds elapsed: {1}", "TinyIoC", (end - start).TotalMilliseconds));
 }
Beispiel #11
0
        protected override void RequestStartup(TinyIoC.TinyIoCContainer container, Nancy.Bootstrapper.IPipelines pipelines)
        {
            var formsAuthConfiguration =
                new FormsAuthenticationConfiguration
            {
                RedirectUrl = "~/login",
                UserMapper  = container.Resolve <IUserMapper>(),
            };

            FormsAuthentication.Enable(pipelines, formsAuthConfiguration);
            base.RequestStartup(container, pipelines);
        }
        public void When_a_resolutionException_has_no_inner_should_return_the_resolutionException()
        {
            var tinyIoCContainer = new TinyIoC.TinyIoCContainer();
            tinyIoCContainer.Register<IFoo, Foo>();

            MethodThatThrows m = () => tinyIoCContainer.Resolve<IFoo>().ShouldNotBeNull();

            Exception exception = StatLight.Console.Program.ResolveNonTinyIocException(m.GetException());

            exception.ShouldNotBeNull();
            exception.ShouldBeOfType(typeof(TinyIoC.TinyIoCResolutionException));
        }
Beispiel #13
0
        public void When_a_resolutionException_has_an_inner_should_return_the_innerException()
        {
            var tinyIoCContainer = new TinyIoC.TinyIoCContainer();

            tinyIoCContainer.Register <IFoo, Foo2>();

            MethodThatThrows m = () => tinyIoCContainer.Resolve <IFoo>().ShouldNotBeNull();

            Exception exception = StatLight.Console.Program.ResolveNonTinyIocException(m.GetException());

            exception.ShouldNotBeNull()
            .ShouldBeOfType(typeof(StatLightException));
        }
Beispiel #14
0
        protected override void InitialiseInternal(TinyIoC.TinyIoCContainer container)
        {
            base.InitialiseInternal(container);

            var formsAuthConfiguration =
                new FormsAuthenticationConfiguration()
            {
                RedirectUrl = "~/login",
                UserMapper  = container.Resolve <IUserMapper>(),
            };

            FormsAuthentication.Enable(this, formsAuthConfiguration);
        }
Beispiel #15
0
        void LoadBrokerEventHandlers(TinyIoC.TinyIoCContainer container)
        {
            var handlers =
                from t in GetType().Assembly.GetTypes()
                where t.GetInterfaces().Any(x => x.Name == typeof(IBrokerEventHandler).Name)
                select(IBrokerEventHandler) container.Resolve(t);

            foreach (var handler in handlers)
            {
                brokerEventHandlers.Add(handler.EventType, handler);
                logger.Log("Registered Broker Event Handler: {0} for event type: {1}", handler.GetType().Name, handler.EventType.ToString());
            }
        }
Beispiel #16
0
        protected override void ApplicationStartup(TinyIoC.TinyIoCContainer container, IPipelines pipelines)
        {
            base.ApplicationStartup(container, pipelines);

            pipelines.EnableBasicAuthentication(new BasicAuthenticationConfiguration(
                                                    container.Resolve <IUserValidator>(),
                                                    "RateAllTheThings"));

            pipelines.OnError += (context, exception) =>
            {
                exception.SendToAirbrake();
                return(null);
            };
        }
Beispiel #17
0
    static int Main(string[] args)
    {
      var container = new TinyIoC.TinyIoCContainer();
      container.RegisterInterfaceImplementations("CopyOnChange");
      container.RegisterInterfaceImplementations("CopyOnChange.Factory");

      var program = container.Resolve<IProgram>();
      try { return program.Run(args); }
      catch (Exception ex)
      {
        Console.WriteLine("The following error occurred:{0}{1}", Environment.NewLine, ex);
        return 1;
      }
    }
    protected override void InitialiseInternal(TinyIoC.TinyIoCContainer container)
    {
        base.InitialiseInternal(container);

        var formsAuthConfiguration =
            new FormsAuthenticationConfiguration()
        {
            RedirectUrl    = "~/login",
            UsernameMapper = container.Resolve <IUsernameMapper>(),
        };

        FormsAuthentication.Enable(this, formsAuthConfiguration);
        //Adding a check on the pipeline to validate if the user is still authorised by facebook.
        this.BeforeRequest.AddItemToEndOfPipeline(FacebookAuthenticatedCheckPipeline.CheckUserIsNothAuthorisedByFacebookAnymore);
    }
Beispiel #19
0
        protected override void InitialiseInternal(TinyIoC.TinyIoCContainer container)
        {
            base.InitialiseInternal(container);

            var formsAuthConfiguration =
                new FormsAuthenticationConfiguration()
            {
                Passphrase     = "SuperSecretPass",
                Salt           = "AndVinegarCrisps",
                HmacPassphrase = "UberSuperSecure",
                RedirectUrl    = "/login",
                UsernameMapper = container.Resolve <IUsernameMapper>(),
            };

            FormsAuthentication.Enable(this, formsAuthConfiguration);
        }
Beispiel #20
0
        static int Main(string[] args)
        {
            TinyIoC.TinyIoCContainer container = new TinyIoC.TinyIoCContainer();
              container.Register<ArgumentsModel>(new ArgumentsModel(args));
              container.RegisterInterfaceImplementations("MFilesDeleter.Service", TinyIoCExtensions.RegisterOptions.AsSingleton, TinyIoCExtensions.RegisterTypes.AsInterfaceTypes);
              container.RegisterInterfaceImplementations("MFilesDeleter.Factory", TinyIoCExtensions.RegisterOptions.AsSingleton, TinyIoCExtensions.RegisterTypes.AsInterfaceTypes);

              try
              {
            var program = container.Resolve<Program>();
            return program.Run();
              }
              catch (Exception ex)
              {
            Console.WriteLine(string.Format("The following error occurred:{0}{1}", ex, Environment.NewLine));
            return 1;
              }
        }
Beispiel #21
0
        static int Main(string[] args)
        {
            TinyIoC.TinyIoCContainer container = new TinyIoC.TinyIoCContainer();
            container.Register <ArgumentsModel>(new ArgumentsModel(args));
            container.RegisterInterfaceImplementations("MFilesDeleter.Service", TinyIoCExtensions.RegisterOptions.AsSingleton, TinyIoCExtensions.RegisterTypes.AsInterfaceTypes);
            container.RegisterInterfaceImplementations("MFilesDeleter.Factory", TinyIoCExtensions.RegisterOptions.AsSingleton, TinyIoCExtensions.RegisterTypes.AsInterfaceTypes);

            try
            {
                var program = container.Resolve <Program>();
                return(program.Run());
            }
            catch (Exception ex)
            {
                Console.WriteLine(string.Format("The following error occurred:{0}{1}", ex, Environment.NewLine));
                return(1);
            }
        }
Beispiel #22
0
 /// <summary>
 /// Resolves the given type
 /// </summary>
 /// <typeparam name="T">The type</typeparam>
 /// <returns>The resolved object</returns>
 public virtual T Resolve <T>() where T : class
 {
     return(container.Resolve <T>());
 }
Beispiel #23
0
 protected override void ApplicationStartup(TinyIoC.TinyIoCContainer container, IPipelines pipeline)
 {
     container.Register <IAccountService, AccountService>().AsSingleton();
     base.ApplicationStartup(container, pipeline);
     pipeline.EnableBasicAuthentication(new BasicAuthenticationConfiguration(container.Resolve <IUserValidator>(), "AgbaraVOIP"));
 }
 public ISingleton New_Resolve_Singleton()
 {
     return(_NewContainer.Resolve <ISingleton>());
 }
Beispiel #25
0
 public static T Get <T>() where T : class
 {
     return(ioc.Resolve <T>());
 }
 public static IEnumerable <T> ResolveImplementationsOf <T>(this TinyIoC.TinyIoCContainer container, object caller)
 {
     return(caller.GetType().Assembly.GetTypes()
            .Where(t => t.GetInterfaces().Any(i => i.Name == typeof(T).Name))
            .Select(t => (T)container.Resolve(t)));
 }
Beispiel #27
0
 public static T Resolve <T>() where T : class
 {
     return(_container.Resolve <T>());
 }