Ejemplo n.º 1
0
 private void OnClickOKButton(object sender, EventArgs e)
 {
     IMxUIService service = (IMxUIService) this.GetService(typeof(IMxUIService));
     CodeDocumentLanguage codeLanguage = null;
     string fileName = this.GetFileName();
     string itemPath = (this._location != null) ? this._location : this._locationText.Text.Trim();
     string str3 = null;
     if (!this._project.ValidateProjectItemName(fileName))
     {
         service.ReportError("'" + fileName + "' is not a valid file name.\r\nPlease try again.", this.Text, true);
         this._fileNameText.Focus();
     }
     else if ((this._location == null) && !this._project.ValidateProjectItemPath(itemPath, true))
     {
         service.ReportError("'" + itemPath + "' is not a valid location for the new file.\r\nPlease try again.", this.Text, true);
         this._locationText.Focus();
     }
     else
     {
         try
         {
             byte[] buffer;
             try
             {
                 str3 = this._project.CombinePath(itemPath, fileName);
                 if (!this._project.ProjectItemExists(str3) || (service.ShowMessage("A file with the path '" + str3 + "' already exists.\r\nClick 'Yes' to continue and overwrite the existing file.\r\nClick 'No' to pick a different file.", this.Text, MessageBoxIcon.Question, MessageBoxButtons.YesNo, MessageBoxDefaultButton.Button2) != DialogResult.No))
                 {
                     goto Label_013D;
                 }
                 this._fileNameText.Focus();
             }
             catch
             {
                 service.ReportError("Unable to create the specified file.\r\nPlease try again.", this.Text, true);
                 this._fileNameText.Focus();
             }
             return;
         Label_013D:
             buffer = null;
             try
             {
                 DocumentInstanceArguments instanceArguments = null;
                 if ((this._currentTemplateItem.DocumentType.TemplateFlags & TemplateFlags.HasCode) == TemplateFlags.None)
                 {
                     instanceArguments = new DocumentInstanceArguments(fileName);
                 }
                 else
                 {
                     codeLanguage = this.GetCodeLanguage();
                     string namespaceName = string.Empty;
                     string str5 = string.Empty;
                     if (this._classInfoCheckBox.Checked)
                     {
                         namespaceName = this._namespaceText.Text.Trim();
                         str5 = this._classText.Text.Trim();
                         if (codeLanguage != null)
                         {
                             ICodeGenerator generator = codeLanguage.CodeDomProvider.CreateGenerator();
                             if (!generator.IsValidIdentifier(str5))
                             {
                                 service.ReportError("'" + str5 + "' is not a valid class name.\r\nPlease try again.", this.Text, true);
                                 this._classText.Focus();
                                 return;
                             }
                             foreach (string str6 in namespaceName.Split(new char[] { '.' }))
                             {
                                 if (!generator.IsValidIdentifier(str6))
                                 {
                                     service.ReportError("'" + namespaceName + "' is not a valid namespace name.\r\nPlease try again.", this.Text, true);
                                     this._namespaceText.Focus();
                                     return;
                                 }
                             }
                         }
                     }
                     instanceArguments = new DocumentInstanceArguments(fileName, codeLanguage, namespaceName, str5);
                 }
                 buffer = this._currentTemplateItem.DocumentType.Instantiate(base.ServiceProvider, instanceArguments);
             }
             catch
             {
                 service.ReportError("Unable to use the selected document template to create a new file.\r\nPlease try again.", this.Text, true);
                 buffer = null;
             }
             if (buffer != null)
             {
                 DocumentProjectItem item = this._project.ParsePath(str3, true) as DocumentProjectItem;
                 if (item != null)
                 {
                     Stream stream = null;
                     try
                     {
                         stream = item.GetStream(ProjectItemStreamMode.Write);
                         if (buffer.Length != 0)
                         {
                             stream.Write(buffer, 0, buffer.Length);
                         }
                         this._newProjectItem = item;
                     }
                     finally
                     {
                         if (stream != null)
                         {
                             stream.Close();
                             stream = null;
                         }
                     }
                 }
             }
         }
         catch (Exception exception)
         {
             service.ReportError(exception.Message, this.Text, false);
         }
         if (this._newProjectItem != null)
         {
             IPreferencesService service2 = (IPreferencesService) this.GetService(typeof(IPreferencesService));
             if (service2 != null)
             {
                 PreferencesStore preferencesStore = service2.GetPreferencesStore(typeof(AddFileDialog));
                 if (preferencesStore != null)
                 {
                     if (this._location == null)
                     {
                         preferencesStore.SetValue("Location", itemPath, string.Empty);
                     }
                     preferencesStore.SetValue("View", (this._templateListView.View == View.List) ? 1 : 0, 0);
                 }
             }
             if (codeLanguage != null)
             {
                 ILanguageManager manager = (ILanguageManager) this.GetService(typeof(ILanguageManager));
                 if (manager != null)
                 {
                     ((LanguageManager) manager).SetCurrentCodeLanguage(codeLanguage);
                 }
             }
             base.DialogResult = DialogResult.OK;
             base.Close();
         }
         else
         {
             this._fileNameText.Focus();
         }
     }
 }
Ejemplo n.º 2
0
 public byte[] RunDocumentWizard(string documentWizardTypeName, DocumentInstanceArguments instanceArguments)
 {
     return (byte[]) base.RunPlugin(documentWizardTypeName, instanceArguments);
 }
Ejemplo n.º 3
0
 protected virtual byte[] GetTemplateContent(IServiceProvider serviceProvider, DocumentInstanceArguments instanceArguments)
 {
     byte[] buffer = null;
     Stream stream = null;
     try
     {
         string templateFilePath;
         bool flag = (this.TemplateFlags & Microsoft.Matrix.Core.Documents.TemplateFlags.HasCode) != Microsoft.Matrix.Core.Documents.TemplateFlags.None;
         bool flag2 = flag | ((this.TemplateFlags & Microsoft.Matrix.Core.Documents.TemplateFlags.HasMacros) != Microsoft.Matrix.Core.Documents.TemplateFlags.None);
         if ((this.TemplateFlags & Microsoft.Matrix.Core.Documents.TemplateFlags.HasCode) == Microsoft.Matrix.Core.Documents.TemplateFlags.None)
         {
             templateFilePath = this.GetTemplateFilePath();
         }
         else
         {
             templateFilePath = this.GetTemplateFilePath(instanceArguments.CodeLanguage);
         }
         stream = new FileStream(templateFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
         int length = (int) stream.Length;
         buffer = new byte[length];
         stream.Read(buffer, 0, length);
         if (flag2)
         {
             this._instanceArgs = instanceArguments;
             buffer = this.ProcessMacros(buffer);
         }
     }
     finally
     {
         this._instanceArgs = null;
         if (stream != null)
         {
             stream.Close();
             stream = null;
         }
     }
     if (buffer == null)
     {
         buffer = new byte[0];
     }
     return buffer;
 }
Ejemplo n.º 4
0
 public byte[] Instantiate(IServiceProvider serviceProvider, DocumentInstanceArguments instanceArguments)
 {
     if (serviceProvider == null)
     {
         throw new ArgumentNullException("serviceProvider");
     }
     if (instanceArguments == null)
     {
         throw new ArgumentNullException("instanceArguments");
     }
     if (!this.CanCreateNew)
     {
         throw new InvalidOperationException();
     }
     if (this.CreateUsingTemplate)
     {
         return this.GetTemplateContent(serviceProvider, instanceArguments);
     }
     return new byte[0];
 }
Ejemplo n.º 5
0
 protected override byte[] GetTemplateContent(IServiceProvider serviceProvider, DocumentInstanceArguments instanceArguments)
 {
     DocumentWizardHost host = new DocumentWizardHost(serviceProvider);
     return host.RunDocumentWizard(this._wizardType, instanceArguments);
 }
Ejemplo n.º 6
0
 protected override sealed object RunPlugin(object initializationData)
 {
     this._instanceArguments = (DocumentInstanceArguments) initializationData;
     return this.Run();
 }
Ejemplo n.º 7
0
 protected override void Dispose()
 {
     this._instanceArguments = null;
     base.Dispose();
 }