/// <summary> /// Returns an instance of <see cref="Microsoft.ApplicationBlocks.UIProcess.IStatePersistence"/> /// for the given <see cref="Microsoft.ApplicationBlocks.UIProcess.StatePersistenceProviderSettings"/>. /// </summary> /// <param name="providerSettings">The settings for state persistence.</param> /// <returns>The instance of IStatePersistence. It gets this from the internal cache, if possible.</returns> public static IStatePersistence Create(StatePersistenceProviderSettings providerSettings) { string statePersistenceKey = providerSettings.Type + "," + providerSettings.Assembly; IStatePersistence spp = (IStatePersistence)_statePersistenceCache[statePersistenceKey]; if (spp == null) { try { // now create instance based on that type info spp = (IStatePersistence)GenericFactory.Create(providerSettings); // pass in parameters to spp init method. this is where spp's find data they need such as // connection strings, etc. spp.Init(providerSettings.AdditionalAttributes); } catch (Exception e) { throw new UIPException(Resource.ResourceManager.FormatMessage(Resource.Exceptions.RES_ExceptionCantCreateStatePersistenceProvider, providerSettings.Type) + UIPException.GetFirstExceptionMessage(e), e); } // lock collection lock (_statePersistenceCache.SyncRoot) _statePersistenceCache[statePersistenceKey] = spp; } // return it return(spp); }
/// <summary> /// Initializes a new instance of the CryptHelper class. /// </summary> /// <param name="registryPath">Path to the registry key that contains the key used to /// perform encryption and decription.</param> internal CryptHelper(string registryPath) { try { //Request the permission to access the given registry key. RegistryPermission permission = new RegistryPermission(RegistryPermissionAccess.Read, Registry.LocalMachine.Name + "\\" + registryPath); permission.Demand(); } catch (System.Security.SecurityException e) { throw new UIPException(Resource.ResourceManager[Resource.Exceptions.RES_ExceptionSecureSqlProviderRegistryPermissions] + UIPException.GetFirstExceptionMessage(e), e); } _registryKey = Registry.LocalMachine.OpenSubKey(registryPath, false); if (_registryKey == null) { throw new UIPException(Resource.ResourceManager[Resource.Exceptions.RES_ExceptionSecureSqlProviderSymmetricKey]); } }
/// <summary> /// Encrypts a stream of bytes by using a TripleDES symmetric algorithm. /// </summary> /// <param name="plainValue">Stream of bytes to be encrypted.</param> /// <param name="key">Symmetric algorithm key.</param> /// <returns>An encrypted stream of bytes.</returns> private byte[] Encrypt(byte[] plainValue, byte[] key) { byte[] chiperValue = {}; TripleDES algorithm = TripleDESCryptoServiceProvider.Create(); MemoryStream memStream = new MemoryStream(); CryptoStream cryptoStream = new CryptoStream(memStream, algorithm.CreateEncryptor(key, IV), CryptoStreamMode.Write); try { cryptoStream.Write(plainValue, 0, plainValue.Length); cryptoStream.Flush(); cryptoStream.FlushFinalBlock(); chiperValue = memStream.ToArray(); } catch (Exception e) { throw new UIPException(Resource.ResourceManager[Resource.Exceptions.RES_ExceptionSecureSqlProviderCantEncrypt] + UIPException.GetFirstExceptionMessage(e), e); } finally { memStream.Close(); cryptoStream.Close(); } return(chiperValue); }
/// <summary> /// Navigates to the next node or view. /// </summary> /// <param name="nextNode">The node or view to navigate to.</param> public override void Navigate(string nextNode) { string previousView = CurrentState.CurrentView; CurrentState.NavigateValue = nextNode; UIPManager.InvokeEventHandlers(CurrentState); CurrentState.CurrentView = CurrentState.NavigateValue; CurrentState.NavigateValue = ""; CurrentState.Save(); try { ViewManager.ActivateView(previousView, CurrentState.CurrentView, this); } catch (Exception ex) { throw new UIPException(Resource.ResourceManager.FormatMessage(Resource.Exceptions.RES_ExceptionCantActivateView, nextNode) + UIPException.GetFirstExceptionMessage(ex), ex); } }
/// <summary> /// Decrypts an encrypted stream of bytes by using a TripleDES symmetric algorithm. /// </summary> /// <param name="cipherValue">The encrypted stream of bytes to be decrypted.</param> /// <param name="key">Symmetric algorithm key.</param> /// <returns>A stream of bytes.</returns> private byte[] Decrypt(byte[] cipherValue, byte[] key) { byte[] plainValue = new byte[cipherValue.Length]; TripleDES algorithm = TripleDESCryptoServiceProvider.Create(); MemoryStream memStream = new MemoryStream(cipherValue); CryptoStream cryptoStream = new CryptoStream(memStream, algorithm.CreateDecryptor(key, IV), CryptoStreamMode.Read); try { cryptoStream.Read(plainValue, 0, plainValue.Length); } catch (Exception e) { throw new UIPException(Resource.ResourceManager[Resource.Exceptions.RES_ExceptionSecureSqlProviderCantDecrypt] + UIPException.GetFirstExceptionMessage(e), e); } finally { //Flush the stream buffer cryptoStream.Close(); } return(plainValue); }
private void StartTask(TaskArgumentsHolder args) { FormSettings hostSettings = _settings[_settings.StartFormName]; ViewSettings startFormSettings = UIPConfiguration.Config.GetViewSettingsFromName(hostSettings.Name); CurrentState.CurrentView = startFormSettings.Name; try { ViewManager.ActivateView(null, startFormSettings.Name, this, args); } catch (System.Threading.ThreadAbortException) {} catch (Exception ex) { throw new UIPException(Resource.ResourceManager.FormatMessage(Resource.Exceptions.RES_ExceptionCantActivateView, startFormSettings.Name) + UIPException.GetFirstExceptionMessage(ex), ex); } CurrentState.Save(); if (hostSettings.InitialView != null) { Navigate(hostSettings.InitialView); } }
private void StartTask(TaskArgumentsHolder args) { ControllerBase firstController = ControllerFactory.Create(_startView.Name, this); firstController.EnterTask(null); CurrentState.CurrentView = _startView.Name; CurrentState.Save(); try { ViewManager.ActivateView(null, _startView.Name, this, args); } catch (System.Threading.ThreadAbortException) {} catch (Exception ex) { throw new UIPException(Resource.ResourceManager.FormatMessage(Resource.Exceptions.RES_ExceptionCantActivateView, _startView.Name) + UIPException.GetFirstExceptionMessage(ex), ex); } }
/// <summary> /// Navigates to the next node in the navigation graph. /// </summary> /// <param name="nextNode">The next node.</param> public override void Navigate(string nextNode) { string previousView = CurrentState.CurrentView; CurrentState.NavigateValue = nextNode; UIPManager.InvokeEventHandlers(CurrentState); ViewSettings nextView = UIPConfiguration.Config.GetNextViewSettings( Name, CurrentState.CurrentView, CurrentState.NavigateValue); CurrentState.CurrentView = nextView.Name; CurrentState.NavigateValue = ""; CurrentState.Save(); try { ActivateNextView(previousView, CurrentState.CurrentView); } catch (System.Threading.ThreadAbortException) {} catch (Exception ex) { throw new UIPException(Resource.ResourceManager.FormatMessage(Resource.Exceptions.RES_ExceptionCantActivateView, nextView.Name) + UIPException.GetFirstExceptionMessage(ex), ex); } }
private void StartTask(TaskArgumentsHolder holder) { CurrentState.NavigationGraph = Name; if (CurrentState.CurrentView != null && CurrentState.CurrentView.Length > 0) { _startView = UIPConfiguration.Config.GetViewSettingsFromName(CurrentState.CurrentView); } ControllerBase firstController = ControllerFactory.Create(StartView.Name, this); firstController.EnterTask(holder); CurrentState.CurrentView = StartView.Name; CurrentState.NavigateValue = ""; CurrentState.Save(); try { ViewManager.ActivateView(null, StartView.Name, this); } catch (System.Threading.ThreadAbortException) {} catch (Exception ex) { throw new UIPException(Resource.ResourceManager.FormatMessage(Resource.Exceptions.RES_ExceptionCantActivateView, StartView.Name) + UIPException.GetFirstExceptionMessage(ex), ex); } }
/// <summary> /// Creates an object using the full name type contained in typeSettings. /// </summary> /// <param name="typeSettings">A typeSetting object with the needed type information to create a class instance.</param> /// <param name="args">Constructor arguments.</param> /// <returns>An instance of the specified type.</returns> public static object Create(ObjectTypeSettings typeSettings, object[] args) { Assembly assemblyInstance = null; Type typeInstance = null; try { // Use full assembly name to get assembly instance assemblyInstance = Assembly.Load(typeSettings.Assembly); } catch (Exception e) { throw new UIPException(Resource.ResourceManager.FormatMessage(Resource.Exceptions.RES_ExceptionCantLoadAssembly, typeSettings.Assembly) + UIPException.GetFirstExceptionMessage(e), e); } // use type name to get type from assembly try { typeInstance = assemblyInstance.GetType(typeSettings.Type, true, false); } catch (Exception e) { throw new UIPException(Resource.ResourceManager.FormatMessage(Resource.Exceptions.RES_ExceptionCantGetTypeFromAssembly, typeSettings.Type, typeSettings.Assembly) + UIPException.GetFirstExceptionMessage(e), e); } try { if (args != null) { return(Activator.CreateInstance(typeInstance, args)); } else { return(Activator.CreateInstance(typeInstance)); } } catch (Exception e) { throw new UIPException(Resource.ResourceManager.FormatMessage(Resource.Exceptions.RES_ExceptionCantCreateInstanceUsingActivate, typeInstance) + UIPException.GetFirstExceptionMessage(e), e); } }