⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 manifestutilitymainform.cs

📁 怎样的图象处理的
💻 CS
📖 第 1 页 / 共 3 页
字号:

			if(keyDialog.ShowDialog() == DialogResult.OK)
			{
				System.IO.StreamReader sr = new 
					System.IO.StreamReader(keyDialog.FileName);
				key.Text = sr.ReadToEnd();
				sr.Close();
			}

		}

		
		private void browseForPostProcessor_Click(object sender, System.EventArgs e)
		{
			postProcessorDialog.InitialDirectory = folderPath.Text;
			if(postProcessorDialog.ShowDialog() == DialogResult.OK)
			{
				postProcessorAssembly.Text = postProcessorDialog.FileName;
			}

		}

		
		private void postProcessorAssembly_TextChanged(object sender, System.EventArgs e)
		{
			ListClasses(postProcessorAssembly.Text, "IPostProcessor", postProcessorClass);
		}

		
		private void usePostProcessor_CheckedChanged(object sender, System.EventArgs e)
		{
			postProcessorAssembly.Enabled = usePostProcessor.Checked;
			postProcessorClass.Enabled = usePostProcessor.Checked;
			browseForPostProcessor.Enabled = usePostProcessor.Checked;
		}

		
		private void fileGenerateKeysMenu_Click(object sender, System.EventArgs e)
		{
			createNewKeys();
		}

		
		private void createManifest_Click(object sender, System.EventArgs e)
		{
			generateManifestFile();
		}


		private void fileCreateManifestMenu_Click(object sender, System.EventArgs e)
		{
			generateManifestFile();
		}

		
		private void fileExitMenu_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		
		#endregion

		#region utility functions

		private void initializeDialogs()
		{
			//folderPath.Text = folderDialog.SelectedPath + @"\";
			folderPath.Text = AppDomain.CurrentDomain.BaseDirectory;
			validatorAssembly.Text = System.AppDomain.CurrentDomain.BaseDirectory + "Microsoft.ApplicationBlocks.ApplicationUpdater.dll";
			validatorDialog.InitialDirectory = System.AppDomain.CurrentDomain.BaseDirectory;
			
//  can only use FolderBrowserDialog in FX1.1
#if FRAMEWORK_1_1
			keyDialog.InitialDirectory = folderDialog.SelectedPath;
			newKeyDialog.InitialDirectory = folderDialog.SelectedPath;
#else
			
			keyDialog.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory;
			newKeyDialog.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory;
#endif
		}

		
		private void generateManifestFile()
		{
			try
			{
				ManifestSettings manifest = new ManifestSettings();
				manifest.FolderPath = folderPath.Text;
				manifest.UpdateLocation = updateLocation.Text;
				manifest.Version = version.Text;
				manifest.Key = key.Text;
				manifest.ValidatorAssembly = validatorAssembly.Text;
				manifest.ValidatorClass = validatorClass.Text;
				manifest.UsePostProcessor = usePostProcessor.Checked;
				manifest.PostProcessorAssembly = postProcessorAssembly.Text;
				manifest.PostProcessorClass = postProcessorClass.Text;
				XmlDocument manifestDoc = manifest.Create();
				if ( DialogResult.OK == manifestDialog.ShowDialog() )
				{
					manifestDoc.Save(manifestDialog.FileName);
					MessageBox.Show("Manifest Saved");
				}
				else
				{
					MessageBox.Show( "Manifest save cancelled." );
				}
			}
			catch( Exception e )
			{
				HandleTerminalError( e );
			}
		}

		
		private void ListClasses(string assembly, string interfaceType, ComboBox listControl)
		{
			Assembly asm;
			Type[] types;
			Type typeInstance;

			// clear the existing list
			listControl.Items.Clear();
			listControl.Text = "";

			try
			{
			
				asm = Assembly.LoadFrom(  assembly );
				types = asm.GetTypes();
				foreach( Type type in types )
				{
					typeInstance = type.GetInterface( interfaceType, false );
					if( null != typeInstance )
					{
						listControl.Items.Add( type.FullName );
					}
				}
				listControl.SelectedIndex = 0;
			}
			catch(FileNotFoundException f)
			{
				HandleTerminalError( f );
			}
			catch (Exception e)
			{
				HandleTerminalError( e );
			}
			
		}

		
		private void createNewKeys()
		{
			try
			{
				// Instantiate the key generator
				KeyGenerator keyGen = new KeyGenerator();

				// Get the public and private keys
				XmlDocument privateKey = keyGen.PrivateKey;
				XmlDocument publicKey = keyGen.PublicKey;

				// save the private key
				newKeyDialog.FileName = "PrivateKey.xml";
				newKeyDialog.Title = "Save Private Key";
				if(newKeyDialog.ShowDialog() == DialogResult.OK)
				{
					privateKey.Save(newKeyDialog.FileName);
				}

				// save the public key
				newKeyDialog.FileName = "PublicKey.xml";
				newKeyDialog.Title = "Save Public Key";
				if(newKeyDialog.ShowDialog() == DialogResult.OK)
				{
					publicKey.Save(newKeyDialog.FileName);
				}

				keyGen = null;
			}
			catch( Exception e )
			{
				HandleTerminalError( e );
			}
		}


		private void HandleTerminalError( Exception e )
		{
			StringBuilder sb = new StringBuilder( 5000 );
			//  pass off to recursive fn
			RecurseErrorStack( e, sb );
			//  show error
			MessageBox.Show( sb.ToString() );		
		}

		
		private void RecurseErrorStack( Exception e , StringBuilder sb )
		{
			if( null != e )
			{
				sb.Append( String.Format( "ERROR: '{0}'{1}STACK: {2}{3}", e.Message, Environment.NewLine, e.StackTrace, Environment.NewLine ) );
				//  now recurse to roll up inner exceptions
				RecurseErrorStack( e.InnerException, sb );
			}
		}

		
		#endregion

		#region Tooltips

		private void SetToolTips()
		{
		
			this.toolTip1.SetToolTip(this.folderPath, "Enter the PHYSICAL path on the server where the actual update files are located; " +
				"this is not a URL, this is the path that the manifest utility will use to find these files and generate the manifest.");
			


			//  can only use this object w/ FX1.1
#if FRAMEWORK_1_1
			this.toolTip1.SetToolTip(this.browseForFolder, "Click here to browse to the folder on the server where the new update files are l" +
				"ocated.");
#else
			this.toolTip1.SetToolTip(this.browseForFolder, "You are using FRAMEWORK 1.0, enter the folder path manually in the text box to the left.");
#endif
			this.toolTip1.SetToolTip(this.updateLocation, @"Enter the URL (or UNC if using alternate downloaders) where the CLIENTS will look to find the updated files.  Usually this is a URL of the form ""http://myServer/Updater/2.0.0.0/"" where the last part of the URL is the versioned folder number...not necessary but will help keep things organized.");
			
			this.toolTip1.SetToolTip(this.version, "The version number of the new update.  It is HIGHLY RECOMMENDED that you use stan" +
				"dard versioning conventions as shown--\"2.0.0.0\", or \"3.1.75.298\" for instance.");
			
			this.toolTip1.SetToolTip(this.browseForKey, "Click on this button to select the private key, or symmetric key, in an xml file;" +
				" this key will be used to sign the files and manifest.");
			
			this.toolTip1.SetToolTip(this.browseForValidatorAssembly, @"Click on this button to find the ASSEMBLY (DLL or EXE) that contains an implementation of IValidator you wish to use to sign the files.  NOTE that the assembly MUST contain an IValidator implementation.  Also note that this must be the same IValidator that is used by the clients (according to their configuration files) to verify the files.");
			
			this.toolTip1.SetToolTip(this.validatorClass, "Once you have selected a Validator assembly above, all the public classes which i" +
				"mplement IValidator will appear here.  Select the one you wish to use.  NOTE tha" +
				"t you must sign the files/manifest with the SAME validator as the clients use to" +
				" verify them.");
			
			this.toolTip1.SetToolTip(this.usePostProcessor, "Check this box if you wish to run a Post Processor on the clients when you have c" +
				"ompleted an update.  See the documentation for more help on the enormously power" +
				"ful Post Processor concept.");

			this.toolTip1.SetToolTip(this.browseForPostProcessor, "Click this button to select an ASSEMBLY (EXE or DLL) that contains at least one p" +
				"ublic member which implements IPostProcessor.");
			
			this.toolTip1.SetToolTip(this.postProcessorClass, "When you have selected an IPostProcessor implementation above, the list of availa" +
				"ble PostProcessors will appear here.  Select the one you wish the clients to use" +
				" when they complete an update.");
			
		}

		#endregion
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -