private Maybe<IDocumentIndex> DoGetDocumentFinder(AccountName accountName, DocumentIndexTypeToken documentIndexTypeToken)
		{
			Lazy<IDocumentIndex> fetched;
			return _documentIndexes[documentIndexTypeToken].TryGetValue(accountName.Value, out fetched)
				? Maybe.Return(fetched.Value)
				: Maybe.Nothing;
		}
		public ProfileGateway(IProfileReadonly profile, AccountName accountName, ITpBus bus)
		{
			_profile = profile;
			_accountName = accountName;
			_bus = bus;
			_storage = _profile.Get<ITargetProcessMessage>();
		}
		public IEnumerable<Profile> GetAll(AccountName accountName)
		{
			using (var context = CreateDataContext())
			{
				return SelectAccount(context.Accounts, accountName).Single().Profiles;
			}
		}
		public MashupDto GetMashup(AccountName account, string mashupName)
		{
			_log.Info(string.Format("Getting mashup with name '{0}'", mashupName));

			string mashupFolderPath = GetMashupFolderPath(account, mashupName);

			if (!Directory.Exists(mashupFolderPath))
			{
				return null;
			}

			var script = Directory.GetFiles(mashupFolderPath, "*.js");
			var config = Directory.GetFiles(mashupFolderPath, MashupDto.PlaceholdersCfgFileName);

			if (!script.Any())
			{
				return null;
			}

			var scriptFileInfo = new FileInfo(script.First());
			var mashup = CreateMashupDto(config, scriptFileInfo);
			_log.Info(string.Format("Mashup with name '{0}' retrieved", mashupName));

			return mashup;
		}
		public Mashup GetMashup(AccountName account, string mashupName)
		{
			_log.Info(string.Format("Getting mashup with name '{0}'", mashupName));
			Mashup mashup = _mashupLoader.Load(GetMashupFolderPath(account, mashupName), mashupName);			
			_log.Info(string.Format("Mashup with name '{0}' retrieved", mashupName));
			return mashup;
		}
		public MashupScriptStorage(IPluginContext context, IMashupLocalFolder folder, ILogManager logManager, IMashupLoader mashupLoader)
		{
			_folder = folder;
			_mashupLoader = mashupLoader;
			_log = logManager.GetLogger(GetType());
			_accountName = context.AccountName;
		}
		public void WriteOnceReadTwice()
		{
			int beforeProfileAdd = 0;
			int afterProfileAdded = 0;
			var account1Name = new AccountName("account1");
			AccountCollection.GetOrCreate(account1Name);
			ExecuteConcurrently(() =>
			{
				Interlocked.Increment(ref beforeProfileAdd);
				IAccount account = AccountCollection.GetOrCreate(account1Name);
				account.Profiles.Add(new ProfileCreationArgs(new ProfileName("~"), new object()));
				Interlocked.Increment(ref afterProfileAdded);
			}, () =>
			{
				var accountFirstVersion = AccountCollection.GetOrCreate(account1Name);
				var accountSecondVersion = AccountCollection.GetOrCreate(account1Name);
				bool sameVersion = false;
				if (Interlocked.Increment(ref beforeProfileAdd) == 1)
				{
					sameVersion = (accountFirstVersion == accountSecondVersion);
					sameVersion.Should(Be.True, "sameVersion.Should(Be.True)");
				}
				if (Interlocked.Increment(ref afterProfileAdded) == 2)
				{
					IAccount latestAccountVersion = AccountCollection.GetOrCreate(account1Name);
					latestAccountVersion.Profiles.Count().Should(Be.EqualTo(1), "latestAccountVersion.Profiles.Count().Should(Be.EqualTo(1))");
					if (sameVersion)
					{
						(latestAccountVersion == accountFirstVersion).Should(Be.False, "(latestAccountVersion == accountFirstVersion).Should(Be.False)");
					}
				}
			});
			AccountCollection.GetOrCreate(account1Name).Profiles.Count().Should(Be.EqualTo(1), "AccountCollection.GetOrCreate(account1Name).Profiles.Count().Should(Be.EqualTo(1))");
		}
		public Profile Update(ProfileName profileName, bool initialized, AccountName accountName)
		{
			var index = _profiles[accountName].FindIndex(x => x.Name == profileName.Value);
			_profiles[accountName][index].Initialized = initialized;
			_profiles[accountName][index].Name = profileName.Value;
			return _profiles[accountName][index];
		}
        public ContextQueryPlanBuilder(IDocumentIndexProvider documentIndexProvider, IDocumentIdFactory documentIdFactory, AccountName accountName, IProfileReadonly profile, IEntityTypeProvider entityTypeProvider)
		{
			_documentIndexProvider = documentIndexProvider;
			_documentIdFactory = documentIdFactory;
            _accountName = accountName;
			_profile = profile;
			_entityTypeProvider = entityTypeProvider;
		}
		public static void ShutdownDocumentIndexesIfRunning(this IDocumentIndexProvider documentIndexProvider, AccountName accountName, DocumentIndexShutdownSetup setup)
		{
			IEnumerable<IDocumentIndex> documentIndexes = documentIndexProvider.DocumentTypes.Select(t => documentIndexProvider.GetDocumentIndex(accountName, t)).Choose();
			foreach (IDocumentIndex documentIndex in documentIndexes)
			{
				documentIndex.Shutdown(setup);
			}
		}
		public ProfileDomainObject Create(Profile profile, AccountName accountName)
		{
			return new ProfileDomainObject(profile.Name, accountName, profile.Initialized, _pluginMetadata.ProfileType)
					{
						EventAggregator = _eventAggregator,
						ProfileRepository = this,
						StorageRepository = new ProfileStorageRepository(new ProfileId(profile.Id), _profileStoragePersister, _pluginMetadata)
					};
		}
		public void Delete(ProfileName profileName, AccountName accountName)
		{
			using (var context = CreateDataContext())
			{
				var profile = SelectProfile(context.Accounts, profileName, accountName);
				context.Profiles.DeleteOnSubmit(profile);
				context.SubmitChanges();
			}
		}
		public QueryPlanBuilder(IPluginContext pluginContext, IProfileReadonly profile, IDocumentIndexProvider documentIndexProvider, IEntityTypeProvider entityTypeProvider, IDocumentIdFactory documentIdFactory)
		{
			_accountName = pluginContext.AccountName;
			_profile = profile;
			_documentIndexProvider = documentIndexProvider;
			_entityTypeProvider = entityTypeProvider;
			_documentIdFactory = documentIdFactory;
			_contextQueryPlanBuilder = new ContextQueryPlanBuilder(_documentIndexProvider, _documentIdFactory, pluginContext.AccountName, _profile, _entityTypeProvider);
		}
		public void RemoveAccount()
		{
			var accountName = new AccountName("Account");
			_accountCollection.GetOrCreate(accountName);
			Assert.IsTrue(_accountCollection.Any(c => c.Name == accountName.Value));
			_accountHandler.Handle(new AccountRemovedMessage(accountName.Value));
			_accountHandler.Handle(_bus.PluginCommands.OfType<AccountRemovedLastStepMessage>().Single());
			Assert.IsFalse(_accountCollection.Any(c => c.Name == accountName.Value));
		}
		public void Dispose()
		{
			if (_disposed) return;
			_disposed = true;

			_accountName = null;
			_bus = null;
			_storage = null;
		}
		public IAccount GetOrCreate(AccountName accountName)
		{
			IAccount account;
			if(_accounts.TryGetValue(accountName, out account))
			{
				return account;
			}

			return _accounts[accountName] = new AccountDomainObject(accountName, new ProfileCollection(accountName, new ProfileDomainObject[0]));
		}
        internal static PluginAccount CreatePluginAccount(PluginName pluginName, AccountName accountName,
		                                                PluginProfile[] pluginProfiles)
        {
            return new PluginAccount
                   	{
                   		PluginName = pluginName,
                   		Name = accountName,
                   		PluginProfiles = pluginProfiles
                   	};
        }
		public AccountDomainObject GetBy(AccountName accountName)
		{
			var account = _accountPersister.GetBy(accountName);
			if(account == null)
			{
				return null;
			}

			return CreateAccount(account);
		}
 private AccountDomainObject CreateAccount(AccountName accountName, IEnumerable<Profile> profiles)
 {
     var profileDomainObjects = profiles.Select(p => _profileFactory.Create(p, accountName)).ToList();
     var profileCollection = new ProfileCollection(accountName, profileDomainObjects)
                                 {
                                     EventAggregator = _eventAggregator,
                                     ProfileRepository = _profileRepository
                                 };
     return new AccountDomainObject(accountName, profileCollection);
 }
		public PluginMashupMessage CreatePluginMashupMessage(AccountName accountName)
		{
			return new PluginMashupMessage
			{
				MashupName = GetMashupName(accountName),
				Placeholders = GetPlaceholders(),
				PluginMashupScripts = GetMashupScripts(),
				PluginName = string.Empty
			};
		}
 public Account GetBy(AccountName accountName)
 {
     using (var context = CreateDataContext())
     {
         var dataLoadOptions = new DataLoadOptions();
         dataLoadOptions.LoadWith<Account>(a => a.Profiles);
         context.LoadOptions = dataLoadOptions;
         return context.Accounts.Single(x => x.Plugin.Name == _pluginName && x.Name == accountName.Value);
     }
 }
		public Profile Update(ProfileName profileName, bool initialized, AccountName accountName)
		{
			using (var context = CreateDataContext())
			{
				var profileToUpdate = SelectProfile(context.Accounts, profileName, accountName);
				profileToUpdate.Initialized = initialized;
				context.SubmitChanges();
				return profileToUpdate;
			}
		}
		public ProfileDomainObject(ProfileDomainObject other):base(other)
		{
			_profileName = other._profileName;
			_accountName = other._accountName;
			_profileSettingsType = other._profileSettingsType;
			Initialized = other.Initialized;
			_settings = null;
			EventAggregator = other.EventAggregator;
			ProfileRepository = other.ProfileRepository;
		}
		public IEnumerable<int> GetVersions(AccountName accountName, DocumentIndexSetup documentIndexSetup)
		{
			string folder = GetFileFolder(accountName, documentIndexSetup);
			string versionedFilenameMask = _documentIndexDataTypeService.CreateVersionedFilenameMask(_fileName);
			return _fileService.GetFiles(folder, versionedFilenameMask)
								.Select(name => _documentIndexDataTypeService.ParseVersion(new FileInfo(name).Name))
								.Choose()
								.Distinct()
								.ToList();
		}
		public void Remove(AccountName accountName)
		{
			var account = _accounts.FirstOrDefault(x => x.Name == accountName);
			if (account == null)
			{
				return;
			}

			RemoveProfiles(account);
		}
		public ProfileDomainObject(ProfileName profileName, AccountName accountName, bool initialized, Type profileSettingsType)
		{
			_profileName = profileName;
			_accountName = accountName;
			_profileSettingsType = profileSettingsType;
			Initialized = initialized;
			_settings = null;
			EventAggregator = null;
			ProfileRepository = null;
		}
		public Account GetBy(AccountName accountName)
		{
			var account = _accounts.FirstOrDefault(x => x.Name == accountName);
			if(account == null)
			{
				return null;
			}

			LoadProfiles(account);
			return account;
		}
		public void RemoveAccount(RoutableTransportMode mode, bool isQueueDelete)
		{
			_msmqTransport.RoutableTransportMode = mode;
			var accountName = new AccountName("Account");
			_accountCollection.GetOrCreate(accountName);
			Assert.IsTrue(_accountCollection.Any(c => c.Name == accountName.Value));
			_accountHandler.Handle(new AccountRemovedMessage(accountName.Value));
			_accountHandler.Handle(_bus.PluginCommands.OfType<AccountRemovedLastStepMessage>().Single());
			Assert.IsFalse(_accountCollection.Any(c => c.Name == accountName.Value));
			Assert.AreEqual(_msmqTransport.IsQueueDeleted, isQueueDelete);
		}
 public Account Add(AccountName accountName)
 {
     using (var context = CreateDataContext())
     {
         var newAccount = new Account {Name = accountName.Value};
         var plugin = context.Plugins.Single(x => x.Name == _pluginName);
         plugin.Accounts.Add(newAccount);
         context.SubmitChanges();
         return newAccount;
     }
 }
		public Profile Add(ProfileName profileName, bool initialized, AccountName accountName)
		{
			using (var context = CreateDataContext())
			{
				var profiles = SelectAccount(context.Accounts, accountName).Single().Profiles;
				var profileToSave = new Profile {Name = profileName.Value, Initialized = initialized};
				profiles.Add(profileToSave);
				context.SubmitChanges();
				return profileToSave;
			}
		}
Exemple #31
0
 public bool Equals(AccountName other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Equals(other.Value, Value));
 }