Exemplo n.º 1
0
    public ActionResult Index(int id)
    {
        var model = new Model();

        model.Customer = this.dataAccess.Get(id);
        Owned <DataAccess> dataAccessForAsyncTaskHolder = null;

        try
        {
            dataAccessForAsyncTaskHolder = dataAccessFactory();
            dataAccessForAsyncTaskHolder.Value.ExecuteAsyncTask(() =>
                                                                // you'll need a completion callback
            {
                // finish the task if required
                // dipose the owned instance
                dataAccessForAsyncTaskHolder.Dispose();
            });
        }
        catch
        {
            if (dataAccessForAsyncTaskHolder != null)
            {
                dataAccessForAsyncTaskHolder.Dispose();
            }
            throw;
        }
        return(View(model));
    }
Exemplo n.º 2
0
 public void DisposingOwned_CallsDisposeOnLifetimeToken()
 {
     var lifetime = new DisposeTracker();
     var owned = new Owned<string>("unused", lifetime);
     owned.Dispose();
     Assert.True(lifetime.IsDisposed);
 }
Exemplo n.º 3
0
        private EngineRuntime CreateRuntime(string engineId)
        {
            Owned <EngineRuntime> runtime = _engineRunnerFactory(engineId);

            _runtimes.TryAdd(engineId, runtime);
            return(runtime.Value);
        }
Exemplo n.º 4
0
        public void WhenInitialisedWithValue_ReturnsSameFromValueProperty()
        {
            var value = "Hello";
            var owned = new Owned <string>(value, new Mock <IDisposable>().Object);

            Assert.AreSame(value, owned.Value);
        }
Exemplo n.º 5
0
        public void WhenInitialisedWithValue_ReturnsSameFromValueProperty()
        {
            var value = "Hello";
            var owned = new Owned <string>(value, new DisposeTracker());

            Assert.Same(value, owned.Value);
        }
Exemplo n.º 6
0
 public void DisposingOwned_CallsDisposeOnLifetimeToken()
 {
     var lifetime = new DisposeTracker();
     var owned = new Owned<string>("unused", lifetime);
     owned.Dispose();
     Assert.True(lifetime.IsDisposed);
 }
Exemplo n.º 7
0
        public JsonResult UpdateOwned(string[] owned, string id)
        {
            Owned o = db.Owned.Find(Convert.ToInt32(id));

            o.owned = String.Join(",", owned);

            if (o.owned == "")
            {
                db.Remove(o);
                db.SaveChanges();
                return(Json("'Success':'true'"));
            }

            db.Entry(o).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
                return(Json("'Success':'true'"));
            }
            catch (Exception e)
            {
                return(Json("'Success':'false'"));
            }
        }
Exemplo n.º 8
0
        public JsonResult AddOwned(string Team, string[] Owned)
        {
            var uId = User.FindFirstValue(ClaimTypes.NameIdentifier);

            if (db.Owned.Any(u => u.userId == uId && u.team == Team))
            {
                var owned = db.Owned.FirstOrDefault(u => u.userId == uId && u.team == Team);
                UpdateOwned(Owned, owned.id.ToString());

                return(Json("'Success':'true'"));
            }
            else
            {
                Owned o = new Owned
                {
                    userId = uId,
                    team   = Team,
                    owned  = String.Join(",", Owned)
                };

                db.Owned.Add(o);

                try
                {
                    db.SaveChanges();
                    return(Json("'Success':'true'"));
                }
                catch (Exception e)
                {
                    return(Json("'Success':'false'"));
                }
            }
        }
Exemplo n.º 9
0
 private void SetViewModel(ViewModelType viewModelType)
 {
     this.currentOwnedViewModel?.Dispose();
     this.currentViewModelType  = viewModelType;
     this.currentOwnedViewModel = this.viewModelDictionary[viewModelType]();
     this.OnPropertyChanged(nameof(this.CurrentViewModel));
 }
Exemplo n.º 10
0
        private EngineRunner CreateRunner(string engineId)
        {
            Owned <EngineRunner> runner = _engineRunnerFactory(engineId);

            _runners.TryAdd(engineId, runner);
            return(runner.Value);
        }
Exemplo n.º 11
0
        public void DisposingOwned_CallsDisposeOnLifetimeToken()
        {
            var o     = new MockDisposable();
            var owned = new Owned <string>("unused", o);

            owned.Dispose();
            Assert.AreEqual(1, o.disposed);
        }
Exemplo n.º 12
0
 public void DisposingOwned_CallsDisposeOnLifetimeToken()
 {
     var lifetime = new Mock<IDisposable>();
     lifetime.Setup(l => l.Dispose()).Verifiable();
     var owned = new Owned<string>("unused", lifetime.Object);
     owned.Dispose();
     lifetime.VerifyAll();
 }
Exemplo n.º 13
0
 public Service1(IConfig config, ILogger logger, IExceptionHandler exceptionHandler, ISecurityProvider securityProvider, IClassA classA,
                 Owned <IClassB> ownedClassB, IUnitOfWork <SimpleContext> uow)
     : base(config, logger, exceptionHandler, securityProvider)
 {
     ClassA      = classA;
     OwnedClassB = ownedClassB;
     Uow         = uow;
 }
        private static void AssertInstancePerOwnedResolvesToOwnedScope(Owned <MessageHandler> owned, IServiceWithType tag)
        {
            var handler          = owned.Value;
            var dependentService = handler.DependentService;

            Assert.Equal(tag, handler.LifetimeScope.Tag);
            Assert.Same(handler.LifetimeScope, dependentService.LifetimeScope);
        }
Exemplo n.º 15
0
 /// <summary>
 /// Swaps the contents of 'target' with 'source' if the buffers are allocated (1),
 /// copies the contents of 'source' to 'target' otherwise (2).
 /// Groups should be of same TotalLength in case 2.
 /// </summary>
 public static bool SwapOrCopyContent(MemoryGroup <T> target, MemoryGroup <T> source)
 {
     if (source is Owned ownedSrc && ownedSrc.Swappable &&
         target is Owned ownedTarget && ownedTarget.Swappable)
     {
         Owned.SwapContents(ownedTarget, ownedSrc);
         return(true);
     }
Exemplo n.º 16
0
        public async Task DisposingOwnedAsynchronously_CallsDisposeOnLifetimeTokenIfAsyncDisposableNotDeclared()
        {
            var lifetime = new DisposeTracker();
            var owned    = new Owned <string>("unused", lifetime);
            await owned.DisposeAsync();

            Assert.True(lifetime.IsDisposed);
        }
        static void AssertInstancePerOwnedResolvesToOwnedScope(Owned<MessageHandler> owned, IServiceWithType tag)
        {
            var handler = owned.Value;
            var dependentService = handler.DependentService;

            Assert.Equal(tag, handler.LifetimeScope.Tag);
            Assert.Same(handler.LifetimeScope, dependentService.LifetimeScope);
        }
        static void AssertInstancePerOwnedResolvesToOwnedScope(Owned <MessageHandler> owned, IServiceWithType tag)
        {
            var handler          = owned.Value;
            var dependentService = handler.DependentService;

            Assert.That(handler.LifetimeScope.Tag, Is.EqualTo(tag));
            Assert.That(dependentService.LifetimeScope, Is.SameAs(handler.LifetimeScope));
        }
Exemplo n.º 19
0
        public OptionsPage()
        {
#if !DEBUG // Debug builds don't trigger the WPF bug described below
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
#endif

            _optionsPageControl = ApiPortVSPackage.LocalServiceProvider
                                  .GetService(typeof(Owned <OptionsPageControl>)) as Owned <OptionsPageControl>;
        }
Exemplo n.º 20
0
        /// <summary>Initializes a new instance of the <see cref="XMenuItem" /> class.</summary>
        /// <param name="func">The function.</param>
        /// <autogeneratedoc />
        /// TODO Edit XML Comment Template for #ctor
        public XMenuItem([NotNull] Owned <Func <Type, ILogger> > func)
        {
            if (func == null)
            {
                throw new ArgumentNullException(nameof(func));
            }

            func.Value(typeof(XMenuItem));
        }
Exemplo n.º 21
0
 public OwnedReporting(Owned <ConsoleLog> log)
 {
     if (log == null)
     {
         throw new ArgumentNullException(paramName: nameof(log));
     }
     this.log = log;
     Console.WriteLine("Reporting initialized");
 }
        /// <summary>
        ///
        /// </summary>
        public static void DisposableWork()
        {
            Func <String, Owned <IDisposableDependency> > factory = container.ResolveNamed <Func <String, Owned <IDisposableDependency> > >("disposable-factory");

            using (Owned <IDisposableDependency> item = factory("owned"))
            {
                Console.Error.WriteLine(item.Value.Message());
            }
        }
Exemplo n.º 23
0
        public OptionsPage()
        {
#if !DEBUG // Debug builds don't trigger the WPF bug described below
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
#endif

            _optionsPageControl = ApiPortVSPackage.LocalServiceProvider
                .GetService(typeof(Owned<OptionsPageControl>)) as Owned<OptionsPageControl>;
        }
Exemplo n.º 24
0
        public static bool TryAllocate(
            UniformUnmanagedMemoryPool pool,
            long totalLengthInElements,
            int bufferAlignmentInElements,
            AllocationOptions options,
            out MemoryGroup <T> memoryGroup)
        {
            Guard.NotNull(pool, nameof(pool));
            Guard.MustBeGreaterThanOrEqualTo(totalLengthInElements, 0, nameof(totalLengthInElements));
            Guard.MustBeGreaterThanOrEqualTo(bufferAlignmentInElements, 0, nameof(bufferAlignmentInElements));

            int blockCapacityInElements = pool.BufferLength / ElementSize;

            if (bufferAlignmentInElements > blockCapacityInElements)
            {
                memoryGroup = null;
                return(false);
            }

            if (totalLengthInElements == 0)
            {
                throw new InvalidMemoryOperationException("Allocating 0 length buffer from UniformByteArrayPool is disallowed");
            }

            int numberOfAlignedSegments = blockCapacityInElements / bufferAlignmentInElements;
            int bufferLength            = numberOfAlignedSegments * bufferAlignmentInElements;

            if (totalLengthInElements > 0 && totalLengthInElements < bufferLength)
            {
                bufferLength = (int)totalLengthInElements;
            }

            int sizeOfLastBuffer = (int)(totalLengthInElements % bufferLength);
            int bufferCount      = (int)(totalLengthInElements / bufferLength);

            if (sizeOfLastBuffer == 0)
            {
                sizeOfLastBuffer = bufferLength;
            }
            else
            {
                bufferCount++;
            }

            UnmanagedMemoryHandle[] arrays = pool.Rent(bufferCount);

            if (arrays == null)
            {
                // Pool is full
                memoryGroup = null;
                return(false);
            }

            memoryGroup = new Owned(pool, arrays, bufferLength, totalLengthInElements, sizeOfLastBuffer, options);
            return(true);
        }
Exemplo n.º 25
0
        /// <summary>
        ///
        /// </summary>
        public void DisposableWork()
        {
            // Code bevore Constructor Injection
            Func <String, Owned <IDisposableDependency> > factory = Autofac.ContainerConfig.container.ResolveNamed <Func <String, Owned <IDisposableDependency> > >("disposable-factory");

            using (Owned <IDisposableDependency> item = factory("owned"))
            {
                Console.Error.WriteLine(item.Value.Message());
            }
        }
Exemplo n.º 26
0
        public void DisposingOwned_CallsDisposeOnLifetimeToken()
        {
            var lifetime = new Mock <IDisposable>();

            lifetime.Setup(l => l.Dispose()).Verifiable();
            var owned = new Owned <string>("unused", lifetime.Object);

            owned.Dispose();
            lifetime.VerifyAll();
        }
Exemplo n.º 27
0
        public static ISafeInvoker <T> CreateSafeInvoker <T>(T value) where T : class
        {
            var lifeTime = new LifetimeScope(new ComponentRegistry());

            var owned = new Owned <T>(value, lifeTime);

            var safeInvoker = new SafeInvoker <T>(() => owned);

            return(safeInvoker);
        }
Exemplo n.º 28
0
        private async Task GatherPlaytime()
        {
            Running = true;
            List <IPlay> plays = await Task.Run(() => dataProvider.GetPlaysAsync(UserName));

            foreach (var game in Owned.Union(PrevOwned))
            {
                game.MinPlayed = plays.Where(p => p.Game.Id == game.Id).Sum(p => p.Minutes);
            }
            Running = false;
        }
        public async Task <ActionResult <Owned> > PostOwned(Owned owned)
        {
            //_context.Owned.Add(owned);

            _OwnedCarRepository.PostCar(owned);
            //await _context.SaveChangesAsync();



            return(CreatedAtAction("GetOwned", new { id = owned.CusId }, owned));
        }
Exemplo n.º 30
0
        public void InstancePerOwnedTest()
        {
            ContainerBuilder builder = new ContainerBuilder();

            builder.RegisterType <Service>().AsSelf().InstancePerOwned <IRoot>();
            builder.RegisterType <RootA>().Keyed <IRoot>("A");
            builder.RegisterType <RootB>().Keyed <IRoot>("B");
            IContainer    container = builder.Build();
            Owned <IRoot> ownedRoot = container.ResolveKeyed <Owned <IRoot> >("A");

            Assert.That(ownedRoot.Value.Dependency, Is.Not.Null);
        }
Exemplo n.º 31
0
        public void SingleInstanceTest()
        {
            ContainerBuilder builder = new ContainerBuilder();

            builder.RegisterType <Service>().AsSelf().SingleInstance();
            builder.RegisterType <RootA>().Keyed <IRoot>("A");
            builder.RegisterType <RootB>().Keyed <IRoot>("B");
            IContainer    container = builder.Build();
            Owned <IRoot> ownedRoot = container.ResolveKeyed <Owned <IRoot> >("A");
            Service       service   = container.Resolve <Service>();

            Assert.That(ReferenceEquals(ownedRoot.Value.Dependency, service), Is.True);
        }
Exemplo n.º 32
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            View      = ViewFactory();
            _owned    = ViewModelFactory();
            ViewModel = _owned.Value;

            if (View != null)
            {
                View.DataContext = ViewModel;
            }

            OnLoaded();
        }
Exemplo n.º 33
0
 public ChampionInventory(IEnumerable <ChampionDTO> src)
 {
     foreach (var champ in src)
     {
         if (champ.Owned)
         {
             Owned.Add(champ.ChampionId);
         }
         if (champ.FreeToPlay)
         {
             Free.Add(champ.ChampionId);
         }
     }
 }
Exemplo n.º 34
0
        public UsersModel(Owned <IModelHandler <IUserModel, IUser, IUserProfile> > scope)
        {
            if (scope == null)
            {
                throw new ArgumentNullException(nameof(scope));
            }
            if (scope.Value == null)
            {
                throw new ArgumentNullException($"{nameof(scope)}.{nameof(scope.Value)}");
            }

            using (scope)
            {
                Users = scope.Value.GetMany <IUser>(users => users.Where(u => u != null));
            }
        }
Exemplo n.º 35
0
        public void SimpleNonDisposableTest()
        {
            Owned<IBasicService> owned = new Owned<IBasicService>();
            BasicService basicService = new BasicService();

            owned.SetValue(basicService);

            Assert.True(ReferenceEquals(owned.Value, basicService));

            owned.Dispose();
        }
Exemplo n.º 36
0
        public void SimpleDisposableTest()
        {
            Owned<IDisposableService> owned = new Owned<IDisposableService>();
            DisposableService disposableService = new DisposableService();
            bool eventFired = false;

            disposableService.Disposing += (sender, args) => eventFired = true;

            owned.SetValue(disposableService);

            Assert.True(ReferenceEquals(owned.Value, disposableService));

            owned.Dispose();

            Assert.True(eventFired);
        }
Exemplo n.º 37
0
 public void WhenInitialisedWithValue_ReturnsSameFromValueProperty()
 {
     var value = "Hello";
     var owned = new Owned<string>(value, new DisposeTracker());
     Assert.Same(value, owned.Value);
 }
Exemplo n.º 38
0
 public void WhenInitialisedWithValue_ReturnsSameFromValueProperty()
 {
     var value = "Hello";
     var owned = new Owned<string>(value, new Mock<IDisposable>().Object);
     Assert.AreSame(value, owned.Value);
 }