Exemplo n.º 1
0
        /// <summary>
        /// Shows the dialog
        /// </summary>
        /// <param name="hWndOwner">Handle of the control to be parent</param>
        /// <returns>DialogResult.OK if user presses OK, else DialogResult.Cancel</returns>
        public DialogResult ShowDialog(IntPtr hWndOwner)
        {
            bool flag = false;

            if (Environment.OSVersion.Version.Major >= 6)
            {
                var r = new Reflector("System.Windows.Forms");

                uint num = 0;
                Type typeIFileDialog = r.GetType("FileDialogNative.IFileDialog");
                object dialog = r.Call(ofd, "CreateVistaDialog");
                r.Call(ofd, "OnBeforeVistaDialog", dialog);

                uint options = (uint)r.CallAs(typeof(System.Windows.Forms.FileDialog), ofd, "GetOptions");
                options |= (uint)r.GetEnum("FileDialogNative.FOS", "FOS_PICKFOLDERS");
                r.CallAs(typeIFileDialog, dialog, "SetOptions", options);

                object pfde = r.New("FileDialog.VistaDialogEvents", ofd);
                object[] parameters = new object[] { pfde, num };
                r.CallAs2(typeIFileDialog, dialog, "Advise", parameters);
                num = (uint)parameters[1];
                try
                {
                    int num2 = (int)r.CallAs(typeIFileDialog, dialog, "Show", hWndOwner);
                    flag = 0 == num2;
                }
                finally
                {
                    r.CallAs(typeIFileDialog, dialog, "Unadvise", num);
                    GC.KeepAlive(pfde);
                }
            }
            else
            {
                var fbd = new FolderBrowserDialog();
                fbd.Description = this.Title;
                fbd.SelectedPath = this.InitialDirectory;
                fbd.ShowNewFolderButton = false;
                if (fbd.ShowDialog(new WindowWrapper(hWndOwner)) != DialogResult.OK) return DialogResult.Cancel;
                ofd.FileName = fbd.SelectedPath;
                flag = true;
            }

            return flag ? DialogResult.OK : DialogResult.Cancel;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Shows the dialog</summary>
        /// <param name="owner">Control to be parent</param>
        /// <returns>True if the user presses OK else false</returns>
        public DialogResult ShowDialog(IWin32Window owner)
        {
            DialogResult result;

            if (Environment.OSVersion.Version.Major >= 6)
            {
                var r = new Reflector("System.Windows.Forms");

                uint num = 0;
                Type typeIFileDialog = r.GetType("FileDialogNative.IFileDialog");
                object dialog = r.Call(m_ofd, "CreateVistaDialog");
                r.Call(m_ofd, "OnBeforeVistaDialog", dialog);

                uint options = (uint)r.CallAs(typeof(FileDialog), m_ofd, "GetOptions");
                options |= (uint)r.GetEnum("FileDialogNative.FOS", "FOS_PICKFOLDERS");
                r.CallAs(typeIFileDialog, dialog, "SetOptions", options);

                object pfde = r.New("FileDialog.VistaDialogEvents", m_ofd);
                object[] parameters = new[] { pfde, num };
                r.CallAs2(typeIFileDialog, dialog, "Advise", parameters);
                num = (uint)parameters[1];
                try
                {
                    int num2 = (int)r.CallAs(typeIFileDialog, dialog, "Show", owner == null ? IntPtr.Zero : owner.Handle);
                    result = (0 == num2) ? DialogResult.OK : DialogResult.Cancel;
                }
                finally
                {
                    r.CallAs(typeIFileDialog, dialog, "Unadvise", num);
                    GC.KeepAlive(pfde);
                }
            }
            else
            {
                using (var fbd = new FolderBrowserDialog())
                {
                    fbd.Description = Description;
                    fbd.SelectedPath = InitialDirectory;
                    fbd.ShowNewFolderButton = false;
                    result = fbd.ShowDialog(owner);
                    if (result == DialogResult.OK)
                        m_ofd.FileName = fbd.SelectedPath;
                }
            }

            return result;
        }
Exemplo n.º 3
0
    // ========================================================================
    // Properties

    #region === Properties


    #endregion

    // ========================================================================
    // Methods

    #region === Methods

    /// <summary>
    /// The main entry point of this class. Imports the assembly which is given
    /// as the parameter.
    /// </summary>
    /// <param name="fileName">The file name and path of the assembly to import.</param>
    /// <returns><c>True</c>, if the import was successful.</returns>
    public bool ImportAssembly(string fileName)
    {
      if (string.IsNullOrEmpty(fileName))
      {
        MessageBox.Show(Strings.Error_NoAssembly, Strings.Error_MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
        return false;
      }
      try
      {
        diagram.Name = Path.GetFileName(fileName);
        diagram.RedrawSuspended = true;

        IncludeFilter includeFilter = new IncludeFilter();
        includeFilter.Rules.AddRange(settings.FilterRules);
        IFilter filter = includeFilter;
        if(!settings.UseAsWhiteList)
        {
          filter = new InvertFilter(includeFilter);
        }

        NClassImportFilter nClassImportFilter = new NClassImportFilter(filter);
        Reflector reflector = new Reflector();
        filter = nClassImportFilter;
        NRAssembly nrAssembly = reflector.Reflect(fileName, ref filter);
        nClassImportFilter = (NClassImportFilter)filter;

        AddInterfaces(nrAssembly.Interfaces);
        AddClasses(nrAssembly.Classes);
        AddStrcts(nrAssembly.Structs);
        AddDelegates(nrAssembly.Delegates);
        AddEnums(nrAssembly.Enums);

        ArrangeTypes();

        RelationshipCreator relationshipCreator = new RelationshipCreator();
        NRRelationships nrRelationships = relationshipCreator.CreateRelationships(nrAssembly, settings.CreateNestings,
                                                                                  settings.CreateGeneralizations,
                                                                                  settings.CreateRealizations,
                                                                                  settings.CreateAssociations);
        AddRelationships(nrRelationships);

        if(nClassImportFilter.UnsafeTypesPresent)
        {
          MessageBox.Show(null, Strings.UnsafeTypesPresent, Strings.WarningTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }
      }
      catch (ReflectionTypeLoadException)
      {
        MessageBox.Show(Strings.Error_MissingReferencedAssemblies, Strings.Error_MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
        return false;
      }
      catch (FileLoadException)
      {
        MessageBox.Show(Strings.Error_MissingReferencedAssemblies, Strings.Error_MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
        return false;
      }
      catch (BadImageFormatException)
      {
        MessageBox.Show(Strings.Error_BadImageFormat, Strings.Error_MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
        return false;
      }
      catch (Exception ex)
      {
        MessageBox.Show(String.Format(Strings.Error_GeneralException, ex), Strings.Error_MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
        return false;
      }
      finally
      {
        diagram.RedrawSuspended = false;
      }

      return true;
    }