Example #1
0
        public void WordFindAndReplaceTestMultiply()
        {
            var apiKey = new Dictionary <string, string>()
            {
                { "AppSecret", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" },
                { "AppId", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" }
            };

            var config = new Configuration(apiKey: apiKey);

            config.ApiClient = new ApiClient(config);

            var word = new WordApi(config);

            word.WordFindAndReplace("letterlegal5.doc", "letterlegal5_replace2.doc", new List <string> {
                "1", "2"
            }, new List <string> {
                "!", "!"
            });

            var file   = new FileApi(config);
            var result = file.FileList();

            Assert.IsTrue(result.Contains("letterlegal5_replace2.doc"));
        }
Example #2
0
 /// <summary>
 /// Try to detect the main window handle for a document instance
 /// </summary>
 /// <param name="document">target document instance</param>
 /// <returns>main window handle or 0 if failed</returns>
 public int TryGetMainWindowHandle(WordApi.Document document)
 {
     if (null == document)
         throw new ArgumentNullException("document");
     int hwnd = TryGetHostApplicationWindowHandle(document);
     return hwnd;
 }
Example #3
0
        /// <summary>
        /// Try to detect the associated main window from a document has an expanded ribbon ui
        /// </summary>
        /// <param name="document">target document</param>
        /// <param name="throwExceptionIfFailed">throw exception if its failed to detect, otherwise returns false</param>
        /// <returns>true if ribbon is expanded, otherwise false</returns>
        public bool TryGetRibbonIsExpanded(WordApi.Document document, bool throwExceptionIfFailed)
        {
            if (null == document)
                throw new ArgumentNullException("document");
            int handle = TryGetMainWindowHandle(document);
            if (handle <= 0)
            {
                if (throwExceptionIfFailed)
                    throw new NetRuntimeSystem.ComponentModel.Win32Exception();
                else
                    return false;                
            }

            NetOffice.Tools.WndUtils.ChildWindowEnumerator childEnumerator = new NetOffice.Tools.WndUtils.ChildWindowEnumerator(new IntPtr(handle), "Ribbon");
            IntPtr[] handles = childEnumerator.EnumerateWindows(2000);
            if (null != handles && handles.Length > 0)
            {
                NetRuntimeSystem.Drawing.Rectangle rect = NetOffice.Tools.WndUtils.WindowEnumerator.GetWindowRect(handles[0]);
                return rect.Height >= _ribbonHeightExpandedLimit;
            }
            else
            {
                if (throwExceptionIfFailed)
                    throw new NetRuntimeSystem.Runtime.InteropServices.ExternalException();
                else
                    return false;                
            }
        }
        public void ConvertToPdf(Configuration config, string resultFileName, string fileType, string format, int count)
        {
            var    WordApi       = new WordApi(config);
            Stream file          = new FileStream(resultFileName, FileMode.Open, FileAccess.ReadWrite);
            Stream outFileStream = new FileStream("C:/docconversion/" + resultFileName + "_Metric.txt", FileMode.OpenOrCreate, FileAccess.Write);

            var outFile = new StreamWriter(outFileStream);
            var timer   = new Stopwatch();

            for (var i = 0; i < count; i++)
            {
                file.Seek(0, SeekOrigin.Begin);
                var response = WordApi.WordConvertPostWithHttpInfo("ConvDocFile_" + i + ".docx", "PDF", file);
                if (response.StatusCode >= 200 && response.StatusCode <= 205)
                {
                    var pdfResponse = WordApi.WordConvertToPDFWithHttpInfo("ConvDocFile_" + i + ".docx", "ConvDocFile_" + i + ".pdf");
                    if (pdfResponse.Data != null && pdfResponse.StatusCode >= 200 && pdfResponse.StatusCode <= 205)
                    {
                        outFile.WriteLine(response.Data + "\n");
                    }
                    Console.WriteLine("File " + i + " upload success!");
                }
                else
                {
                    Console.WriteLine("File upload failed!");
                }
            }
            file.Close();
            outFile.Close();
        }
Example #5
0
        /// <summary>
        /// Creates an instance of the application
        /// </summary>
        /// <param name="application">owner application</param>
        /// <param name="ownerAssembly">owner assembly</param>
        public CommonUtils(WordApi.Application application, Assembly ownerAssembly)
            : base(application, ownerAssembly)
        {
            if (null == application)
                throw new ArgumentNullException("application");

            _ownerApplication = application;
        }
Example #6
0
        public void WordConvertToPDFTest()
        {
            var apiKey = new Dictionary <string, string>()
            {
                { "AppSecret", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" },
                { "AppId", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" }
            };

            var config = new Configuration(apiKey: apiKey);

            config.ApiClient = new ApiClient(config);

            var word   = new WordApi(config);
            var result = word.WordConvertToPDF("letterlegal5.doc", "letterlegal5.pdf");

            Assert.IsTrue(result.Contains("letterlegal5"));
        }
Example #7
0
        public void WordThumbnailTestRange()
        {
            var apiKey = new Dictionary <string, string>()
            {
                { "AppSecret", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" },
                { "AppId", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" }
            };

            var config = new Configuration(apiKey: apiKey);

            config.ApiClient = new ApiClient(config);

            var word   = new WordApi(config);
            var result = word.WordThumbnail("letterlegal5.doc", startPageNumber: 1, endPageNumber: 2);

            Assert.AreEqual(2, result.Count());
        }
Example #8
0
        public void WordGetDocumentPropertiesTest()
        {
            var apiKey = new Dictionary <string, string>()
            {
                { "AppSecret", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" },
                { "AppId", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" }
            };

            var config = new Configuration(apiKey: apiKey);

            config.ApiClient = new ApiClient(config);

            var word   = new WordApi(config);
            var result = word.WordGetDocumentProperties("letterlegal5.doc");

            Assert.AreEqual("Sample document created with MS Word", result["Title"]);
        }
Example #9
0
        public void WordPageWordCountTest()
        {
            var apiKey = new Dictionary <string, string>()
            {
                { "AppSecret", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" },
                { "AppId", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" }
            };

            var config = new Configuration(apiKey: apiKey);

            config.ApiClient = new ApiClient(config);

            var word   = new WordApi(config);
            var result = word.WordPageWordCount("letterlegal5.doc", 1);

            Assert.AreEqual(94, result);
        }
Example #10
0
        public void Start()
        {
            var apiClient = new ApiClient(WebApi);
            var signer    = new AuthSigner(BotKey);

            _userApi    = new UserApi(apiClient, signer);
            _wordApi    = new WordApi(apiClient);
            _serviceApi = new ServiceApi(apiClient);
            _folderApi  = new FolderApi(apiClient);

            _userApi.LoginUser(new ApiUser {
                Id = AdminId
            });
            _restWordRepository = new RestWordRepository(_wordApi, _userApi, _serviceApi, _folderApi);

            _testWords         = GetTestWords();
            _testWordFileBytes = GetTestWordFileBytes();

            FillDb();
        }
Example #11
0
        public void WordTextWatermarkTest()
        {
            var apiKey = new Dictionary <string, string>()
            {
                { "AppSecret", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" },
                { "AppId", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" }
            };

            var config = new Configuration(apiKey: apiKey);

            config.ApiClient = new ApiClient(config);

            var word = new WordApi(config);

            word.WordTextWatermark("letterlegal5.doc", "letterlegal5_watermark.doc", "Hello World");

            var file   = new FileApi(config);
            var result = file.FileList();

            Assert.IsTrue(result.Contains("letterlegal5_watermark.doc"));
        }
Example #12
0
        public void WordMailMergeTest()
        {
            var apiKey = new Dictionary <string, string>()
            {
                { "AppSecret", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" },
                { "AppId", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" }
            };

            var config = new Configuration(apiKey: apiKey);

            config.ApiClient = new ApiClient(config);

            var word = new WordApi(config);

            word.WordMailMerge("template1.docx", "mailmerge.docx", "source3.txt");

            var file   = new FileApi(config);
            var result = file.FileList();

            Assert.IsTrue(result.Contains("source3.txt"));
        }
        public void PdfViewer(Configuration config, string sourceFileName, string sourceFileType, string resultFileName, string resultfileType, int offset, int count)
        {
            var WordApi = new WordApi(config);

            if (!Directory.Exists(ConfigurationManager.AppSettings["SourcePath"] + "metrics/"))
            {
                Directory.CreateDirectory(ConfigurationManager.AppSettings["SourcePath"] + "metrics/");
            }

            Stream outFileStream = new FileStream(ConfigurationManager.AppSettings["SourcePath"] + "metrics/" + resultFileName + "_" + resultfileType + "_" + offset / count + "_Metric.txt", FileMode.OpenOrCreate, FileAccess.Write);

            var outFile = new StreamWriter(outFileStream);
            var timer   = new Stopwatch();

            for (var i = offset; i < offset + count; i++)
            {
                var response = WordApi.WordConvertToPDFWithHttpInfo(Path.GetFileNameWithoutExtension(sourceFileName) + /*"_" + i +*/ Path.GetExtension(sourceFileName) + sourceFileType, Path.GetFileNameWithoutExtension(resultFileName) + "_" + i + Path.GetExtension(resultFileName) + resultfileType);
                if (response.StatusCode >= 200 && response.StatusCode <= 205)
                {
                    //var pdfResponse = WordApi.WordConvertToPDFWithHttpInfo(sourceFileName + "_" + i + "." + sourceFileType, resultFileName + "_" + i + "." + resultfileType);
                    if (response.Data != null && response.StatusCode >= 200 && response.StatusCode <= 205)
                    {
                        var data = response.Data.Replace("\"", "");
                        outFile.WriteLine(data + "\n\n");
                        Console.WriteLine(sourceFileName + "_" + i + "." + sourceFileType + " view success!");
                    }
                    else
                    {
                        outFile.WriteLine(sourceFileName + "_" + i + "." + sourceFileType + " view failed!");
                        Console.WriteLine(sourceFileName + "_" + i + "." + sourceFileType + " view failed!");
                    }
                }
                else
                {
                    Console.WriteLine("File view failed!");
                }
            }
            Console.WriteLine("\n\nAll " + sourceFileType + " files converted successfully!");
            outFile.Close();
        }
Example #14
0
        public void WordSetDocumentPropertiesTest()
        {
            var apiKey = new Dictionary <string, string>()
            {
                { "AppSecret", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" },
                { "AppId", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" }
            };

            var config = new Configuration(apiKey: apiKey);

            config.ApiClient = new ApiClient(config);

            var word = new WordApi(config);
            var prop = new Properties();

            prop.Add("Title", "Set Metadata Test");
            word.WordSetDocumentProperties("letterlegal5.doc", "letterlegal5_metadata.doc", prop);

            var result = word.WordGetDocumentProperties("letterlegal5_metadata.doc");

            Assert.AreEqual("Set Metadata Test", result["Title"]);
        }
Example #15
0
        public void WordImageWatermarkPostTest()
        {
            var apiKey = new Dictionary <string, string>()
            {
                { "AppSecret", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" },
                { "AppId", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" }
            };

            var config = new Configuration(apiKey: apiKey);

            config.ApiClient = new ApiClient(config);

            var stream = File.Open("D://Temp/temp.png", FileMode.Open);

            var word = new WordApi(config);

            word.WordImageWatermarkPost("letterlegal5.doc", "letterlegal5_image_watermark.doc", stream);

            var file   = new FileApi(config);
            var result = file.FileList();

            Assert.IsTrue(result.Contains("letterlegal5_image_watermark.doc"));
        }
Example #16
0
        static void Main()
        {
            var configurationRoot = new ConfigurationBuilder()
                                    .AddJsonFile("appsettings.json")
                                    .Build();

            var telegramBotKey   = configurationRoot[TelegramBotKey];
            var userId           = configurationRoot[UserIdKey];
            var connectionString = configurationRoot[OldSqlDbKey];
            var site             = configurationRoot[NewWebApiKey];

            var apiClient  = new ApiClient(site);
            var signer     = new AuthSigner(telegramBotKey);
            var userApi    = new UserApi(apiClient, signer);
            var wordApi    = new WordApi(apiClient);
            var serviceApi = new ServiceApi(apiClient);
            var datetime   = serviceApi.GetDatetime() ?? DateTime.Now;

            apiClient.OnAuthenticationRequest += (o, e) =>
            {
                userApi.LoginUser(new ApiUser {
                    Id = userId
                });
            };

            using (var context = new LearnChineseContext(connectionString))
            {
                var users = context.User;

                var usersCount = 0;
                foreach (var user in users)
                {
                    try
                    {
                        userApi.CreateUser(new User
                        {
                            CurrentFolderId = 0,
                            CurrentWordId   = context.Score.Where(a => a.IdUser == user.IdUser && a.IsInLearnMode)
                                              .Select(a => a.IdWord).FirstOrDefault(),
                            IdUser      = user.IdUser,
                            Name        = user.Name,
                            JoinDate    = user.JoinDate,
                            LastCommand = user.LastCommand,
                            Mode        = user.Mode,
                            Who         = RightEnum.Write
                        });
                        usersCount++;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"{user.IdUser} {user.Name} - user is not added: Error {ex.Message}");
                    }
                }
                Console.WriteLine($"User count is {usersCount}");

                var words = context.Word;

                var wordsCount = 0;
                foreach (var word in words)
                {
                    try
                    {
                        var score = context.Score.FirstOrDefault(a => a.IdWord == word.Id);

                        var scoreApi = new Score {
                            Name = string.Empty
                        };
                        if (score == null)
                        {
                            scoreApi.LastView                  = datetime;
                            scoreApi.LastLearned               = null;
                            scoreApi.OriginalWordCount         = 0;
                            scoreApi.OriginalWordSuccessCount  = 0;
                            scoreApi.PronunciationCount        = 0;
                            scoreApi.PronunciationSuccessCount = 0;
                            scoreApi.TranslationCount          = 0;
                            scoreApi.TranslationSuccessCount   = 0;
                            scoreApi.RightAnswerNumber         = null;
                            scoreApi.ViewCount                 = 0;
                        }
                        else
                        {
                            scoreApi.LastView      = score.LastView;
                            scoreApi.LastLearned   = score.LastLearned;
                            scoreApi.LastLearnMode = score.LastLearnMode;

                            scoreApi.OriginalWordCount         = score.OriginalWordCount ?? 0;
                            scoreApi.OriginalWordSuccessCount  = score.OriginalWordSuccessCount ?? 0;
                            scoreApi.PronunciationCount        = score.PronunciationCount ?? 0;
                            scoreApi.PronunciationSuccessCount = score.PronunciationSuccessCount ?? 0;
                            scoreApi.TranslationCount          = score.TranslationCount ?? 0;
                            scoreApi.TranslationSuccessCount   = score.TranslationSuccessCount ?? 0;

                            scoreApi.RightAnswerNumber = score.RightAnswerNumber;
                            scoreApi.ViewCount         = score.ViewCount ?? 0;
                        }

                        var fileA = context.WordFileA.FirstOrDefault(a => a.IdWord == word.Id);
                        var fileO = context.WordFileO.FirstOrDefault(a => a.IdWord == word.Id);
                        var fileP = context.WordFileP.FirstOrDefault(a => a.IdWord == word.Id);
                        var fileT = context.WordFileT.FirstOrDefault(a => a.IdWord == word.Id);

                        if (fileA == null || fileO == null || fileP == null || fileT == null)
                        {
                            Console.WriteLine($"{word.OriginalWord} - word is not added: file is null");
                            continue;
                        }

                        var fileAId = wordApi.AddFile(new WordFileBytes {
                            Bytes = fileA.Bytes
                        });
                        var fileOId = wordApi.AddFile(new WordFileBytes {
                            Bytes = fileO.Bytes
                        });
                        var filePId = wordApi.AddFile(new WordFileBytes {
                            Bytes = fileP.Bytes
                        });
                        var fileTId = wordApi.AddFile(new WordFileBytes {
                            Bytes = fileT.Bytes
                        });

                        wordApi.AddWord(new Word
                        {
                            FolderId       = 0, LastModified = word.LastModified, OwnerId = word.IdOwner,
                            OriginalWord   = word.OriginalWord, Pronunciation = word.Pronunciation,
                            SyllablesCount = word.SyllablesCount, Translation = word.Translation, Usage = word.Usage,
                            Score          = scoreApi,
                            CardAll        = new WordFile
                            {
                                CreateDate = fileA.CreateDate, Height = fileA.Height ?? 0, Width = fileA.Width ?? 0,
                                Id         = fileAId
                            },
                            CardOriginalWord = new WordFile
                            {
                                CreateDate = fileO.CreateDate, Height = fileO.Height ?? 0, Width = fileO.Width ?? 0,
                                Id         = fileOId
                            },
                            CardPronunciation = new WordFile
                            {
                                CreateDate = fileP.CreateDate, Height = fileP.Height ?? 0, Width = fileP.Width ?? 0,
                                Id         = filePId
                            },
                            CardTranslation = new WordFile
                            {
                                CreateDate = fileT.CreateDate, Height = fileT.Height ?? 0, Width = fileT.Width ?? 0,
                                Id         = fileTId
                            }
                        });
                        wordsCount++;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"{word.OriginalWord} - word is not added: Error {ex.Message}");
                    }
                }
                Console.WriteLine($"Word count is {wordsCount}");
            }
            Console.ReadKey();
        }
Example #17
0
        public void ConfigureServices(IServiceCollection services)
        {
            var botSettings = BotSettings;
            var tClient     = new TelegramBotClient(botSettings.TelegramBotKey)
            {
                Timeout = botSettings.PollingTimeout
            };

            var apiClient          = new ApiClient(botSettings.ApiPublicUrl);
            var wordApi            = new WordApi(apiClient);
            var signer             = new AuthSigner(botSettings.TelegramBotKey);
            var userApi            = new UserApi(apiClient, signer);
            var serviceApi         = new ServiceApi(apiClient);
            var folderApi          = new FolderApi(apiClient);
            var log4NetService     = new Log4NetService();
            var restWordRepository = new RestWordRepository(wordApi, userApi, serviceApi, folderApi);
            var antiDdosChecker    = new AntiDdosChecker(GetDateTime);

            var commandManager = new CommandManager(GetCommands, GetHiddenCommands,
                                                    new Dictionary <string, ECommands> {
                { botSettings.ServiceCommandPassword, ECommands.Admin }
            });

            apiClient.OnAuthenticationRequest += (o, e) =>
            {
                userApi.LoginUser(new ApiUser {
                    Id = botSettings.UserId.ToString()
                });
            };

            services.AddSingleton(a => antiDdosChecker);
            services.AddSingleton(bS => botSettings);
            services.AddSingleton(cl => tClient);
            services.AddSingleton <ICommandManager>(commandManager);
            services.AddSingleton <ILogService>(log4NetService);
            services.AddSingleton <IWordRepository>(restWordRepository);

            var flashCardUrl = $"{botSettings.ApiPublicUrl}/word/file";

            services.AddSingleton(qh =>
                                  new QueryHandler(tClient, log4NetService, restWordRepository, antiDdosChecker, flashCardUrl, commandManager, MaxUploadFileSize));

            services.AddSingleton <ISyllableColorProvider, ClassicSyllableColorProvider>();
            services.AddSingleton <IChineseWordParseProvider, PinyinChineseWordParseProvider>();
            services.AddSingleton <IStudyProvider, ClassicStudyProvider>();
            services.AddSingleton <ISyllablesToStringConverter, ClassicSyllablesToStringConverter>();
            services.AddSingleton <IChinesePinyinConverter, Pinyin4NetConverter>();
            services.AddSingleton <IFlashCardGenerator, FontFlashCardGenerator>();

            services.AddTransient(a => new AboutCommand(ReleaseNotesInfo, AboutInfo));
            services.AddTransient(a => new HelpCommand(GetCommands));
            services.AddTransient(a => new StartCommand(GetCommands, botSettings.WebhookPublicUrl));
            services.AddTransient(a => new FolderCommand(ServiceProvider.GetService <IWordRepository>(), botSettings.FolderManagementText));

            services.AddTransient(a => new DefaultCommand(ServiceProvider.GetService <IWordRepository>()));
            services.AddTransient(a => new ImportCommand(ServiceProvider.GetService <IChineseWordParseProvider>(),
                                                         ServiceProvider.GetService <IWordRepository>(), ServiceProvider.GetService <IFlashCardGenerator>(),
                                                         MaxUploadFileSize));
            services.AddTransient(a => new AddCommand(ServiceProvider.GetService <IChineseWordParseProvider>(), ServiceProvider.GetService <IWordRepository>(), ServiceProvider.GetService <IFlashCardGenerator>()));
            services.AddTransient(a => new ViewCommand(ServiceProvider.GetService <IWordRepository>()));
            services.AddTransient(a => new DeleteCommand(ServiceProvider.GetService <IWordRepository>()));
            services.AddTransient(a => new EditCommand(ServiceProvider.GetService <IWordRepository>(),
                                                       ServiceProvider.GetService <IChineseWordParseProvider>(), ServiceProvider.GetService <ImportCommand>(),
                                                       ServiceProvider.GetService <IFlashCardGenerator>()));
            services.AddTransient(a => new LearnWritingCommand(ServiceProvider.GetService <IStudyProvider>(),
                                                               ServiceProvider.GetService <EditCommand>()));
            services.AddTransient(a => new LearnViewCommand(ServiceProvider.GetService <IStudyProvider>(),
                                                            ServiceProvider.GetService <EditCommand>()));
            services.AddTransient(a => new LearnSpeakCommand(ServiceProvider.GetService <IStudyProvider>(),
                                                             ServiceProvider.GetService <EditCommand>()));
            services.AddTransient(a => new LearnTranslationCommand(ServiceProvider.GetService <IStudyProvider>(),
                                                                   ServiceProvider.GetService <EditCommand>()));
            services.AddTransient(a => new ModeCommand(ServiceProvider.GetService <IWordRepository>()));

            services.AddTransient(a => new PreInstallCommand(ServiceProvider.GetService <IWordRepository>()));

            services.AddTransient(a => new AdminCommand(ServiceProvider.GetService <IChineseWordParseProvider>(), ServiceProvider.GetService <IWordRepository>(), ServiceProvider.GetService <IFlashCardGenerator>(),
                                                        MaxUploadFileSize, PreInstalledFolder, botSettings.ServerUserId, botSettings.AdminUserId, tClient));
            services.AddTransient(a => new WebCommand(signer, botSettings.ApiPublicUrl));

            services.AddSingleton(a => new AntiDdosChecker(GetDateTime));

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }
Example #18
0
 /// <summary>
 /// Creates an instance of the application
 /// </summary>
 /// <param name="application">owner application</param>
 public CommonUtils(WordApi.Application application)
     : base(application)
 {
     _ownerApplication = application;
 }
Example #19
0
        private int TryGetHostApplicationWindowHandleFromDesktop(WordApi.Document document)
        {
            try
            {
                int result = 0;
                NetOffice.Tools.WndUtils.WindowEnumerator enumerator = new NetOffice.Tools.WndUtils.WindowEnumerator("OpusApp");
                IntPtr[] handles = enumerator.EnumerateWindows(2000);

                foreach (IntPtr item in handles)
                {
                    object proxyDocument = GetAccessibleObject(item);
                    if (null != proxyDocument)
                    {
                        try
                        {
                            bool equals = Equal(document.UnderlyingObject, proxyDocument);
                            if (equals)
                                result = (int)item;
                            break;
                        }
                        catch
                        {
                            throw;
                        }
                        finally
                        {
                            Marshal.ReleaseComObject(proxyDocument);
                        }
                    }
                }

                return result;
            }
            catch (Exception exception)
            {
                NetOffice.Core.Default.Console.WriteException(exception);
                return 0;
            }
        }
Example #20
0
 private int TryGetHostApplicationWindowHandle(WordApi.Document document)
 {
     int result = TryGetHostApplicationWindowHandleFromDesktop(document);
     return result;
 }