/// <summary> /// Adds an object to the cache and uses generic type. /// </summary> /// <param name="timeout">Time the object should be kept, after which it can be disposed.</param> /// <param name="key">Key which will be used to retrieve the same object.</param> /// <param name="value">The instance of the object that should be stored in cache.</param> public void Add <T>(TimeSpan timeout, string key, T value) { Asserter.AssertIsNotNullOrEmptyString("key", key); Asserter.AssertIsNotNull("value", value); LocalCacheStorage.Add(key, value); }
/// <summary> /// /// </summary> /// <param name="assembly"></param> /// <param name="startupArgs"></param> public ApplicationInfo(Assembly assembly, string[] startupArgs, StartupArgumentFlagCollection flags) { if (startupArgs == null) { startupArgs = new string[0]; } if (startupArgs.Length > 0) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < startupArgs.Length; i++) { sb.AppendFormat("{0}{1}", startupArgs[i], i + 1 == startupArgs.Length ? "" : ","); } Tracer.Verbose("Application started with the following startup arguments: {0}", sb.ToString()); } Asserter.AssertIsNotNull(assembly, "assembly"); _assembly = assembly; _startupArgs = startupArgs; _startupArgumentParser = new StartupArgumentParser(StartupArgumentFormats.All, false, flags); _startupArgumentParser.Parse(startupArgs); }
/// <summary> /// Adds an object to the cache. It is upto the implementer on how long it wishes to keep the item in cache. /// Typically it will be govered by the TimeToExpire property being set. /// </summary> /// <param name="key">Key which will be used to retrieve the same object.</param> /// <param name="value">The instance of the object that should be stored in cache.</param> public void Add(string key, object value) { Asserter.AssertIsNotNullOrEmptyString("key", key); Asserter.AssertIsNotNull("value", value); LocalCacheStorage.Add(key, value); }
/// <summary> /// Executes the specified command text as a non-query returning the number of records affected. If you need /// the records affected, be sure that SET NOCOUNT OFF is enabled so it can return the number of records /// affected, otherwise, it will return -1. /// </summary> /// <param name="dbContext">The IDbContext to use.</param> /// <param name="commandText">The command text to execute.</param> /// <param name="parameters">The parameters to use during execution.</param> /// <param name="commandType">The type of command the command text is.</param> /// <returns>Returns a System.Int32 based on the number of record affected during the specified query.</returns> public int ExecuteNonQuery(string commandText, Dictionary <string, object> parameters, CommandType commandType, bool useReturnForCount) { Asserter.AssertIsNotNullOrEmptyString("commandText", commandText); Asserter.AssertIsNotNull("parameters", parameters); int recordsAffected = 0; DbContext dbContext = (DbContext)_Context; try { if (dbContext.Database.Connection.State != System.Data.ConnectionState.Open) { dbContext.Database.Connection.Open(); } using (DbCommand dbCommand = dbContext.Database.Connection.CreateCommand()) { dbCommand.CommandTimeout = CommonSettingsConfigSection.GetSection().DbContextCommandTimeout; dbCommand.CommandText = commandText; dbCommand.CommandType = commandType; foreach (string key in parameters.Keys) { DbParameter dbParameter = dbCommand.CreateParameter(); dbParameter.ParameterName = key; dbParameter.Value = parameters[key]; dbCommand.Parameters.Add(dbParameter); } // Uses the RETURN value of the stored procedure for the count, otherwise, // uses the total @@ROWCOUNT, will return -1 if SET NOCOUNT ON is specified. -cbb if (useReturnForCount) { DbParameter dbParameter = dbCommand.CreateParameter(); dbParameter.Direction = ParameterDirection.ReturnValue; dbParameter.ParameterName = "returnValue"; dbCommand.Parameters.Add(dbParameter); dbCommand.ExecuteNonQuery(); if (dbParameter != null && dbParameter.Value != DBNull.Value) { recordsAffected = (int)dbParameter.Value; } } else { recordsAffected = dbCommand.ExecuteNonQuery(); } } } finally { if (dbContext.Database.Connection != null && dbContext.Database.Connection.State != ConnectionState.Closed) { dbContext.Database.Connection.Close(); } } return(recordsAffected); }
public ShellForm(IKernel kernel) { Asserter.AssertIsNotNull(kernel, "kernel"); _kernel = kernel; _applicationService = _kernel.Get <IApplicationService>(); _storageService = _kernel.Get <IStorageService>(); _settingsService = _kernel.Get <ISettingsService>(); _siteService = _kernel.Get <ISiteService>(); _controller = _kernel.Get <ShellController>(); Asserter.AssertIsNotNull(_applicationService, "_applicationService"); Asserter.AssertIsNotNull(_storageService, "_storageService"); Asserter.AssertIsNotNull(_settingsService, "_settingsService"); Asserter.AssertIsNotNull(_siteService, "_siteService"); InitializeComponent(); _siteService.Register(SiteNames.ContentSite, contentPanel); _siteService.Register(SiteNames.NavigationSite, navigationPanel); _siteService.Register(SiteNames.ContentActionsSite, contentActionPanel); SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw, true); }
protected CommandBase(Action <object> executeMethod, Func <object, bool> canExecuteMethod) { Asserter.AssertIsNotNull(executeMethod, "executeMethod"); Asserter.AssertIsNotNull(canExecuteMethod, "canExecuteMethod"); _executeMethod = executeMethod; _canExecuteMethod = canExecuteMethod; }
/// <summary> /// Adds a range of <see cref="T:CoreVelocity.DataAccess.ICriteriaParameter"/> instances to the collection. /// </summary> /// <param name="critieriaParameters">The collection of <see cref="T:CoreVelocity.DataAccess.ICriteriaParameter"/> instances to add to the collection.</param> public void AddRange(IEnumerable <ICriteriaParameter> critieriaParameters) { Asserter.AssertIsNotNull("critieriaParameters", critieriaParameters); foreach (ICriteriaParameter criteriaParameter in critieriaParameters) { criteriaParameter.ParameterName = getParameterName(criteriaParameter.ParameterName); Add(criteriaParameter); } }
/// <summary> /// Creates a parameter and adds it to the collection. /// </summary> /// <param name="parameterName">Name of the parameter.</param> /// <param name="value">Value of the parameter.</param> public void Add(string parameterName, object value) { Asserter.AssertIsNotNull("parameterName", parameterName); Asserter.AssertIsNotNull("value", value); string propertyName = parameterName; parameterName = getParameterName(parameterName); Add(new CriteriaParameter(parameterName, value, propertyName)); }
public NetState(PacketRegistry packetRegistry) { Asserter.AssertIsNotNull(packetRegistry, "packetRegistry"); _packetRegistry = packetRegistry; _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); _recvBuffer = new BufferPool("Receive Buffer", 16, 4096); _messagePump = new MessagePump(); _buffer = new ByteQueue(); }
public SettingsService( IStorageService storageService, IApplicationService applicationService) { Asserter.AssertIsNotNull(storageService, "storageService"); Asserter.AssertIsNotNull(applicationService, "applicationService"); _storageService = storageService; _applicationService = applicationService; }
public override void OnClick(IKernel kernel) { IStorageService storageService = kernel.Get <IStorageService>(); ISettingsService settingsService = kernel.Get <ISettingsService>(); ShellForm form = kernel.Get <ShellForm>(); Asserter.AssertIsNotNull(form, "form"); if (MessageBoxEx.Show(form, "This will remove all applied patches for this server from your computer. Are you sure you want to continue?", "ConnectUO 2.0", MessageBoxButtons.YesNoCancel) == DialogResult.Yes) { if (storageService.ServerIsCurrentlyBeingPlayed(Item.Server)) { MessageBoxEx.Show(form, "ConnectUO has detected that you are currently playing this server and cannot reset the patches until the Ultima Online client connected bas been closed.", "ConnectUO 2.0"); return; } else { storageService.ResetPatches((int)Item.Server.Id); try { string serverDirectory = Path.Combine(settingsService.PatchDirectory, Uri.EscapeDataString(Item.Server.Name)); if (Directory.Exists(serverDirectory)) { FileInfo[] files = new DirectoryInfo(serverDirectory).GetFiles(); for (int i = 0; i < files.Length; i++) { try { files[i].Delete(); } catch (Exception ex) { //These aren't crucial, just log as info... Tracer.Info(ex); } } } } catch (Exception ex) { //These aren't crucial, just log as info... Tracer.Info(ex); } } MessageBoxEx.Show(form, "Patch Reset Complete.", "ConnectUO 2.0"); } }
/// <summary> /// Removes the specified <see cref="T:CoreVelocity.DataAccess.ICriteriaParameter"/> instance from the <see cref="T:CoreVelocity.DataAccess.CriteriaParameterCollection" />. /// </summary> /// <param name="item">The <see cref="T:CoreVelocity.DataAccess.ICriteriaParameter"/> to remove.</param> /// <returns>true if the <see cref="T:CoreVelocity.DataAccess.ICriteriaParameter"/> instance was removed; otherwise, false.</returns> public bool Remove(ICriteriaParameter item) { Asserter.AssertIsNotNull("item", item); ICriteriaParameter critieriaParameter = _innerList.Where(c => c.ParameterName.ToUpper() == item.ParameterName.ToUpper()).FirstOrDefault(); if (critieriaParameter != null) { if (_innerList.Remove(critieriaParameter)) { return(true); } } return(false); }
/// <summary> /// Copies the <see cref="T:CoreVelocity.DataAccess.SortedField"/> array to the collection. /// </summary> /// <param name="array">The array of <see cref="T:CoreVelocity.DataAccess.SortedField"/> instances to copy to the collection.</param> /// <param name="arrayIndex">Index of the <see cref="T:CoreVelocity.DataAccess.SortedField"/> in the array to copy to the collection.</param> public void CopyTo(ICriteriaParameter[] array, int arrayIndex) { Asserter.AssertIsNotNull("array", array); Asserter.AssertRange("arrayIndex", 0, array.Length, arrayIndex); if (arrayIndex < 0 || arrayIndex > array.Length) { throw new ArgumentOutOfRangeException("arrayIndex"); } List <ICriteriaParameter> tempList = new List <ICriteriaParameter>(); tempList.AddRange(_innerList); tempList.CopyTo(array, arrayIndex); }
/// <summary> /// Updates an object in cache. /// </summary> /// <param name="key">The key of the item to update.</param> /// <param name="value">The value to update it to.</param> public void Update(TimeSpan timeout, string key, object value) { Asserter.AssertIsNotNullOrEmptyString("key", key); Asserter.AssertIsNotNull("value", value); object returnValue; if (LocalCacheStorage.TryGetValue(key, out returnValue)) { LocalCacheStorage[key] = value; } else { throw new CacheKeyNotFoundException(key, CacheStoreName, GetType()); } }
public static string BuildPlayString(Server server) { Asserter.AssertIsNotNull(server, "server"); StringBuilder sb = new StringBuilder(); sb.AppendFormat("{0}={1}&", Id, server.Id); sb.AppendFormat("{0}={1}&", NameTolken, server.Name); sb.AppendFormat("{0}={1}&", HostTolken, server.HostAddress); sb.AppendFormat("{0}={1}&", PortTolken, server.Port); sb.AppendFormat("{0}={1}&", RemoveEncTolken, server.RemoveEncryption); sb.AppendFormat("{0}={1}", AllowRazorTolken, server.AllowRazor); return(sb.ToString()); }
// TODO: Utilize IUnitOfWork, and create a DbTransaction manager for IUnitOfWork. This applies to all of the Execute.*(.*) methods below. // TODO: RE-FACTOR Executes to use a single private method for executing the actual query to keep from all of this duplicate connection code. public IEnumerable <T> Execute <T>(string commandText, Dictionary <string, object> parameters, CommandType commandType) { Asserter.AssertIsNotNullOrEmptyString("commandText", commandText); Asserter.AssertIsNotNull("parameters", parameters); List <T> results = new List <T>(); DbContext dbContext = (DbContext)_Context; try { if (dbContext.Database.Connection.State != System.Data.ConnectionState.Open) { dbContext.Database.Connection.Open(); } using (DbCommand dbCommand = dbContext.Database.Connection.CreateCommand()) { dbCommand.CommandTimeout = CommonSettingsConfigSection.GetSection().DbContextCommandTimeout; dbCommand.CommandText = commandText; dbCommand.CommandType = commandType; foreach (string key in parameters.Keys) { DbParameter dbParameter = dbCommand.CreateParameter(); dbParameter.ParameterName = key; dbParameter.Value = parameters[key]; dbCommand.Parameters.Add(dbParameter); } using (DbDataReader dataReader = dbCommand.ExecuteReader()) { if (dataReader.HasRows) { Mapper.CreateMap <IDataReader, T>().IgnoreAllNonExisting(); results = Mapper.Map <IDataReader, List <T> >(dataReader); } } } } finally { if (dbContext.Database.Connection != null && dbContext.Database.Connection.State != ConnectionState.Closed) { dbContext.Database.Connection.Close(); } } return(results); }
public NavigationControl(IKernel kernel) : this() { Asserter.AssertIsNotNull(kernel, "kernel"); _kernel = kernel; _shellController = _kernel.Get <IShellController>(); _storageService = _kernel.Get <IStorageService>(); Asserter.AssertIsNotNull(_shellController, "_shell"); Asserter.AssertIsNotNull(_storageService, "_storageService"); _shellController.CurrentViewChanged += new EventHandler(shellController_CurrentViewChanged); serverListsGroupControl.SelectPublicServers(); }
public object ExecuteScalar(string commandText, Dictionary <string, object> parameters, CommandType commandType) { Asserter.AssertIsNotNullOrEmptyString("commandText", commandText); Asserter.AssertIsNotNull("parameters", parameters); object scalarValue = null; DbContext dbContext = (DbContext)_Context; try { if (dbContext.Database.Connection.State != System.Data.ConnectionState.Open) { dbContext.Database.Connection.Open(); } using (DbCommand dbCommand = dbContext.Database.Connection.CreateCommand()) { dbCommand.CommandTimeout = CommonSettingsConfigSection.GetSection().DbContextCommandTimeout; dbCommand.CommandText = commandText; dbCommand.CommandType = commandType; foreach (string key in parameters.Keys) { DbParameter dbParameter = dbCommand.CreateParameter(); dbParameter.ParameterName = key; dbParameter.Value = parameters[key]; dbCommand.Parameters.Add(dbParameter); } scalarValue = dbCommand.ExecuteScalar(); } } finally { if (dbContext.Database.Connection != null && dbContext.Database.Connection.State != ConnectionState.Closed) { dbContext.Database.Connection.Close(); } } return(scalarValue); }
public void Initialize() { _shell = _kernel.Get <IShell>(); _applicationService = _kernel.Get <IApplicationService>(); _storageService = _kernel.Get <IStorageService>(); _settingsService = _kernel.Get <ISettingsService>(); _siteService = _kernel.Get <ISiteService>(); Asserter.AssertIsNotNull(_shell, "_shell"); Asserter.AssertIsNotNull(_applicationService, "_applicationService"); Asserter.AssertIsNotNull(_storageService, "_storageService"); Asserter.AssertIsNotNull(_settingsService, "_settingsService"); Asserter.AssertIsNotNull(_siteService, "_siteService"); _storageService.Error += (s, e) => _shell.SetStatus(string.Format("Error: {0}", e.Exception.Message)); _storageService.ServersUpdateBegin += (s, e) => _shell.SetStatus("Updating Servers..."); _storageService.ServersUpdateComplete += (s, e) => _shell.SetStatus(string.Empty); CreateViews(); CurrentView = Views.PublicServers; }
public ShellController(IKernel kernel) { Asserter.AssertIsNotNull(kernel, "kernel"); _kernel = kernel; }
/// <summary> /// Adds an <seealso cref="CoreVelocity.Core.Data.ICritieriaParameter"/> to the collection. /// </summary> /// <param name="criteriaParameter">The <seealso cref="CoreVelocity.Core.Data.ICritieriaParameter"/> to add to the collection.</param> public void Add(ICriteriaParameter criteriaParameter) { Asserter.AssertIsNotNull("criteriaParameter", criteriaParameter); criteriaParameter.ParameterName = getParameterName(criteriaParameter.ParameterName); _innerList.Add(criteriaParameter); }
/// <summary> /// Determines whether the CriteriaParameter collection contains the specified parameter /// </summary> /// <param name="criteriaParameter">The parameter to check the collection for</param> /// <returns>True if the ICriteriaParameter collection contains the parameter</returns> public bool Contains(ICriteriaParameter criteriaParameter) { Asserter.AssertIsNotNull("criteriaParameter", criteriaParameter); return(_innerList.Where(item => criteriaParameter.ParameterName.ToUpper() == item.ParameterName.ToUpper()).FirstOrDefault() != null); }
public SearchResults <T> ExecuteWithPaging(string commandText, Dictionary <string, object> parameters, CommandType commandType, PageSort pageSort) { Asserter.AssertIsNotNullOrEmptyString("commandText", commandText); Asserter.AssertIsNotNull("parameters", parameters); SearchResults <T> searchResults = new SearchResults <T>(); DbContext dbContext = (DbContext)_Context; try { if (dbContext.Database.Connection.State != System.Data.ConnectionState.Open) { dbContext.Database.Connection.Open(); } using (DbCommand dbCommand = dbContext.Database.Connection.CreateCommand()) { dbCommand.CommandTimeout = CommonSettingsConfigSection.GetSection().DbContextCommandTimeout; dbCommand.CommandText = commandText; dbCommand.CommandType = commandType; if (pageSort != null) { dbCommand.Parameters.AddPageSort(pageSort); } foreach (string key in parameters.Keys) { DbParameter dbParameter = dbCommand.CreateParameter(); dbParameter.ParameterName = key; dbParameter.Value = parameters[key]; dbCommand.Parameters.Add(dbParameter); } using (DbDataReader dataReader = dbCommand.ExecuteReader()) { if (dataReader.HasRows) { List <T> results = new List <T>(); Mapper.CreateMap <IDataReader, T>().IgnoreAllNonExisting(); results = Mapper.Map <IDataReader, List <T> >(dataReader); if (results != null) { searchResults.Results = results; } else { searchResults.Results = new List <T>(); } if (dataReader.NextResult()) { if (dataReader.Read()) { searchResults.RowsAffected = Convert.ToInt32(dataReader[0]); } else { throw new DataException("The query or stored procedure for a paged query must return TWO record sets, the record set of the actual records in the first record set and the number of total rows as a scalar value in the second record set."); } } } } } } finally { if (dbContext.Database.Connection != null && dbContext.Database.Connection.State != ConnectionState.Closed) { dbContext.Database.Connection.Close(); } } return(searchResults); }
private void optionsGroupControl_AboutClick(object sender, EventArgs e) { Asserter.AssertIsNotNull(_shellController, "_shell"); _shellController.CurrentView = Views.About; }
public override void OnClick(IKernel kernel) { IStorageService storageService = kernel.Get <IStorageService>(); ShellForm form = kernel.Get <ShellForm>(); Asserter.AssertIsNotNull(form, "form"); Asserter.AssertIsNotNull(Item.Server, "Item.Server"); form.SetStatus("Preparing to play {0}...", Item.Server.Name); string uri = CuoUri.BuildPlayString(Item.Server); if (Item.Server.HasPatches) { Tracer.Verbose("Server has patches, checking..."); if (Item.Server.Public) { form.SetStatus("Retrieving patching information for {0}...", Item.Server.Name); try { ServerPatch[] patches = storageService.GetPatches((int)Item.Server.Id); Tracer.Verbose("Found {0} patches...", patches.Length); StringBuilder sb = new StringBuilder(); for (int i = 0; i < patches.Length; i++) { sb.AppendFormat("{0}|{1}{2}", patches[i].PatchUrl, patches[i].Version, i + 1 < patches.Length ? ";" : ""); } uri = string.Join(string.Format("&{0}=", CuoUri.PatchesTolken), new string[] { uri, sb.ToString() }); } catch (Exception ex) { Tracer.Error(ex); MessageBoxEx.Show(form, "Unable to get patch information for this server. See the debug log for details.", "ConnectUO 2.0"); } } else { try { LocalPatch[] patches = storageService.GetLocalPatches((int)Item.Server.Id); Tracer.Verbose("Found {0} patches...", patches.Length); StringBuilder sb = new StringBuilder(); for (int i = 0; i < patches.Length; i++) { sb.AppendFormat("{0}|{1}{2}", patches[i].PatchUrl, patches[i].Version, i + 1 < patches.Length ? ";" : ""); } uri = string.Join(string.Format("&{0}=", CuoUri.PatchesTolken), new string[] { uri, sb.ToString() }); } catch (Exception ex) { Tracer.Error(ex); MessageBoxEx.Show(form, "Unable to get patch information for this server. See the debug log for details.", "ConnectUO 2.0"); } } } Tracer.Verbose("Play URI: {0}", uri); uri = string.Format("cuo://{0}", Uri.EscapeDataString(Convert.ToBase64String(Encoding.UTF8.GetBytes(uri)))); kernel.Get <CuoUri>().Play(uri); form.SetStatus(string.Empty); }
private void serverListsGroupControl_LocalServersClick(object sender, EventArgs e) { Asserter.AssertIsNotNull(_shellController, "_shell"); _shellController.CurrentView = Views.LocalServers; }
public RelayCommand(Action <T> executeMethod, Func <T, bool> canExecuteMethod) : base(o => executeMethod((T)o), o => canExecuteMethod((T)o)) { Asserter.AssertIsNotNull(executeMethod, "executeMethod"); Asserter.AssertIsNotNull(canExecuteMethod, "canExecuteMethod"); }
public TraceMessageEventArgs(TraceMessage traceMessage) { Asserter.AssertIsNotNull(traceMessage, "traceMessage"); TraceMessage = traceMessage; }
private void connectionGroupControl_UpdateServersClick(object sender, EventArgs e) { Asserter.AssertIsNotNull(_storageService, "_storageService"); _storageService.UpdateServers(); }