Esempio n. 1
0
        private void UpdateAssemblyLocation()
        {
            this.toolTip.RemoveAll();

            TypeLibraryConverter converter = new TypeLibraryConverter();

            if (this.typeLibraryComboBox.SelectedItem != null)
            {
                TypeLibraryItem item = (TypeLibraryItem)this.typeLibraryComboBox.SelectedItem;
                toolTip.SetToolTip(this.typeLibraryComboBox, item.Location);

                converter.TypeLibraryLocation = item.Location;
            }
            else
            {
                converter.TypeLibraryLocation = this.typeLibraryComboBox.Text;
            }

            string fileName = "Interop." + converter.AssemblyLocation;

            string outputPath = null;

            if (this.assemblyTextBox.Text.Length > 0)
            {
                outputPath = Path.GetDirectoryName(this.assemblyTextBox.Text);
            }
            else
            {
                outputPath = this.OutputPath;
            }

            this.assemblyTextBox.Text = Path.Combine(outputPath, fileName);
        }
Esempio n. 2
0
        private void ImportButton_Click(object sender, EventArgs e)
        {
            string typeLibraryLocation = Environment.ExpandEnvironmentVariables(this.TypeLibraryLocation);
            string assemblyLocation    = Environment.ExpandEnvironmentVariables(this.AssemblyLocation);

            if (File.Exists(assemblyLocation))
            {
                if (MessageBox.Show(string.Format("File '{0}' exists. Do you want to overwrite?", assemblyLocation), "Silverlight Loader Add-In", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                {
                    return;
                }

                File.Delete(assemblyLocation);
            }

            this.acceptButton.Click  -= new EventHandler(this.ImportButton_Click);
            this.acceptButton.Enabled = false;
            this.cancelButton.Enabled = false;

            this.Controls.Remove(this.optionsButton);
            this.Controls.Remove(this.assemblyTextBox);
            this.Controls.Remove(this.assemblyLabel);
            this.Controls.Remove(this.typeLibraryLabel);
            this.Controls.Remove(this.browseButton);
            this.Controls.Remove(this.typeLibraryComboBox);

            this.logTextBox.Location   = new Point(12, 12);
            this.logTextBox.Size       = new Size(408 - 12 - 12, 90);
            this.logTextBox.ReadOnly   = true;
            this.logTextBox.Multiline  = true;
            this.logTextBox.MaxLength  = 1024 * 1024 * 8;
            this.logTextBox.ScrollBars = ScrollBars.Vertical;
            this.logTextBox.WordWrap   = false;
            this.Controls.Add(this.logTextBox);

            this.typeLibraryConverter = new TypeLibraryConverter();
            this.typeLibraryConverter.AssemblyLocation       = assemblyLocation;
            this.typeLibraryConverter.TypeLibraryLocation    = typeLibraryLocation;
            this.typeLibraryConverter.AssemblyNamespace      = this.optionDialog.AssemblyNamespace;
            this.typeLibraryConverter.AssemblyVersion        = this.optionDialog.AssemblyVersion;
            this.typeLibraryConverter.PrimaryInteropAssembly = this.optionDialog.PrimaryInteropAssembly;
            this.typeLibraryConverter.UnsafeInterfaces       = this.optionDialog.UnsafeInterfaces;
            this.typeLibraryConverter.SafeArrayAsSystemArray = this.optionDialog.SafeArrayAsSystemArray;

            // Read Public Key
            if (File.Exists(this.optionDialog.PublicKey))
            {
                using (FileStream stream = File.OpenRead(this.optionDialog.PublicKey))
                {
                    byte[] buffer = new byte[(int)stream.Length];
                    stream.Read(buffer, 0, buffer.Length);
                    this.typeLibraryConverter.PublicKey = buffer;
                }
            }

            // Read Key Pair
            if (File.Exists(this.optionDialog.KeyPair))
            {
                using (FileStream stream = File.OpenRead(this.optionDialog.KeyPair))
                {
                    this.typeLibraryConverter.KeyPair = new StrongNameKeyPair(stream);
                }
            }

            this.typeLibraryConverter.Message += new TextEventHandler(this.TypeLibraryConverter_Message);

            MethodInvoker invoker = new MethodInvoker(this.AsyncConvert);

            invoker.BeginInvoke(null, null);
        }