Exemple #1
0
        // ProcessArguments() will process the command-line arguments
        // of this application.
        // If the return value is true, we carry
        // on and start this application.
        // If the return value is false, we terminate
        // this application immediately.
        public bool ProcessStartupArguments(params string[] args)
        {
            bool bRet = true;

            if (args.Length > 0)
            {
                switch (args[0].ToLower())
                {
                case "-embedding":
                    ApplicationWasStartedWithEmbeddingArg = true;
                    break;

                case "-register":
                case "/register":
                    RegisterApplicationForCom();
                    break;

                case "-unregister":
                case "/unregister":
                    UnregisterApplicationForCom();
                    break;

                default:
                    ComDebug.ReportError("Unknown argument: " + args[0] + "\nValid are : -register, -unregister and -embedding");
                    break;
                }
            }

            ComDebug.ReportInfo("{0}.ProcessArguments Embedding={1} IsRunning64bit={2}", GetType().Name, ApplicationWasStartedWithEmbeddingArg, System.Environment.Is64BitProcess);

            return(bRet);
        }
Exemple #2
0
        public int DAdvise(ref FORMATETC pFormatetc, ADVF advf, IAdviseSink adviseSink, out int connection)
        {
            if (null == DataAdviseHolder)
            {
                ComDebug.ReportInfo("{0}.IDataObject.DAdvise -> not implemented!", GetType().Name);
                connection = 0;
                return(ComReturnValue.E_NOTIMPL);
            }
            else
            {
                ComDebug.ReportInfo("{0}.IDataObject.DAdvise {1}, {2}", GetType().Name, DataObjectHelper.FormatEtcToString(pFormatetc), advf);

                try
                {
                    if (pFormatetc.cfFormat != 0)               // if a special format is required
                    {
                        int res = QueryGetData(ref pFormatetc); // ask the render helper for availability of that format
                        if (res != ComReturnValue.S_OK)         // if the required format is not available
                        {
                            connection = 0;                     //  return an invalid connection cookie
                            return(res);                        // and the error
                        }
                    }
                    FORMATETC etc = pFormatetc;
                    DataAdviseHolder.Advise((IDataObject)this, ref etc, advf, adviseSink, out var conn);
                    connection = conn;
                    return(ComReturnValue.NOERROR);
                }
                catch (Exception e)
                {
                    ComDebug.ReportError("{0}.IDataObject.DAdvise exception: {1}", GetType().Name, e);
                    throw;
                }
            }
        }
Exemple #3
0
 public void SetData(ref FORMATETC formatIn, ref STGMEDIUM medium, bool release)
 {
     ComDebug.ReportError("{0}.IDataObject.SetData - NOT SUPPORTED!", GetType().Name);
     if (!System.Diagnostics.Debugger.IsAttached)
     {
         throw new NotSupportedException();
     }
 }
Exemple #4
0
        public static void InternalSaveMiniProject(IStorage pStgSave, AltaxoDocument projectToSave, string graphDocumentName)
        {
            ComDebug.ReportInfo("GraphDocumentDataObject.InternalSaveMiniProject BEGIN");

            try
            {
                Exception saveEx = null;
                Ole32Func.WriteClassStg(pStgSave, typeof(GraphDocumentEmbeddedComObject).GUID);

                // Store the version of this assembly
                {
                    var     assembly = System.Reflection.Assembly.GetExecutingAssembly();
                    Version version  = assembly.GetName().Version;
                    using (var stream = new ComStreamWrapper(pStgSave.CreateStream("AltaxoVersion", (int)(STGM.DIRECT | STGM.READWRITE | STGM.CREATE | STGM.SHARE_EXCLUSIVE), 0, 0), true))
                    {
                        string text      = version.ToString();
                        byte[] nameBytes = System.Text.Encoding.UTF8.GetBytes(text);
                        stream.Write(nameBytes, 0, nameBytes.Length);
                    }
                }

                // Store the name of the item
                using (var stream = new ComStreamWrapper(pStgSave.CreateStream("AltaxoGraphName", (int)(STGM.DIRECT | STGM.READWRITE | STGM.CREATE | STGM.SHARE_EXCLUSIVE), 0, 0), true))
                {
                    byte[] nameBytes = System.Text.Encoding.UTF8.GetBytes(graphDocumentName);
                    stream.Write(nameBytes, 0, nameBytes.Length);
                }

                // Store the project
                using (var stream = new ComStreamWrapper(pStgSave.CreateStream("AltaxoProjectZip", (int)(STGM.DIRECT | STGM.READWRITE | STGM.CREATE | STGM.SHARE_EXCLUSIVE), 0, 0), true))
                {
                    using (var zippedStream = new System.IO.Compression.ZipArchive(stream, System.IO.Compression.ZipArchiveMode.Create))
                    {
                        var info = new Altaxo.Serialization.Xml.XmlStreamSerializationInfo();
                        projectToSave.SaveToZippedFile(zippedStream, info);
                    }
                    stream.Close();
                }

                if (null != saveEx)
                {
                    throw saveEx;
                }
            }
            catch (Exception ex)
            {
                ComDebug.ReportError("InternalSaveMiniProject, Exception ", ex);
            }
            finally
            {
                Marshal.ReleaseComObject(pStgSave);
            }

            ComDebug.ReportInfo("GraphDocumentDataObject.InternalSaveMiniProject END");
        }
Exemple #5
0
        public void Save(IStorage pStgSave, bool fSameAsLoad)
        {
            ComDebug.ReportInfo("{0}.IPersistStorage.Save fSameAsLoad={1}", GetType().Name, fSameAsLoad);

            try
            {
                Exception saveEx = null;
                Ole32Func.WriteClassStg(pStgSave, GetType().GUID);

                // Store the version of this assembly
                {
                    var     assembly = System.Reflection.Assembly.GetExecutingAssembly();
                    Version version  = assembly.GetName().Version;
                    using (var stream = new ComStreamWrapper(pStgSave.CreateStream("AltaxoVersion", (int)(STGM.DIRECT | STGM.READWRITE | STGM.CREATE | STGM.SHARE_EXCLUSIVE), 0, 0), true))
                    {
                        string text      = version.ToString();
                        byte[] nameBytes = System.Text.Encoding.UTF8.GetBytes(text);
                        stream.Write(nameBytes, 0, nameBytes.Length);
                    }
                }

                // Store the name of the item
                using (var stream = new ComStreamWrapper(pStgSave.CreateStream("AltaxoGraphName", (int)(STGM.DIRECT | STGM.READWRITE | STGM.CREATE | STGM.SHARE_EXCLUSIVE), 0, 0), true))
                {
                    byte[] nameBytes = System.Text.Encoding.UTF8.GetBytes(_document.Name);
                    stream.Write(nameBytes, 0, nameBytes.Length);
                }

                // Store the project
                using (var stream = new ComStreamWrapper(pStgSave.CreateStream("AltaxoProjectZip", (int)(STGM.DIRECT | STGM.READWRITE | STGM.CREATE | STGM.SHARE_EXCLUSIVE), 0, 0), true))
                {
                    _comManager.InvokeGuiThread(() =>
                    {
                        saveEx = Current.IProjectService.SaveProject(stream);
                    }
                                                );
                }

                _isDocumentDirty = false;

                if (null != saveEx)
                {
                    throw saveEx;
                }
            }
            catch (Exception ex)
            {
                ComDebug.ReportError("{0}.IPersistStorage:Save threw an exception: {1}", GetType().Name, ex);
            }
            finally
            {
                Marshal.ReleaseComObject(pStgSave);
            }
        }
Exemple #6
0
 public int Unadvise(int dwConnection)
 {
     ComDebug.ReportInfo("{0}.IOleObject.Unadvise", GetType().Name);
     try
     {
         _oleAdviseHolder.Unadvise(dwConnection);
         return(ComReturnValue.NOERROR);
     }
     catch (Exception e)
     {
         ComDebug.ReportError("{0}.IOleObject.Unadvise threw an exception: {0}", GetType().Name, e);
         throw;
     }
 }
Exemple #7
0
 public int Advise(System.Runtime.InteropServices.ComTypes.IAdviseSink pAdvSink, out int cookie)
 {
     ComDebug.ReportInfo("{0}.IOleObject.Advise", GetType().Name);
     try
     {
         _oleAdviseHolder.Advise(pAdvSink, out cookie);
         return(ComReturnValue.NOERROR);
     }
     catch (Exception e)
     {
         ComDebug.ReportError("{0}.IOleObject.Advise caused an exception: {1}", GetType().Name, e);
         throw;
     }
 }
Exemple #8
0
 /// <summary>
 /// Notifies a container when an embedded object's window is about to become invisible.
 /// The container uses this information to remove the shading when the object is not visible any more.
 /// </summary>
 public virtual void SendAdvise_HideWindow()
 {
     ComDebug.ReportInfo("{0}.SendAdvise.HideWindow -> Calling IOleClientSite.OnShowWindow(false)", GetType().Name);
     try
     {
         if (null != _clientSite)
         {
             _clientSite.OnShowWindow(false);
         }
     }
     catch (Exception ex)
     {
         ComDebug.ReportError("{0}.SendAdvise.HideWindow -> Exception while calling _clientSite.OnShowWindow(false), Details: {0}", GetType().Name, ex.Message);
     }
 }
Exemple #9
0
 public void GetDataHere(ref System.Runtime.InteropServices.ComTypes.FORMATETC format, ref System.Runtime.InteropServices.ComTypes.STGMEDIUM medium)
 {
     ComDebug.ReportInfo("{0}.IDataObject.GetDataHere({1})", GetType().Name, DataObjectHelper.ClipboardFormatName(format.cfFormat));
     // Allows containers to duplicate this into their own storage.
     try
     {
         if (InternalGetDataHere(ref format, ref medium))
         {
             return; // data could be provided
         }
     }
     catch (Exception e)
     {
         ComDebug.ReportError("{0}.IDataObject.GetDataHere threw an exception: {1}", GetType().Name, e);
         throw;
     }
     Marshal.ThrowExceptionForHR(ComReturnValue.DATA_E_FORMATETC);
 }
Exemple #10
0
        public void GetData(ref FORMATETC format, out STGMEDIUM medium)
        {
            ComDebug.ReportInfo("{0}.IDataObject.GetData({1})", GetType().Name, DataObjectHelper.FormatEtcToString(format));

            try
            {
                // Locate the data
                foreach (var rendering in Renderings)
                {
                    if ((rendering.format.tymed & format.tymed) > 0 &&
                        rendering.format.dwAspect == format.dwAspect &&
                        rendering.format.cfFormat == format.cfFormat &&
                        rendering.renderer != null)
                    {
                        // Found it. Return a copy of the data.

                        medium = new STGMEDIUM
                        {
                            tymed = rendering.format.tymed & format.tymed
                        };
                        medium.unionmember = rendering.renderer(medium.tymed);
                        if (medium.tymed == TYMED.TYMED_ISTORAGE || medium.tymed == TYMED.TYMED_ISTREAM)
                        {
                            medium.pUnkForRelease = Marshal.GetObjectForIUnknown(medium.unionmember);
                        }
                        else
                        {
                            medium.pUnkForRelease = null;
                        }
                        return;
                    }
                }
            }
            catch (Exception e)
            {
                ComDebug.ReportError("{0}.IDataObject.GetData threw an exception {1}", GetType().Name, e);
                throw;
            }

            ComDebug.ReportInfo("{0}.IDataObject.GetData, no data delivered!", GetType().Name);
            medium = new STGMEDIUM();
            // Marshal.ThrowExceptionForHR(ComReturnValue.DV_E_FORMATETC);
        }
Exemple #11
0
        public IEnumFORMATETC EnumFormatEtc(DATADIR direction)
        {
            ComDebug.ReportInfo("{0}.IDataObject.EnumFormatEtc", GetType().Name);
            try
            {
                // We only support GET
                if (DATADIR.DATADIR_GET == direction)
                {
                    return(new EnumFormatEtc(new List <FORMATETC>(Renderings.Select(x => x.format))));
                }
            }
            catch (Exception e)
            {
                ComDebug.ReportError("{0}.IDataObject.EnumFormatEtc exception: {1}", GetType().Name, e);
                throw;
            }

            throw new NotImplementedException("Can not use registry here because a return value is not supported");
        }
Exemple #12
0
 public void DUnadvise(int connection)
 {
     if (null == DataAdviseHolder)
     {
         ComDebug.ReportInfo("{0}.IDataObject.DUnadvise connection={1} -> not implemented!", GetType().Name, connection);
         return;
     }
     else
     {
         ComDebug.ReportInfo("{0}.IDataObject.DUnadvise connection={1}", GetType().Name, connection);
         try
         {
             DataAdviseHolder.Unadvise(connection);
         }
         catch (Exception e)
         {
             ComDebug.ReportError("{0}.IDataObject.DUnadvise exception {1}", GetType().Name, e);
             throw;
         }
     }
 }
Exemple #13
0
        public int DoVerb(int iVerb, IntPtr lpmsg, IOleClientSite pActiveSite, int lindex, IntPtr hwndParent, COMRECT lprcPosRect)
        {
            ComDebug.ReportInfo("{0}.IOleObject.DoVerb {1}", GetType().Name, iVerb);
            try
            {
                // I saw OLEIVERB_HIDE come in as 253.  Perhaps a unsigned
                // byte conversion happening somewhere.
                if (iVerb >= 250 && iVerb <= 255)
                {
                    int new_iverb = iVerb - 256;
                    ComDebug.ReportWarning("{0}.IOleObject.DoVerb -> Fixing iVerb: {1} -> {2}", GetType().Name, iVerb, new_iverb);
                    iVerb = new_iverb;
                }

                _lastVerb = iVerb;

                switch (iVerb)
                {
                case (int)OLEIVERB.OLEIVERB_HIDE:
                    ComDebug.ReportInfo("{0}.IOleObject.DoVerb OLEIVERB_HIDE", GetType().Name);
                    _comManager.ApplicationAdapter.HideMainWindow();
                    SendAdvise_HideWindow();
                    break;

                case (int)OLEIVERB.OLEIVERB_PRIMARY:
                case (int)OLEIVERB.OLEIVERB_SHOW:
                case (int)OLEIVERB.OLEIVERB_OPEN:

                    if ((int)OLEIVERB.OLEIVERB_PRIMARY == iVerb)
                    {
                        ComDebug.ReportInfo("{0}.IOleObject.DoVerb OLEIVERB_PRIMARY", GetType().Name);
                    }
                    if ((int)OLEIVERB.OLEIVERB_SHOW == iVerb)
                    {
                        ComDebug.ReportInfo("{0}.IOleObject.DoVerb OLEIVERB_SHOW", GetType().Name);
                    }
                    if ((int)OLEIVERB.OLEIVERB_OPEN == iVerb)
                    {
                        ComDebug.ReportInfo("{0}.IOleObject.DoVerb OLEIVERB_OPEN", GetType().Name);
                    }
                    _comManager.ApplicationAdapter.ShowMainWindow();
                    if (pActiveSite != null)
                    {
                        ComDebug.ReportInfo("{0}.IOleObject.DoVerb -> calling ClientSite.ShowObject()", GetType().Name);
                        try
                        {
                            pActiveSite.ShowObject();
                        }
                        catch (Exception ex)
                        {
                            ComDebug.ReportInfo("{0}.IOleObject.DoVerb pActiveSite.ShowObject caused an exception: {1}", GetType().Name, ex);
                        }

                        SendAdvise_ShowWindow();
                    }

                    return(ComReturnValue.NOERROR);

                default:
                    ComDebug.ReportError("{0}.IOleObject.DoVerb Unexpected verb: {1}", GetType().Name, iVerb);
                    return(ComReturnValue.OLEOBJ_S_INVALIDVERB);
                }
                ComDebug.ReportInfo("{0}.IOleObject.DoVerb -> returning NOERROR", GetType().Name);
                return(ComReturnValue.NOERROR);
            }
            catch (Exception e)
            {
                ComDebug.ReportError("{0}.IOleObject.DoVerb throw an exception. Details: {1}", GetType().Name, e);
                throw;
            }
        }
Exemple #14
0
        public int Close(tagOLECLOSE dwSaveOption)
        {
            ComDebug.ReportInfo("{0}.IOleObject.Close {1}", GetType().Name, dwSaveOption);
            try
            {
                bool save = false, cancelled = false;

                switch (dwSaveOption)
                {
                case tagOLECLOSE.OLECLOSE_SAVEIFDIRTY:
                    save = true;
                    break;

                case tagOLECLOSE.OLECLOSE_PROMPTSAVE:
                    _comManager.InvokeGuiThread(
                        new Action(() =>
                    {
                        // If asked to prompt, do so only if dirty: if we get a YES, save as
                        // usual and close.  On NO, just close.  On CANCEL, return
                        // OLE_E_PROMPTSAVECANCELLED.
                        var r = System.Windows.MessageBox.Show("Save?", "Box", System.Windows.MessageBoxButton.YesNoCancel);
                        switch (r)
                        {
                        case System.Windows.MessageBoxResult.Yes:
                            save = true;
                            break;

                        case System.Windows.MessageBoxResult.Cancel:
                            cancelled = true;
                            break;
                        }
                    }));
                    break;

                case tagOLECLOSE.OLECLOSE_NOSAVE:
                    break;

                default:
                    ComDebug.ReportError("{0}.IOleObject.Close called with unknown parameter: {1}", GetType().Name, dwSaveOption);
                    break;
                }

                if (cancelled)
                {
                    ComDebug.ReportInfo("{0}.IOleObject.Close -> OLE_E_PROMPTSAVECANCELLED", GetType().Name);
                    return(ComReturnValue.OLE_E_PROMPTSAVECANCELLED);
                }

                if (save)
                {
                    SendAdvise_SaveObject();
                    SendAdvise_Saved();
                }

                // Regardless of whether the form has been shown we must
                // do all the normal shutdown actions.  (e.g. WinWord 2007)
                ComDebug.ReportInfo("{0}.IOleObject.Close -> BeginInvoke MainWindow.Close", GetType().Name);
                _comManager.ApplicationAdapter.BeginClosingApplication();
                return(ComReturnValue.NOERROR);
            }
            catch (Exception e)
            {
                ComDebug.ReportError("{0}.IOleObject.Close threw an exception: {1}", GetType().Name, e);
                throw;
            }
            // }
        }
Exemple #15
0
        public int Load(IStorage pstg)
        {
            if (!(null == _document))
            {
                throw new InvalidOperationException(nameof(_document) + " should be null");
            }

            string  documentName = null;
            Version altaxoVersion;

            ComDebug.ReportInfo("{0}.IPersistStorage.Load", GetType().Name);

            try
            {
                using (var stream = new ComStreamWrapper(pstg.OpenStream("AltaxoVersion", IntPtr.Zero, (int)(STGM.READ | STGM.SHARE_EXCLUSIVE), 0), true))
                {
                    var bytes = new byte[stream.Length];
                    stream.Read(bytes, 0, bytes.Length);
                    var versionString = System.Text.Encoding.UTF8.GetString(bytes);
                    altaxoVersion = Version.Parse(versionString);
                }
                ComDebug.ReportInfo("{0}.IPersistStorage.Load -> Version: {1}", GetType().Name, altaxoVersion);
            }
            catch (Exception ex)
            {
                ComDebug.ReportInfo("{0}.IPersistStorage.Load Failed to load stream AltaxoVersion, exception: {1}", GetType().Name, ex);
            }

            try
            {
                using (var stream = new ComStreamWrapper(pstg.OpenStream("AltaxoGraphName", IntPtr.Zero, (int)(STGM.READ | STGM.SHARE_EXCLUSIVE), 0), true))
                {
                    var bytes = new byte[stream.Length];
                    stream.Read(bytes, 0, bytes.Length);
                    documentName = System.Text.Encoding.UTF8.GetString(bytes);
                }
                ComDebug.ReportInfo("{0}.IPersistStorage.Load -> Name of GraphDocument: {1}", GetType().Name, documentName);
            }
            catch (Exception ex)
            {
                ComDebug.ReportInfo("{0}.IPersistStorage.Load Failed to load stream AltaxoGraphName, exception: {1}", GetType().Name, ex);
            }

            try
            {
                Exception exInner    = null;
                string    loadErrors = null;

                using (var streamWrapper = new ComStreamWrapper(pstg.OpenStream("AltaxoProjectZip", IntPtr.Zero, (int)(STGM.READ | STGM.SHARE_EXCLUSIVE), 0), true))
                {
                    _comManager.InvokeGuiThread(() =>
                    {
                        try
                        {
                            Current.IProjectService.CloseProject(true);
                            loadErrors = Current.IProjectService.LoadProjectFromStream(streamWrapper);
                        }
                        catch (Exception ex)
                        {
                            exInner = ex;
                        }
                    });
                }
                if (null != exInner)
                {
                    throw exInner;
                }

                if (!string.IsNullOrEmpty(loadErrors))
                {
                    ComDebug.ReportInfo("{0}.IPersistStorage.Load Project loaded with errors: {1}", GetType().Name, loadErrors);
                }
                else
                {
                    ComDebug.ReportInfo("{0}.IPersistStorage.Load Project loaded successfully", GetType().Name);
                }
            }
            catch (Exception ex)
            {
                ComDebug.ReportInfo("{0}.IPersistStorage.Load Failed to load stream AltaxoProjectZip, exception: {1}", GetType().Name, ex);
            }

            Marshal.ReleaseComObject(pstg);

            Altaxo.Graph.GraphDocumentBase newDocument = null;

            if (null != documentName)
            {
                if (Current.Project.GraphDocumentCollection.TryGetValue(documentName, out var newDocGdi))
                {
                    newDocument = newDocGdi;
                }
                else if (Current.Project.Graph3DDocumentCollection.TryGetValue(documentName, out var newDoc3D))
                {
                    newDocument = newDoc3D;
                }
            }

            if (null == newDocument)
            {
                if (null != Current.Project.GraphDocumentCollection.FirstOrDefault())
                {
                    newDocument = Current.Project.GraphDocumentCollection.First();
                }
                else if (null != Current.Project.Graph3DDocumentCollection.FirstOrDefault())
                {
                    newDocument = Current.Project.Graph3DDocumentCollection.First();
                }
            }

            if (null != newDocument)
            {
                Document = newDocument;
                _comManager.InvokeGuiThread(() => Current.IProjectService.ShowDocumentView(Document));
                ComDebug.ReportInfo("{0}.IPersistStorage.Load ShowDocumentView for {1}", GetType().Name, Document.Name);
            }

            if (null == Document)
            {
                ComDebug.ReportError("{0}.IPersistStorage.Load Document is null, have to throw an exception now!!", GetType().Name);
                throw new InvalidOperationException();
            }

            _isDocumentDirty = false;
            return(ComReturnValue.S_OK);
        }
Exemple #16
0
 public int ParseDisplayName(IBindCtx pbc, string pszDisplayName, out int pchEaten, out IMoniker ppmkOut)
 {
     ComDebug.ReportError("{0}.ParseDisplayName -> not implemented!", GetType().Name);
     throw new NotImplementedException();
 }