Skip to content
jackkoolage edited this page Jan 22, 2020 · 11 revisions

4sharedSDK

Download:https://github.com/jackkoolage/4sharedSDK/releases
NuGet: NuGet

Features:

  • Assemblies for .NET 4.5.2 and .NET Standard 2.0 and .NET Core 2.1
  • Just one external reference (Newtonsoft.Json)
  • Easy installation using NuGet
  • Upload/Download tracking support
  • Proxy Support
  • Upload/Download cancellation support

List of functions:

Token

  1. Login
  2. Register

Account(Mine)

  1. UserInfo
  2. UpdateUserInfo
  3. GetAvatarPicture
  4. SetAvatarPicture

Comment

  1. ListComments
  2. Create
  3. Delete
  4. Reply
  5. ReportAsSpam
  6. UnReportAsSpam

Data

  1. SearchRoot
  2. EmptyRecycleBin
  3. ListRoot
  4. RootID
  5. RecycleBinID
  6. ListRecycleBin
  7. RestoreRecycleBin
  8. GetLinkForFile

File

  1. Upload
  2. UploadLargeFile
  3. Update
  4. UpdateLargeFile
  5. Copy
  6. CopyMultiple
  7. Move
  8. MoveMultiple
  9. Trash
  10. UnTrash
  11. TrashMultiple
  12. Delete
  13. DeleteMultiple
  14. Metadata
  15. EditMetadata
  16. ChangePrivacy
  17. Rename
  18. Download
  19. DownloadLargeFile
  20. DownloadAsStream
  21. ImportToMyAccount
  22. ThumbnailUrl
  23. UnZip
  24. Exists

Folder

  1. Password
  2. SetDescription
  3. ChangePermission
  4. ChangePrivacy
  5. Search
  6. ListSubFiles
  7. ListSubFolders
  8. Create
  9. Copy
  10. CopyMultiple
  11. Move
  12. MoveMultiple
  13. UnTrash
  14. Trash
  15. Delete
  16. DeleteMultiple
  17. TrashMultiple
  18. Rename
  19. Metadata
  20. Exists
  21. ExistsInTargetFolder

User

  1. SearchFiles
  2. Metadata
  3. AvatarPicture
  4. ListFilesRelatedToFile

CodeMap:

codemap

Code simple:

'first login (one time only)

    Async Sub Login_Base64()
        Dim lgnBase64 = Await FourSharedSDK.GetToken.Login_Base64("JackKoolage@go.com", "123456")
        PropertyGrid1.SelectedObject = (lgnBase64)
    End Sub

'Set your client
    Dim Clnt As FourSharedSDK.IClient = New FourSharedSDK.FClient(lgnBase64, Nothing)



'Functions:
Imports FourSharedSDK.utilitiez

    Async Sub UserInfo()
        Dim rslt = Await Clnt.Account.UserInfo()
        PropertyGrid1.SelectedObject = rslt
    End Sub

    Async Sub UpdateUserInfo()
        Dim rslt = Await Clnt.Account.UpdateUserInfo(Nothing, Nothing, Nothing, Nothing, AllowSearchEnum.disabled)
        DataGridView1.Rows.Add(rslt.allowSearch.ToString)
    End Sub

    Async Sub GetAvatarPicture()
        Dim rslt = Await Clnt.Account.AvatarPicture(ImageSizeEnum._72x72)
        DataGridView1.Rows.Add(rslt)
    End Sub

    Async Sub SetAvatarPicture()
        Dim rslt = Await Clnt.Account.SetAvatarPicture("C:\1e.jpg", UploadTypes.FilePath, "1e.jpg", Nothing, Nothing)
        MsgBox(rslt)
    End Sub

    Async Sub LisSubtFiles()
        Dim rslt = Await Clnt.Folders.ListSubFiles("Dir_id", Nothing, 100, 0)
        DataGridView1.Rows.Add("name", "IsPrivate", "id", "size", "thumbnailUrl", "parentId", "downloadUrl", "ImgUrl")
        For Each onz In rslt.files
            DataGridView1.Rows.Add(onz.name, onz.IsPrivate, onz.id, onz.size, onz.thumbnailUrl, onz.parentId, onz.downloadUrl, onz.ImgUrl(ImageSizeEnum._320x240))
        Next
    End Sub

    Async Sub ListSubFolders()
        Dim rslt = Await Clnt.Folders.ListSubFolders("Dir_id", 100, 0)
        DataGridView1.Rows.Add("name", "Privacy", "id", "TotalFiles", "TotalFolders", "parentId", "permissions", "folderLink")
        For Each onz In rslt.folders
            DataGridView1.Rows.Add(onz.name, onz.Privacy.ToString, onz.id, onz.TotalFiles, onz.TotalFolders, onz.parentId, onz.permissions.ToString, onz.folderLink)
        Next
    End Sub

    Async Sub Search()
        Dim rslt = Await Clnt.Folders.Search("Dir_id", TextBox_searchKeyword.Text, Nothing, 100, 0)
        DataGridView1.Rows.Add("name", "IsPrivate", "id", "size", "thumbnailUrl", "parentId", "downloadUrl", "ImgUrl")
        For Each onz In rslt.files
            DataGridView1.Rows.Add(onz.name, onz.IsPrivate, onz.id, ConvSze(onz.size), onz.thumbnailUrl, onz.parentId, onz.downloadUrl, onz.ImgUrl(ImageSizeEnum._320x240))
        Next
    End Sub

    Async Sub SearchRoot()
        Dim rslt = Await Clnt.Data.SearchRoot(TextBox_searchKeyword.Text, Nothing, 100, 0)
        DataGridView1.Rows.Add("name", "IsPrivate", "id", "size", "thumbnailUrl", "parentId", "downloadUrl", "ImgUrl")
        For Each onz In rslt.files
            DataGridView1.Rows.Add(onz.name, onz.IsPrivate, onz.id, ConvSze(onz.size), onz.thumbnailUrl, onz.parentId, onz.downloadUrl, onz.ImgUrl(ImageSizeEnum._320x240))
        Next
    End Sub

    Async Sub Create()
        Dim onz = Await Clnt.Folders.Create("Dir_id", "lolo", "this is a new folder of")
        DataGridView1.Rows.Add("name", "Privacy", "id", "TotalFiles", "TotalFolders", "parentId", "permissions", "folderLink")
        DataGridView1.Rows.Add(onz.name, onz.Privacy.ToString, onz.id, onz.TotalFiles, onz.TotalFolders, onz.parentId, onz.permissions.ToString, onz.folderLink)
    End Sub

    Async Sub Rename()
        Dim onz = Await Clnt.Folders.Rename("Dir_id", "MyNewName")
        PropertyGrid1.SelectedObject = onz
    End Sub

    Async Sub ChangePermission()
        Dim onz = Await Clnt.Folders.ChangePermission("Dir_id", FolderPermissionsEnum.read)
        PropertyGrid1.SelectedObject = onz
    End Sub

    Async Sub ChangePrivacy()
        Dim onz = Await Clnt.Folders.ChangePrivacy("Dir_id", PrivacyEnum.private)
        PropertyGrid1.SelectedObject = onz
    End Sub

    Async Sub Password()
        Dim onz = Await Clnt.Folders.Password("Dir_id", "1905")
        PropertyGrid1.SelectedObject = onz
    End Sub

    Async Sub FolderMetadata()
        Dim onz = Await Clnt.Folders.Metadata("Dir_id")
        PropertyGrid1.SelectedObject = onz
    End Sub

    Async Sub FileMetadata()
        Dim onz = Await Clnt.Files.Metadata("File_id", AddFieldsEnum.ImageMetainfo)
        PropertyGrid1.SelectedObject = onz
    End Sub

    Async Sub Exists()
        Dim onz = Await Clnt.Folders.Exists("Dir_id")
        MsgBox(onz)
    End Sub

    Async Sub SetDescription()
        Dim onz = Await Clnt.Folders.SetDescription("Dir_id", "look at this")
        PropertyGrid1.SelectedObject = onz
    End Sub

    Async Sub ListRoot()
        Dim getRootId= Await Clnt.Account.UserInfo()
        Dim rslt = Await Clnt.Data.ListRoot(getRootId.rootFolderId, 100, 0)
        PropertyGrid1.SelectedObject = rslt.CurrentFolderOptions.Settings
        DataGridView1.Rows.Add(rslt.FilesFoldersList.UsedSpace)
        DataGridView1.Rows.Add(rslt.FilesFoldersList.DailyTrafficUsage)

        For Each onz In rslt.FilesFoldersList.FoldersList
            DataGridView1.Rows.Add(onz.name, onz.Privacy.ToString, onz.id, ConvSze(onz.size), onz.CreatedDate)
        Next
        For Each onz In rslt.FilesFoldersList.FilesList
            DataGridView1.Rows.Add(onz.name, onz.canPreview, onz.id, ConvSze(onz.size), onz.ThumbUrl, onz.CreatedDate, onz.Ext, onz.typeCss)
        Next
    End Sub

    Async Sub UsersSearchFiles()
        Dim rslt = Await Clnt.Users.SearchFiles("big", FileTypeEnum.Archives, Nothing, Nothing, Nothing, SortByEnum.size, OrderByEnum.asc, 100, 0)

        For Each onz In rslt.items
            DataGridView1.Rows.Add(onz.fileName, onz.fileId, onz.fileUrl, ConvSze(onz.fileSize), onz.dirName, onz.dirId, onz.dirPath, onz.category, onz.thumbnailUrl)
        Next
        L_Counter.Text = rslt.items.Count
    End Sub

    Async Sub Upload()
        Dim frm As New DeQma.FileFolderDialogs.VistaOpenFileDialog With {.Multiselect = False}
        If frm.ShowDialog = DialogResult.OK AndAlso Not String.IsNullOrEmpty(frm.FileName) Then

            Dim UploadCancellationToken As New Threading.CancellationTokenSource()
            Dim _ReportCls As New Progress(Of FourSharedSDK.ReportStatus)(Sub(ReportClass As FourSharedSDK.ReportStatus)
                                                                              Label1.Text = String.Format("{0}/{1}", ConvSze(ReportClass.BytesTransferred), ConvSze(ReportClass.TotalBytes))
                                                                              ProgressBar1.Value = CInt(ReportClass.ProgressPercentage)
                                                                              Label2.Text = If(CStr(ReportClass.TextStatus) Is Nothing, "Uploading...", CStr(ReportClass.TextStatus))
                                                                          End Sub)
            Dim rslt = Await Clnt.Files.Upload(frm.FileName, UploadTypes.FilePath, "Dir_id", IO.Path.GetFileName(frm.FileName), _ReportCls, UploadCancellationToken.Token)
            PropertyGrid1.SelectedObject = rslt
        End If
    End Sub

    Async Sub UploadLargeFile()
        Dim frm As New DeQma.FileFolderDialogs.VistaOpenFileDialog With {.Multiselect = False}
        If frm.ShowDialog = DialogResult.OK AndAlso Not String.IsNullOrEmpty(frm.FileName) Then

            Dim UploadCancellationToken As New Threading.CancellationTokenSource()
            Dim _ReportCls As New Progress(Of FourSharedSDK.ReportStatus)(Sub(ReportClass As FourSharedSDK.ReportStatus)
                                                                              Label1.Text = String.Format("{0}/{1}", ConvSze(ReportClass.BytesTransferred), ConvSze(ReportClass.TotalBytes))
                                                                              ProgressBar1.Value = CInt(ReportClass.ProgressPercentage)
                                                                              Label2.Text = If(CStr(ReportClass.TextStatus) Is Nothing, "Uploading...", CStr(ReportClass.TextStatus))
                                                                          End Sub)
            Dim sze = New IO.FileInfo(frm.FileName).Length
            Dim rslt = Await Clnt.Files.UploadLargeFile(frm.FileName, UploadTypes.FilePath, "Dir_id", IO.Path.GetFileName(frm.FileName), sze, _ReportCls, UploadCancellationToken.Token)
            PropertyGrid1.SelectedObject = rslt
        End If
    End Sub

    Async Sub FileUpdate()
        Dim frm As New DeQma.FileFolderDialogs.VistaOpenFileDialog With {.Multiselect = False}
        If frm.ShowDialog = DialogResult.OK AndAlso Not String.IsNullOrEmpty(frm.FileName) Then

            Dim UploadCancellationToken As New Threading.CancellationTokenSource()
            Dim _ReportCls As New Progress(Of FourSharedSDK.ReportStatus)(Sub(ReportClass As FourSharedSDK.ReportStatus)
                                                                              Label1.Text = String.Format("{0}/{1}", ConvSze(ReportClass.BytesTransferred), ConvSze(ReportClass.TotalBytes))
                                                                              ProgressBar1.Value = CInt(ReportClass.ProgressPercentage)
                                                                              Label2.Text = If(CStr(ReportClass.TextStatus) Is Nothing, "Uploading...", CStr(ReportClass.TextStatus))
                                                                          End Sub)
            Dim rslt = Await Clnt.Files.Update(frm.FileName, UploadTypes.FilePath, "File_id", "Dir_id", IO.Path.GetFileName(frm.FileName), _ReportCls, UploadCancellationToken.Token)
            PropertyGrid1.SelectedObject = rslt
        End If
    End Sub

    Async Sub UpdateLargeFile()
        Dim frm As New DeQma.FileFolderDialogs.VistaOpenFileDialog With {.Multiselect = False}
        If frm.ShowDialog = DialogResult.OK AndAlso Not String.IsNullOrEmpty(frm.FileName) Then

            Dim UploadCancellationToken As New Threading.CancellationTokenSource()
            Dim _ReportCls As New Progress(Of FourSharedSDK.ReportStatus)(Sub(ReportClass As FourSharedSDK.ReportStatus)
                                                                              Label1.Text = String.Format("{0}/{1}", ConvSze(ReportClass.BytesTransferred), ConvSze(ReportClass.TotalBytes))
                                                                              ProgressBar1.Value = CInt(ReportClass.ProgressPercentage)
                                                                              Label2.Text = If(CStr(ReportClass.TextStatus) Is Nothing, "Uploading...", CStr(ReportClass.TextStatus))
                                                                          End Sub)
            Dim sze = New IO.FileInfo(frm.FileName).Length
            Dim rslt = Await Clnt.Files.UpdateLargeFile(frm.FileName, UploadTypes.FilePath, "File_id", "Dir_id", IO.Path.GetFileName(frm.FileName), sze, _ReportCls, UploadCancellationToken.Token)
            PropertyGrid1.SelectedObject = rslt
        End If
    End Sub

    Async Sub ThumbnailUrl()
        Dim onz = Await Clnt.Files.ThumbnailUrl("File_id", ImageSizeEnum._320x240)
        DataGridView1.Rows.Add(onz)
    End Sub

    Async Sub DeleteMultipleFiles()
        Dim onz = Await Clnt.Files.DeleteMultiple(New List(Of String) From {"File_id_1", "File_id_2", "File_id_3"})
        DataGridView1.Rows.Add(onz)
    End Sub

    Async Sub Download()
        Dim frm As New DeQma.FileFolderDialogs.VistaFolderBrowserDialog With {.ShowNewFolderButton = True}
        If frm.ShowDialog = DialogResult.OK AndAlso Not String.IsNullOrEmpty(frm.SelectedPath) Then
            Dim UploadCancellationToken As New Threading.CancellationTokenSource()
            Dim _ReportCls As New Progress(Of FourSharedSDK.ReportStatus)(Sub(ReportClass As FourSharedSDK.ReportStatus)
                                                                              Label1.Text = String.Format("{0}/{1}", ConvSze(ReportClass.BytesTransferred), ConvSze(ReportClass.TotalBytes))
                                                                              ProgressBar1.Value = CInt(ReportClass.ProgressPercentage)
                                                                              Label2.Text = If(CStr(ReportClass.TextStatus) Is Nothing, "Downloading...", CStr(ReportClass.TextStatus))
                                                                          End Sub)
            Dim getFileId= Await Clnt.Files.Metadata("File_id")
            Await Clnt.Files.Download(getFileId.path, frm.SelectedPath, _ReportCls, UploadCancellationToken.Token)
        End If
    End Sub

    Async Sub UsersMetadata()
        Dim rslt = Await Clnt.Users.Metadata("User_id")
        PropertyGrid1.SelectedObject = rslt
    End Sub

    Async Sub UsersAvatar()
        Dim rslt = Await Clnt.Users.AvatarPicture("User_id", ImageSizeEnum._2560x1600)
        DataGridView1.Rows.Add(rslt)
    End Sub

    Async Sub ExistsInDir()
        Dim rslt = Await Clnt.Folders.ExistsInTargetFolder("New%20folder", "Dir_id")
        DataGridView1.Rows.Add(rslt)
    End Sub

    Async Sub TrashMultipleFolders()
        Dim onz = Await Clnt.Folders.TrashMultiple(New List(Of String) From {"Dir_id_1", "Dir_id_2"})
        DataGridView1.Rows.Add(onz)
    End Sub

    Async Sub ListComments()
        Dim rslt = Await Clnt.Comments.ListComments("File_id", 100, 0)

        For Each onz In rslt.comments
            DataGridView1.Rows.Add(onz.Comment, onz.id, onz.User.userName)
        Next
    End Sub

    Async Sub Comment()
        Dim rslt = Await Clnt.Comments.Create("File_id", "test api")
        PropertyGrid1.SelectedObject = rslt
    End Sub

    Async Sub CommentDelete()
        Dim rslt = Await Clnt.Comments.Delete("File_id", "Comment_id")
        MsgBox(rslt)
    End Sub

    Async Sub ReplyComment()
        Dim rslt = Await Clnt.Comments.Reply("File_id", "Comment_id", "testing message...")
        PropertyGrid1.SelectedObject = rslt
    End Sub

    Async Sub ReportAsSpam_UnReportAsSpam()
        Dim reporting = Await Clnt.Comments.ReportAsSpam("Comment_id")
        Dim rslt2 = Await Clnt.Comments.UnReportAsSpam(reporting)
    End Sub

    Async Sub ListFilesRelatedToFile()
        Dim rslt = Await Clnt.Users.ListFilesRelatedToFile("File_id", 100, 0)

        For Each onz In rslt.files
            DataGridView1.Rows.Add(onz.name, onz.IsPrivate, onz.id, ConvSze(onz.size), onz.thumbnailUrl, onz.parentId, onz.downloadUrl, onz.ImgUrl(ImageSizeEnum._320x240))
        Next
    End Sub

    Async Sub ImportToMyAccount()
        Dim rslt = Await Clnt.Files.ImportToMyAccount("File_id", "ImportToDir_id")
        PropertyGrid1.SelectedObject = rslt
    End Sub

    Async Sub RootID()
        Dim rslt = Await Clnt.Data.RootID()
        DataGridView1.Rows.Add(rslt)
    End Sub

    Async Sub EmptyRecycleBin()
        Dim rslt = Await Clnt.Data.EmptyRecycleBin()
        DataGridView1.Rows.Add(rslt)
    End Sub

    Async Sub RecycleBinID()
        'Dim rslt = Await Clnt.Data.RecycleBinID()
        Dim rslt = Await Clnt.Data.RecycleBinID("Root_id")
        DataGridView1.Rows.Add(rslt)
    End Sub

    Async Sub ListRecycleBin()
        Dim recBinId = Await Clnt.Data.RecycleBinID
        Dim rslt = Await Clnt.Data.ListRecycleBin(recBinId, 100, 0)

        For Each onz In rslt.files
            DataGridView1.Rows.Add(onz.name, onz.time, onz.id, ConvSze(onz.size), onz.recoverPath)
        Next
        For Each onz In rslt.dirs
            DataGridView1.Rows.Add(onz.name, onz.time, onz.id, ConvSze(onz.size), onz.recoverPath)
        Next
    End Sub

    Async Sub RestoreRecycleBin()
        Dim recBinId = Await Clnt.Data.RecycleBinID
        Dim rslt = Await Clnt.Data.RestoreRecycleBin(recBinId)
        DataGridView1.Rows.Add(rslt)
    End Sub

    Async Sub GetLinkForFile()
        Dim rslt = Await Clnt.Data.GetLinkForFile()
        DataGridView1.Rows.Add(rslt)
    End Sub

    Async Sub FileUnZip()
        Dim rslt = Await Clnt.Files.UnZip("File_id")
        DataGridView1.Rows.Add(rslt)
    End Sub

    Async Sub FileExists()
        Dim rslt = Await Clnt.Files.Exists("File_id")
        DataGridView1.Rows.Add(rslt)
    End Sub





Clone this wiki locally