ApplicationContext

Namespace: Google.Apis.Core
We found 10 examples in language CSharp for this search. You will see 54 fragments of code.

Other methods

    public static void AddCPUCodeName(CPU_codename _codeName, bool _option)
    {
      try
      {
        if(Warning(_option, _codeName.Name))
        {
          using (ApplicationContext db = new ApplicationContext())
          {
            db.CPU_codename.Add(_codeName);
            db.SaveChanges();
            MessageBox.Show("Добавление прошло успешно!");
          }
        }
      }
      catch (Exception ex)
      {
        MessageBox.Show(ex.Message);
      }
    }

    public static void AddSocket(Sockets _socket, bool _options)
    {
      try
      {
        if(Warning(_options, _socket.Name))
        {
          using (ApplicationContext db = new ApplicationContext())
          {
            db.Sockets.Add(_socket);
            db.SaveChanges();
            MessageBox.Show("Добавление прошло успешно!");
          }
        }
      }
      catch (Exception ex)
      {
        MessageBox.Show(ex.Message);
      }
    }

    public static void AddChipset(Chipset _chipset, bool _option)
    {
      try
      {
        if(Warning(_option, _chipset.Name))
        {
          using(ApplicationContext db = new ApplicationContext())
          {
            db.Chipset.Add(_chipset);
            db.SaveChanges();
            MessageBox.Show("Добавление прошло успешно!");
          }
        }
      }
      catch (Exception ex)
      {
        MessageBox.Show(ex.Message);
      }
    }

    public static void AddChanel(RAM_chanels _chanel, bool _option)
    {
      try
      {
        if (Warning(_option, _chanel.Name))
        {
          using (ApplicationContext db = new ApplicationContext())
          {
            db.RAM_chanels.Add(_chanel);
            db.SaveChanges();
            MessageBox.Show("Добавление прошло успешно!");
          }
        }
      }
      catch(Exception ex)
      {
        MessageBox.Show(ex.Message);
      }
    }
    public static void AddFormFactor(Form_factors _formFactor, bool _option)
    {
      try
      {
        if (Warning(_option, _formFactor.Name))
        {
          using (ApplicationContext db = new ApplicationContext())
          {
            db.Form_factors.Add(_formFactor);
            db.SaveChanges();
            MessageBox.Show("Добавление прошло успешно!");
          }
        }
      }
      catch (Exception ex)
      {
        MessageBox.Show(ex.Message);
      }
    }
    public static void AddMemoryType(Memory_types _type, bool _option)
    {
      try
      { 
        if (Warning(_option, _type.Name))
        {
          using (ApplicationContext db = new ApplicationContext())
          {
            db.Memory_types.Add(_type);
            db.SaveChanges();
            MessageBox.Show("Добавление прошло успешно!");
          }
        }
      }
      catch (Exception ex)
      {
        MessageBox.Show(ex.Message);
      }
    }


        [HttpPost]
        [Route("add")]
        public IActionResult Add(Todo todo)
        {
            applicationContext.Add(todo);
            applicationContext.SaveChanges();
            return Redirect("list");
        }

        [HttpGet]
        [Route("{id}/delete")]
        public IActionResult Delete([FromRoute] long Id)
        {
            Todo deletedTodo = applicationContext.Todos.FirstOrDefault(t => t.Id == Id);
            applicationContext.Remove(deletedTodo);
            applicationContext.SaveChanges();
            return RedirectToAction("List");
        }

        [HttpDelete]
        [Route("{id}/delete")]
        public IActionResult DeleteWithPostman([FromRoute] long Id)
        {
            Todo deletedTodo = applicationContext.Todos.FirstOrDefault(t => t.Id == Id);
            applicationContext.Remove(deletedTodo);
            applicationContext.SaveChanges();
            return Ok();
        }

        [HttpGet]
        [Route("{id}/update")]
        public IActionResult GetUpdatePage([FromRoute] long Id)
        {
            Todo editableTodo = applicationContext.Todos.FirstOrDefault(t => t.Id == Id);
            ViewData["assignees"] = applicationContext.Assignees.ToList();
            return View("Update", editableTodo);
        }

        [HttpPost]
        [Route("{id}/update")]
        public IActionResult Update(long assigneeId, Todo todo)
        {
            if (assigneeId != 0)
            {
                todo.Assignee = (applicationContext.Assignees.Find(assigneeId));
            }
            applicationContext.Update(todo);
            applicationContext.SaveChanges();
            return RedirectToAction("List");
        }

        [HttpPut]
        [Route("{id}/update")]
        public IActionResult UpdateWithPostman([FromRoute]long id,Todo todo)
        {
            todo.Id = id;
            applicationContext.Update(todo);
            applicationContext.SaveChanges();
            return RedirectToAction("List");
        }


        [HttpGet]
        [Route("")]
        [Route("list")]
        public IActionResult List()
        {
            // Create a SQL query in the background
            var assignees = applicationContext.Assignees.ToList();
            
            return View(assignees);
        }

        [HttpPost]
        [Route("add")]
        public IActionResult Add(Assignee assignee)
        {
            applicationContext.Add(assignee);
            applicationContext.SaveChanges();
            return Redirect("list");
        }

        [HttpGet]
        [Route("{id}/todos")]
        public IActionResult ListTodos([FromRoute] long Id)
        {
            Assignee assignee = applicationContext.Assignees.Include(a => a.Todos).FirstOrDefault(a => a.Id == Id);
            List<Todo> todos = assignee.Todos;
            return View("Todos", todos);
        }

        [HttpGet]
        [Route("api/{id}/todos")]
        public Object ListTodosJson([FromRoute] long Id)
        {
            List<Todo> todos = applicationContext.Assignees.FirstOrDefault(a => a.Id == Id).Todos;
            return todos;
        }

        [HttpGet]
        [Route("{id}/delete")]
        public IActionResult Delete([FromRoute] long Id)
        {
            Todo deletedTodo = applicationContext.Todos.FirstOrDefault(t => t.Id == Id);
            applicationContext.Remove(deletedTodo);
            applicationContext.SaveChanges();
            return RedirectToAction("List");
        }

        [HttpDelete]
        [Route("{id}/delete")]
        public IActionResult DeleteWithPostman([FromRoute] long Id)
        {
            Todo deletedTodo = applicationContext.Todos.FirstOrDefault(t => t.Id == Id);
            applicationContext.Remove(deletedTodo);
            applicationContext.SaveChanges();
            return Ok();
        }


        [HttpPost]
        [Route("add")]
        public IActionResult Add(Todo todo)
        {
            applicationContext.Add(todo);
            applicationContext.SaveChanges();
            return Redirect("list");
        }

        [HttpGet]
        [Route("{id}/delete")]
        public IActionResult Delete([FromRoute] long Id)
        {
            Todo deletedTodo = applicationContext.Todos.FirstOrDefault(t => t.Id == Id);
            applicationContext.Remove(deletedTodo);
            applicationContext.SaveChanges();
            return RedirectToAction("List");
        }

        [HttpDelete]
        [Route("{id}/delete")]
        public IActionResult DeleteWithPostman([FromRoute] long Id)
        {
            Todo deletedTodo = applicationContext.Todos.FirstOrDefault(t => t.Id == Id);
            applicationContext.Remove(deletedTodo);
            applicationContext.SaveChanges();
            return Ok();
        }

        [HttpGet]
        [Route("{id}/update")]
        public IActionResult GetUpdatePage([FromRoute] long Id)
        {
            Todo editableTodo = applicationContext.Todos.FirstOrDefault(t => t.Id == Id);
            return View("Update", editableTodo);
        }

        [HttpPost]
        [Route("{id}/update")]
        public IActionResult Update(Todo todo)
        {
            applicationContext.Update(todo);
            applicationContext.SaveChanges();
            return RedirectToAction("List");
        }

        [HttpPut]
        [Route("{id}/update")]
        public IActionResult UpdateWithPostman([FromRoute]long id,Todo todo)
        {
            todo.Id = id;
            applicationContext.Update(todo);
            applicationContext.SaveChanges();
            return RedirectToAction("List");
        }


        public static void ReadAllData() {
            using (ApplicationContext db = new ApplicationContext())
            {
                // получаем объекты из бд и выводим на консоль
                var users = db.Users.ToList();
                Console.WriteLine("Список объектов:");
                foreach (User u in users)
                {
                    Console.WriteLine($"{u.Id}.{u.Name} - {u.Age}");
                }
            }
        }

        public static void ClearTable() {
            using (ApplicationContext db = new ApplicationContext())
            {
                db.Users.RemoveRange(db.Users);
                db.SaveChanges();
            }
        }

        #region Distributed Operations
        public static User SelectFirstOrDefault()
        {
            using (var db = new ApplicationContext())
            {
                return db.Users.FirstOrDefault();
            }
        }

        public static User SelectUser(int userId) {
            using (var db = new ApplicationContext())
            {
                return db.Users.Find(userId);
            }
        }

        public static void UpdateUser(User user)
        {
            using (var db = new ApplicationContext())
            {
                db.Users.Update(user);
                db.SaveChanges();
            }
        }


        public List<User> findAll()
        {
            using (ApplicationContext db = new ApplicationContext())
            {
                return db.Users.ToList();
            }
        }

        public User findById(int id)
        {
            using (ApplicationContext db = new ApplicationContext())
            {
                return db.Users
                    .Where(user => user.Id == id)
                    .FirstOrDefault();
            }
        }

        public List<User> findByName(String name)
        {
            using (ApplicationContext db = new ApplicationContext())
            {
                return db.Users
                .Where(user => user.Name == name)
                .ToList();
            }
        }

        public List<User> findByAge(int age)
        {
            using (ApplicationContext db = new ApplicationContext())
            {
                return db.Users
                .Where(user => user.Age == age)
                .ToList();
            }
        }

        public List<User> findByAgeInRange(int fromAge, int toAge)
        {
            using (ApplicationContext db = new ApplicationContext())
            {
                return db.Users
                .Where(user => user.Age >= fromAge && user.Age <= toAge)
                .ToList();
            }
        }

        public User addUser(User user)
        {
            using(ApplicationContext db = new ApplicationContext())
            {
                db.Users.Add(user);
                db.SaveChanges();
                return user;
            }
        }


        public void WithInterceptor(IConsumerInterceptor interceptor)
        {
            applicationContext.ObjectFactory.AddObjectPostProcessor(new ConsumerInterceptor(interceptor, applicationContext));
        }

        public void RegisterDefaultServices(IEnumerable<Assembly> assemblies)
        {
            applicationContext.RegisterSingleton<IServiceLocator>(() => new SpringServiceLocator(applicationContext));
            foreach (var assembly in assemblies)
                applicationContext.RegisterSingletons<IBusConfigurationAware>(assembly);

            var locator = applicationContext.Get<IServiceLocator>();
            foreach (var busConfigurationAware in applicationContext.GetAll<IBusConfigurationAware>())
                busConfigurationAware.Configure(config, this, locator);

            foreach (var module in config.MessageModules)
                applicationContext.RegisterSingleton(module, module.FullName);

            applicationContext.RegisterSingleton<IReflection>(() => new SpringReflection());
            applicationContext.RegisterSingleton(config.SerializerType);
            applicationContext.RegisterSingleton<IEndpointRouter>(() => new EndpointRouter());
        }

        public void RegisterBus()
        {
            var busConfig = (RhinoServiceBusConfiguration)config;

            applicationContext.RegisterSingleton<IStartableServiceBus>(() => new DefaultServiceBus(applicationContext.Get<IServiceLocator>(),
                                                   applicationContext.Get<ITransport>(),
                                                   applicationContext.Get<ISubscriptionStorage>(),
                                                   applicationContext.Get<IReflection>(),
                                                   applicationContext.GetAll<IMessageModule>().ToArray(),
                                                   busConfig.MessageOwners.ToArray(),
                                                   applicationContext.Get<IEndpointRouter>()));

            applicationContext.RegisterSingleton(() => new CreateQueuesAction(applicationContext.Get<IQueueStrategy>(), applicationContext.Get<IServiceBus>()));
        }

        public void RegisterPrimaryLoadBalancer()
        {
            var loadBalancerConfig = (LoadBalancerConfiguration)config;

            applicationContext.RegisterSingleton(() =>
                {
                    MsmqLoadBalancer balancer = new MsmqLoadBalancer(applicationContext.Get<IMessageSerializer>(),
                                                                            applicationContext.Get<IQueueStrategy>(),
                                                                            applicationContext.Get<IEndpointRouter>(),
                                                                            loadBalancerConfig.Endpoint,
                                                                            loadBalancerConfig.ThreadCount,
                                                                            loadBalancerConfig.Transactional,
                                                                            applicationContext.Get<IMessageBuilder<Message>>());
                    balancer.ReadyForWorkListener = applicationContext.Get<MsmqReadyForWorkListener>();
                    return balancer;
                });

            applicationContext.RegisterSingleton<IDeploymentAction>(() => new CreateLoadBalancerQueuesAction(applicationContext.Get<IQueueStrategy>(), applicationContext.Get<MsmqLoadBalancer>()));
        }

        public void RegisterSecondaryLoadBalancer()
        {
            var loadBalancerConfig = (LoadBalancerConfiguration)config;

            applicationContext.RegisterSingleton<MsmqLoadBalancer>(() =>
                {
                    MsmqSecondaryLoadBalancer balancer = new MsmqSecondaryLoadBalancer(applicationContext.Get<IMessageSerializer>(),
                                                                                                        applicationContext.Get<IQueueStrategy>(),
                                                                                                        applicationContext.Get<IEndpointRouter>(),
                                                                                                        loadBalancerConfig.Endpoint,
                                                                                                        loadBalancerConfig.PrimaryLoadBalancer,
                                                                                                        loadBalancerConfig.ThreadCount,
                                                                                                        loadBalancerConfig.Transactional,
                                                                                                        applicationContext.Get<IMessageBuilder<Message>>());
                    balancer.ReadyForWorkListener = applicationContext.Get<MsmqReadyForWorkListener>();
                    return balancer;
                });

            applicationContext.RegisterSingleton<IDeploymentAction>(() => new CreateLoadBalancerQueuesAction(applicationContext.Get<IQueueStrategy>(), applicationContext.Get<MsmqLoadBalancer>()));
        }

        public void RegisterReadyForWork()
        {
            var loadBalancerConfig = (LoadBalancerConfiguration)config;

            applicationContext.RegisterSingleton(() => new MsmqReadyForWorkListener(applicationContext.Get<IQueueStrategy>(),
                                                                                    loadBalancerConfig.ReadyForWork,
                                                                                    loadBalancerConfig.ThreadCount,
                                                                                    applicationContext.Get<IMessageSerializer>(),
                                                                                    applicationContext.Get<IEndpointRouter>(),
                                                                                    loadBalancerConfig.Transactional,
                                                                                    applicationContext.Get<IMessageBuilder<Message>>()));

            applicationContext.RegisterSingleton<IDeploymentAction>(() => new CreateReadyForWorkQueuesAction(applicationContext.Get<IQueueStrategy>(), applicationContext.Get<MsmqReadyForWorkListener>()));
        }


        /// <include file='doc\ApplicationContext.uex' path='docs/doc[@for="ApplicationContext.Dispose"]/*' />
        /// <devdoc>
        ///     Disposes the context. This should dispose the mainForm. This is
        ///     called immediately after the thread's message loop is terminated.
        ///     Application will dispose all forms on this thread by default.
        /// </devdoc>
        public void Dispose() {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        /// <include file='doc\ApplicationContext.uex' path='docs/doc[@for="ApplicationContext.Dispose2"]/*' />
        protected virtual void Dispose(bool disposing) {
            if (disposing) {
                if (mainForm != null) {
                    if (!mainForm.IsDisposed) {
                        mainForm.Dispose();
                    }
                    mainForm = null;
                }
            }
        }

        /// <include file='doc\ApplicationContext.uex' path='docs/doc[@for="ApplicationContext.ExitThread"]/*' />
        /// <devdoc>
        ///     Causes the thread's message loop to be terminated. This
        ///     will call ExitThreadCore.
        /// </devdoc>
        public void ExitThread() {
            ExitThreadCore();
        }

        /// <include file='doc\ApplicationContext.uex' path='docs/doc[@for="ApplicationContext.ExitThreadCore"]/*' />
        /// <devdoc>
        ///     Causes the thread's message loop to be terminated.
        /// </devdoc>
        protected virtual void ExitThreadCore() {
            if (ThreadExit != null) {
                ThreadExit(this, EventArgs.Empty);
            }
        }

        /// <include file='doc\ApplicationContext.uex' path='docs/doc[@for="ApplicationContext.OnMainFormClosed"]/*' />
        /// <devdoc>
        ///     Called when the mainForm is closed. The default implementation
        ///     of this will call ExitThreadCore.
        /// </devdoc>
        protected virtual void OnMainFormClosed(object sender, EventArgs e) {
            ExitThreadCore();
        }
    
        /// <devdoc>
        ///     Called when the mainForm is closed. The default implementation
        ///     of this will call ExitThreadCore.
        /// </devdoc>
        private void OnMainFormDestroy(object sender, EventArgs e) {
            Form form = (Form)sender;
            if (!form.RecreatingHandle) {
                form.HandleDestroyed -= new EventHandler(OnMainFormDestroy);
                OnMainFormClosed(sender, e);
            }
        }

        public void OnApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            if (ShouldExecute(applicationContext))
            {
                ApplicationInitialized(umbracoApplication, applicationContext);
            }
        }

        public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            if (ShouldExecute(applicationContext))
            {
                ApplicationStarting(umbracoApplication, applicationContext);
            }
        }

        public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            if (ShouldExecute(applicationContext))
            {
                ApplicationStarted(umbracoApplication, applicationContext);
            }
        }

        /// <summary>
        /// Overridable method to execute when the ApplicationContext is created and other static objects that require initialization have been setup
        /// </summary>
        /// <param name="umbracoApplication"></param>
        /// <param name="applicationContext"></param>
        protected virtual void ApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            
        }

        /// <summary>
        /// Overridable method to execute when All resolvers have been initialized but resolution is not frozen so they can be modified in this method
        /// </summary>
        /// <param name="umbracoApplication"></param>
        /// <param name="applicationContext"></param>
        protected virtual void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {

        }

        /// <summary>
        /// Overridable method to execute when Bootup is completed, this allows you to perform any other bootup logic required for the application.
        /// Resolution is frozen so now they can be used to resolve instances.
        /// </summary>
        /// <param name="umbracoApplication"></param>
        /// <param name="applicationContext"></param>
        protected virtual void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {

        }


        public static Pitch CreatePitch(ApplicationContext applicationContext, PitchDTO pitchDTO)
        {
            if (applicationContext == null)
            {
                throw new ArgumentNullException(nameof(applicationContext));
            }

            Pitch pitch = new Pitch()
            {
                Badge = applicationContext.Badges.FirstOrDefault(b => b.Name == pitchDTO.BadgeName),
                BadgeLevel = applicationContext.BadgeLevels.FirstOrDefault(b=>b.Level== pitchDTO.OldLVL),
                PitchMessage = pitchDTO.PitchMessage,
                PitchedLevel = pitchDTO.PitchedLVL,            
        };
            return pitch;
        }   

Google.ApplicationContext : Object

Methods :

public static ILogger get_Logger()
public static Void RegisterLogger(ILogger loggerToRegister = )
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()

Other methods