有人可以提供有关我的 LotusScript 代理的反馈吗?
您好,我不是开发人员,因此不了解最佳实践。 我创建它是为了绕过日志数据的手动数据复制。 该代理适用于单个提要,我将复制该提要并针对每个其他提要进行调整。 对于指定的提要,它会读取上次处理的日志以及今天和昨天迄今为止处理的文件数。 它还对输入文件夹中的文件进行计数并读取服务器的时区。 每个数据项均以 csv 逗号分隔并通过电子邮件发送,随后托管在网站上。 感谢任何建设性的批评。
Sub Initialize
Dim customername As String
Dim servername As String
Dim feedname As String
Dim alertthresholdinhours As Integer
Dim inputfeedpath As String
' Set for each feed
customername = "gRrhio"
servername = "gRrhioEdge2"
feedname = "FF Thompson ADT"
alertthresholdinhours = 6
inputfeedpath = "\\mhinec\elycon\data\adt\*.*"
' Counts files in input folder
Dim pathName As String, fileName As String
Dim inputfeedcounter As Integer
inputfeedcounter = 0
pathName$ = inputfeedpath
fileName$ = Dir$(pathName$, 0)
Do While fileName$ <> ""
inputfeedcounter = inputfeedcounter + 1
fileName$ = Dir$()
Loop
Dim entry As NotesViewEntry
Dim vc As NotesViewEntryCollection
Dim filesprocessed As Integer
Dim session As New NotesSession
Dim db As NotesDatabase
Dim newDoc As NotesDocument
Dim rtitem As NotesRichTextItem
Set db = session.CurrentDatabase
Dim view As NotesView
Set view = db.GetView( "Sessions\by Feed" )
Set newDoc = New NotesDocument( db )
Set rtitem = New NotesRichTextItem( newDoc, "Body" )
Dim todaysdate As New NotesDateTime("Today")
Dim flag As Integer
Dim counter As Integer
Dim files As Integer
Dim errors As Integer
Dim lastdate As String
Dim lastdayran As String
Dim lasttime As String
Dim lasttimeran As String
Dim filesp As Integer
Dim lastdayfiles As Integer
Dim lastdaysfiles2 As Integer
Dim terrors As Integer
Dim lastdayerrors As Integer
lastdate = ""
lastdayran = ""
counter = 0
flag = 0
filesp = 0
lastdayfiles = 0
lastdaysfiles2 = 0
terrors = 0
lastdayerrors = 0
' Finds date for last time processed, counts files processed and errors
While flag = 0
Dim dateTime As New NotesDateTime(todaysdate.DateOnly)
Dim keyarray(1) As Variant
keyarray(0) = feedname
Set keyarray(1) = dateTime
Set vc = view.GetAllEntriesByKey(keyarray, False)
Set entry = vc.GetFirstEntry
If entry Is Nothing Then
Call todaysdate.AdjustDay(-1)
End If
While Not entry Is Nothing
files = 0
Forall colval In entry.ColumnValues
If counter = 9 Then
counter = 0
Elseif counter = 8 Then
counter = 9
Elseif counter = 7 Then
counter = 8
Elseif counter = 6 Then
errors = Cint(colval)
counter = 7
Elseif counter = 5 Then
counter = 6
Elseif counter = 4 Then
files = Cint(colval)
counter = 5
Elseif counter = 3 Then
counter = 4
Elseif counter = 2 Then
counter = 3
lasttime = colval
Elseif counter = 1 Then
counter = 2
lastdate = colval
Elseif counter = 0 Then
counter = 1
End If
End Forall
filesp = filesp + files
terrors = terrors + errors
Set entry=vc.GetNextEntry (entry)
flag = 1
Wend
Wend
lastdayfiles = filesp
lastdayerrors = terrors
lastdayran = lastdate
lasttimeran = lasttime
'Counts previous files processed
filesp = 0
terrors = 0
lastdate = ""
flag = 0
Call todaysdate.AdjustDay(-1)
While flag = 0
Dim dateTime2 As New NotesDateTime(todaysdate.DateOnly)
Dim keyarray2(1) As Variant
keyarray2(0) = feedname
Set keyarray2(1) = dateTime2
Set vc = view.GetAllEntriesByKey(keyarray2, False)
Set entry = vc.GetFirstEntry
If entry Is Nothing Then
Call todaysdate.AdjustDay(-1)
End If
While Not entry Is Nothing
files = 0
Forall colval In entry.ColumnValues
If counter = 9 Then
counter = 0
Elseif counter = 8 Then
counter = 9
Elseif counter = 7 Then
counter = 8
Elseif counter = 6 Then
counter = 7
Elseif counter = 5 Then
counter = 6
Elseif counter = 4 Then
files = Cint(colval)
counter = 5
Elseif counter = 3 Then
counter = 4
Elseif counter = 2 Then
counter = 3
Elseif counter = 1 Then
counter = 2
Elseif counter = 0 Then
counter = 1
End If
End Forall
filesp = filesp + files
Set entry=vc.GetNextEntry (entry)
flag = 1
Wend
Wend
lastdaysfiles2 = filesp
' Prints line of CSV into body of email
Call rtitem.AppendText ( customername )
Call rtitem.AppendText ( ", " )
Call rtitem.AppendText ( servername )
Call rtitem.AppendText ( ", " )
Call rtitem.AppendText ( datetime.timezone )
Call rtitem.AppendText ( ", " )
Call rtitem.AppendText ( lastdayran )
Call rtitem.AppendText ( " " )
Call rtitem.AppendText ( lasttimeran )
Call rtitem.AppendText ( ", " )
Call rtitem.AppendText ( lastdayfiles )
Call rtitem.AppendText ( ", " )
Call rtitem.AppendText ( lastdayerrors )
Call rtitem.AppendText ( ", " )
Call rtitem.AppendText ( lastdaysfiles2 )
Call rtitem.AppendText ( ", " )
Call rtitem.AppendText ( inputfeedcounter )
Call rtitem.AppendText ( ", " )
Call rtitem.AppendText ( alertthresholdinhours )
Call newDoc.Save( False, True )
newDoc.Subject = feedname
' Running from server line should be
'newDoc.SendTo = "Ecmon Feedcheck/Ecmonitor@ECMONITOR"
newDoc.SendTo = "AX1Forward Feedcheck/[email protected]"
newDoc.Send( False )
End Sub
Hi there I'm not a developer and so am unaware of best practices. I created this to bypass manual data copying of log data. This agent is for a single feed which I'll copy and adjust for each additional one. For the specified feed it reads the log for the last time processed and number of files processed so far today and for yesterday. It also counts files in the input folder and reads the server's timezone. Each data item is separated by a comma for csv and emailed, which later is hosted on a website. Thanks for any constructive criticism.
Sub Initialize
Dim customername As String
Dim servername As String
Dim feedname As String
Dim alertthresholdinhours As Integer
Dim inputfeedpath As String
' Set for each feed
customername = "gRrhio"
servername = "gRrhioEdge2"
feedname = "FF Thompson ADT"
alertthresholdinhours = 6
inputfeedpath = "\\mhinec\elycon\data\adt\*.*"
' Counts files in input folder
Dim pathName As String, fileName As String
Dim inputfeedcounter As Integer
inputfeedcounter = 0
pathName$ = inputfeedpath
fileName$ = Dir$(pathName$, 0)
Do While fileName$ <> ""
inputfeedcounter = inputfeedcounter + 1
fileName$ = Dir$()
Loop
Dim entry As NotesViewEntry
Dim vc As NotesViewEntryCollection
Dim filesprocessed As Integer
Dim session As New NotesSession
Dim db As NotesDatabase
Dim newDoc As NotesDocument
Dim rtitem As NotesRichTextItem
Set db = session.CurrentDatabase
Dim view As NotesView
Set view = db.GetView( "Sessions\by Feed" )
Set newDoc = New NotesDocument( db )
Set rtitem = New NotesRichTextItem( newDoc, "Body" )
Dim todaysdate As New NotesDateTime("Today")
Dim flag As Integer
Dim counter As Integer
Dim files As Integer
Dim errors As Integer
Dim lastdate As String
Dim lastdayran As String
Dim lasttime As String
Dim lasttimeran As String
Dim filesp As Integer
Dim lastdayfiles As Integer
Dim lastdaysfiles2 As Integer
Dim terrors As Integer
Dim lastdayerrors As Integer
lastdate = ""
lastdayran = ""
counter = 0
flag = 0
filesp = 0
lastdayfiles = 0
lastdaysfiles2 = 0
terrors = 0
lastdayerrors = 0
' Finds date for last time processed, counts files processed and errors
While flag = 0
Dim dateTime As New NotesDateTime(todaysdate.DateOnly)
Dim keyarray(1) As Variant
keyarray(0) = feedname
Set keyarray(1) = dateTime
Set vc = view.GetAllEntriesByKey(keyarray, False)
Set entry = vc.GetFirstEntry
If entry Is Nothing Then
Call todaysdate.AdjustDay(-1)
End If
While Not entry Is Nothing
files = 0
Forall colval In entry.ColumnValues
If counter = 9 Then
counter = 0
Elseif counter = 8 Then
counter = 9
Elseif counter = 7 Then
counter = 8
Elseif counter = 6 Then
errors = Cint(colval)
counter = 7
Elseif counter = 5 Then
counter = 6
Elseif counter = 4 Then
files = Cint(colval)
counter = 5
Elseif counter = 3 Then
counter = 4
Elseif counter = 2 Then
counter = 3
lasttime = colval
Elseif counter = 1 Then
counter = 2
lastdate = colval
Elseif counter = 0 Then
counter = 1
End If
End Forall
filesp = filesp + files
terrors = terrors + errors
Set entry=vc.GetNextEntry (entry)
flag = 1
Wend
Wend
lastdayfiles = filesp
lastdayerrors = terrors
lastdayran = lastdate
lasttimeran = lasttime
'Counts previous files processed
filesp = 0
terrors = 0
lastdate = ""
flag = 0
Call todaysdate.AdjustDay(-1)
While flag = 0
Dim dateTime2 As New NotesDateTime(todaysdate.DateOnly)
Dim keyarray2(1) As Variant
keyarray2(0) = feedname
Set keyarray2(1) = dateTime2
Set vc = view.GetAllEntriesByKey(keyarray2, False)
Set entry = vc.GetFirstEntry
If entry Is Nothing Then
Call todaysdate.AdjustDay(-1)
End If
While Not entry Is Nothing
files = 0
Forall colval In entry.ColumnValues
If counter = 9 Then
counter = 0
Elseif counter = 8 Then
counter = 9
Elseif counter = 7 Then
counter = 8
Elseif counter = 6 Then
counter = 7
Elseif counter = 5 Then
counter = 6
Elseif counter = 4 Then
files = Cint(colval)
counter = 5
Elseif counter = 3 Then
counter = 4
Elseif counter = 2 Then
counter = 3
Elseif counter = 1 Then
counter = 2
Elseif counter = 0 Then
counter = 1
End If
End Forall
filesp = filesp + files
Set entry=vc.GetNextEntry (entry)
flag = 1
Wend
Wend
lastdaysfiles2 = filesp
' Prints line of CSV into body of email
Call rtitem.AppendText ( customername )
Call rtitem.AppendText ( ", " )
Call rtitem.AppendText ( servername )
Call rtitem.AppendText ( ", " )
Call rtitem.AppendText ( datetime.timezone )
Call rtitem.AppendText ( ", " )
Call rtitem.AppendText ( lastdayran )
Call rtitem.AppendText ( " " )
Call rtitem.AppendText ( lasttimeran )
Call rtitem.AppendText ( ", " )
Call rtitem.AppendText ( lastdayfiles )
Call rtitem.AppendText ( ", " )
Call rtitem.AppendText ( lastdayerrors )
Call rtitem.AppendText ( ", " )
Call rtitem.AppendText ( lastdaysfiles2 )
Call rtitem.AppendText ( ", " )
Call rtitem.AppendText ( inputfeedcounter )
Call rtitem.AppendText ( ", " )
Call rtitem.AppendText ( alertthresholdinhours )
Call newDoc.Save( False, True )
newDoc.Subject = feedname
' Running from server line should be
'newDoc.SendTo = "Ecmon Feedcheck/Ecmonitor@ECMONITOR"
newDoc.SendTo = "AX1Forward Feedcheck/[email protected]"
newDoc.Send( False )
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
对于不是开发人员,您可以编写大量代码:)
如果您正在寻找一些课程来开始成为一名优秀的开发人员,那么请采纳 Mitch 的建议(来自评论)并将其分解为子例程。 第 1 课:这里肯定有一些重复代码,将重复代码放入方法(函数或子例程)中总是一个好主意,这样它只存在一次。 计算已处理文件和以前已处理文件的部分看起来很相似,并且可能会放入如下例程中:
但是,如果我正确理解您的代码,您甚至可以节省对此的需要。 您似乎只是尝试从视图条目的列中获取值,而不是在中间执行那个奇怪的循环。 假设您对第 4 列的值感兴趣。 您可以通过索引访问来简单地获取所需列的值。 例如,您的文件变量可以通过此行直接设置为第 4 列的值
无论如何,底线是如果此代码有效,那么您就有了一个良好的开端!
For not being a developer, you can write a lot of code :)
If you are looking for some lessons to start becoming a good developer, then take Mitch's advice (from the comments) and break up this into subroutines. Lesson 1: There's definitely some repetitve code here, and it's always a good idea to put repetitive code into a method (function or subroutine) so it only exists once. The section that counts files processed and previous files processed looks similar and could probably be put into a routine like:
However, you might even be able to save the need for that if I'm understanding your code correctly. Instead of doing that strange loop in the middle, it appears you're are trying to simply get a value from a column of a viewentry. Say you are interetsed in column 4's value. You can simply get at the value for the column you want by accessing it by index. For example, your files variable could be set directly to column 4's value by this line
Anyway, bottom line is if this code works then you're off to a good start!
在更多的风格方面,我总是发现,当其他人
Option 'Explicit'
您关于复制此代理以解决同一问题的其他实例的评论也提出了一个标志。 尝试找出这些代理之间的共同点,并将这些功能推送到脚本库中。 此类事情在维护代码时可以节省大量时间,因为您不需要考虑每个代理的不同之处(例如,我的更改是否适用于该代理的所有实例,还是仅适用于其中的一些实例?)
On more of the style side of things, I've always found it easier to maintain other people's code when they've
Option 'Explicit'
in the Declarations sectionYour comment about copying this agent for other instances of the same problem also raises a flag. Try to work out what is common between these agents and push those functions into a script library. This sort of thing saves a lot of time when maintaining the code as you don't need to think about in what way each agent is different (Eg. does my change apply to all instances of this agent, or just some of them?)
你想要更多地分解你的代码......一件小事。 取而代之的
是双重否定和流行的脑筋急转弯..写:
这也允许你用 exit do 打破循环
You want to decompose your code much more and ... one little thing. Instead of
which is a double negation and a popular brain bender.. write:
This also allows you to break out of the loop with exit do
您可以优化两个 ForAll 循环。
这是第一个的样子:
这是第二个的样子:
you can optimize both of your ForAll loops.
This is how the first one would look:
This is how the second would one would look like:
关于这一点的注释
正如 ken 所说,您可以通过使用entry.ColumnValues(x) 方法获取columnValues,因此不需要对值进行交互。 但; 你本来可以这样做
Just a note regarding this bit
As ken says you can get columnValues by using the entry.ColumnValues(x) method so interating through the values is un-needed. But; you could have done this
已经有一些优点了。 如果您有共享公共对象的变量,则要添加到它们,然后创建一个类。 将变量添加到该类中。
因此,不要说:
您可以拥有:
和引用:
这样做的优点是您可以添加方法来操作该数据,并且您知道代码与该对象相关,而不是在您的应用程序中寻找。
Some good points already. To add to them if you have variables that share a common object then create a class. Add your variables to that class.
So instead of say:
You can have:
and reference:
The advantage of this is you can add methods to manipulate that data and you know the code relates to that object rather then hunting through your application.