Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

c# > vb conversion

Hi, ive been trying to convert c# code to vb.net, i found someone also trying to do it but they had no response on their post on another forum, here is where they got up to which is about the same where im stuck, i can convert most but the other sections such as reading the json file from the folder and such not too sure. Im not fluent in c#

here is the c# code
Code
using System;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using Google.Apis.Upload;
using Google.Apis.Util.Store;
using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data;

{
 /// <summary>
 /// YouTube Data API v3 sample: upload a video.
 /// Relies on the Google APIs Client Library for .NET, v1.7.0 or higher.
 /// See https://developers.google.com/api-client-library/dotnet/get_started
 /// </summary>
 internal class UploadVideo
 {
   [STAThread]
   static void Main(string[] args)
   {
     Console.WriteLine("YouTube Data API: Upload Video");
     Console.WriteLine("==============================");

     try
     {
       new UploadVideo().Run().Wait();
     }
     catch (AggregateException ex)
     {
       foreach (var e in ex.InnerExceptions)
       {
         Console.WriteLine("Error: " + e.Message);
       }
     }

     Console.WriteLine("Press any key to continue...");
     Console.ReadKey();
   }

   private async Task Run()
   {
     UserCredential credential;
     using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
     {
       credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
           GoogleClientSecrets.Load(stream).Secrets,
           // This OAuth 2.0 access scope allows an application to upload files to the
           // authenticated user's YouTube channel, but doesn't allow other types of access.
           new[] { YouTubeService.Scope.YoutubeUpload },
           "user",
           CancellationToken.None
       );
     }

     var youtubeService = new YouTubeService(new BaseClientService.Initializer()
     {
       HttpClientInitializer = credential,
       ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
     });

     var video = new Video();
     video.Snippet = new VideoSnippet();
     video.Snippet.Title = "Default Video Title";
     video.Snippet.Description = "Default Video Description";
     video.Snippet.Tags = new string[] { "tag1", "tag2" };
     video.Snippet.CategoryId = "22"; // See https://developers.google.com/youtube/v3/docs/videoCategories/list
     video.Status = new VideoStatus();
     video.Status.PrivacyStatus = "unlisted"; // or "private" or "public"
     var filePath = @"REPLACE_ME.mp4"; // Replace with path to actual movie file.

     using (var fileStream = new FileStream(filePath, FileMode.Open))
     {
       var videosInsertRequest = youtubeService.Videos.Insert(video, "snippet,status", fileStream, "video/*");
       videosInsertRequest.ProgressChanged += videosInsertRequest_ProgressChanged;
       videosInsertRequest.ResponseReceived += videosInsertRequest_ResponseReceived;

       await videosInsertRequest.UploadAsync();
     }
   }

   void videosInsertRequest_ProgressChanged(Google.Apis.Upload.IUploadProgress progress)
   {
     switch (progress.Status)
     {
       case UploadStatus.Uploading:
         Console.WriteLine("{0} bytes sent.", progress.BytesSent);
         break;

       case UploadStatus.Failed:
         Console.WriteLine("An error prevented the upload from completing.\n{0}", progress.Exception);
         break;
     }
   }

   void videosInsertRequest_ResponseReceived(Video video)
   {
     Console.WriteLine("Video id '{0}' was successfully uploaded.", video.Id);
   }
 }
}
This is the current code for vb where im also stuck at
Code
Imports System
Imports System.IO
Imports System.Reflection
Imports System.Threading
Imports System.Threading.Tasks

Imports Google.Apis.Auth.OAuth2
Imports Google.Apis.Services
Imports Google.Apis.Upload
Imports Google.Apis.Util.Store
Imports Google.Apis.YouTube.v3
Imports Google.Apis.YouTube.v3.Data

   Private Shared Sub Main(args As String())
       Console.WriteLine("YouTube Data API: Upload Video")
       Console.WriteLine("==============================")

       Try
           New UploadVideo().Run().Wait()
       Catch ex As AggregateException
           For Each e As var In ex.InnerExceptions
               Console.WriteLine("Error: " + e.Message)
           Next
       End Try

       Console.WriteLine("Press any key to continue...")
       Console.ReadKey()
   End Sub

   Private Function Run() As Task
       Dim credential As UserCredential
       Using stream = New FileStream("client_secrets.json", FileMode.Open, FileAccess.Read)
           ' This OAuth 2.0 access scope allows an application to upload files to the
           ' authenticated user's YouTube channel, but doesn't allow other types of access.
           credential = Await GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets, New () {YouTubeService.Scope.YoutubeUpload}, "user", CancellationToken.None)
       End Using

       Dim youtubeService__1 = New YouTubeService(New BaseClientService.Initializer() With { _
           Key .HttpClientInitializer = credential, _
           Key .ApplicationName = Assembly.GetExecutingAssembly().GetName().Name _
       })

       Dim video = New Video()
       video.Snippet = New VideoSnippet()
       video.Snippet.Title = "Default Video Title"
       video.Snippet.Description = "Default Video Description"
       video.Snippet.Tags = New String() {"tag1", "tag2"}
       video.Snippet.CategoryId = "22"
       ' See https://developers.google.com/youtube/v3/docs/videoCategories/list
       video.Status = New VideoStatus()
       video.Status.PrivacyStatus = "unlisted"
       ' or "private" or "public"
       Dim filePath = "REPLACE_ME.mp4"
       ' Replace with path to actual movie file.
       Using fileStream = New FileStream(filePath, FileMode.Open)
           Dim videosInsertRequest = youtubeService__1.Videos.Insert(video, "snippet,status", fileStream, "video/*")
           AddHandler videosInsertRequest.ProgressChanged, AddressOf videosInsertRequest_ProgressChanged
           AddHandler videosInsertRequest.ResponseReceived, AddressOf videosInsertRequest_ResponseReceived

           Await videosInsertRequest.UploadAsync()
       End Using
   End Function

   Private Sub videosInsertRequest_ProgressChanged(progress As Google.Apis.Upload.IUploadProgress)
       Select Case progress.Status
           Case UploadStatus.Uploading
               Console.WriteLine("{0} bytes sent.", progress.BytesSent)
               Exit Select

           Case UploadStatus.Failed
               Console.WriteLine("An error prevented the upload from completing." & vbLf & "{0}", progress.Exception)
               Exit Select
       End Select
   End Sub

   Private Sub videosInsertRequest_ResponseReceived(video As Video)
       Console.WriteLine("Video id '{0}' was successfully uploaded.", video.Id)
   End Sub
End Class


About 9-10 errors, here they are

New UploadVideo().Run().Wait() 'syntax error for 'New"
Type 'var' is not defined (For Each e As Var in ex.InnerExceptoons)
'Await' not declared (credential = Await Google) also end of statement expected
'Key' (end of statement expected)
'youtubeService__1' (not declaredd)
'Progress Changed' not an event of 'Object'
'ResoinseRecieved' not event of object
and 'await' once again; not declared
Call New UploadVideo().Run().Wait() (add call)
For Each e in ex.InnerExceptoons (delete var)
maybe framework version or async missing ('Await' not declared)
add Async Function Run() As Task (add async to function)
delete (Key)
cus the key error you get it youtubeService__1 not declared
[Image: bitcoin.png] Be Nice For Once 15hVUVz7xA4kazHdk2BuErENGCskVwjYXP


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by debugDec 22, 2020 04:51 PM 0 228 Dec 22, 2020 04:51 PM
Last Post: debug
[Shell] by HackooJul 27, 2017 10:43 AM 1 673 Jul 27, 2017 10:43 AM
Last Post: x4x552
[Shell] by eridanusNov 5, 2016 11:07 PM 3 189 Nov 5, 2016 11:07 PM
Last Post: eridanus