message id from GetResultData - vb.net

I cannot seem to get or store the id of the post message I create. I am using this code to post a message:
Try
Dim fb = New FacebookClient(_accessToken)
AddHandler fb.PostCompleted, Function(o, e)
If (e.Cancelled) Then
ElseIf e.Error IsNot Nothing Then
MessageBox.Show(e.Error.Message)
Else
Dim result As Object = e.GetResultData()
_lastMessageId = result.Id
End If
Return MessageBox.Show("Message Posted successfully")
End Function
Dim parameters As Object = New ExpandoObject()
parameters.message = TextBox1.Text
fb.PostTaskAsync("me/feed", parameters)
MsgBox("This is the last message id " & _lastMessageId)
Catch ex As FacebookApiException
MessageBox.Show(ex.Message)
End Try
I just want to store the posted id so I can delete it later.
Here is the working code that i came up with thanks to prabir
Dim fb = New FacebookClient(_accessToken)
Dim parameters As Object = New ExpandoObject()
parameters.message = "Testing"
Dim task = fb.PostTaskAsync("me/feed", parameters)
task.ContinueWith(Function(t)
If t.Exception Is Nothing Then
Dim result As Object = t.Result
_lastMessageId = result.id
Else
MsgBox("error occurred")
End If
Return t.Result
End Function)

here is c# code which might help you get started with it.
Since you are using XTaskAsync methods use ContinueWith instead of PostCompleted.
fb.PostTaskAsync("me/feed", parameters)
.ContinueWith(t= > {
if(!t.IsFaulted) {
dynamic result = t.Result;
}
});
XTaskAsync methods returns Task<object>

Related

User not verified after migrating from Authy to Verify

We had earlier asked a question regarding migrating the data from Authy to Verify API. We were following the steps provided in this URL.
(https://www.stackoverflow.com/questions/74302235/migrate-authy-totp-to-verify)
However, when we are migrating the user, the user is not verified even after the migration. Here is the code which we are using
Dim oAuthy = New clsAuthy(apiKey, False)
'Fetch details from authy to migrate to verify
Dim authyDetails As clsAuthySecret = oAuthy.GetAuthyDetails(item("TwilioAuthyId"))
oAuthy = Nothing
'Migrate data to verify API
With oVerify
.GenerateQRCode(item("UserName"), item("UserId").ToString(), authyDetails.Secret)
.VerifyToken(.FactorID, authyDetails.OTP, item("UserId").ToString())
FactorId = .FactorID
VerifyUrl = .QrUrl
End With
Public Function GetAuthyDetails(ByRef AuthyID As String) As clsAuthySecret
Dim apiResponse As clsAuthySecret
Dim url = String.Format("{0}/protected/json/users/{1}/secret/export", Me.baseUrl, AuthyID, Me.apikey)
Try
client.Headers.Set("X-Authy-API-Key", Me.apikey)
Dim response = client.DownloadString(url)
apiResponse = JsonConvert.DeserializeObject(Of clsAuthySecret)(response)
apiResponse.RawResponse = response
Catch ex As WebException
apiResponse = New clsAuthySecret()
apiResponse.Status = AuthyStatus.BadRequest 'bad request
apiResponse.Message = ex.Message
'apiResponse.RawResponse = ex.Response.ToString()
End Try
If (apiResponse.Success) Then
apiResponse.Status = AuthyStatus.Success
End If
Return apiResponse
End Function
Public Function GenerateQRCode(ByVal Email As String,
ByVal UserID As String,
ByVal Secret As String
) As Task(Of Boolean)
Try
TwilioClient.Init(_accountSID, _authToken)
Dim newFactor = NewFactorResource.Create(friendlyName:=Email,
factorType:=NewFactorResource.FactorTypesEnum.Totp,
pathServiceSid:=_serviceSID,
pathIdentity:=UserID.ToLower(),
bindingSecret:=Secret)
_factorID = newFactor.Sid
_qrUrl = JObject.Parse(newFactor.Binding.ToString())("uri")
Catch ex As Exception
_responseMessage = ex.Message
Return False
End Try
Return True
End Function
Public Function VerifyToken(ByVal FactorID As String,
ByVal Token As String,
ByVal UserID As String
) As Task(Of Boolean)
Try
TwilioClient.Init(_accountSID, _authToken)
Dim factor = FactorResource.Update(authPayload:=Token,
pathServiceSid:=_serviceSID,
pathIdentity:=UserID.ToLower(),
pathSid:=FactorID)
If factor.Status.ToString = "verified" Then
Return True
Else
Return False
End If
Catch ex As Exception
_responseMessage = ex.Message
Return False
End Try
End Function
Is there anything we are missing from our end? Following is the response as shown in the image link below
https://i.stack.imgur.com/lhTkE.png

Convert jscript to vb.net

We use Kaspersky Security Center to manage AV on all our domain computers. I was looking for an external way to move computers to different groups and change the comments we give them in the Kaspersky Security Center. Kaspersky gave me some links to check out but I have no idea where to start on this. I was looking to code this in a VB.Net Windows Form Application.
My question is how do i convert or make the below jscript work in a VB.net Windows form. I'm going to have a sql table loaded with the Kaspersky Host ID, Comment and GroupID. once a day i want to iterate down through that sql table and only update the computers that need changes made wither to their comment or group. (the sql part i already have written)
Here is what im Aiming for:
Dim reader3 As SqlDataReader
Dim strconnection3 As String
strconnection3 = data_source_all 'defined globally
Dim SqlConnection3 As New SqlConnection(strconnection3)
Dim cmd3 As New SqlCommand
cmd3.CommandText = "SELECT kaspersky_hostid, kaspersky_comment, pc_info_comment, kaspersky_groupid FROM pc_info where (pc_status = 'active')"
cmd3.CommandType = CommandType.Text
cmd3.Connection = SqlConnection3
SqlConnection3.Open()
reader3 = cmd3.ExecuteReader()
If reader3.HasRows Then
While reader3.Read()
If reader3(1).ToString = reader3(2).ToString Then
Else
Update_Host_Comment(reader3(0).ToString,reader3(2).ToString)
End If
End While
SqlConnection3.Close()
SqlConnection3.Dispose()
cmd3.Dispose()
Else
End If
Public Sub Update_Host_Comment(ByVal hostid As String, ByVal comment As String)
'Converted JScript
'var oHosts = new ActiveXObject("klakaut.KlAkHosts");
'oHosts.AdmServer = AcquireAdServerProxy();
'var strHostName = hostid; //name of the host to change attributes
'//Fill container with attributes to change
'var oProps = new ActiveXObject("klakaut.KlAkParams");
'oProps.Item("KLHST_WKS_COMMENT") = comment; //Change Comment
'oHosts.UpdateHost(strHostName, oProps);
End Sub
Link1: https://support.kaspersky.com/9291
Link2: https://support.kaspersky.com/2810
below is the JScript i want to run with vb.net:
function AcquireAdServerProxy()
{
var oSrvConnectionProps = new ActiveXObject("klakaut.KlAkParams");
oSrvConnectionProps.Add("Address", "localhost:13291");
oSrvConnectionProps.Add("UseSSL", true);
var oAdmServer = new ActiveXObject("klakaut.KlAkProxy");
oAdmServer.Connect(oSrvConnectionProps);
return oAdmServer;
};
function Update_Host_Comment(hostid,comment)
{
var oHosts = new ActiveXObject("klakaut.KlAkHosts");
oHosts.AdmServer = AcquireAdServerProxy();
var strHostName = hostid; //name of the host to change attributes
//Fill container with attributes to change
var oProps = new ActiveXObject("klakaut.KlAkParams");
oProps.Item("KLHST_WKS_COMMENT") = comment; //Change Comment
oHosts.UpdateHost(strHostName, oProps);
};
function Update_Host_Group(hostid,groupid)
{
var oHosts = new ActiveXObject("klakaut.KlAkHosts");
oHosts.AdmServer = AcquireAdServerProxy();
var strHostName = hostid; //name of the host to change attributes
//Fill container with attributes to change
var oProps = new ActiveXObject("klakaut.KlAkParams");
oProps.Item("KLHST_WKS_GROUPID") = groupid; //Change group
oHosts.UpdateHost(strHostName, oProps);
};
//Calling Functions
Update_Host_Comment("SomeHostID","Some Comment Text");
Update_Host_Group("SomeHostID","Some GroupID");
06/04/18 Edit: Here is the code i tried:
Public Function AcquireAdServerProxy()
Try
Dim oSrvConnectionProps = CreateObject("klakaut.KlAkParams")
oSrvConnectionProps.Add("Address", "localhost:13291")
oSrvConnectionProps.Add("UseSSL", True)
Dim oAdmServer = CreateObject("klakaut.KlAkProxy")
oAdmServer.Connect(oSrvConnectionProps)
Return oAdmServer
Catch ex As Exception
MsgBox(ex.ToString)
Return False
End Try
End Function
Public Function Update_Host_Comment(ByVal hostid As String, ByVal comment As String) As Boolean
Try
Dim ohosts = CreateObject("klakaut.KlAkHosts")
ohosts.AdmServer = AcquireAdServerProxy()
Dim strHostName = hostid
'Fill container with attributes to change
Dim oProps = CreateObject("klakaut.KlAkParams")
oProps.Item("KLHST_WKS_COMMENT") = comment
ohosts.UpdateHost(strHostName, oProps)
Return True
Catch ex As Exception
MsgBox(ex.ToString)
Return False
End Try
End Function
Public Function Update_Host_Group(ByVal hostid As String, ByVal groupid As Integer) As Boolean
Try
Dim ohosts = CreateObject("klakaut.KlAkHosts")
ohosts.AdmServer = AcquireAdServerProxy()
Dim strHostName = hostid
'Fill container with attributes to change
Dim oProps = CreateObject("klakaut.KlAkParams")
oProps.Item("KLHST_WKS_GROUPID") = groupid
ohosts.UpdateHost(strHostName, oProps)
Return True
Catch ex As Exception
MsgBox(ex.ToString)
Return False
End Try
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Label4.Text = "Processing ..."
Label4.Update()
Try
If TextBox1.Text <> Nothing Then
If TextBox2.Text <> Nothing Then
If Update_Host_Comment(TextBox1.Text, TextBox2.Text.ToUpper) Then
Label4.Text = "Comment Updated"
Label4.Update()
Else
Label4.Text = "Comment Update Error"
Label4.Update()
End If
Else
End If
If TextBox3.Text <> Nothing And IsNumeric(TextBox3.Text) Then
If Update_Host_Group(TextBox1.Text, TextBox3.Text) Then
Label4.Text = Label4.Text & " / Group Updated"
Label4.Update()
Else
Label4.Text = Label4.Text & " / Group Update Error"
Label4.Update()
End If
Else
End If
End If
Catch ex As Exception
Label4.Text = "Error"
Label4.Update()
End Try
End Sub
End Class
This is the error i get when i run it:
System.Runtime.InteropServices.COMException (0xE0FF04FD): Transport level error while connecting to http://localhost:13291: failed to resolve address at Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack, Boolean IgnoreReturn) at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, Boolean IgnoreReturn) at kaspersky_api.Form1.AcquireAdServerProxy()

Adding a dynamic member to an ExpandoObject

In the following method I am trying to add a dynamic member to an expando object but it throws an exception:
public member not found for expand object
Private Sub GetAckValues()
Try
Dim ack_duration As String = String.Empty
Dim ack_by_user_fkid As String = String.Empty
Dim ack_time As String = String.Empty
ack_duration = txtdefaultack.Text
ack_by_user_fkid = Convert.ToString(Session("user_code"))
Dim Ack_Detail As Object = New ExpandoObject()
Ack_Detail.ack_duration = ack_duration
Ack_Detail.ack_by_user_fkid = ack_by_user_fkid
receiptObject.StatusObject = Ack_Detail
Catch ex As Exception
logger.Error("Enter JobRequest form done by :" & LoggedinUserId, ex)
End Try
End Sub
Should this:
Ack_Detail.ack_duration = Ack_Detail.ack_duration
actually be this:
Ack_Detail.ack_duration = ack_duration

Is it possible to assembly loadfrom Microsoft.Office.Interop.Word.dll

When i try this
oAssembly = Assembly.LoadFrom("C:\dynamicdlls\Microsoft.Office.Interop.Word.dll")
oType = oAssembly.GetType("Microsoft.Office.Interop.Word.Application")
Try
oObject = Activator.CreateInstance(oType)
Dim doc As Object = oObject.Documents.Open("C:\worddoc\test.docx")
Dim count As Integer = doc.Words.Count
For i As Integer = 1 To count
Dim text As String = doc.Words(i).Text
Console.WriteLine("Word {0} = {1}", i, text)
Next
oObject.Quit()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
I get "Cannot create an instance of an interface".
I Know there is a better alternative to this, I am just exploring this method and would like to know if this is possible and how would one do it.

async function in mvc4 vb.net

i have the below structure :
this is my controller :
Public Function InsertRegistration() as string
dim res = t.Insertregistration(jsonparam.status)
return res
End Function
this is my class :
Public Function InsertRegistration(byval status as string) as string
sql.Insertregistration(status)
return "1"
End Function
this is my model function :
Public Function InsertRegistration(ByVal status As String) As Boolean
Dim TConnSQL As New SqlConnection(sql)
Dim CommSQL As New SqlClient.SqlCommand("JK_SP_INSERT_PROFILE", TConnSQL)
Dim paramSQL As SqlClient.SqlParameter
Dim data_ada As SqlDataAdapter
Dim dt As DataSet
Try
CommSQL.CommandType = CommandType.StoredProcedure
paramSQL = New SqlClient.SqlParameter("#STATUS", SqlDbType.NVarChar, 100)
paramSQL.Direction = ParameterDirection.Input
paramSQL.Value = STATUS
CommSQL.Parameters.Add(paramSQL)
CommSQL.ExecuteNonQuery()
InsertRegistration= True
Catch ex As System.Data.SqlClient.SqlException
WriteToText("Nbl.InsertRegistration", ex.ToString)
InsertRegistration= False
Catch ex As Exception
WriteToText("Nbl.InsertRegistration", ex.ToString)
InsertRegistration= False
Finally
If (IsNothing(CommSQL) = False) Then CommSQL.Dispose()
If TConnSQL.State <> ConnectionState.Closed Then TConnSQL.Close()
End Try
End Function
is there a way to return the result 1 in an asynchronous way that the function sql.Insertregistration(status) keeps running in background after i return the result to the client?
Simply put your function sql.Insertregistration(status) as in below code:
(new Task<bool>(() =>
{
return sql.Insertregistration(status);
})).Start();
Note: Please take care of the cross thread ooperations.