示例#1
0
 /// <summary/>
 internal override void SerializeCore(BplBinaryWriter stream, object value) {
    var array = (ICollection)value;
    var count = array.Count;
    stream.WriteInt(count);
    if (count > 0) {
       var converter = BplLanguage.BinaryConverters[PrimitiveItemType];
       foreach (var item in array) {
          converter.Serialize(stream, item);
       }
    }
 }
示例#2
0
      /// <summary>Formats the input BPL object into the output XML document.</summary>
      public override bool Format(BplObject input) {
         if (!PrepareFormatter(input)) return false;

         try {
            var writer = new BplBinaryWriter();
            writer.Serialize(input);
            Output = _toHexString(writer.ToByteArray());
         } catch (Exception e) {
            AddException(e);
         }

         return Success;
      }
      private bool _isEqual(BplObject o1, BplObject o2) {
         var w1 = new BplBinaryWriter();
         w1.Serialize(o1);
         var b1 = w1.ToByteArray();

         var w2 = new BplBinaryWriter();
         w2.Serialize(o2);
         var b2 = w2.ToByteArray();

         if (b1.Length != b2.Length) {
            return false;
         }

         for (var i = 0; i < b1.Length; i++) {
            if (b1[i] != b2[i]) {
               return false;
            }
         }

         return true;
      }
示例#4
0
      /// <summary>Serializes <see cref="BplMessage"/> so that it's ready for network transporting.</summary>
      public static byte[] Serialize(BplMessage message) {
         Assumption.NotNull(message);

         var writer = new BplBinaryWriter();
         writer.Serialize(message);

         var protocol = message.GetProtocol();
         var body = writer.ToByteArray();
         if (body.Length > protocol.MaxPayload) BplRuntimeException.Throw("Serialized message payload ({0}) is more than maximum allowed ({1})".Substitute(body.Length, protocol.MaxPayload));

         var data = new byte[HeaderSize + body.Length];
         Buffer.BlockCopy(BitConverter.GetBytes(body.Length), 0, data, 0, 4);
         Buffer.BlockCopy(_serializeProtocolVersion(protocol.Version), 0, data, 4, 8);
         Buffer.BlockCopy(BitConverter.GetBytes(CRC32.Compute(data, 0, HeaderSize - 4)), 0, data, 12, 4);
         Buffer.BlockCopy(body, 0, data, HeaderSize, body.Length);
         return data;
      }
示例#5
0
 /// <summary/>
 internal override void SerializeCore(BplBinaryWriter stream, object value) {
    throw new NotSupportedException("Serialization of delegate primitives is not supported");
 }
示例#6
0
 /// <summary>Implements <see cref="M:IBplBinaryConverter.Serialize(BplBinaryWriter, object)"/>.</summary>
 public void Serialize(BplBinaryWriter stream, object value) {
    if (value == null) {
       if (!SupportsDefaultValues) {
          throw new BplConversionException(TEXT.BplConverter_NullValue.Substitute(this));
       }
    } else {
       if (!value.IsA(UnderlyingType)) {
          throw new BplConversionException(TEXT.BplConverter_IncompatibleValue.Substitute(this));
       }
    }
    try {
       SerializeCore(stream, value);
    } catch (Exception e) {
       throw new BplConversionException(TEXT.BplConverter_SerializeFailure.Substitute(this, e.Message), e);
    }
 }
示例#7
0
 // Connects with the implementations of the serialize method on derived classes
 internal abstract void SerializeCore(BplBinaryWriter stream, object value);
示例#8
0
 /// <summary/>
 internal override void SerializeCore(BplBinaryWriter stream, object value) {
    stream.WriteNullable(PrimitiveItemType.UnderlyingType, value);
 }
示例#9
0
      private bool _saveFile(bool saveAs) {
         var path = _replaceExtension(InputFile, OutputFormat);
         if (path.IsEmpty() || saveAs) {
            path = FileDialogs.ChooseFileToSave(Shell.UserDataFolder, "Save BPL File" + (saveAs ? " As" : ""), _bplFileFilter);
            if (path.IsEmpty()) return false;
            InputFile = _replaceExtension(path, InputFormat);
         }

         var success = false;
         try {
            if (OutputFormat == BplFormat.Binary) {
               var parser = new BplHexParser();
               parser.Parse(_output.Text);
               var writer = new BplBinaryWriter();
               writer.Serialize(parser.Output);
               File.WriteAllBytes(path, writer.ToByteArray());
            } else {
               File.WriteAllText(path, _output.Text);
            }
            IsDirty = false;
            success = true;
         } catch (Exception e) {
            MessageBox.Show("Failed to save '{0}' file. {1}".Substitute(path, e.Message));
         }
         return success;
      }
示例#10
0
      internal void Handle(UpdateGridSites input) {
         Log.Trace("Processing {0} OPCOs", input.Operators.Count);

         if (input.Operators.Count == 0) {
            Log.Trace("No OPCOs to process, exiting");
            Reply(true);
            return;
         }

         Log.Trace("Store {0} public sites", input.Sites.Count);
         using (var dbConn = DatabaseManager.DbConn()) {
            var dbSites = new List<SiteInfo>();

            foreach (var op in input.Operators) {
               dbSites.AddRange(dbConn.ExecuteBpl(new SiteGetByOwnerId { OwnerId = op.Id }));
            }

            var toUpdate = new List<SiteInfo>();

            var toAdd = new List<SiteInfo>();
            toAdd.AddRange(input.Sites);

            var toDelete = new List<SiteInfo>();
            toDelete.AddRange(dbSites);

            foreach (var iSite in input.Sites) {
               foreach (var dSite in dbSites) {
                  if (iSite.SiteId == dSite.SiteId) {
                     toAdd.Remove(iSite);
                     toDelete.Remove(dSite);

                     var iWriter = new BplBinaryWriter();
                     iWriter.Serialize(iSite);
                     var iBytes = iWriter.ToByteArray();

                     var dWriter = new BplBinaryWriter();
                     dWriter.Serialize(dSite);
                     var dBytes = dWriter.ToByteArray();

                     if (iBytes.Length != dBytes.Length) {
                        toUpdate.Add(iSite);
                     } else {
                        for (var i = 0; i < iBytes.Length; i++) {
                           if (iBytes[i] != dBytes[i]) {
                              toUpdate.Add(iSite);
                              break;
                           }
                        }
                     }

                     break;
                  }
               }
            }

            dbConn.BeginTransaction(this);

            foreach (var s in toUpdate) {
               dbConn.ExecuteBpl(new SiteSave { i = s });
            }

            foreach (var s in toAdd) {
               dbConn.ExecuteBpl(new SiteSave { i = s });
               dbConn.ExecuteBpl(new SiteOwnerAdd { SiteId = s.SiteId, OwnerId = s.Operator.Id });
            }

            foreach (var s in toDelete) {
               dbConn.ExecuteBpl(new SiteDeleteBySiteIdOwnerId { SiteId = s.SiteId, OwnerId = s.Operator.Id });
            }

            dbConn.CommitTransaction();
         }

         Reply(true);
      }