How to convert 'Integer' to 'Timestamps'? - discord.net

**I did a effort but got error while testing
Error BC30311 Value of type 'Integer' cannot be converted to 'Timestamps'.**
I have tried this :
Public Sub test()
client = New DiscordRpcClient("test")
client.Logger = New ConsoleLogger
client.Initialize()
client.SetPresence(New RichPresence With {
.Details = "test",
.Assets = New Assets() With {
.LargeImageKey = "test",
.LargeImageText = "test",
.Timestamps = 0
})
Dim timer = New System.Timers.Timer(150)
AddHandler timer.Elapsed, Sub(sender, args)
client.Invoke()
End Sub
timer.Start()
client.Invoke()
End Sub
here the problem is "Timestamps = 0", So how can i solve.
im trying to use discord rich Presence elapsed timer.

This is actually more of an issue with this Discord-RPC-Csharp library than it is with C#. That being said, I looked into it anyway.
The example code given in the repository for this project shows this as an example
Timestamps = Timestamps.FromTimeSpan(10)
See the error you got is an error specific to C# for when trying to assign one value type to a complete different type. An Integer is not a Timestamp, and a Timestamp is not an Integer. So we need to figure out what Timestamps actually is. So the best way to do this is to right-click on Timestamps and go to "Go To Definition" or hit F12 on it.
Now in RichPresence.cs you can see the class definition for Timestamps. You will see four options
Timestamps.Now
Timestamps.FromTimeSpan(double seconds)
Timestamps.FromTimeSpan(Timespan timespan)
in addition to a constructor
new Timestamps(DateTime start, DateTime end)
Since you haven't told us what this timestamp is supposed to represent in your code, I'll leave it to you to figure out which one of these you want/need to use.

Related

VB.net Unable to cast object of type System.Collections.Generic.list to type string

Please forgive me in advanced for my lack of coding knowledge.
I'm using a NuGet package called KuCoin.Net and have everything setup and connected. I can run the command and Place a Buy order so I know my Api settings are correct. The issue I'm having is when I run the following code:
Public Async Function GetBalancesAsync() As Task
Dim kucoinClient = New KucoinClient(New KucoinClientOptions() With {
.ApiCredentials = New KucoinApiCredentials("xxx", "xxx", "xxx"),
.LogLevel = LogLevel.Debug,
.RequestTimeout = TimeSpan.FromSeconds(60),
.FuturesApiOptions = New KucoinRestApiClientOptions With {
.ApiCredentials = New KucoinApiCredentials("xxx", "xxx", "xxx"),
.AutoTimestamp = False
}})
Dim accountData = Await kucoinClient.SpotApi.Account.GetAccountsAsync()
MessageBox.show(accountData.data)
End Function
I guess I'm needing to convert the list to a string so I can display it into a Messagebox.
The Error I recieve is as follows:
Unable to cast object of type 'System.Collections.Generic.List`1[Kucoin.Net.Objects.Models.Spot.KucoinAccount]' to type 'System.String'
Here is some additional info if this helps
Error
accountData
Any help is much appreciated
You can generate your String yourself using a StringBuilder while enumerating through accountData.Data:
Dim sb As New System.Text.StringBuilder
For Each account As Kucoin.Net.Objects.Models.Spot.KucoinAccount In accountData.data
sb.AppendLine(account.ToString)
Next
MessageBox(sb.ToString())
You can change account.ToString to something more appropriate like accout.Number perhaps (see the properties the KucoinAccount object has).

Using Visual Studios 2013 and VB.net, how to capitalize lets in a textfield mixed with numbers

I am and entry level programmer and i have a task that is asking me to modify a page that takes and entry from a textfield that is mixed with letters and numbers. this field is called a "job#" and then the page will search a database for that in particular job. problem is that it only searches it if its in capital letters. need to have it accept caps and lower case letters. it is in VB.net. and i went to the controller and i have this code here
Try
res.success = True
res.message = ""
Dim r = New Objects.Business.Capital.CapitalRequest(jobNumber)
Dim req = New ViewModels.Business.Capital.CapitalRequest(r)
Models.Core.Approvals.AddIApprovableToCache(r)
res.data = req
Return New PCA.Core.Web.JSON.JSONPResult() With { _
.Data = res,
.Callback = callback
}
i tried to tack on "ToUpper() after the (jobnumber) because i thought that is where it takes the number entered and applies it to a variable to search the database for it. but it says that 'ToUpper()' is not a member of 'Trident.Objects.Business.Capital.CapitalRequest' im assuming the parent class doesnt have the package where ToUpper() is ?
i tried to tack on "ToUpper() after the (jobnumber) because i thought
that is where it takes the number entered and applies it to a variable
to search the database for it. but it says that 'ToUpper()' is not a
member of 'Trident.Objects.Business.Capital.CapitalRequest'
Instead of
Dim r = New Objects.Business.Capital.CapitalRequest(jobNumber).ToUpper()
use
Dim r = New Objects.Business.Capital.CapitalRequest(jobNumber.ToUpper())

Disable WebBrowser caching

I am new here and really want your help.
I've been trying to disable my webbrowser's cache but I get overload resolution failed because no accessible "Navigate" without a narrowing conversion. I'm stuck and I don't know what to do anymore, I did search all the possible solutions but found no answer.
Here's my code:
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Const navNoReadFromCache As Long = 4
Const navNoHistory As Long = 2
Const navNoWriteToCache As Long = 8
Dim navflags As Long
navflags = navNoHistory + navNoWriteToCache
WebBrowser1.Navigate("url", 4)
End Sub
End Class
Original Error message is:
Error 2 Overload resolution failed because no accessible 'Navigate' can be called without a narrowing conversion:
'Public Sub Navigate(urlString As String, newWindow As Boolean)': Argument matching parameter 'newWindow' narrows from 'Integer' to 'Boolean'.
'Public Sub Navigate(urlString As String, targetFrameName As String)': Argument matching parameter 'targetFrameName' narrows from 'Integer' to 'String'.
.NET WebBrowserControl doesn't have overload what accept int or long argument.
So, you can't set BrowserNavConstants (this for IWebBrowser2 not .NET WebBrowserControl) value to .NET WebBrowserControl.
I found following page:
http://msdn.microsoft.com/en-us/library/40x214wa%28v=vs.110%29.aspx
The WebBrowser control stores Web pages from recently visited sites in a cache on the local hard disk. Each page can specify an expiration date indicating how long it will remain in the cache. When the control navigates to a page, it saves time by displaying a cached version, if one is available, rather than downloading the page again.
Use the Refresh method to force the WebBrowser control to reload the current page by downloading it, ensuring that the control displays the latest version.
Updated.
I try the code following, that looks like work fine :
private void button1_Click(object sender, EventArgs e) {
webBrowser1.Navigate("http://www.google.co.jp");
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
webBrowser1.Refresh(WebBrowserRefreshOption.Completely);
}
This loads page two times.
So after some time of searching and testing different methods I came with a good result.
Shell("RunDll32.exe InetCpl.cpl, ClearMyTracksByProcess 8", vbHide)
This is the code I used to delete the cache that held my web browser on a blackscreen.
What it does is search for the Internet Explorer's Temporary files and deletes them, the vbHide has to be kept next to the comma to work, what is does is hide the window that pops us telling you it deletes temp files.

Entity Model Not Being Updated on SaveChanges

I have a misunderstanding somewhere with the Entity Framework. This code is from my unit testing:
Public Sub UpdateRosterLinkTest()
Dim target As PlayerAdmin = New PlayerAdmin()
target.PlayerAdminManager = playerAdminTestManager
target.Team = playerAdminTestManager.GetAirForceMensBB()
playerAdminTestManager.resetRosterLink(target)
Assert.IsNull(target.Team.RosterLink)
Dim playerAdmin As PlayerAdmin = New PlayerAdmin()
playerAdmin.TeamId = 12434
playerAdmin.RosterLink = "Roster Link"
playerAdmin.UpdateRosterLink()
Dim team As DAL.Team = playerAdminTestManager.GetAirForceMensBB()
Assert.AreEqual("Roster Link", team.RosterLink)
End Sub
I'm creating a PlayerAdmin, which is a model class. target.Team is an Entity object. What I do is reset the RosterLink field in the Team just to make sure our test starts out at the same place. Then I call the UpdateRosterLink() function. That looks like:
Function UpdateRosterLink() As Integer
If (PlayerAdminManager Is Nothing) Then
PlayerAdminManager = New PlayerAdminManager()
End If
Team = PlayerAdminManager.GetTeamByTeamId(TeamId)
Team.RosterLink = RosterLink
Dim numberOfChanges As Integer = PlayerAdminManager.SaveChanges()
Return numberOfChanges
End Function
When I run this code, I can see the changes saved to the SQL Server this pulls from (RosterLink = Roster Link, like I set in the unit test).
However, my unit test is failing, because team.RosterLink is still Nothing. The function GetAirForceMensBB() returns the Team with TeamId = 12434:
Function GetAirForceMensBB() As DAL.Team
Return (From team In Container.Teams Where team.TeamId = 12434).SingleOrDefault
End Function
I'm sure I'm using the entity framework incorrectly and it probably has something to do with the fact that I am calling the PlayerAdminTestManager in different places, but I don't understand why. Although, I set the PlayerAdminManager to be the PlayerAdminTestManager. PlayerAdminTestManager extends PlayerAdminManager, fyi.
Why is team.RosterLink not showing the update from UpdateRosterLink?
Thanks
EDIT
Container is my ObjectContext. This is how I access the information stored in the database. Container.Teams represents my Teams table.
The problem was I was referencing different instantiations of the Container (each manager created its own). Thus, the entity items were not attached to anything.
Doh!

How do I check whether a Linq-to-SQL object is already attached to a DataContext?

I have an object that may have been inflated via a plain old DataContext, or may just have been new-ed up with just its .ID property set. There's no way to know for sure. I'm looking to rehydrate the entire object from whatever is in the database. If the object was new-ed up, I can call .Attach() on the table object and refresh from the Data Context with no trouble. But, if the object was already inflated from the DataContext I get the error: "Cannot attach an entity that already exists.". There's no timestamp field or anything like that - just an integer primary key being used to control the rehydration. I'd like to know if there's a way to conditionally attach. Here's the code - it works the way I want it to, but this seems a hackish way to go about it:
' myDC is a shared instance of a vanilla DataContext...
' myObj is an instance of a linqed-up `SomeLinqObject`
Dim tbl = myDC.GetTable(Of SomeLinqObject)()
Try
tbl.Attach(myObj) ' <-- Wish I could just TryAttach() here!
Catch ex As Exception
If ex.Message = "Cannot attach an entity that already exists." Then
' Do nothing
Else
Throw
End If
End Try
myDC.Refresh(RefreshMode.OverwriteCurrentValues, myObj) ' Rehydrate
-- EDIT --
Thanks to Isaac's answer, here's the revised code:
Dim tbl = myDC.GetTable(Of SomeLinqObject)()
Dim isAttached = (tbl.GetOriginalEntityState(myObj) IsNot Nothing)
If Not isAttached Then tbl.Attach(myObj)
myDC.Refresh(RefreshMode.OverwriteCurrentValues, myObj) ' Rehydrate
GetOriginalEntityState(T entity) on Table -might- be what you're looking for. If you pass it an entity that you've loaded from the context, it returns the original version of the entity held in the context. If you pass it a new entity (or I believe one simply not sourced from that context), it returns null.
var context = new DataClasses1DataContext();
var person = context.Person.First();
var isAttachedToContext = context.Person.GetOriginalEntityState(person) != null; // returns true
var isNewEntityAttachedToContext = context.Peoples.GetOriginalEntityState(new Person()) != null; // returns false
Apologies - answer is in C# but I hope you get the gist!