Macro Recording and Playback

SyntaxEditor for Silverlight Forum

Posted 5 years ago by Al
Version: 12.1.0131
Avatar

Can someone please give me an example of how to playback specific recorded macros?

 

I can record a macro with code like:

Dim _Recordings As New Dictionary(Of String, String)

Dim s As New StringWriter
Dim xw As XmlWriter = XmlWriter.Create(s)

editor.MacroRecording.LastMacroAction.WriteToXml(xw)
xw.Close()

_Recordings.Add(Key_Box.Text.Trim, s.ToString)

 

Now assuming I have several _Recordings how do I specify an individual for playback.

 

Trying:

Dim sr As New StringReader(_Recordings("A"))
Dim xr As XmlReader = XmlReader.Create(sr)
editor.MacroRecording.LastMacroAction.ReadFromXml(xr)
editor.ActiveView.ExecuteEditAction(New RunMacroAction)
editor.Focus()

Always runs the last macro recorded not the one from the xml in _Recordings("A")

Trying the same but with CurrentMacroAction like:

editor.MacroRecording.CurrentMacroAction.ReadFromXml(xr)

fails because

editor.MacroRecording.CurrentMacroAction is nothing.

Any tips would be great.

 

Thanks,

 

-Al

Comments (3)

Posted 5 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Al,

I believe you can create a new MacroAction and call ReadFromXml on it to initialize it.  Then just pass that to ExecuteEditAction.


Actipro Software Support

Posted 5 years ago by Al
Avatar

Thanks that gave me a bit of a hint in the right direction but I was unable to load saved macros using the ReadFromXML call.

 

It appears (to me - and I am usually doing something wrong) there is a bug in the MacroAction.ReadFromXML() call.

 

If I have code like:

Dim Content = "<?xml version=""1.0"" encoding=""utf-16""?><MacroAction><EditAction AssemblyName=""ActiproSoftware.SyntaxEditor.Silverlight"" TypeName=""ActiproSoftware.Windows.Controls.SyntaxEditor.EditActions.TypingAction"" Text=""a"" Overwrite=""False"" /><EditAction AssemblyName=""ActiproSoftware.SyntaxEditor.Silverlight"" TypeName=""ActiproSoftware.Windows.Controls.SyntaxEditor.EditActions.TypingAction"" Text=""s"" Overwrite=""False"" /><EditAction AssemblyName=""ActiproSoftware.SyntaxEditor.Silverlight"" TypeName=""ActiproSoftware.Windows.Controls.SyntaxEditor.EditActions.TypingAction"" Text=""d"" Overwrite=""False"" /><EditAction AssemblyName=""ActiproSoftware.SyntaxEditor.Silverlight"" TypeName=""ActiproSoftware.Windows.Controls.SyntaxEditor.EditActions.TypingAction"" Text=""f"" Overwrite=""False"" /><EditAction AssemblyName=""ActiproSoftware.SyntaxEditor.Silverlight"" TypeName=""ActiproSoftware.Windows.Controls.SyntaxEditor.EditActions.TypingAction"" Text=""a"" Overwrite=""False"" /><EditAction AssemblyName=""ActiproSoftware.SyntaxEditor.Silverlight"" TypeName=""ActiproSoftware.Windows.Controls.SyntaxEditor.EditActions.TypingAction"" Text=""s"" Overwrite=""False"" /><EditAction AssemblyName=""ActiproSoftware.SyntaxEditor.Silverlight"" TypeName=""ActiproSoftware.Windows.Controls.SyntaxEditor.EditActions.TypingAction"" Text=""d"" Overwrite=""False"" /><EditAction AssemblyName=""ActiproSoftware.SyntaxEditor.Silverlight"" TypeName=""ActiproSoftware.Windows.Controls.SyntaxEditor.EditActions.TypingAction"" Text=""f"" Overwrite=""False"" /></MacroAction>"

 

Using sr As StringReader = New StringReader(content)
   Using xr As XmlReader = XmlReader.Create(sr)

      Dim x As New MacroAction

      x.ReadFromXml(xr)      

   End Using
End Using

 

It will not work.  Examining the properties of x after the x.ReadFromXML(xr) line shows:

{ActiproSoftware.Windows.Controls.SyntaxEditor.EditActions.MacroAction}
CanRecordInMacro: False
Count: 0
Item: In order to evaluate an indexed property, the property must be qualified and the arguments must be explicitly supplied by the user.
Key: "Macro"
Results: Expanding will process the collection

Where in this case "Count" should be 8

I traced this down to inside the ReadFromXML() call there should be an extra "XMLReader.Read()" call before checking the XMLReader.Depth and then the attempt to determine the type for creation of TypingAction with Activator.CreateInstance() fails because the System.Type can not be determined.

I had to modify the type.GetType() call to be able to find the type and return it.

So in the end to get this to work I had to write my own ReadFromXML() call.

I have a small project I can upload if you are interested in the fix.  Or maybe let me know if I am just doing something stupid in the above example.

 

Thanks,

-Al

Posted 5 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Al,

Yes please do send over your sample to our support address and we'll take a look at it.  Please rename the .zip file extension so it doesn't get spam blocked and reference this thread.  Thanks!


Actipro Software Support

The latest build of this product (v2018.1 build 0232) was released 10 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.