INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2   Go Down

Author Topic: FileAutomation  (Read 10415 times)

PhDSM

  • Regular Member
  • World Citizen
  • ***
  • Posts: 193
FileAutomation
« on: September 10, 2014, 08:18:42 am »

Hello,

I've upgraded from Version 17  and I have an Automation process that doesn't work anymore.
Did you change something in MJFilesAutomation * Search(string strSearch).
I can access the server but I always get  "0 found" for all of my searches
Is there any change in Search string between version 17 and 20 ?
Thanks
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42372
  • Shoes gone again!
Re: FileAutomation
« Reply #1 on: September 10, 2014, 08:58:46 am »

It should work.

What if you search for a really simple string, like a?
Logged
Matt Ashland, JRiver Media Center

PhDSM

  • Regular Member
  • World Citizen
  • ***
  • Posts: 193
Re: FileAutomation
« Reply #2 on: September 10, 2014, 10:43:54 am »

it is a very basic one  : Playlist="NeedInfoDB"

I 've try with other like Name="Let"   and it is the same
Example of my code  ( I call MCA fron VBA (Office))

    Set MCA = GetObject(, "MediaJukebox Application")
    Set MJVersion = MCA.getversion()
    MJVersionSt = MJVersion.Version   
                    => Ok  :  it Shows 20.0.12
 
    SearchString = "Name=""Let"""     '    or Playlist=""NeedInfoDB"""
    Set MJSchList = MCA.Search(SearchString)
    NbFilePlayList = MJSchList.GetNumberFiles() 
      => Doesn t work get 0 in all case  instead of 59   or 22
 
  Set MJCurList = MCA.GetCurPlaylist()
   NbFileCurPlayList = MJCurList.GetNumberFiles()   
=> Ok get the right number

The code worked well on MC-17
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42372
  • Shoes gone again!
Re: FileAutomation
« Reply #3 on: September 10, 2014, 11:50:30 am »

Just as a test search for a without quotes.  Or even specify an empty search.  Does that return matches?
Logged
Matt Ashland, JRiver Media Center

PhDSM

  • Regular Member
  • World Citizen
  • ***
  • Posts: 193
Re: FileAutomation
« Reply #4 on: September 11, 2014, 01:34:23 am »

Whatever I put I always get 0
I've changed Library and get same result.
Logged

PhDSM

  • Regular Member
  • World Citizen
  • ***
  • Posts: 193
Re: FileAutomation
« Reply #5 on: September 27, 2014, 04:19:39 am »

I ve tried on another PC with Windows 7  and install MC 20.  Same problem   MCA.search   always return  nothing

I've also tried with a new library, still nothing.

If I load MC17, it works
Logged

PhDSM

  • Regular Member
  • World Citizen
  • ***
  • Posts: 193
Re: FileAutomation
« Reply #6 on: September 27, 2014, 05:04:19 am »

I've tried a workaround as my search was  to get a specific playlist.
So I get  through all playlists to find mine.
Again, the program  works in MC17  and not in MC20
Is there a problem with MC20  or in  my programing ?


  Set MJPlaylists = MCA.GetPlaylists()
  MJNbPlaylists = MJPlaylists.GetNumberPlaylists()
   Found = False
  i = 0
  Do
    Set CurPLPtr = MJPlaylists.GetPlaylist(i)
    If CurPLPtr.Name = "NeedInfoDB" Then Found = True
    i = i + 1
  Loop Until i = MJNbPlaylists - 1 Or Found
     
  If Not trouve Then
     MsgBox ("List NeedInfoDB not Found ")
  End If
 
Logged

PhDSM

  • Regular Member
  • World Citizen
  • ***
  • Posts: 193
Re: FileAutomation
« Reply #7 on: September 29, 2014, 11:20:28 am »

in my previous example
MJPlaylists.GetNumberPlaylists()  works and returns the good number (299 in my case)

but  MJPlaylists.GetPlaylist(i)   returns nothing,  whatever (i) is
Logged

PhDSM

  • Regular Member
  • World Citizen
  • ***
  • Posts: 193
Re: FileAutomation
« Reply #8 on: November 05, 2014, 03:59:32 am »

Do you have any news about this issue ?

I've tried with :
 - all recent version of MJ20 (up to 20.0.30), 
 - with Windows 8 &  windows 7,
 -  4 different PCs,  with VBA from Office 2007, 2010. 2013

it works only If I use MC17, but I don't what you've changed since MC 17 ?

I still stuck with this issue.
After trying to move my list to the "Playing now" and accessing it thru .GetCurPlaylist() I get the good number of file but then the
.GetFile(i) doesn't work.


If you can't fix it , I will need to return to MC 17.  Is there any tool to convert back MC20.0 library to MC17.
Regards
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42372
  • Shoes gone again!
Re: FileAutomation
« Reply #9 on: November 05, 2014, 09:21:31 am »

I just can't reproduce the issue.  I wonder if there's some middleware on your computer that's standing in between MC and you?  A virus checker or something?
Logged
Matt Ashland, JRiver Media Center

PhDSM

  • Regular Member
  • World Citizen
  • ***
  • Posts: 193
Re: FileAutomation
« Reply #10 on: November 05, 2014, 10:37:12 am »

What is strange is that some API works other don't  and MC17 works with the same config.
I've also tried on 3 different hardwares
I've tries without the Antivirus, It doesn't change.
I don't know how to investigate further. My VBA apps was working well from MC11 up to MC17.
 Is it the link between VBA and MC API that cause the problem?
Do you see any test that I can do ?
Regards


Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42372
  • Shoes gone again!
Re: FileAutomation
« Reply #11 on: November 05, 2014, 11:22:58 am »

Is it the link between VBA and MC API that cause the problem?

I guess it's possible.  Can you try a C++ example as a test?
Logged
Matt Ashland, JRiver Media Center

PhDSM

  • Regular Member
  • World Citizen
  • ***
  • Posts: 193
Re: FileAutomation
« Reply #12 on: November 09, 2014, 11:04:54 am »

I'm not very familiar with C or C++, however I develop a new little standalone program in VB2010 to test (my previous apps was in VBA for MS-Office).
I've tried on 2 different computers (one in Win 7 the other in Win 8.1).
The program is simple :
 Get MC version,  Get Number of Playlist,  Get Number of Field
 Do  a Search of a string and display number of entries found

I run it on MC 17 and MC 20

On both computer on MC17
 Get MC version   => works ok
 Get Number of Playlist   => works ok
 Get Number of Field   => works ok
 Do  a Search of a string  => works ok

On both computer on MC20
 Get MC version   => works ok
 Get Number of Playlist   => works ok
 Get Number of Field   => works ok
 Do  a Search of a string  => always return 0

Attached a screen capture.
I can send you the exe and the source so you can try it on your instance of MC20 to see what happen.

I have also other quality issues with MC20 compared to MC 17, I will treat them in a separate thread
Thanks

Logged

PhDSM

  • Regular Member
  • World Citizen
  • ***
  • Posts: 193
Re: FileAutomation
« Reply #13 on: November 09, 2014, 11:09:18 am »

I loaded the wrong file,  here is the good screen capture
Logged

gvanbrunt

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1232
  • MC Nerd
Re: FileAutomation
« Reply #14 on: November 09, 2014, 11:17:55 am »

What does MJPlaylists.GetPlaylist(0) return?

Seems to be something to do with enumerations.

Also what Visual Studio Runtime versions do you have installed on your computer?
Logged

PhDSM

  • Regular Member
  • World Citizen
  • ***
  • Posts: 193
Re: FileAutomation
« Reply #15 on: November 10, 2014, 03:21:20 am »

The result is strange :
 
   CurPLPtr = MJPlaylists.GetPlaylist(0)  works and I can access .name

but
   Dim i As Integer
   i = 0
   CurPLPtr = MJPlaylists.GetPlaylist(i)

Fails : The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))

on MC20 only
Logged

PhDSM

  • Regular Member
  • World Citizen
  • ***
  • Posts: 193
Re: FileAutomation
« Reply #16 on: November 10, 2014, 09:08:12 am »

I've installed MC19 and MC 18 on a separate PC (Win 7) 
and got the same issue, I looks like the problem starts with MC18.0. 
Logged

gvanbrunt

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1232
  • MC Nerd
Re: FileAutomation
« Reply #17 on: November 10, 2014, 09:34:53 am »

what visual studio runtimes do you have on those computers?

Matt:
I remember there were some changes in the compiler used at various points. Anything between V17 and V20?
Logged

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: FileAutomation
« Reply #18 on: November 10, 2014, 10:24:00 am »

The COM API was broken in 18.0.90, as I mentioned here:
http://yabb.jriver.com/interact/index.php?topic=76147.msg516343#msg516343

This was part of the big last push to pull out Windows-specific code before the Mac version launched.  If you'd like, the last version before these changes was 18.0.78.  You can try that one and see if it fixes your issue.

The whole COM API was fixed though as of build 91, with a few other details tweaked in the builds afterwards.  I've had no issues with it since then.

MCAutoQueue makes heavy use of an iterating Playlist system like the one you have there, though, and it works fine with current builds.  I build it in Visual Studio 2012, though, and it is targeted at .NET 4.0.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: FileAutomation
« Reply #19 on: November 10, 2014, 10:40:05 am »

I just checked through my code.  I don't have anything that uses MJAutomation.Search() that I found in a brief look.  However, I do have Playlist iteration code that does basically what you are trying to do here:

Set MJPlaylists = MCA.GetPlaylists()
  MJNbPlaylists = MJPlaylists.GetNumberPlaylists()
   Found = False
  i = 0
  Do
    Set CurPLPtr = MJPlaylists.GetPlaylist(i)
    If CurPLPtr.Name = "NeedInfoDB" Then Found = True
    i = i + 1
  Loop Until i = MJNbPlaylists - 1 Or Found
     
  If Not trouve Then
     MsgBox ("List NeedInfoDB not Found ")
  End If
 

Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: FileAutomation
« Reply #20 on: November 10, 2014, 10:42:15 am »

Code (in C#):

Code: [Select]
/// <summary>
/// Gets a sorted string-type list of all of the Playlist names currently in MC
/// </summary>
/// <returns>string-type List or null if it failed</returns>
public static List<string> GetMCPlaylistNames()
{
// Iterate through all of the Playlists in MC and build a list of all of their names
MediaCenter.IMJPlaylistsAutomation mcPlaylists = Instance.GetPlaylists();
// Check to see if it worked and if there are any playlists at all
if (mcPlaylists == null || mcPlaylists.GetNumberPlaylists() <= 0)
return null;
List<string> playlistNames = new List<string>();
for (int i = 0; i < mcPlaylists.GetNumberPlaylists(); i++)
{
// Check the Playlist's name against the one in settings
MediaCenter.IMJPlaylistAutomation currPlaylist = mcPlaylists.GetPlaylist(i);
string fullPlaylistPath;
if (currPlaylist.Path == "")
{
fullPlaylistPath = currPlaylist.Name;
}
else
{
fullPlaylistPath = currPlaylist.Path + "\\" + currPlaylist.Name;
}
playlistNames.Add(fullPlaylistPath);
}

playlistNames.Sort();
return playlistNames;
}

/// <summary>
/// Returns the IMJPlaylistAutomation object that we want for the given Playlist path
/// </summary>
/// <param name="playlistFullName"></param>
/// <returns>a IMJPlaylistAutomation object reference to the playlist request, or null if it failed</returns>
public static MediaCenter.IMJPlaylistAutomation GetPlaylist(string playlistFullName)
{
// Check to see if they sent us something silly
if (playlistFullName == "" || playlistFullName == null)
return null;
// Iterate through all of the Playlists in MC until you find the one we want
MediaCenter.IMJPlaylistsAutomation mcPlaylists = Instance.GetPlaylists();
// Check to see if it worked and if there are any playlists at all
if (mcPlaylists == null || mcPlaylists.GetNumberPlaylists() <= 0)
return null;
MediaCenter.IMJPlaylistAutomation currPlaylist = null;
bool success = false;
for (int i = 0; i < mcPlaylists.GetNumberPlaylists(); i++)
{
// Check the Playlist's name against the one in settings
currPlaylist = mcPlaylists.GetPlaylist(i);
string fullPlaylistPath;
if (currPlaylist.Path == "")
{
fullPlaylistPath = currPlaylist.Name;
}
else
{
fullPlaylistPath = currPlaylist.Path + "\\" + currPlaylist.Name;
}
success = fullPlaylistPath.Equals(playlistFullName, StringComparison.OrdinalIgnoreCase);
if (success) break;
}

// If we found it, return it, otherwise return null
if (success)
{
return currPlaylist;
}
else
{
return null;
}
}

That's old code, and some of the comments are a bit whacked (sorry), but it does work perfectly with the current build of MC20.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

gvanbrunt

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1232
  • MC Nerd
Re: FileAutomation
« Reply #21 on: November 10, 2014, 11:14:37 am »

Oh yes, Glynor reminded me of something else to check. What version of .Net are you targeting?
Logged

gvanbrunt

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1232
  • MC Nerd
Re: FileAutomation
« Reply #22 on: November 10, 2014, 11:18:05 am »

One thing that also comes to mind here is Visual Basic. I'm not an expert as I use C# for the most part. That said I remember VB handling how values are passed between functions and COM. I think that is what is at play here, but for the life of me I can't remember the details.

I picked up on this thread because it rang a bell, but I just can't remember the details.
Logged

gvanbrunt

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1232
  • MC Nerd
Re: FileAutomation
« Reply #23 on: November 10, 2014, 11:29:06 am »

Also try this:

Dim i As UInteger
   i = 0
   CurPLPtr = MJPlaylists.GetPlaylist(i)
Logged

gvanbrunt

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1232
  • MC Nerd
Re: FileAutomation
« Reply #24 on: November 10, 2014, 11:34:13 am »

one more thing: You are rebuilding the COM wrapper for each version right? I.E. the MC20 version of the wrapper has to be created from the MC20 version of MC.
Logged

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: FileAutomation
« Reply #25 on: November 10, 2014, 02:17:26 pm »

one more thing: You are rebuilding the COM wrapper for each version right? I.E. the MC20 version of the wrapper has to be created from the MC20 version of MC.

You don't need to do this with .NET, unless I misunderstand what you mean. My old compiled apps work fine with MC20.

It uses whichever copy is registered with COM, which is the last one launched (hence the UAC prompt).
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: FileAutomation
« Reply #26 on: November 10, 2014, 02:20:01 pm »

I can test the Search() method from .NET 4.0 C# relatively easily.  But it seems like he has other issues.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

gvanbrunt

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1232
  • MC Nerd
Re: FileAutomation
« Reply #27 on: November 10, 2014, 03:11:49 pm »

You don't need to do this with .NET, unless I misunderstand what you mean. My old compiled apps work fine with MC20.

It uses whichever copy is registered with COM, which is the last one launched (hence the UAC prompt).

I haven't used .net and com in quite some time so please correct me if I'm wrong. From what I remember you reference a dll file that contains the com interface and Visual Studio automatically creates an interop wrapper. You can either do the interop manually or use the one created. What I'm guessing may be happening is he is using MC 17 dll as a reference when "creating the wrapper". Something may have changed in the implementation between 17 and 18 that requires building the wrapper off of the newer version. Technically it should work providing nothing has changed, but there may be something that has broken the interface in between versions. Something to try at least...
Logged

gvanbrunt

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1232
  • MC Nerd
Re: FileAutomation
« Reply #28 on: November 10, 2014, 03:15:08 pm »

I can test the Search() method from .NET 4.0 C# relatively easily.  But it seems like he has other issues.

Can you try running the simple code he posted using VB? I think the issue may lie with VB as opposed to c#. Back in the day when I used to do lots of .Net I remember their being some differences when using interop with the 2.
Logged

PhDSM

  • Regular Member
  • World Citizen
  • ***
  • Posts: 193
Re: FileAutomation
« Reply #29 on: November 10, 2014, 03:36:36 pm »

I checked with UInterger instead of integer, it doesn't change.

Here is my test code in VB :

      Sub TestMC(ByVal SearchStr As String)
        '==============
        Dim MCA, MJVersion, MJPlaylists, MJSchList, MJFields, CurPLPtr, CurFilePtr, FileList As Object
        Dim i, MJNbPlaylists, NbFilePlayList As UInteger
        Dim Trouve As Boolean
        Dim PLName, FLName, LName As String

        ' First try to get an already running Mediacenter
        On Error Resume Next
        MCA = GetObject(, "MediaJukebox Application")
        If Err.Number = 429 Then
            'Then, create a new Mediacenter
            On Error GoTo 0
            MCA = CreateObject("MediaJukebox Application")
        Else
            If Err.Number <> 0 Then
                MsgBox("Erreur chargement MediaCenter #" + CStr(Err.Number) + " / " + Err.Description)
            End If
        End If
        On Error GoTo 0

        MJVersion = MCA.getversion()
        'Put version in the VBForm
        Form1.Version.Text = MJVersion.Version

        MJFields = MCA.getFields()
        'Put NbField in the VBForm
        Form1.NbField.Text = MJFields.GetNumberFields

        MJPlaylists = MCA.GetPlaylists()
        'Put NbPlaylist in the VBForm
        Form1.NbPlaylist.Text = MJPlaylists.GetNumberPlaylists()
        MJNbPlaylists = MJPlaylists.GetNumberPlaylists()

        CurPLPtr = MJPlaylists.GetPlaylist(0)
        PLName = CurPLPtr.Name
        FileList = CurPLPtr.GetFiles()
        NbFilePlayList = FileList.GetNumberFiles()
        'check if GetFile works with 0
        CurFilePtr = FileList.GetFile(0)
        FLName = CurFilePtr.Name
        'check if GetFile works with i = 0
        i = 0
        CurFilePtr = FileList.GetFile(i)
        FLName = CurFilePtr.Name

        'check if GetPlaylist works with 0
        CurPLPtr = MJPlaylists.GetPlaylist(0)
        LName = CurPLPtr.Name
        'check if GetPlaylist works with i = 0
        i = 0
        Trouve = False
        Do
            CurPLPtr = MJPlaylists.GetPlaylist(i)
            If CurPLPtr.Name = "NeedInfoDB" Then Trouve = True
            i = i + 1
        Loop Until i = MJNbPlaylists - 1 Or Trouve

        MJSchList = MCA.Search(SearchStr)
        'Put GetNumberFiles of Search in the VBForm
        Form1.NbTrouve.Text = MJSchList.GetNumberFiles()

    End Sub
Logged

gvanbrunt

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1232
  • MC Nerd
Re: FileAutomation
« Reply #30 on: November 10, 2014, 04:05:12 pm »

There have been a lot of questions asked here. Can you please provide the answers so we can continue to help you.

Thanks
Logged

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: FileAutomation
« Reply #31 on: November 10, 2014, 05:35:21 pm »

I haven't used .net and com in quite some time so please correct me if I'm wrong. From what I remember you reference a dll file that contains the com interface and Visual Studio automatically creates an interop wrapper. You can either do the interop manually or use the one created. What I'm guessing may be happening is he is using MC 17 dll as a reference when "creating the wrapper". Something may have changed in the implementation between 17 and 18 that requires building the wrapper off of the newer version. Technically it should work providing nothing has changed, but there may be something that has broken the interface in between versions. Something to try at least...

Kinda... With any version of MC I've programmed against (so, going way back) you don't reference against the DLL file directly.  In fact, MC doesn't even include one.  You reference against a TLB file, which is kind-of a "library descriptor" stub file.

This doesn't change.  You can test it yourself if you want.  Download an old version of my MCUtilities application pack, such as this one from July 2013, and try to run one of them using MC20 (which didn't exist when it was built).

I don't have time to test right now, but I'm 99% sure it'll still work (though, of course, bugs won't be fixed).
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: FileAutomation
« Reply #32 on: November 10, 2014, 06:09:08 pm »

I don't have time to test right now, but I'm 99% sure it'll still work (though, of course, bugs won't be fixed).

Just tested, and yes, it works fine.

Now, it is possible, I suppose that the TLB file was broken in an incompatible way with MC 18.0.90.  But you can download a zipped version of MCUtilities 1.0.2 (built 07/05/2013) and it works just fine with the current MC 20.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: FileAutomation
« Reply #33 on: November 10, 2014, 06:13:27 pm »

Can you try running the simple code he posted using VB? I think the issue may lie with VB as opposed to c#. Back in the day when I used to do lots of .Net I remember their being some differences when using interop with the 2.

Yes.  VB makes my eyes bleed though.  I'll need to know how to set up my MC library to get an expected result.  :P
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: FileAutomation
« Reply #34 on: November 10, 2014, 06:14:43 pm »

There have been a lot of questions asked here. Can you please provide the answers so we can continue to help you.

+1
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: FileAutomation
« Reply #35 on: November 10, 2014, 11:25:31 pm »

So, I made a Project in Visual Studio 2012 with the exact test code shown above, wired up to a simple form (like the one in the screenshot above).  I fixed a few minor syntax errors (perhaps a difference in style between older and newer versions of VB), but otherwise it is exactly as originally coded.

I too am getting an exception when you try to use an Integer value with GetFile() or most other IMJAutomation methods that take integers.  It does look odd.  This works:

Code: [Select]
'check if GetFile works with 0
CurFilePtr = FileList.GetFile(0)
FLName = CurFilePtr.Name

This throws an exception:

Code: [Select]
'check if GetFile works with i = 0
i = 0
CurFilePtr = FileList.GetFile(i)
FLName = CurFilePtr.Name

It could be as simple as a casting issue.  However, I don't see why you are doing all of this:

Code: [Select]
Dim MCA, MJVersion, MJPlaylists, MJSchList, MJFields, CurPLPtr, CurFilePtr, FileList As Object
Why are you defining those variables as "dumb" Objects?  You should be using the IMJAutomation interfaces appropriate to the types, and then you'll actually get Intellisense to work, if nothing else.  It makes it almost impossible to debug, and I don't know VB well enough (and am not otherwise motivated enough) to figure it out.

I can tell you that this class's GetMC function works (in C#):

Code: [Select]
/// <summary>
/// Gets the MC Core Automation object
/// This is used ONLY by the Instance Property
/// </summary>
private static IMJAutomation GetMC()
{
// Run the connection timer
RunConnectionTimer();
// Get the MC Instance!
MCAutomation mcAutomation;
try
{
// Try to connect to a running instance of MC
mcAutomation = GetRunningMC();
}
catch (Exception e)
{
// Check the type of exception we got.  Certain types can be handled.
switch (e.HResult)
{
case -2147221005:
{
throw new InvalidOperationException(
"MC isn't registered properly in COM.  Reinstall the current version of Media Center.", e);
}
case -2147221021:
{
// Then the exception was "Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))"
// Which is what happens when MC isn't currently running.
ClassLogger.Info("No running instance of MC found.");
// Try to create an instance of MC instead
mcAutomation = LaunchMC();
}
break;
default:
{
// Then we don't know what the error was, so throw it.
throw;
}
}
}
return mcAutomation;
}

/// <summary>
/// This attempts to connect to an already running copy of MC.
/// </summary>
/// <returns>The MCAutomation instance for the connected copy of MC.</returns>
private static MCAutomation GetRunningMC()
{
ClassLogger.Info("Attempting to connect to running instance of MC.");
// Try to connect to a running instance of MC
var mcAutomation = (MCAutomation)Marshal.GetActiveObject("MediaJukebox Application");
if (ValidateInstance(mcAutomation))
{
// Kill the connection timer
ConnectionTimer.Enabled = false;
ClassLogger.Info("Successfully connected to Media Center.");
return mcAutomation;
}
else return null;  // This will never get returned because ValidateInstance will throw an exception.
}

/// <summary>
/// This attempts to launch MC and returns the MCAutomation instance.
/// </summary>
/// <returns>The MCAutomation instance after launching.</returns>
private static MCAutomation LaunchMC()
{
ClassLogger.Info("Launching Media Center...");
try
{
var mcAutomation =
(MCAutomation) Activator.CreateInstance(Type.GetTypeFromProgID("MediaJukebox Application"));
if (ValidateInstance(mcAutomation))
{
// Kill the connection timer
ConnectionTimer.Enabled = false;
ClassLogger.Info("Successfully launched Media Center.");
LaunchedMC = true;
return mcAutomation;
}
else return null;  // This will never get returned because ValidateInstance will throw an exception.
}
catch (Exception ex)
{
// Something terrible happened
ConnectionTimer.Enabled = false;
ClassLogger.Fatal("Launching MC Failed: {0}", ex.Message);
ClassLogger.Fatal(ex);
throw;
}
}
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: FileAutomation
« Reply #36 on: November 10, 2014, 11:36:34 pm »

I think the issue is that MC internally doesn't use the same integer format as VB is defining the Integer variable (i in the example above).  Probably using a Long or something else.  But, because you are defining the COM objects all as "dumb" objects, the compiler can't figure it out and cast to the proper type for you, so it throws.

If you are going to use strongly typed variables (unlike in vbscript, for example) then I think you need to actually get the real interface from the MC object.  My C# code does it well above, though I don't know how to convert that to VB anymore.

I know you can do it in VB.  I have done it, but it is all very old stuff and I don't have it working or in my head anymore.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

PhDSM

  • Regular Member
  • World Citizen
  • ***
  • Posts: 193
Re: FileAutomation
« Reply #37 on: November 11, 2014, 07:22:31 am »

Let me  summarize the situation

Context:

I'm an Early Adopter of MC starting with MediaJukeBox. Over 12 years of utilisation I build a 80000 entries database with Audio, Images and Video.
Since MJAutomation in 2008 I developped a link between an Excel Database (Movie database) and MC using VB for application (par of MS-Office)
Last summer I migrated to MC 20.0 from MC17 and since then without change my environment, I occured several problems.
One of them is the fact that my VBA apps doesn't work anymore. (I will start other threads with my other problems when I will have enough time)

Problem :

Within my VBA code the call to .search(string)  always return 0 whatever string is.
Also calls to .Getfile(i) or .Getplaylist(i)  fails (throw exception).
After check on my sider , code works ok with MC17 and fails witrh MC18, MC19, MC20.

Current situation :

From what I understand from previous messages, you change MJAutomation API with version 18.0.78 to pullout windows-specific code.
It seems that the new version of MJAutomation API works well with C++ but not with VB  (VBA or VB2010 or VB2012)

Problem seems to be link with the parameters, or parameters type.
  .Getfile(0) works  but Getfile(i)  with i=0   as Integer, Uinteger doesn't
That could also be the reason for .search  but based on my testing  .Search("let")  or .Search(SearchString) with SearchString='Let' both returns 0.

What is different between old MJAutomation (up MC 18.0.78) and new MJAutomation (after MC 18.0.78) that make VB inoperative.

Final question :

How to make MJAutomation working from VB ?

I will seach on my side how to better define variable type to map MC object Model.

Thanks very much for your help

Phil

Logged

gvanbrunt

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1232
  • MC Nerd
Re: FileAutomation
« Reply #38 on: November 11, 2014, 08:36:08 am »

It's pretty much what I thought then. From memory VB interacts slightly different than C# when doing COM interop. It has to do with Varient types. Which you shouldn't be using anyway. You can use them, but it is poor form in a type safe language.

To start to fix your code you should use Option Strict. https://support.microsoft.com/kb/311329?wa=wsignin1.0

That will force all your variable to be strictly cast or the compiler will throw an error. That may be all you have to do to fix the issue.
Logged

PhDSM

  • Regular Member
  • World Citizen
  • ***
  • Posts: 193
Re: FileAutomation
« Reply #39 on: November 11, 2014, 10:44:52 am »

Thanks for your answer.
After investigating, the Option Strict & Explicit , didn't change anything.
However after checking VB forums, I change the code to "force conversion" i.e.  I coded the following way :
   .GetFile( CInt(i) )                                  instead of  .GetFile(i)
   .Search( CStr("Playlist=""NeedInfoDB""") )  instead of  .Search("Playlist=""NeedInfoDB""")
and it works !!!
Problem solved !
Thanks for your active support.
I will now investigate my others problems with MC20, sorry but you will hear from me again.
Cheers

Ph
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42372
  • Shoes gone again!
Re: FileAutomation
« Reply #40 on: November 11, 2014, 11:06:49 am »

Problem solved !

Wow, that's nice!  Thanks for sharing what you've learned.
Logged
Matt Ashland, JRiver Media Center

gvanbrunt

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1232
  • MC Nerd
Re: FileAutomation
« Reply #41 on: November 11, 2014, 11:46:41 am »

Yes that is good to hear. Just to recap VB doesn't handle type conversion the same as C#. What you ended up doing is explicitly casting to to native types, which fixes the issue.

I think you can also use Option Strict which enforces strict typing, but there must also be something else as this alone didn't work. I know you can do COM interop in VB without explicit casting. Can't remember how though.

You can also use the MarshalAs attribute to tell the compiler how to send the call to the COM object.
Logged

PhDSM

  • Regular Member
  • World Citizen
  • ***
  • Posts: 193
Re: FileAutomation
« Reply #42 on: November 11, 2014, 12:08:45 pm »

Quick question to conclude.
What is the internal type for Date like lastPlayed date ?   .Set("Last Played", ??)
I've tried Int, Double, Long, none of them seems to work.
Logged

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: FileAutomation
« Reply #43 on: November 11, 2014, 12:43:37 pm »

Yes that is good to hear. Just to recap VB doesn't handle type conversion the same as C#. What you ended up doing is explicitly casting to to native types, which fixes the issue.

I think you can also use Option Strict which enforces strict typing, but there must also be something else as this alone didn't work. I know you can do COM interop in VB without explicit casting. Can't remember how though.

You can also use the MarshalAs attribute to tell the compiler how to send the call to the COM object.

Yes.  I'm glad to hear you straightened it out.  I'm also glad I wasn't crazy and it was a casting issue.

You would almost certainly not have to cast explicitly if you marshaled the objects to strongly typed Interfaces instead of using generic objects.  But, I don't know modern VB well enough to say for sure (the vast majority of my VB knowledge is from the 6.x days before .NET existed).
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: FileAutomation
« Reply #44 on: November 11, 2014, 12:45:42 pm »

Quick question to conclude.
What is the internal type for Date like lastPlayed date ?   .Set("Last Played", ??)
I've tried Int, Double, Long, none of them seems to work.

I don't know what the actual format of the number is, but they're stored in the database using a scheme identical to Excel's.

It would probably not be an integer, because there is a fractional part of the number (for the time).
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

gvanbrunt

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1232
  • MC Nerd
Re: FileAutomation
« Reply #45 on: November 11, 2014, 01:56:25 pm »

Quick question to conclude.
What is the internal type for Date like lastPlayed date ?   .Set("Last Played", ??)
I've tried Int, Double, Long, none of them seems to work.

I just want to make sure you turned on Option Strict and then changed all the variant data type to strongly typed ones. This should have worked. Implicitly casting calls is kludge not a fix. You wouldn't have to cast anything if that was done as far as I know.
Logged

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: FileAutomation
« Reply #46 on: November 13, 2014, 11:14:31 pm »

Implicitly casting calls is kludge not a fix.

+1  (In a strongly-typed language like VB.NET anyway.)

You wouldn't have to cast anything if that was done as far as I know.

Yeah.  I'm pretty much 99.9% sure it would work right.  And, it would be obviously better because Intellisense would work too.  In most cases, you don't even need all of those additional variables because you can do stuff right inline.  So, this:

       MJPlaylists = MCA.GetPlaylists()
        'Put NbPlaylist in the VBForm
        Form1.NbPlaylist.Text = MJPlaylists.GetNumberPlaylists()
        MJNbPlaylists = MJPlaylists.GetNumberPlaylists()

        CurPLPtr = MJPlaylists.GetPlaylist(0)
        PLName = CurPLPtr.Name
        FileList = CurPLPtr.GetFiles()

Becomes this:

Code: [Select]
Form1.NbPlaylist.Text = MCA.GetPlaylists().GetumberPlaylists()
PLName = MCA.GetPlaylists().GetPlaylist(0).Name
FileList = MCA.GetPlaylists().GetPlaylist(0).GetFiles()

etc...

If I'm motivated, I might whip up some general-purpose VB code that does the marshaling thing right and put it in the Wiki.  If you're writing a compiled application and not a script I don't know why you'd pick VB over C# anyway, but to each their own I guess.

But I don't know, because remembering all I forgot about VB will make my brain hurt for a while.  :P
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

PhDSM

  • Regular Member
  • World Citizen
  • ***
  • Posts: 193
Re: FileAutomation
« Reply #47 on: November 14, 2014, 02:15:25 am »

Thanks for this feedback.

In fact I use VBA  which is the Macro Language of MS-Office, because I just develop a link between MC and an Excel movie Database.
I agree that VB would not be the best choice for a stand alone application, but to link MC with MS-Office VBA is the easiest.

I agree with you about the intermediate variables. There were not in the original code, I just put then in debugging to see step by step what MC is returning.
So far I've been able to adapt my code to MC20. For you information regarding the dates, it works if I pass them as strings.

Now i will concentrated to fix my Communication issue between my MC20 server MC 20 remote computer that occurs since MC17 to MC20 migration (see : New Problems since migration fom MC17 to MC20 thread)
Thanks again for all your support


Logged

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: FileAutomation
« Reply #48 on: November 14, 2014, 08:57:06 am »

In fact I use VBA  which is the Macro Language of MS-Office, because I just develop a link between MC and an Excel movie Database.
I agree that VB would not be the best choice for a stand alone application, but to link MC with MS-Office VBA is the easiest.

Yeah, sorry... I got that.  When I said what I said it wasn't intended to criticize your choice here.

At the very least (this is clunky) you should be able to cast the MCA variable to a proper IMJAutomation object after you get it.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

gvanbrunt

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1232
  • MC Nerd
Re: FileAutomation
« Reply #49 on: November 14, 2014, 09:26:24 am »

Ahhh that is the part I kept missing. I thought you were using VB.Net instead of VBA. Now I see why you have to "marshall by hand".

You can also use VB.Net and Visual Studio with Office instead of VBA. It does take more work initially, but is soooooo much nicer to work with doing the development and debugging. Bit of a learning curve to go that route though.
Logged
Pages: [1] 2   Go Up