コード例 #1
0
 /// <summary>
 /// Export the image from the tmpfile to the presentation with the supplied name
 /// </summary>
 /// <param name="presentationName">Name of the presentation to insert to</param>
 /// <param name="tmpFile">Filename of the image file to insert</param>
 /// <param name="imageSize">Size of the image</param>
 /// <param name="title">A string with the image title</param>
 /// <returns></returns>
 public static bool ExportToPresentation(string presentationName, string tmpFile, Size imageSize, string title)
 {
     using (IPowerpointApplication powerpointApplication = COMWrapper.GetInstance <IPowerpointApplication>()) {
         if (powerpointApplication != null)
         {
             LOG.DebugFormat("Open Presentations: {0}", powerpointApplication.Presentations.Count);
             for (int i = 1; i <= powerpointApplication.Presentations.Count; i++)
             {
                 IPresentation presentation = powerpointApplication.Presentations.item(i);
                 if (presentation != null && presentation.Name.StartsWith(presentationName))
                 {
                     try {
                         AddPictureToPresentation(presentation, tmpFile, imageSize, title);
                         return(true);
                     } catch (Exception e) {
                         LOG.Error(e);
                     }
                 }
             }
         }
     }
     return(false);
 }
コード例 #2
0
ファイル: OneNoteExporter.cs プロジェクト: zhk/greenshot
 /// <summary>
 /// Export the capture to the specified page
 /// </summary>
 /// <param name="surfaceToUpload">ISurface</param>
 /// <param name="page">OneNotePage</param>
 /// <returns>bool true if everything worked</returns>
 public static bool ExportToPage(ISurface surfaceToUpload, OneNotePage page)
 {
     using (IOneNoteApplication oneNoteApplication = COMWrapper.GetOrCreateInstance <IOneNoteApplication>()) {
         return(ExportToPage(oneNoteApplication, surfaceToUpload, page));
     }
 }
コード例 #3
0
ファイル: OneNoteExporter.cs プロジェクト: zhk/greenshot
        /// <summary>
        /// Get the captions of all the open word documents
        /// </summary>
        /// <returns></returns>
        public static List <OneNotePage> GetPages()
        {
            List <OneNotePage> pages = new List <OneNotePage>();

            try {
                using (IOneNoteApplication oneNoteApplication = COMWrapper.GetOrCreateInstance <IOneNoteApplication>()) {
                    if (oneNoteApplication != null)
                    {
                        // ReSharper disable once RedundantAssignment
                        string notebookXml = "";
                        oneNoteApplication.GetHierarchy("", HierarchyScope.hsPages, out notebookXml, XMLSchema.xs2010);
                        if (!string.IsNullOrEmpty(notebookXml))
                        {
                            Log.Debug(notebookXml);
                            StringReader reader = null;
                            try {
                                reader = new StringReader(notebookXml);
                                using (XmlTextReader xmlReader = new XmlTextReader(reader)) {
                                    reader = null;
                                    OneNoteSection  currentSection  = null;
                                    OneNoteNotebook currentNotebook = null;
                                    while (xmlReader.Read())
                                    {
                                        if ("one:Notebook".Equals(xmlReader.Name))
                                        {
                                            string id = xmlReader.GetAttribute("ID");
                                            if (id != null && (currentNotebook == null || !id.Equals(currentNotebook.ID)))
                                            {
                                                currentNotebook = new OneNoteNotebook
                                                {
                                                    ID   = xmlReader.GetAttribute("ID"),
                                                    Name = xmlReader.GetAttribute("name")
                                                };
                                            }
                                        }
                                        if ("one:Section".Equals(xmlReader.Name))
                                        {
                                            string id = xmlReader.GetAttribute("ID");
                                            if (id != null && (currentSection == null || !id.Equals(currentSection.ID)))
                                            {
                                                currentSection = new OneNoteSection
                                                {
                                                    ID     = xmlReader.GetAttribute("ID"),
                                                    Name   = xmlReader.GetAttribute("name"),
                                                    Parent = currentNotebook
                                                };
                                            }
                                        }
                                        if ("one:Page".Equals(xmlReader.Name))
                                        {
                                            // Skip deleted items
                                            if ("true".Equals(xmlReader.GetAttribute("isInRecycleBin")))
                                            {
                                                continue;
                                            }
                                            OneNotePage page = new OneNotePage
                                            {
                                                Parent = currentSection,
                                                Name   = xmlReader.GetAttribute("name"),
                                                ID     = xmlReader.GetAttribute("ID")
                                            };
                                            if (page.ID == null || page.Name == null)
                                            {
                                                continue;
                                            }
                                            page.IsCurrentlyViewed = "true".Equals(xmlReader.GetAttribute("isCurrentlyViewed"));
                                            pages.Add(page);
                                        }
                                    }
                                }
                            } finally
                            {
                                reader?.Dispose();
                            }
                        }
                    }
                }
            } catch (COMException cEx) {
                if (cEx.ErrorCode == unchecked ((int)0x8002801D))
                {
                    Log.Warn("Wrong registry keys, to solve this remove the OneNote key as described here: http://microsoftmercenary.com/wp/outlook-excel-interop-calls-breaking-solved/");
                }
                Log.Warn("Problem retrieving onenote destinations, ignoring: ", cEx);
            } catch (Exception ex) {
                Log.Warn("Problem retrieving onenote destinations, ignoring: ", ex);
            }
            pages.Sort(delegate(OneNotePage p1, OneNotePage p2) {
                if (p1.IsCurrentlyViewed || p2.IsCurrentlyViewed)
                {
                    return(p2.IsCurrentlyViewed.CompareTo(p1.IsCurrentlyViewed));
                }
                return(string.Compare(p1.DisplayName, p2.DisplayName, StringComparison.Ordinal));
            });
            return(pages);
        }
コード例 #4
0
 private static IWordApplication WordApplication()
 {
     return((IWordApplication)COMWrapper.GetOrCreateInstance(typeof(IWordApplication)));
 }
コード例 #5
0
 private static IPowerpointApplication PowerpointApplication()
 {
     return((IPowerpointApplication)COMWrapper.GetOrCreateInstance(typeof(IPowerpointApplication)));
 }
コード例 #6
0
 private static IExcelApplication ExcelApplication()
 {
     return((IExcelApplication)COMWrapper.GetOrCreateInstance(typeof(IExcelApplication)));
 }
コード例 #7
0
ファイル: test.cs プロジェクト: valerix120/Documenti
        public void Test()
        {
            const int numeroDocumenti = 1;
            const int numeroRighe     = 10;
            Stopwatch stopWatch       = new Stopwatch();

            stopWatch.Start();
            // INIZIALIZZO L'OGGETTO COM WRAPPER
            using (IVB6ComWrapper wrapper = COMWrapper.CreateInstance <IVB6ComWrapper>())
            {
                // ISTANZIO IL MOTORE DOCUMENTALE
                wrapper.Initialize("GAMMA", "GAMMANEXT8", "sa", "teamsystem", "GammaEnterprise", "TeamSa", "TeamSa", 1);

                wrapper.CreateCOMObject(REGDOC_PROGID, REGDOC_INSTANCE_KEY);
                wrapper.AssignSessionObject(REGDOC_INSTANCE_KEY, SessionObjectNames.ActiveInterface, "RegDocIn.ActiveInterface");
                wrapper.AssignSessionObject(REGDOC_INSTANCE_KEY, SessionObjectNames.Connection, "RegDocIn.Connection");
                wrapper.AssignSessionProperty(REGDOC_INSTANCE_KEY, SessionPropertyNames.ConnectionString, "RegDocIn.ConnectionString");

                object       comObject = wrapper.GetCOMObject(REGDOC_INSTANCE_KEY);
                CLSMG_REGDOC regdoc    = COMWrapper.Wrap <CLSMG_REGDOC>(comObject);

                Console.WriteLine("Wrapper inizializzato in {0}", stopWatch.Elapsed);
                stopWatch.Restart();
                // INIZIALIZZA
                using (CLSMG_REGDOCIN regdocin = COMWrapper.Wrap <CLSMG_REGDOCIN>(regdoc.RegDocIn))
                {
                    regdocin.Ditta           = 1;
                    regdocin.Documento       = "CLI-DDT";
                    regdocin.Avanzamento     = true;
                    regdocin.GestDocTestata  = true;
                    regdocin.GestDocTestaRif = true;
                    regdocin.GestDocTotali   = true;
                    regdocin.GestDocDatiAcc  = true;
                    regdocin.GestDocCorpo    = true;
                    regdocin.GestDocCorpoOrd = true;
                    regdocin.Transaction     = true;
                    // parametri per non far uscire le message box
                    regdocin.VuotiModalitaBatch = true;
                    regdocin.GestioneAssociazioneNotaCredito = true;
                    regdocin.BatchMode = false;
                }
                regdoc.Initialize();
                Console.WriteLine("RegDoc inizializzato in {0}", stopWatch.Elapsed);
                BeforeBeginTransactionEventHandler  beforeBeginTransaction  = REGDOC_BeforeBeginTransaction;
                AfterBeginTransactionEventHandler   afterBeginTransaction   = REGDOC_AfterBeginTransaction;
                BeforeCommitTransactionEventHandler beforeCommitTransaction = REGDOC_BeforeCommitTransaction;
                AfterCommitTransactionEventHandler  afterCommitTransaction  = REGDOC_AfterCommitTransaction;
                AvanzamentoEventHandler             avanzamento             = REGDOC_Avanzamento;
                ErrorsOccurredEventHandler          errors   = REGDOC_ErrorsOccurred;
                WarningOccurredEventHandler         warnings = REGDOC_WarningOccurred;

                regdoc.BeforeBeginTransaction  += beforeBeginTransaction;
                regdoc.AfterBeginTransaction   += afterBeginTransaction;
                regdoc.BeforeCommitTransaction += beforeCommitTransaction;
                regdoc.AfterCommitTransaction  += afterCommitTransaction;
                regdoc.Avanzamento             += avanzamento;
                regdoc.ErrorsOccurred          += errors;
                regdoc.WarningOccurred         += warnings;

                for (int indexTestata = 1; indexTestata <= numeroDocumenti; indexTestata++)
                {
                    Console.WriteLine("{0} - INIZIO SCRITTURA DOCUMENTI NR. {1}", DateTime.Now, indexTestata);

                    // APRO TUTTI I RECORDSET VUOTI
                    regdoc.OpenAllEmptyRecordsets();

                    // AGGIUNGO LA TESTATA CON TUTTI I DATI
                    regdoc.AddNewDocTestata(false, false, true);
                    regdoc.AddNewDocTestaRif();
                    regdoc.AddNewDocTotali();
                    regdoc.AddNewDocDatiAcc();
                    regdoc.CambiaDocTestataDataDoc(DateTime.Now.Date);
                    regdoc.CambiaDocTestataCliFor(1);

                    // CICLO PER AGGIUNGERE 10 RIGHE DI CORPO
                    for (int indexRighe = 1; indexRighe <= numeroRighe; indexRighe++)
                    {
                        regdoc.AddNewDocCorpo();
                        regdoc.CambiaDocCorpoCodart("A1", "", true, false, false);
                        regdoc.CambiaDocCorpoQta1(indexRighe);
                        regdoc.UpdateDocCorpo(false, true, false, false, true, true, false);
                    }

                    // CALCOLO I TOTALI DEL DOCUMENTO
                    //regdoc.RicalcolaTotaliDaRigheCorpo(true, true, true, true, false, false);
                    regdoc.UpdateDocTestata();

                    Console.WriteLine("{0} - FINE SCRITTURA DOCUMENTI NR. {1}", DateTime.Now, indexTestata);
                }

                regdoc.BeforeBeginTransaction  -= beforeBeginTransaction;
                regdoc.AfterBeginTransaction   -= afterBeginTransaction;
                regdoc.BeforeCommitTransaction -= beforeCommitTransaction;
                regdoc.AfterCommitTransaction  -= afterCommitTransaction;
                regdoc.Avanzamento             -= avanzamento;
                regdoc.ErrorsOccurred          -= errors;
                regdoc.WarningOccurred         -= warnings;

                wrapper.SetNothingInCOMObject(REGDOC_INSTANCE_KEY, "RegDocIn.ActiveInterface");
                wrapper.SetNothingInCOMObject(REGDOC_INSTANCE_KEY, "RegDocIn.Connection");
                wrapper.SetNothingInCOMObject(REGDOC_INSTANCE_KEY, "RegDocIn");

                regdoc.Terminate();

                regdoc.Dispose();
                regdoc    = null;
                comObject = null;

                wrapper.ReleaseCOMObject(REGDOC_INSTANCE_KEY);
                wrapper.Terminate();
            }
        }