RoboSharp icon indicating copy to clipboard operation
RoboSharp copied to clipboard

Method to save multiple jobs (e.g. content of RoboQueue)

Open PCAssistSoftware opened this issue 3 years ago • 1 comments

We currently have a great way to save single jobs (.RCJ files) from RoboSharp which works really well (thanks @RFBomb)

But it would be nice to also have a way to be able to save the contents of a "RoboQueue" e.g. all the jobs you currently have in your queue and their related settings.

My Initial Thoughts

  • Preferably to a single file if possible, rather than lots of separate ".RCJ" job files, as it could get quite messy if you have a lot of jobs in your queue.

  • Unlike single jobs these don't necessarily need to be backward compatible with RoboCopy so we can use whatever format we like? perhaps XML would be a good fit? or JSON?

Just opening it up here for discussion, with the hope that someone may be able to help implement something in the future :)

Always here for testing and inspiration....... and whatever other help I can provide......

PCAssistSoftware avatar Feb 22 '22 18:02 PCAssistSoftware

As far as readability goes, my personal take is that XML is the way to go, but that's what I'm used to.

I would suggest trying to simply use the C# xml serializer to see what it spits out into a file when run against the RoboCommand/RoboQueue objects.

You can tag properties with [XMLIgnore] to avoid the serialize caring about them. Also note only public properties with Get and Set will be serialized.

RFBomb avatar Feb 22 '22 21:02 RFBomb

Been a while since I last looked at this, but now have a need for it again, so finally got round to looking at it again.

In hindsight actually not sure if I really need to save the contents of a "RoboQueue" as first thought, but I do need a way to save the individual RoboCommand's from a RoboQueue so to speak. So for example if I have added several jobs to a queue, to either be able to loop through the queue and save each one to a .RCJ file, or to select a specific one (by name) and save that.

BEFORE adding the RoboCommand's to the queue I could easily use the SaveasJobFile Function. But AFTER they are in a RoboQueue there is no easy way that I can see that I can then do this. It would be handy if you could loop through all jobs in a queue and save them or just select one by name and save it. Would this be a plausible idea? Hope this make sense, as typing it late at night as I think it through.

PCAssistSoftware avatar Oct 14 '23 23:10 PCAssistSoftware

Once you have used "SaveAsJobFile" how do you then get it back in again - as can't find a corresponding "LoadFromJobFile"??

PCAssistSoftware avatar Oct 14 '23 23:10 PCAssistSoftware

That's a good idea for a static RoboCommand method, that returns a RoboCommand.

I just took a quick peek to refresh myself though. Since the JobFile has to be parsed, and isn't guaranteed to contain all info related to running a job.

Use JobFile.ParseJobFile()

JobFile implements IRoboCommand, so you should be able to run it directly

RFBomb avatar Oct 15 '23 00:10 RFBomb

BEFORE adding the RoboCommand's to the queue I could easily use the SaveasJobFile Function. But AFTER they are in a RoboQueue there is no easy way that I can see that I can then do this. It would be handy if you could loop through all jobs in a queue and save them or just select one by name and save it. Would this be a plausible idea? Hope this make sense, as typing it late at night as I think it through.

RoboQueue implements IEnumerable<IRoboCommand>

You can do a 'ForEach(var cmd in RoboQueue)' and iterate across the collection. You can also use System.LINQ with it.

RFBomb avatar Oct 15 '23 00:10 RFBomb

@RFBomb

SaveAsJobFile is causing a System.NullReferenceException in RoboCommand.cs on line 658 - see screenshot below

image

PCAssistSoftware avatar Oct 15 '23 11:10 PCAssistSoftware

That's a good idea for a static RoboCommand method, that returns a RoboCommand.

I just took a quick peek to refresh myself though. Since the JobFile has to be parsed, and isn't guaranteed to contain all info related to running a job.

Use JobFile.ParseJobFile()

JobFile implements IRoboCommand, so you should be able to run it directly

Okay so I understand I can run JobFile.ParseJobFile("C:\Users\darre\OneDrive\Desktop\job.rcj"), but how do I add the results of this to a RoboCommand or RoboQueue

If I do the below it knows a command had been added as count is 1, but content is nothing

image

Dim x As JobFile = JobFile.ParseJobFile("C:\Users\darre\OneDrive\Desktop\job.rcj")

q.AddCommand(x)

PCAssistSoftware avatar Oct 15 '23 11:10 PCAssistSoftware

BEFORE adding the RoboCommand's to the queue I could easily use the SaveasJobFile Function. But AFTER they are in a RoboQueue there is no easy way that I can see that I can then do this. It would be handy if you could loop through all jobs in a queue and save them or just select one by name and save it. Would this be a plausible idea? Hope this make sense, as typing it late at night as I think it through.

RoboQueue implements IEnumerable

You can do a 'ForEach(var cmd in RoboQueue)' and iterate across the collection. You can also use System.LINQ with it.

Got that part working, thanks - tried it last night and it wasn't working, but was due to intellisense not showing .SaveAsJobFile as an available option, restarted computer and updated VS and it then showed as expected.

PCAssistSoftware avatar Oct 15 '23 12:10 PCAssistSoftware

Line 658 I don't think is needed, as the LastDataReceived field took over that role. Likely oversight.

We should create a unit test for the JobOptions / JobFile stuff to catch this. I can take a peek today

RFBomb avatar Oct 15 '23 12:10 RFBomb

See #183

RFBomb avatar Oct 15 '23 15:10 RFBomb

@PCAssistSoftware this should now be closable

RFBomb avatar Oct 25 '23 02:10 RFBomb