コード例 #1
0
        /// <summary>
        /// Create New RDC Record
        /// </summary>
        public bool InsertRemoteView(string licenseId, int childid, int deviceid, string snapshotlocation,
                                     byte[] imgtostore, byte[] thumbnail)
        {
            var remoteView = new Rdc
            {
                LicenseId         = licenseId,
                ChildId           = childid,
                DeviceId          = deviceid,
                SnapshotLocaltion = snapshotlocation,
                Snapshot          = imgtostore,
                Thumbnail         = thumbnail,
                Created           = DateTime.UtcNow,
                Updated           = DateTime.UtcNow,
                Version           = "1.0"
            };

            using (var context = new CustomerInfoRepository())
            {
                context.RemoteViews.Add(remoteView);

                try
                {
                    context.SaveChanges();
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }
コード例 #2
0
ファイル: ZsprToRdc.cs プロジェクト: avvie/SMZ3Randomizer
        public static void Run(ZsprToRdcOptions opts)
        {
            var inputFilename  = opts.File;
            var outputFilename = Path.ChangeExtension(opts.File, "z3.rdc");

            if (!File.Exists(opts.File))
            {
                Console.Error.WriteLine($"The file {opts.File} does not exist");
            }

            using var input  = File.OpenRead(opts.File);
            using var output = File.Open(outputFilename, FileMode.Create);

            var zspr = Zspr.Parse(input);

            var meta = new MetaDataBlock(new JObject(
                                             new JProperty("title", zspr.Title),
                                             new JProperty("author", zspr.Author)));

            var sprite = new LinkSprite();

            sprite.Parse(new MemoryStream(zspr.Content));

            Rdc.Write(output, zspr.AuthorAscii, meta, sprite);
        }
コード例 #3
0
        public static void Run(SpriteInventoryOptions opts)
        {
            if (!Directory.Exists(opts.Directory))
            {
                Console.Error.WriteLine($"The directory {opts.Directory} does not exist");
                return;
            }

            var root  = opts.Directory;
            var files = Enumerable.Concat(
                Directory.EnumerateFiles(root, "*.rdc", SearchOption.AllDirectories),
                Directory.EnumerateFiles(root, "*.rdc.gz", SearchOption.AllDirectories)
                );
            var sprites = files.Select(path => {
                using var stream = OpenReadInnerStream(path);
                var rdc          = Rdc.Parse(stream);

                var game =
                    rdc.Contains <LinkSprite>() ? Game.Z3 :
                    rdc.Contains <SamusSprite>() ? Game.SM : Game.None;

                return(game switch {
                    Game.None => (Game.None, null),
                    _ => (game, data: new {
                        title = ComposeSpriteName(rdc, stream, path),
                        path = Path.GetRelativePath(root, path).Replace('\\', '/')
                    }),
                });
            });
コード例 #4
0
 public virtual byte[] Send(out int length, out int actualLength)
 {
     try
     {
         PadTo(4);
         dataLength = (int)(Position - dataPosition);
         header.MSize(dataLength);
         mS.Flush();
         Position = headerPosition;
         Add(header, false);
         byte[] mBuffer = mS.GetBuffer();
         byte[] iBuffer = new byte[dataLength];
         for (int i = 0; i < dataLength; i++)
         {
             iBuffer[i] = mBuffer[i + (int)dataPosition];
         }
         header.SignMessage(mBuffer, headerLength, iBuffer, socket.HostIP);
         popper.OnBeforeCompress(mBuffer, headerLength);
         byte[] zBuffer = new byte[dataLength];
         actualLength = headerLength + dataLength + 8;
         popper.OnBeforeCompress(iBuffer, dataLength);
         int compLength = Rdc.Compress(iBuffer, dataLength, zBuffer);
         Position = dataLengthPosition;
         if (compLength > 0)
         {
             dataLength = compLength;
             Add(dataLength, false);
             bW.Write(zBuffer, 0, dataLength);
             popper.OnAfterCompress(zBuffer, dataLength);
             mS.Flush();
         }
         else
         {
             Add(dataLength, false);
         }
         length = headerLength + dataLength + 8;
         socket.Write(mBuffer, length);
         writeDuration = socket.WriteDuration;
         return(mBuffer);
     }
     catch (Exception ex)
     {
         throw new RpcException("Error Sending buffer to Server", ex);
     }
 }
コード例 #5
0
 public virtual byte[] Receive(out int length, out int actualLength)
 {
     byte[] result = null;
     try
     {
         int    headerLength = 0;
         int    dataLength   = 0;
         byte[] read1        = socket.Read(out headerLength);
         readDuration = socket.ReadDuration;
         byte[] read2 = new byte[0];
         popper.OnAfterUncompress(read1, headerLength);
         BinaryWriter bW = new BinaryWriter(mS);
         bW.Write(read1, 0, headerLength);
         Position = 0;
         header   = (Header)Get(header);
         length   = actualLength = headerLength + 4;
         if (header.MSize() > 0)
         {
             read2         = new byte[0];
             read2         = socket.Read(out dataLength);
             readDuration += socket.ReadDuration;
             popper.OnBeforeUncompress(read2, dataLength);
             actualLength += header.MSize() + 4;
             length       += dataLength + 4;
             Position      = 0;
             if (header.MSize() > dataLength)
             {
                 byte[] zBuff = new byte[header.MSize()];
                 int    zLen  = Rdc.Decompress(read2, dataLength, zBuff);
                 popper.OnAfterUncompress(zBuff, zLen);
                 bW.Write(zBuff, 0, zLen);
                 result = zBuff;
             }
             else
             {
                 bW.Write(read2, 0, dataLength);
                 result = read2;
             }
             Position = 0;
         }
         if (header.ESize() > 0)
         {
             read2         = new byte[0];
             read2         = socket.Read(out dataLength);
             readDuration += socket.ReadDuration;
             popper.OnBeforeUncompress(read2, dataLength);
             actualLength += header.ESize() + 4;
             length       += dataLength + 4;
             if (header.ESize() > dataLength)
             {
                 byte[] zBuff = new byte[header.ESize()];
                 int    zLen  = Rdc.Decompress(read2, dataLength, zBuff);
                 popper.OnAfterUncompress(zBuff, zLen);
                 throw new RpcException(header.ReturnCode(), Encoding.Default.GetString(zBuff, 0, zLen));
             }
             else
             {
                 throw new RpcException(header.ReturnCode(), Encoding.Default.GetString(read2, 0, dataLength));
             }
         }
         if (header.ReturnCode() != 0)
         {
             throw new RpcException(header.ReturnCode());
         }
     }
     catch (RpcException)
     {
         throw; // bounce this catch up
     }
     catch (Exception ex)
     {
         throw new RpcException("Error Reading from Server", ex);
     }
     return(result);
 }