Ejemplo n.º 1
0
        public bool SaveToFile()
        {
            if (!this.User.IsAdmin)
            {
                return(true);
            }
            bool flag = true;

            MrBuggy6.Core.Cryptography cryptography = new MrBuggy6.Core.Cryptography(Settings.User.Identifier, this.salt);
            FileStream   fileStream   = (FileStream)null;
            BinaryWriter binaryWriter = (BinaryWriter)null;

            try
            {
                fileStream   = new FileStream(this.Path, FileMode.OpenOrCreate, FileAccess.Write);
                binaryWriter = new BinaryWriter((Stream)fileStream);
                binaryWriter.Write(cryptography.Encrypt(this.User.Identifier));
                binaryWriter.Write(cryptography.Encrypt(this.User.MAC));
                binaryWriter.Write(cryptography.Encrypt(this.User.PhoneNumber));
                binaryWriter.Write(cryptography.Encrypt(this.CompetitionInProgress));
                binaryWriter.Write(cryptography.Encrypt(Issue.NextId));
                binaryWriter.Write(cryptography.Encrypt((uint)this.Issues.Count));
                foreach (Issue issue in this.Issues)
                {
                    binaryWriter.Write(cryptography.Encrypt(issue.InternalId));
                    binaryWriter.Write(cryptography.Encrypt(issue.Title));
                    binaryWriter.Write(cryptography.Encrypt(issue.Description));
                    binaryWriter.Write(cryptography.Encrypt(issue.Attr1.Id));
                    binaryWriter.Write(cryptography.Encrypt(issue.Attr2.Id));
                    binaryWriter.Write(cryptography.Encrypt(issue.Attr3.Id));
                    binaryWriter.Write(cryptography.Encrypt(issue.Task.Id));
                    binaryWriter.Write(cryptography.Encrypt(issue.Sent));
                }
                binaryWriter.Write(cryptography.Encrypt(this.ActionsSent));
                binaryWriter.Write(cryptography.Encrypt((uint)this.Actions.Count));
                foreach (Action action in this.Actions)
                {
                    binaryWriter.Write(cryptography.Encrypt(action.ViewId));
                    binaryWriter.Write(cryptography.Encrypt(action.Id));
                }
                binaryWriter.Write(cryptography.Encrypt(this.Report.Content));
                binaryWriter.Write(cryptography.Encrypt(this.Report.Sent));
                binaryWriter.Write(cryptography.Encrypt(this.Report.SynchronizationDate.ToBinary()));
            }
            catch (Exception ex)
            {
                flag = false;
            }
            finally
            {
                if (fileStream != null)
                {
                    binaryWriter.Close();
                    fileStream.Close();
                }
            }
            return(flag);
        }
Ejemplo n.º 2
0
 public bool LoadFromFile()
 {
     if (!this.User.IsAdmin)
     {
         return(true);
     }
     this.Report.Content = string.Empty;
     if (File.Exists(this.Path))
     {
         FileStream   fileStream   = new FileStream(this.Path, FileMode.Open, FileAccess.Read);
         BinaryReader binaryReader = new BinaryReader((Stream)fileStream);
         MrBuggy6.Core.Cryptography cryptography = new MrBuggy6.Core.Cryptography(this.User.Identifier, this.salt);
         try
         {
             if (Settings.User.Identifier != cryptography.DecryptToString(binaryReader.ReadString()))
             {
                 throw new CryptographicException();
             }
             binaryReader.ReadString();
             binaryReader.ReadString();
             this.CompetitionInProgress = cryptography.DecryptToBoolean(binaryReader.ReadString());
             Issue.NextId = cryptography.DecryptToUInt32(binaryReader.ReadString());
             uint uint32_1 = cryptography.DecryptToUInt32(binaryReader.ReadString());
             for (int index = 0; (long)index < (long)uint32_1; ++index)
             {
                 Issue issue = new Issue();
                 issue.InternalId  = cryptography.DecryptToUInt32(binaryReader.ReadString());
                 issue.Title       = cryptography.DecryptToString(binaryReader.ReadString());
                 issue.Description = cryptography.DecryptToString(binaryReader.ReadString());
                 uint id = cryptography.DecryptToUInt32(binaryReader.ReadString());
                 issue.Attr1 = Settings.Attr1List.Find((Predicate <IssueAttr1>)(x => (int)x.Id == (int)id));
                 if (issue.Attr1 == null)
                 {
                     throw new Exception();
                 }
                 id          = cryptography.DecryptToUInt32(binaryReader.ReadString());
                 issue.Attr2 = Settings.Attr2List.Find((Predicate <IssueAttr2>)(x => (int)x.Id == (int)id));
                 if (issue.Attr2 == null)
                 {
                     throw new Exception();
                 }
                 id          = cryptography.DecryptToUInt32(binaryReader.ReadString());
                 issue.Attr3 = Settings.Attr3List.Find((Predicate <IssueAttr3>)(x => (int)x.Id == (int)id));
                 if (issue.Attr3 == null)
                 {
                     throw new Exception();
                 }
                 id         = cryptography.DecryptToUInt32(binaryReader.ReadString());
                 issue.Task = Settings.Tasks.Find((Predicate <IssueTask>)(x => (long)x.Id == (long)id));
                 if (issue.Task == null)
                 {
                     throw new Exception();
                 }
                 issue.Sent = cryptography.DecryptToBoolean(binaryReader.ReadString());
                 this.Issues.Add(issue);
             }
             this.ActionsSent = cryptography.DecryptToBoolean(binaryReader.ReadString());
             uint uint32_2 = cryptography.DecryptToUInt32(binaryReader.ReadString());
             for (int index = 0; (long)index < (long)uint32_2; ++index)
             {
                 this.Actions.Add(new Action()
                 {
                     ViewId = cryptography.DecryptToUInt32(binaryReader.ReadString()),
                     Id     = cryptography.DecryptToUInt32(binaryReader.ReadString())
                 });
             }
             this.Report.Content             = cryptography.DecryptToString(binaryReader.ReadString());
             this.Report.Sent                = cryptography.DecryptToBoolean(binaryReader.ReadString());
             this.Report.SynchronizationDate = DateTime.FromBinary(cryptography.DecryptToInt64(binaryReader.ReadString()));
         }
         catch (CryptographicException ex)
         {
             this.Status = ReportFileStatus.Corrupted;
             return(false);
         }
         catch (Exception ex)
         {
             this.Status = ReportFileStatus.Fragmentary;
             return(false);
         }
         finally
         {
             binaryReader.Close();
             fileStream.Close();
         }
     }
     this.Status = ReportFileStatus.OK;
     return(true);
 }