1

내가 stand alone 응용 프로그램으로 사용할 때 모든 항목이 정상적으로 작동하는 것처럼 보일 때 잡종 서버에서 실행중인 레일 응용 프로그램에 넣으면 무한 루프.레일에서 루비의 WIN32OLE을 사용하여 원격 서버에서 Word 문서를 렌더링

내가 액세스하려고 "은 https : //microsoft/sharepoint/document.doc을"

def generatertm(issue) 
begin 
    word = WIN32OLE.new('word.application') 
    logger.debug("Word Initialized...") 
    word.visible = true 
    myDocLink = "https://microsoft/sharepoint/url.doc" 
    myFile = word.documents.open(myDocLink) 
    logger.debug("File Opened...") 
    puts "Started Reading bookmarks..." 
    myBookMarks = myFile.Bookmarks puts "bookmarks fetched working background task..." 

    print ("Bookmakr Count : " + myBookMarks.Count.to_s + "\n") 

    myBookMarks.each do |i| 
    logger.warn ("Bookmark Name : " + i.Name + "\n") 
    end 
rescue WIN32OLERuntimeError => e 
    puts e.message 
    puts e.backtrace.inspect 
    else 
ensure 

word.activedocument.close(true) # presents save dialog box 
#word.activedocument.close(false) # no save dialog, just close it 
word.quit 
end 
end 

내가 마이크로 소프트 공유 포인트 자격 증명을 제공 한 팝까지 그 시간에 혼자이 코드 스탠드를 실행합니다. 그러나 잡종 레일에서는 무한 루프가됩니다.

Rails를 통해 표시하려면이 팝업을 처리해야합니까?

+0

진행을 - 내가 갔을 때 Windows 환경에서 "Services"로 - Mongrel 서비스 속성에는 "Log On -> Desktop과 상호 작용할 수있게 허용"옵션이 있습니다.이를 확인하고 코드를 실행하려고하면 "대화 형 서비스 탐지 -이 컴퓨터에서 실행중인 프로그램이 메시지를 표시하려고합니다. [내용] 프로그램에서 사용자 또는 사용자의 작업 완료 권한이 필요합니다. 왜 이런 일이 생길까요? [V] 프로그램 세부 정보보기 [메시지보기] [나중에 물어보세요] "브라우저에서 백그라운드 서비스가 아닌이 서비스 프롬프트를 얻는 방법? 올바른 방향으로 가고 있습니까? –

답변

0

win32ole.rb 파일을 패치 한 적이 있습니까?

기본적으로, 여기 패치에 대한 이유 :

t turns out that win32ole.rb patches the thread to call the windows OleInitialize() & OleUninitialize() functions around the yield to the block. However, the MS documentation for CoInitialize (which OleInitialize calls internally) state that: "the first thread in the application that calls CoInitialize with 0 (or CoInitializeEx with COINIT_APARTMENTTHREADED) must be the last thread to call CoUninitialize. Otherwise, subsequent calls to CoInitialize on the STA will fail and the application will not work." http://msdn.microsoft.com/en-us/library/ms678543(v=VS.85).aspx

는 그리고 여기 스레딩 문제를 해결하기 위해 수정 된 win32ole.rb 파일입니다 :

require 'win32ole.so' 

# Fail if not required by main thread. 
# Call OleInitialize and OleUninitialize for main thread to satisfy the following: 
# 
# The first thread in the application that calls CoInitialize with 0 (or CoInitializeEx with COINIT_APARTMENTTHREADED) 
# must be the last thread to call CoUninitialize. Otherwise, subsequent calls to CoInitialize on the STA will fail and the 
# application will not work. 
# 
# See http://msdn.microsoft.com/en-us/library/ms678543(v=VS.85).aspx 
if Thread.main != Thread.current 
    raise "Require win32ole.rb from the main application thread to satisfy CoInitialize requirements." 
else 
    WIN32OLE.ole_initialize 
    at_exit { WIN32OLE.ole_uninitialize } 
end 


# re-define Thread#initialize 
# bug #2618(ruby-core:27634) 

class Thread 
    alias :org_initialize :initialize 
    def initialize(*arg, &block) 
    if block 
     org_initialize(*arg) { 
     WIN32OLE.ole_initialize 
     begin 
      block.call(*arg) 
     ensure 
      WIN32OLE.ole_uninitialize 
     end 
     } 
    else 
     org_initialize(*arg) 
    end 
    end 
end 

http://cowlibob.co.uk/ruby-threads-win32ole-coinitialize-and-counin

+0

예전에 이것을 보았지만 이해하지 못했습니다. 컨텍스트 지금은 내가 이해할 수있는 서비스에 들어갔다. 그래서 당신은 내가이 코드를 사용하여 스레드를 관리해야한다는 것을 의미합니다. 그리고 win32ole.rb에만이 수정 사항을 넣고 사용해야합니까? –

+0

나는 redmine을 사용하고 있습니다. win32ole.rb 만든 및이 코드를 넣어. 이니셜 라이저 폴더에이 파일을 넣었습니다. 나는 잡종 서비스를 다시 시작했습니다. 그러나 서버 localhost : 3000에 액세스하려고했을 때 응답하지 않습니다. 그 로그를 제거해야합니까? on 설정에서? –

+0

내 잡종 로그에서 디버깅했습니다 "/config/initializers/win32ole.rb:12 : 정의되지 않은 메서드 'ole_initialize'for WIN32OLE : Class (NoMethodError)"그리고 내가 더 파고 들었을 때 루비 버전 [ 1.8.7]은 내가 사용하고있는 소스 자체에 win32ole.rb 파일이 없습니다. 즉 http://rxr.whitequark.org/mri/source/ext/win32ole/lib/win32ole.rb?v=1.8.7 –