Exemplo n.º 1
0
        public async Task <IActionResult> Configure(ConfigureJobModel model)
        {
            // TODO: find out why ModelState is invalid with unvalidated state (probably because of the IEnumerable/Dictionary Providers property)
            if (ModelState.ErrorCount == 0)
            {
                try
                {
                    int[] providerIDs = model.GetProviderIDs();

                    List <ProviderInstance> providerInstances = new List <ProviderInstance>(providerIDs.Length);
                    for (int i = 0; i < providerIDs.Length; i++)
                    {
                        Provider provider = await providerRepository.Get(providerIDs[i]);

                        ProviderInstance providerInstance = await providerMappingService.CreateProviderInstance(provider, model.Providers.ElementAt(i));

                        providerInstance.Order = i;
                        providerInstances.Add(providerInstance);
                    }

                    int jobId = await backupJobRepository.AddOrUpdate(model.ID, model.Name, providerInstances);

                    await schedulerService.CreateOrUpdate(jobId, model.CronSchedule);
                }
                catch (Exception ex)
                {
                    logger.LogError(ex, $"Failed to save job '{model.Name}' to database");
                }
            }

            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        public static void Activate(this Scene scene, bool clearOperation = true)
        {
            var            provider  = ProviderInstance.Get <IProvider <Scene, AsyncOperation> >();
            AsyncOperation operation = provider.Get(scene);

            operation.allowSceneActivation = true;

            if (clearOperation)
            {
                provider.Remove(scene);
            }
        }
Exemplo n.º 3
0
        public async Task <ProviderInstance> GetInstance(int id)
        {
            ProviderInstance providerInstance = await context
                                                .ProviderInstances
                                                .Include(pi => pi.Provider)
                                                .Include(pi => pi.Values)
                                                .ThenInclude(pip => pip.Property)
                                                .ThenInclude(pp => pp.Attributes)
                                                .FirstOrDefaultAsync(pi => pi.ID == id);

            return(providerInstance);
        }
        public async Task <int> Add(string name, byte[] sessionData, ProviderInstance providerInstance)
        {
            AuthenticatedSession session = new AuthenticatedSession();

            session.Name        = name;
            session.SessionData = sessionData;
            session.Provider    = providerInstance;

            await context.AuthenticatedSessions.AddAsync(session);

            await context.SaveChangesAsync();

            return(session.ID);
        }
        public async Task <ProviderInstance> CreateProviderInstance(Provider provider, Dictionary <string, string> properties)
        {
            ProviderInstance backupProvider = new ProviderInstance();

            backupProvider.Provider = provider;
            foreach (var property in provider.Properties)
            {
                string value = properties.ContainsKey(property.TypeName) ? properties[property.TypeName] : null;

                ProviderInstanceProperty instanceProperty = new ProviderInstanceProperty();
                instanceProperty.Property = property;
                instanceProperty.Value    = await Parse(value, property.Type, property.Attributes);

                backupProvider.Values.Add(instanceProperty);
            }
            return(backupProvider);
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Configure(ConfigureAuthenticatedSessionModel model)
        {
            if (ModelState.ErrorCount == 0)
            {
                Provider provider = await providerRepository.Get(model.AuthenticationProvider);

                ProviderInstance providerInstance = await providerMappingService.CreateProviderInstance(provider, model.Providers.FirstOrDefault());

                int authenticatedSessionId = await authenticatedSessionRepository.AddOrUpdate(model.ID, model.Name, providerInstance);

                IAuthenticationProvider <object> authenticationProvider = await providerMappingService.CreateProvider <IAuthenticationProvider <object> >(providerInstance);

                authenticationProvider.Initialize($"http://{Request.Host}/Authentication/CompleteAuthentication?id={authenticatedSessionId}", data => StoreSession(authenticatedSessionId, data));
                string redirectUrl = await authenticationProvider.GetOAuthUrl();

                return(Redirect(redirectUrl));
            }

            return(View(model));
        }
Exemplo n.º 7
0
		private void UnregisterPropertyProvider(RuntimeTypeHandle extendableElementRuntimeTypeHandle, ProviderInstance providerInstance)
		{
			Dictionary<RuntimeTypeHandle, LinkedNode<ProviderInstance>> providerDictionary = this.myProviderDictionary;
			LinkedNode<ProviderInstance> existingProviderNode;
			if (providerDictionary.TryGetValue(extendableElementRuntimeTypeHandle, out existingProviderNode))
			{
				LinkedNode<ProviderInstance> testNode = existingProviderNode;
				while (testNode != null)
				{
					if (testNode.Value.IsEquivalentTo(providerInstance))
					{
						LinkedNode<ProviderInstance> head = existingProviderNode;
						testNode.Detach(ref head);
						if (head == null)
						{
							providerDictionary.Remove(extendableElementRuntimeTypeHandle);
						}
						else if (head != existingProviderNode)
						{
							providerDictionary[extendableElementRuntimeTypeHandle] = head;
						}
						return;
					}
					testNode = testNode.Next;
				}
			}
		}
Exemplo n.º 8
0
		private void RegisterPropertyProvider(RuntimeTypeHandle extendableElementRuntimeTypeHandle, ProviderInstance providerInstance)
		{
			Dictionary<RuntimeTypeHandle, LinkedNode<ProviderInstance>> providerDictionary = this.myProviderDictionary;
			LinkedNode<ProviderInstance> existingProviderNode;
			if (providerDictionary.TryGetValue(extendableElementRuntimeTypeHandle, out existingProviderNode))
			{
				LinkedNode<ProviderInstance> lastNode = null;
				LinkedNode<ProviderInstance> testNode = existingProviderNode;
				while (testNode != null)
				{
					if (testNode.Value.IsEquivalentTo(providerInstance))
					{
						return; // Don't add the same callback twice
					}
					lastNode = testNode;
					testNode = testNode.Next;
				}
				lastNode.SetNext(new LinkedNode<ProviderInstance>(providerInstance), ref existingProviderNode);
			}
			else
			{
				providerDictionary[extendableElementRuntimeTypeHandle] = new LinkedNode<ProviderInstance>(providerInstance);
			}
		}
Exemplo n.º 9
0
		private void AddOrRemovePropertyProvider(Type extendableElementType, ProviderInstance providerInstance, bool includeSubtypes, EventHandlerAction action)
		{
			bool register = action == EventHandlerAction.Add;
			if (register)
			{
				this.RegisterPropertyProvider(extendableElementType.TypeHandle, providerInstance);
			}
			else
			{
				this.UnregisterPropertyProvider(extendableElementType.TypeHandle, providerInstance);
			}
			if (includeSubtypes)
			{
				Store store = this.myStore;
				DomainClassInfo domainClassInfo = store.DomainDataDirectory.FindDomainClass(extendableElementType);
				if (null != domainClassInfo)
				{
					foreach (DomainClassInfo subtypeInfo in domainClassInfo.AllDescendants)
					{
						if (register)
						{
							this.RegisterPropertyProvider(subtypeInfo.ImplementationClass.TypeHandle, providerInstance);
						}
						else
						{
							this.UnregisterPropertyProvider(subtypeInfo.ImplementationClass.TypeHandle, providerInstance);
						}
					}
				}
			}
		}
Exemplo n.º 10
0
			/// <summary>
			/// Equals without all of the annoying operator requirements
			/// </summary>
			public bool IsEquivalentTo(ProviderInstance other)
			{
				return myDelegate != null ? myDelegate == other.myDelegate : myInstance == other.myInstance;
			}