VB.NET Visual Studio Outlook 2013 Addin项目 – 事件似乎没有被触发

VB.NET Visual Studio Outlook 2013 Addin项目 – 事件似乎没有被触发,第1张

概述感谢您抽出宝贵时间查看我的第一篇文章. 我正在开发一个Outlook Addin(使用Visual Studio社区2013),以允许用户轻松地为我们的客户服务部门填充电子邮件模板. 插件运行良好,但是我需要添加一些功能,以便在实际发送电子邮件后将一些数据(跟踪KPI)记录到数据库. 经过一些研究,我为Applications itemSend事件实现了一个Class级事件处理程序. 这在开发机器 感谢您抽出宝贵时间查看我的第一篇文章.

我正在开发一个Outlook Addin(使用Visual Studio社区2013),以允许用户轻松地为我们的客户服务部门填充电子邮件模板.
插件运行良好,但是我需要添加一些功能,以便在实际发送电子邮件后将一些数据(跟踪KPI)记录到数据库.

经过一些研究,我为Applications itemSend事件实现了一个Class级事件处理程序.

这在开发机器上完美地工作,但是当我在客户端上发布和安装应用程序时,事件似乎不会被触发,因为不会调用将数据记录到数据库的代码.

由于我无法使其正常工作,我尝试了一个解决方案,然后将其更改为使用已发送文件夹的.ItemAdd事件. (代码是从Pranav借来的:https://easyvsto.wordpress.com/2010/07/27/how-to-save-mail-content-when-a-mail-is-sent-from-outlook/)

这也适用于开发机器,但同样,一旦在客户端macine上安装了插件,事件似乎无法触发.

正如我现在看到两种不同方法的相同行为,它让我觉得有一些显而易见的事情.我错过了什么或没有考虑到某些事情?

代码示例如下:

imports Microsoft.Office.Tools.Ribbonimports System.Runtime.InteropServicesimports System.IOimports mysql.data.MysqLClIEntimports System.DiagnosticsPublic Class ThisAddInPublic WithEvents oSentFolder As Outlook.FolderPublic WithEvents oSentItems As Outlook.ItemsPrivate Sub ThisAddIn_Startup() Handles Me.Startup    oSentFolder = Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.olDefaultFolders.olFolderSentMail)    oSentItems = oSentFolder.ItemsEnd SubPrivate Sub InsertSurveyTimestamp() Handles oSentItems.ItemAdd    System.windows.Forms.MessageBox.Show("oSentItems.ItemAdd Event")End SubPrivate Sub Application_ItemSend(ByVal oItem As Object,ByRef Cancel As Boolean) Handles Application.ItemSend    System.windows.Forms.MessageBox.Show("Application.ItemSend Event")    log.WritetoErrorLog("Application ItemSend Reached","","Event")    If TypeOf oItem Is Outlook.Mailitem Then Call SentMailTimestamp(oItem)    System.windows.Forms.MessageBox.Show("end of Itemsend Event")End SubPrivate Sub SentMailTimestamp(oitem As Outlook.Mailitem)    log.WritetoErrorLog("SentMailTimestamp Sub Reached","Subroutine Flag")    Try        'Dim oitem As Outlook.Mailitem = oSentItems.Item(oSentItems.Count) 'for use with oSentItems.ItemAdd event        'Check the CSOSurvey property exists to make sure its a CSO Survey email,exit if not a CSOSurvey Email        Dim o = oitem.ItemPropertIEs("CSOSurvey")        If (o IsNot nothing) AndAlso (o.Value IsNot nothing) Then            System.Diagnostics.DeBUG.Writeline("CSOsurvey email: " & o.Value.ToString)            log.WritetoErrorLog("Email was CSO Survey","Value: " & o.Value.ToString,"Email Property")        Else            System.Diagnostics.DeBUG.Writeline("CSOsurvey email: Null")            log.WritetoErrorLog("Email was NOT CSO Survey","Email Property")            oitem = nothing            o = nothing            Exit Sub        End If    Catch ex As Exception        MsgBox(ex.Message)    End Try    'Save the timedatestamp of the email template being sent    Using sqlCommand As New MysqLCommand        Dim querystr As String = "INSERT INTO cs_survey_emaillog (SRID,exec,datetimestamp) values(@srID,@exec,@datetimestamp)"        Dim MysqLconn As MysqLConnection        Try            MysqLconn = New MysqLConnection(GlobalVariables.connstr)            MysqLConn.open()        Catch ex As MysqLException            System.windows.Forms.MessageBox.Show("Unable to write to Log. Please contact [email protected]" & vbCrLf & ex.Message)            log.WritetoErrorLog(ex.Message,ex.StackTrace,"MysqL Error")            Exit Sub        End Try        If MysqLconn.State = Data.ConnectionState.Open Then            Try                With sqlCommand                    .Connection = MysqLconn                    .CommandText = querystr                    .CommandType = Data.CommandType.Text                    .Parameters.AdDWithValue("@srID",ThisAddIn.templateSRID)                    .Parameters.AdDWithValue("@exec",ThisAddIn.GetUsername())                    .Parameters.AdDWithValue("@datetimestamp",DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))                    Dim numrec As Integer = .ExecuteNonquery()                    If ThisAddIn.GetUsername = "mclachd" Then System.windows.Forms.MessageBox.Show("query executed. " + numrec.ToString + " Records sent")                End With            Catch ex As MysqLException                log.WritetoErrorLog(ex.Message,"MysqL Error")            Finally                MysqLconn.Close()                MysqLconn.dispose()            End Try        Else            log.WritetoErrorLog("Could not open db connection","MysqL Error")            MysqLconn.dispose()        End If    End UsingEnd Sub

在这种情况下,从未到达SentMailTimeStamp例程.

如果我删除了该呼叫,则两个消息框都将作为两个事件的结果显示.

如果您需要更多细节,请告诉我.

亲切的问候,

大卫

UPDATE
根据Cadogi评论修改了代码.谢谢.

UPDATE2
在Try Catch中将调用包装到SentMailtimeStamp路由中,确实在客户端中有错误.

Private Sub Application_ItemSend(ByVal oItem As Object,"Event")    Try        If TypeOf oItem Is Outlook.Mailitem Then Call SentMailTimestamp(oItem)    Catch ex As Exception        System.windows.Forms.MessageBox.Show(ex.Message)    End Try    System.windows.Forms.MessageBox.Show("end of Itemsend Event")End Sub

错误消息是:

无法加载文件或程序集’mysql.data,version = 6.8.5.0,Culture = neutral,PublicKeyToken = c5687fc88969c44d’或其依赖项之一.系统无法精确指定的文件

很棒,如果感觉有进步的话.我假设已发布的项目将包含所有必需的内容.

更新3
我已经解决了这个问题,感谢Hans向我指出了一些非常简单的调试课程 – 这是一个很难吸取的教训,因为这需要花费几周的时间来解决.

汉斯绝对认真.

There is something obvIoUs you are missing,Office programs are not
that accommodating to add-ins that misbehave. By default any exception
they throw in an “awkward” place is swallowed without a diagnostic.
The only way to tell that this happened is that code you think should
have a sIDe-effect is just not doing its job.

Addin在开发机器而不是客户端上工作的原因是mysql.data引用需要将copy Local属性设置为True.

对于那些最终与我处于类似位置的人来说,解决方法是转到您的项目属性 – >参考.突出显示mysql.data并将copy Local属性更改为True.

谢谢大家的贡献,这对我的学习有所帮助,并帮助缩小了问题的范围.

解决方法 有一些明显的缺失,Office程序不适合容错的插件.默认情况下,它们在“尴尬”的地方抛出的任何异常都会被吞没,而不会进行诊断.告诉这种情况发生的唯一方法是你认为应该有副作用的代码就是不能正常工作.

你做的很好,谷歌“VSTO异常处理”.一个这样的命中是this MSDN article,我将复制粘贴相关部分:

Visual Studio Tools for Office can write all errors that occur during startup to a log file or display each error in a message Box. By default,these options are turned off for application-level projects. You can turn the options on by adding and setting environment variables. To display each error in a message Box,set the VSTO_SUPPRESSdisPLAYALERTS variable to 0 (zero). You can suppress the messages by setting the variable to 1 (one). To write the errors to a log file,set the VSTO_LOgalERTS variable to 1 (one). Visual Studio Tools for Office creates the log file in the folder that contains the application manifest. The default name is .manifest.log. To stop logging errors,set the variable to 0 (zero)

总结

以上是内存溢出为你收集整理的VB.NET Visual Studio Outlook 2013 Addin项目 – 事件似乎没有被触发全部内容,希望文章能够帮你解决VB.NET Visual Studio Outlook 2013 Addin项目 – 事件似乎没有被触发所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1232747.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存