Google Calender Vr3 - How do I add a reminder to an event? - vb.net

So far I am able to insert an event in a calendar using the following code.
Dim calService As CalendarService = calendarFunctions.getCalendarService(txtrefreshToken.Text.Trim)
Dim calEventEntry As New Data.Event
calEventEntry.Summary = "Invoice #123456 Due on dd/mm/yyyy"
calEventEntry.Description = "Client: Acme Printing Ltd."
calEventEntry.Id = "inv5670010"
Dim eventStartDT As New Data.EventDateTime()
eventStartDT.DateTime = DateTime.Now.AddHours(24)
Dim eventStartEndDT As New Data.EventDateTime()
eventStartEndDT.DateTime = DateTime.Now.AddHours(25)
calEventEntry.Start = eventStartDT
calEventEntry.End = eventStartEndDT
Dim er As New EventsResource(calService)
Dim erResp As Data.Event = er.Insert(calEventEntry, txtactiveCal.Text.Trim).Execute()
'SO FAR SO GOOD!
'Add email reminder to event
Dim remR As New EventReminder()
remR.Method = "email"
remR.Minutes = 10
erResp.Reminders.Overrides.Add(remR) ' <<< ERROR: Object reference not set to an instance of an object
In the last block I am trying to add the reminder to the event (I unserstand this must be done after the event has been created?) . On the last line I get the following error:
Object reference not set to an instance of an object
Does anyone know what I'm doing wrong here?

I would suspect Overrides to be null by default so you can't add anything in there unless you initialize them.

I solved this in the end by creating a List(of EventReminder) object adding the desired reminder and binding this to the Overrides property for event.reminders. Hopefully this code may be of help to others.
Dim eventReminder As New List(Of EventReminder)()
eventReminder.Add(New EventReminder() With { _
.Minutes = 10, _
.Method = "email" _
})
Dim de As New Data.Event.RemindersData()
de.UseDefault = False
de.[Overrides] = eventReminder
calEventEntry.Reminders = de
Dim er As New EventsResource(calService)
Dim erResp As Data.Event = er.Insert(calEventEntry, txtactiveCal.Text.Trim).Execute()
Response.Write("Event ID: " & erResp.Id & "<br/>")
Response.Write("Link: " & erResp.HtmlLink & "<br/>")

Related

Solidworks EPDM API IEdmEnumeratorVariable5::SetVar not working as expected

I'm trying to use IEdmEnumeratorVariable5::SetVar to update some file card variables based on user input into a windows form. My code executes, there are no error messages, the file is checked out and checked back in and the appropriate comment is added to the history; however the variables on the card are not updated.
I have verified by stepping through code at runtime that all variables are populated with the correct (as expected) data. The SetVar procedures all go off without a hitch, but the variables on the data card do not change value - even manually refreshing the folder view has no effect.
Below is my code.
This is an add-in application, written as a class-library project in VB using VS Community 2015, with target framework .NET 4.0.
In efforts to make this question more concise; immediately below I've included just the snippet of code doing the set variables work, then I've also included more code so you can get the whole picture if needed.
JUST THE TIP :
This is the code doing the set variables work:
Dim UserManager As IEdmUserMgr5 = .SourceVault
Dim User As IEdmUser5 = UserManager.GetLoggedInUser
CardComment = UserComment & CardComment
CardDate = Today().ToString("yyMMdd", Globalization.CultureInfo.InvariantCulture)
CardBy = User.Name
CardDisposition = UserDisposition
CardVariables.SetVar(DispositionVariable, "#", CardDisposition)
CardVariables.SetVar(CommentVariable, "#", CardComment)
CardVariables.SetVar(ByVariable, "#", CardBy)
CardVariables.SetVar(DateVariable, "#", CardDate)
CardVariables.Flush()
THE BROADER STROKES :
Class module level variables:
Private Structure CommandInfo
Dim SourceVault As IEdmVault11
Dim SourceCommand As EdmCmd
Dim SourceSelection As System.Array
Dim TargetTemplate As System.String
Dim VerifiedPaths As List(Of String)
End Structure
Private ReceivedCommand As CommandInfo
OnCmd procedure (caller):
Public Sub OnCmd(ByRef poCmd As EdmCmd,
ByRef ppoData As System.Array) Implements IEdmAddIn5.OnCmd
Dim CommandToRun As MenuCommand
Try
With ReceivedCommand
.SourceVault = poCmd.mpoVault
.SourceCommand = poCmd
.SourceSelection = ppoData
'Get the command structure for the command ID
Select Case poCmd.meCmdType
Case EdmCmdType.EdmCmd_Menu
CommandToRun = AvailableCommands(.SourceCommand.mlCmdID)
Case EdmCmdType.EdmCmd_CardButton
Select Case True
Case poCmd.mbsComment.ToString.ToUpper.Contains("DISPOSITION")
DispositionRequest()
Case Else : Exit Sub
End Select
Case Else : Exit Sub
End Select
'...... (End Try, End Sub, Etc.)
DispositionRequest procedure (callee):
Private Sub DispositionRequest()
Dim UserDisposition As String
Using Disposition As New DispositionForm
With Disposition
If Not .ShowDialog() = System.Windows.Forms.DialogResult.OK Then Exit Sub
Select Case True
Case .Approve.Checked
UserDisposition = "Approved"
Case .Reject.Checked
UserDisposition = "Rejected"
Case Else : Exit Sub
End Select
End With
End Using
Dim UserComment As String
Using Explanation As New DispositionExplanation
With Explanation
If Not .ShowDialog() = System.Windows.Forms.DialogResult.OK Then Exit Sub
If .ListView1.Items.Count > 0 Then
'do some stuff not relevant to this question...
End If
UserComment = .Comments.Text
End With
End Using
'This next procedure just gets a list of paths from ReceivedCommand.SourceSelection - which is just the ppoData argument from the OnCmd procedure - see code block above!
Dim RequestPaths As List(Of String) = GetSelectedFilePaths()
For Each Path As String In RequestPaths
With ReceivedCommand
Dim RequestFile As IEdmFile5 = .SourceVault.GetFileFromPath(Path)
Dim ParentFolder As IEdmFolder6 = .SourceVault.GetFolderFromPath(System.IO.Path.GetDirectoryName(Path))
Dim UnlockLater As Boolean = False
If Not RequestFile.IsLocked Then
UnlockLater = True
RequestFile.LockFile(ParentFolder.ID, .SourceCommand.mlParentWnd, CInt(EdmLockFlag.EdmLock_Simple))
End If
Dim CardVariables As IEdmEnumeratorVariable5 = RequestFile.GetEnumeratorVariable
'We allow users to re-disposition a request so we want to keep any previous disposition information so it is not lost
Dim CardComment As String = String.Empty
Dim CardBy As String = String.Empty
Dim CardDate As String = String.Empty
Dim CardDisposition As String = String.Empty
Dim Success As Boolean
Const CommentVariable As String = "DispComm"
Const ByVariable As String = "DisposedBy"
Const DateVariable As String = "DisposedDate"
Const DispositionVariable As String = "Disposition"
Success = CardVariables.GetVar(DispositionVariable, "#", CardDisposition)
If Success Then
Success = CardVariables.GetVar(CommentVariable, "#", CardComment)
If Success Then Success = CardVariables.GetVar(ByVariable, "#", CardBy)
If Success Then Success = CardVariables.GetVar(DateVariable, "#", CardDate)
If Success Then CardComment = "Previously dispositioned as: """ & CardDisposition & """ by: " & CardBy & " on: " & CardDate & vbNewLine &
"---------Previous disposition explanation---------" & vbNewLine & CardComment
End If
Dim UserManager As IEdmUserMgr5 = .SourceVault
Dim User As IEdmUser5 = UserManager.GetLoggedInUser
CardComment = UserComment & CardComment
CardDate = Today().ToString("yyMMdd", Globalization.CultureInfo.InvariantCulture)
CardBy = User.Name
CardDisposition = UserDisposition
CardVariables.SetVar(DispositionVariable, "#", CardDisposition)
CardVariables.SetVar(CommentVariable, "#", CardComment)
CardVariables.SetVar(ByVariable, "#", CardBy)
CardVariables.SetVar(DateVariable, "#", CardDate)
CardVariables.Flush()
If UnlockLater Then RequestFile.UnlockFile(lParentWnd:= .SourceCommand.mlParentWnd,
bsComment:="Dispositioned as " & CardDisposition,
lEdmUnlockFlags:=0)
.SourceVault.RefreshFolder(ParentFolder.LocalPath)
End With
Next
End Sub
From the documentation:
bsCfgName : Name of configuration or layout to which to store the variable value; empty string for folders and file types that do not support configurations
I was working with a virtual file, which did not support configurations.
I saw a C example working with a virtual file and they were passing null references, so I reread the documentation and saw that excerpt above, so I changed my code from "#" to String.Empty for the mboconfiguration argument and now it is working!
CardVariables.SetVar(DispositionVariable, String.Empty, CardDisposition)
CardVariables.SetVar(CommentVariable, String.Empty, CardComment)
CardVariables.SetVar(ByVariable, String.Empty, CardBy)
CardVariables.SetVar(DateVariable, String.Empty, CardDate)
CardVariables.Flush()

Affiliate Window API passing columns to Service Causes Application Crash (VB.net)

This generates a crash, and I have no idea why?
I have very little experience using SOAP/WSDL and I think this may be why I have no idea how to even start to debug this.
Sub Main()
Dim service As AWIN.ApiService = New AWIN.ApiService
Dim columns As AWIN.getProductList
Dim AWresults() As AWIN.Product
Dim response As New AWIN.getProductListResponse
Dim total As Integer
Dim activerefine As AWIN.RefineByGroup
Dim refine As AWIN.RefineByGroup
Const token As String = "xxy"
Dim UA As AWIN.UserAuthentication = New AWIN.UserAuthentication
With UA
.sApiKey = token
End With
service.UserAuthenticationValue = UA
columns = New AWIN.getProductList
Dim stringsofthings As String() = {"sId", "iCategoryId", "iMerchantId", "sMerchantProductId", "iAdult", "bHotpick", _
"iUpc", "iEan", "sMpn", "iIsbn", "sName", "sDescription", "sSpecification", _
"sPromotion", "sBrand", "sModel", "sAwDeepLink", "sAwThumbUrl", "sAwImageUrl", _
"sMerchantThumbUrl", "sMerchantImageUrl", "sDeliveryTime", "fPrice", "sCurrency", _
"fStorePrice", "fRrpPrice", "fDeliveryCost", "bWebOffer", "bPreOrder", "sWarranty"}
columns.sColumnToReturn = stringsofthings
response = service.getProductList(columns)
For c = 0 To UBound(response.oProduct)
ReDim Preserve AWresults(c)
AWresults(c) = New AWIN.Product
AWresults(c) = response.oProduct(c)
Console.WriteLine(AWresults.ToString)
Next
Console.ReadLine()
End Sub

why I can't set nothing to variable in vb.net?

I have a a problem with my vb.net.
my code
class business{
buiding as string
}
I load data from mongodb
Dim collection1 = db1.GetCollection(Of business)("tablebusiness")
Dim list = collection1.Find(query1)
For Each abiz In list
Dim biztemp = abiz
biztemp.buiding = nothing '//// (but I get biztemp.building = "") why??
'biztemp.building = "" here
Next

String values left out of PropertyInfo.GetValue

I am not very well-versed in Reflection, but I have been working on this bit of code for a few days trying to obtain the values of class properties. I am using an API to find the values inside of cron jobs managed by the program VisualCron.
I'll explain the structure a bit. Each cron job has several tasks inside of it which have their own settings. The settings are stored in properties inside the TaskClass class that are declared like so:
Public Property <propertyname> As <classname>
Each property is tied to its own class, so for instance there is an Execute property inside TaskClass which is declared like this:
Public Property Execute As TaskExecuteClass
Inside TaskExecuteClass are the properties that hold the values I need. With the below block of code I have been able to retrieve the property values of all types EXCEPT strings. Coincidentally, the string values are the only values I need to get.
I know there must be something wrong with what I've written causing this because I can't find anyone with a similar issue after lots and lots of searching. Can anyone help me please?
Dim strAdd As String = ""
For Each t As VisualCronAPI.Server In vcClient.Servers.GetAll()
For Each f As VisualCron.JobClass In t.Jobs.GetAll
For Each s As VisualCron.TaskClass In f.Tasks
Dim propVal As Object
Dim propInfo As PropertyInfo() = s.GetType().GetProperties()
For i As Integer = 0 To propInfo.Length - 1
With propInfo(i)
If s.TaskType.ToString = propInfo(i).Name.ToString Then
Dim asm As Assembly = Assembly.Load("VisualCron")
Dim typeName As String = String.Format("VisualCron.{0}", propInfo(i).PropertyType.Name)
Dim tp As Type = asm.GetType(typeName)
Dim construct As ConstructorInfo = tp.GetConstructor(Type.EmptyTypes)
Dim classInst As Object = construct.Invoke(Nothing)
Dim classProps As PropertyInfo() = classInst.GetType().GetProperties()
For h As Integer = 0 To classProps.Length - 1
With classProps(h)
If .GetIndexParameters().Length = 0 Then
propVal = .GetValue(classInst, Nothing)
If Not propVal Is Nothing Then
strAdd = f.Name & " - " & s.Name & " - " & .Name & " - " & propVal.ToString
End If
End If
If strAdd <> "" Then
ListBox1.Items.Add(strAdd)
End If
End With
Next
End If
End With
Next
Next s
Next f
Next t
I solved my own problem, albeit in a crappy way. This is probably incredibly inefficient, but speed isn't a necessity in my particular case. Here is the code that works:
Dim strAdd As String = ""
For Each t As VisualCronAPI.Server In vcClient.Servers.GetAll()
For Each f As VisualCron.JobClass In t.Jobs.GetAll
For Each s As VisualCron.TaskClass In f.Tasks
Dim propVal As Object
Dim propInfo As PropertyInfo() = s.GetType().GetProperties()
For i As Integer = 0 To propInfo.Length - 1
With propInfo(i)
If s.TaskType.ToString = propInfo(i).Name.ToString Then
Dim asm As Assembly = Assembly.Load("VisualCron")
Dim typeName As String = String.Format("VisualCron.{0}", propInfo(i).PropertyType.Name)
Dim tp As Type = asm.GetType(typeName)
Dim construct As ConstructorInfo = tp.GetConstructor(Type.EmptyTypes)
Dim classInst As Object = construct.Invoke(Nothing)
Dim classProps As PropertyInfo() = classInst.GetType().GetProperties()
For h As Integer = 0 To classProps.Length - 1
With classProps(h)
If .GetIndexParameters().Length = 0 Then
propVal = .GetValue(CallByName(s, propInfo(i).Name.ToString, [Get]), Nothing)
If Not propVal Is Nothing Then
If propVal.ToString.Contains("\\server\") Or propVal.ToString.Contains("\\SERVER\") Then
strAdd = f.Name & " - " & s.Name & " - " & .Name & " - " & propVal.ToString
ListBox1.Items.Add(strAdd)
End If
End If
End If
End With
Next
End If
End With
Next
Next s
Next f
Next t
The piece of code that made the difference was the
classProps(h).GetValue(CallByName(s, propInfo(i).Name.ToString, [Get]), Nothing)
line.
If there are any suggestions for improving this code - I'm assuming that I've still got a lot of mistakes in here - then please comment for the future viewers of this answer and so I can adjust my code and learn more about how all of this works.

Loop to create multiple series in chart control

I am trying to build a function that returns a chart. I want to have a parameter to account for times where i may need more than one series. How does one loop through to create multiple series? I would think you would need a variable for each series. The function is below. I would think that if there were 5 series that each of the "Dataseries" variables should have their own name. Do I then refer to them by index only?
Public Shared Function MakeChart(ByVal form As Form, Optional ByVal numseries As Integer = 0) As Chart
' Add any initialization after the InitializeComponent() call.
Dim SampleChart As Chart = New Chart()
Dim MainChartArea As ChartArea = New ChartArea()
Dim ChartLegend As Legend = New Legend()
Dim Dataseries As Series = New Series()
Dim seriesname As String = ""
'add additonal series if the parameter exists
If numseries > 0 Then
For i As Integer = 0 To numseries - 1
seriesname = "Series" & Convert.ToString(i)
Dataseries = SampleChart.Series.Add(i)
Dataseries.Name = seriesname
Next
Else
DataSeries = SampleChart.Series.Add("Series1")
Dataseries.Name = "Series1"
End If
form.Controls.Add(SampleChart)
SampleChart.ChartAreas.Add(MainChartArea)
SampleChart.Legends.Add(ChartLegend)
SampleChart.Dock = DockStyle.Fill
SampleChart.TabIndex = 0
Return SampleChart
End Function
Index or String, so yes, you can refer to the series by the name:
MessageBox.Show("First Series is " & SampleChart.Series(0).Name)
or
MessageBox.Show("First Series is " & SampleChart.Series("Series0").Name)
Note though: If the string is not found, the control will throw an ArgumentException error.