Example #1
0
        /// <summary>
        /// Saves the current settings of this object to the registry
        /// </summary>
        /// <returns></returns>
        public bool SaveSettings()
        {
            SnagItAutomation Snag = this;

            byte[] Buffer = null;

            if (!SerializationUtils.SerializeObject(Snag, out Buffer))
            {
                return(false);
            }

            RegistryKey SubKey = Registry.CurrentUser.OpenSubKey(REGISTRY_STORAGE_SUBKEY, true);

            if (SubKey == null)
            {
                SubKey = Registry.CurrentUser.CreateSubKey(REGISTRY_STORAGE_SUBKEY);
            }
            if (SubKey == null)
            {
                return(false);
            }

            SubKey.SetValue("ConfigData", Buffer, RegistryValueKind.Binary);
            SubKey.Close();

            return(true);
        }
Example #2
0
        /// <summary>
        /// Factory method that creates teh SnagItAutomation object by trying to read last capture settings
        /// from the registry.
        /// </summary>
        /// <returns></returns>
        public static SnagItAutomation Create()
        {
            byte[] Buffer = null;


            RegistryKey SubKey = Registry.CurrentUser.OpenSubKey(REGISTRY_STORAGE_SUBKEY);

            if (SubKey != null)
            {
                Buffer = SubKey.GetValue("ConfigData", null, RegistryValueOptions.None) as byte[];
            }


            if (Buffer == null)
            {
                return(new SnagItAutomation());
            }

            // Force Assembly resolving code to fire so we can load the assembly
            // from deserialization to avoid type load error
            AppDomain.CurrentDomain.AssemblyResolve +=
                new ResolveEventHandler(CurrentDomain_AssemblyResolve);

            SnagItAutomation SnagIt = SerializationUtils.DeSerializeObject(Buffer, typeof(SnagItAutomation)) as SnagItAutomation;

            // *** Unhook the event handler for the rest of the application
            AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(CurrentDomain_AssemblyResolve);

            if (SnagIt == null)
            {
                return(new SnagItAutomation());
            }

            return(SnagIt);
        }
Example #3
0
        public override DialogResult CreateContent(IWin32Window dialogOwner, ref string newContent)
        {
            DialogResult dr = DialogResult.OK;

            // *** Result Output file captured
            string OutputFile = null;

            try
            {
                SnagItAutomation SnagIt = SnagItAutomation.Create();
                SnagIt.ActiveForm = Form.ActiveForm;

                SnagItConfigurationForm ConfigForm = new SnagItConfigurationForm(SnagIt);
                if (ConfigForm.ShowDialog() == DialogResult.Cancel)
                {
                    return(DialogResult.Cancel);
                }

                OutputFile = SnagIt.CaptureImageToFile();

                SnagIt.SaveSettings();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to capture image:\r\n\r\n" + ex.Message,
                                "SnagIt Capture Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(DialogResult.Cancel);
            }

            // *** Just embed the image
            if (!string.IsNullOrEmpty(OutputFile))
            {
                newContent = @"<img src='file:///" + OutputFile + "'>\r\n";
            }

            return(dr);
        }
 public SnagItConfigurationForm(SnagItAutomation snagIt)
 {
     this.SnagIt = snagIt;
     InitializeComponent();
 }