cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MEGA Integration >> VB application

mostafafad
Super Contributor

Hello MEGA people !

 

I am trying to build a VB Application to be able to do some tasks in MEGA.

I managed to connect to mega but with direct interaction needed with the Environment to enter the credentials.

 

How can I do supply the user and password to MEGA without direct interaction with MEGA ? (so I can open a transcation do changes and dispatch)

 

Here is my trial where I tried to create a transaction but didn't know how to supply the username and the password, and I wish you can help me in this

 

 

------------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------------

 

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click

 
Dim mApp As New MegaMapp.MegaApplication
Dim mEnv As MegaMapp.MegaEnvironment
Dim mUsr As MegaMapp.MegaUser
Dim oTrans As MegaMapp.MegaTransaction
Dim alltrans As MegaMapp.MegaTransactions

 
Dim i, j As Integer
i = 1
j = 1
 
 
For Each eNvironmetn  In mApp.Environments
 
If mApp.Environments(i).Name.Contains("RepoName") Then
 
mEnv = mApp.Environments.Item(i)
TextBox2.Text = i.ToString() + " " + mEnv.Users("Mega").Name + " " + mEnv.Databases.Item("RepoName").Name
For Each MegaUser In mEnv.Users
 
mEnv.Transactions.Create(mEnv.Databases.Item("RepoName").ObjectID, TextBox2.Text)
 
Else
j = j + 1
End If
Next
 
 
Else
i = i + 1
End If
 
Next
End Sub
 
------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------
3 Replies

Thanks FBoulart for your Reply.

 

Thanks Leslie ! what you sent as a solution worked 

I did some modification to fit and work onHOPEX V1R2 

 

Find it below : 

 

        Dim sAdmUser = "Administrator"
        Dim sAdmPwd = ""
        Dim sUser = "MEGA"
        Dim sPwd = ""
        Dim sEnvPath = "C:\...\EnvName"
        Dim sRepository = "RepoName"
        'Dim oMegaApp = CreateObject("Mega.Application")
        Dim oMegaApp As New MegaMapp.MegaApplication

        Dim oEnvironment = oMegaApp.Environments.item(sEnvPath)
        'open environment in update mode
        oEnvironment.CurrentAdministrator = sAdmUser
        oEnvironment.CurrentPassword = sAdmPwd
        'Msgbox "Environment opened in update mode: " & oEnvironment.Name
        Dim lTransactions = oEnvironment.Transactions
        Dim oTransaction = lTransactions.Create(sRepository, sUser)
        oTransaction.Password = ""
        'Msgbox "Transaction: " & oTransaction.Name
        'get root
        Dim MyRoot = oTransaction.Database.Open
        'perform data update

        Dim oObject = MyRoot.GetCollection("Org-unit").Add("MyAppCreatedOrgunit")
        MsgBox("Object created: " & oObject.Name)




        MyRoot.MegaCommit()
        'close root
        MyRoot.BaseClose()
        'to dispatch transaction
        oTransaction.Dispatch(True)

        'free collections
        MyRoot = Nothing
        lTransactions = Nothing

        'oObject = Nothing
        oTransaction = Nothing

Hello

 

@FBoulart : Your code connects in admin mode which means you block the system database so noone can connect or dispatch duing your script, and I think the original request was for code to connect in transaction mode.

 

@Mostafafad:

A KB article exists on this topic : solution number 415 "API: Connect in transaction mode (example VB Script)"

http://community.mega.com/t5/custom/page/page-id/mega-kb-solution?sid=50120000000mqSCAAY

 

Here is the sample code:

 

sAdmUser = "Administrator"
sAdmPwd = ""
sUser = "User"
sPwd = ""
sEnvPath = "C:\MEGA_Data\Demonstration"
sRepository= "Adventure"

Set oMegaApp = CreateObject("Mega.Application")
Set oEnvironment=oMegaApp.Environments.item(sEnvPath)
'open environment in update mode
oEnvironment.CurrentAdministrator = sAdmUser
oEnvironment.CurrentPassword = sAdmPwd
'Msgbox "Environment opened in update mode: " & oEnvironment.Name
Set lTransactions = oEnvironment.Transactions
Set oTransaction = lTransactions.Create(sRepository,sUser)
oTransaction.Password = ""
'Msgbox "Transaction: " & oTransaction.Name
'get root
Set MyRoot = oTransaction.Database.Open
'perform data update


Set oObject = MyRoot.GetCollection("Org-unit").Add("MyOrgunit")
Msgbox "Object created: " & oObject.Name


MyRoot.MegaCommit
'close root
MyRoot.BaseClose
'to dispatch transaction
oTransaction.Dispatch
'you can alternatively discard transaction
oTransaction.Abort
'you can alternatively refresh transaction

oTransaction.Refresh

'free collections

Set MyRoot = Nothing
Set lTransactions = Nothing
Set lUsers = Nothing
Set lRepositories = Nothing
Set oUser = Nothing
Set oObject = Nothing
Set oTransaction = Nothing

 

regards,

Leslie

Fboulart
Super Contributor

Hi Mostafad, You can try something like.

 

This example is about triggering Logical backup.

 

Hope that helps.

 

Set oMegaApp = CreateObject("Mega.Application")

' path to environment must be as listed in Mega Administrator

 

Set oEnvironment = oMegaApp.Environments.Item("\Env_Path")

 

oEnvironment.CurrentAdministrator = "USR"

oEnvironment.CurrentPassword = "PWD"

 

Set oDatabase = oEnvironment.Databases.Item("SystemDb")

oDatabase.LogicalSave sSysBackupPath, "DumpObjectsOfMerging = On"

 

Set oDatabase = oEnvironment.Databases.Item("Development")

oDatabase.LogicalSave sDevBackupPath, "DumpObjectsOfMerging = On"