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 void DeletePluginProfile(ProfileName pluginProfile)
 {
     ChangeProfiles(profileCollection =>
                    	{
                    		var profile = profileCollection[pluginProfile];
                    		profile.Log.Remove();
                    		profileCollection.Remove(profile);
                    	});
 }
		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 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(ProfileName profileName, AccountName accountName, bool initialized, Type profileSettingsType)
		{
			_profileName = profileName;
			_accountName = accountName;
			_profileSettingsType = profileSettingsType;
			Initialized = initialized;
			_settings = null;
			EventAggregator = null;
			ProfileRepository = null;
		}
		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 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;
			}
		}
 public bool Equals(ProfileName other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Equals(other.Value, Value));
 }
		public Profile Add(ProfileName profileName, bool initialized,  AccountName accountName)
		{
			var profile = new Profile {Name = profileName.Value, Id = Id(), Initialized = initialized};
			if (_profiles.ContainsKey(accountName))
			{
				_profiles[accountName].Add(profile);
			}
			else
			{
				_profiles.Add(accountName, new List<Profile> {profile});
			}
			return profile;
		}
		protected void SendProfileChangedLocalMessage(ProfileName profileName, ITargetProcessMessage profileMessage)
		{
			_bus.SendLocalWithContext(profileName, PluginContext.AccountName, profileMessage);
		}
		private static IProfileGateway CreateProfileGateway(AccountName accountName, ProfileName profileName, bool initialized)
		{
			var account = ObjectFactory.GetInstance<IAccountCollection>().GetOrCreate(accountName);
			_profile = account.Profiles.Add(new ProfileCreationArgs(profileName, new object()));
			if(initialized)
			{
				_profile.MarkAsInitialized();
			}
			else
			{
				_profile.MarkAsNotInitialized();
			}

			_profile.Save();

			return new ProfileGateway(_profile, accountName, ObjectFactory.GetInstance<ITpBus>());
		}
		public ProfileCreationArgs(ProfileName profileName, object settings)
		{
			_profileName = profileName;
			_settings = settings;
		}
        private static void SetCurrentPluginContext(AccountName accountName, ProfileName profileName, string pluginName)
        {
            var context = ObjectFactory.GetInstance<PluginContextMock>();
            context.AccountName = accountName;
            context.PluginName = pluginName;
            context.ProfileName = profileName;

            var profile = ProfileCollection.First(x => x.Name == profileName);
            Bus.SetIn(accountName);
            Bus.SetIn(profile.Name);
        }
		private Profile SelectProfile(IQueryable<Account> accounts, ProfileName profileName, AccountName accountName)
		{
			return SelectAccount(accounts, accountName).SelectMany(a => a.Profiles).Single(p => p.Name == profileName.Value);
		}
		public void Delete(ProfileName profileName, AccountName accountName)
		{
			_profilePersister.Delete(profileName, accountName);
		}
		public PluginContextSnapshot(AccountName accountName, ProfileName profileName, PluginName pluginName)
		{
			_accountName = accountName;
			_profileName = profileName;
			_pluginName = pluginName;
		}
		public void Delete(ProfileName profileName, AccountName accountName)
		{
			_profiles[accountName].RemoveAll(x => x.Name == profileName);
		}
 public static void SetCurrentPluginContext(AccountName accountName, ProfileName profileName)
 {
     SetCurrentPluginContext(accountName, profileName,
                             ObjectFactory.GetInstance<IPluginMetadata>().PluginData.Name);
 }
		public bool Equals(ProfileName other)
		{
			if (ReferenceEquals(null, other)) return false;
			if (ReferenceEquals(this, other)) return true;
			return Equals(other.Value, Value);
		}