source: trunk/CrypPlugins/P2PEditor/Distributed/DistributedJobSerializer.cs @ 2081

Last change on this file since 2081 was 1727, checked in by Paul Lelgemann, 11 years ago

+ P2PEditor can display the status of jobs, if available; Participating displays overlay while loading workspace data
+ KeySearcher can upload status for P2PEditor display

File size: 2.2 KB
Line 
1using System;
2using System.IO;
3
4namespace Cryptool.P2PEditor.Distributed
5{
6    static class DistributedJobSerializer
7    {
8        public static DistributedJob FromReader(BinaryReader reader)
9        {
10            var newJob = new DistributedJob();
11           
12            newJob.Guid = new Guid(reader.ReadBytes(16));
13            newJob.Name = reader.ReadString();
14            newJob.Description = reader.ReadString();
15            newJob.Owner = reader.ReadString();
16            newJob.CreateDate = DateTime.FromBinary(reader.ReadInt64());
17            newJob.FileName = reader.ReadString();
18
19            if (reader.ReadBoolean())
20                newJob.StatusKey = reader.ReadString();
21
22            return newJob;
23        }
24
25        public static DistributedJobStatus StatusFromReader(BinaryReader reader)
26        {
27            var newJobStatus = new DistributedJobStatus();
28
29            newJobStatus.CurrentStatus = (DistributedJobStatus.Status) reader.ReadByte();
30            newJobStatus.Participants = reader.ReadInt64();
31            newJobStatus.Progress = reader.ReadDouble();
32            newJobStatus.StartDate = DateTime.FromBinary(reader.ReadInt64());
33
34            return newJobStatus;
35        }
36
37        public static void ToWriter(DistributedJob distributedJob, BinaryWriter writer)
38        {
39            writer.Write(distributedJob.Guid.ToByteArray());
40            writer.Write(distributedJob.Name);
41            writer.Write(distributedJob.Description);
42            writer.Write(distributedJob.Owner);
43            writer.Write(distributedJob.CreateDate.ToBinary());
44            writer.Write(distributedJob.FileName);
45
46            var hasStatusKey = !string.IsNullOrEmpty(distributedJob.StatusKey);
47            writer.Write(hasStatusKey);
48            if (hasStatusKey)
49                writer.Write(distributedJob.StatusKey);
50        }
51
52        public static void ToWriter(DistributedJobStatus distributedJobStatus, BinaryWriter writer)
53        {
54            writer.Write((byte) distributedJobStatus.CurrentStatus);
55            writer.Write(distributedJobStatus.Participants);
56            writer.Write(distributedJobStatus.Progress);
57            writer.Write(distributedJobStatus.StartDate.ToBinary());
58        }
59    }
60}
Note: See TracBrowser for help on using the repository browser.