예제 #1
0
파일: GraphMap.cs 프로젝트: Sorenly/neuron
        public void Save(string filename)
        {
            Dictionary <ILinkable, int> linkable = new Dictionary <ILinkable, int>();

            foreach (var o in objects)
            {
                linkable[o] = linkable.Count;
            }

            GraphFileFormat gff = new GraphFileFormat();

            gff.numVertices = linkable.Count;
            gff.vertices    = ArrayUtils.ConvertAll(ArrayUtils.ToArray(linkable.Keys), x => new VertexFormat()
            {
                edges    = ArrayUtils.ConvertAll(ArrayUtils.ToArray(x.Edges), y => linkable[y.Key]),
                x        = x.TopLeft.X,
                y        = x.TopLeft.Y,
                numEdges = x.Edges.Count,
                color    = x.MainControl.BackColor.ToArgb()
            });


            using (FormattedWriter fw = new FormattedWriter(filename)) {
                fw.Write(gff);
            }
        }
예제 #2
0
 private static void WriteUserData(UserdataFileFormat udf)
 {
     using (FormattedWriter fw = new FormattedWriter("sites.info"))
     {
         fw.Write(udf);
     }
 }
예제 #3
0
파일: Neurone.cs 프로젝트: Sorenly/neuron
        private void btn_Save_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.ShowDialog();
            sfd.Filter = "Neuron State Files (*.neuron)|*.neuron";
            if (sfd.FileName != null)
            {
                using (FormattedWriter fw = new FormattedWriter(sfd.FileName))
                {
                    ProgramStateFile psf = new ProgramStateFile();
                    psf.version = 0;
                    psf.nodes   = inputs.Concat(hiddens).Concat(outputs).Select(x => new Node()
                    {
                        x    = x.MainControl.Location.X,
                        y    = x.MainControl.Location.Y,
                        size = x.Data.size,
                        name = new StringData()
                        {
                            Contents = x.Data.name
                        },
                        type     = x.Data.fvt,
                        numlinks = x.Edges.Count,
                        links    = x.Edges.Select(edge => new Link()
                        {
                            matrix   = new MatrixFormat(edge.Value.Data.weights.CopyToArray()),
                            nodename = new StringData()
                            {
                                Contents = edge.Key.Data.name
                            }
                        }).ToArray()
                    }).ToArray();
                    psf.numNodes = psf.nodes.Length;

                    psf.configurations = new StringData[data_configurations.Rows.Count];
                    for (int i = 0; i < psf.configurations.Length; i++)
                    {
                        psf.configurations[i].Contents = data_configurations.Rows[i].Cells[2].Value.ToString();
                    }
                    psf.numConfigurations = psf.configurations.Length;

                    psf.trainings = new StringData[data_training.Rows.Count];
                    for (int i = 0; i < psf.trainings.Length; i++)
                    {
                        psf.trainings[i].Contents = data_training.Rows[i].Cells[2].Value.ToString();
                    }
                    psf.numTrainings = psf.trainings.Length;

                    psf.crossValidations = new StringData[data_crossValidationData.Rows.Count];
                    for (int i = 0; i < psf.crossValidations.Length; i++)
                    {
                        psf.crossValidations[i].Contents = data_crossValidationData.Rows[i].Cells[2].Value.ToString();
                    }
                    psf.numCrossValidations = psf.crossValidations.Length;

                    fw.Write(psf);
                }
            }
        }
예제 #4
0
파일: PAKFile.cs 프로젝트: webdes27/aiondb
        public static void SerializeDirToPak(string dir, string pakfile)
        {
            string[] allFiles = recursiveGetFiles(dir, "");

            List <Dir> dirEntryList = new List <Dir>();

            using (FormattedWriter fw = new FormattedWriter(pakfile)) {
                // Write files
                foreach (var file in allFiles)
                {
                    fw.Write(new Signature()
                    {
                        signature = stringFileHeader2
                    });
                    File   f          = new File();
                    byte[] bytes      = System.IO.File.ReadAllBytes(Path.Combine(dir, file));
                    byte[] compressed = decryptBytesWithTable(ZlibCodecCompress(bytes), 0x3ff, 1, table2);
                    f.compressedSize    = (uint)compressed.Length;
                    f.compressionMethod = 8;
                    CRC32 dataCheckSum = new CRC32();
                    f.crc                    = dataCheckSum.GetCrc32(new MemoryStream(bytes));
                    f.data                   = compressed;
                    f.extractSystem          = 0;
                    f.extractVersion         = 20;
                    f.extraField             = new byte[0];
                    f.extraFieldLength       = 0;
                    f.filename               = Encoding.UTF8.GetBytes(file);
                    f.filenameLength         = (ushort)f.filename.Length;
                    f.generalPurposeFlagBits = 0;
                    f.lastModDate            = 0;
                    f.lastModTime            = 0;
                    f.uncompressedSize       = (uint)bytes.Length;
                    fw.Write(f);

                    Dir d = new Dir();
                    d.comment                = new byte[0];
                    d.commentLength          = 0;
                    d.compressedSize         = f.compressedSize;
                    d.compressType           = f.compressionMethod;
                    d.crc                    = f.crc;
                    d.createSystem           = f.extractSystem;
                    d.createVersion          = f.extractVersion;
                    d.date                   = f.lastModDate;
                    d.diskNumberStart        = 0;
                    d.externalFileAttributes = 33;
                    d.extractSystem          = f.extractSystem;
                    d.extractVersion         = f.extractVersion;
                    d.extraField             = new byte[0];
                    d.extraFieldLength       = 0;
                    d.filename               = f.filename;
                    d.filenameLength         = f.filenameLength;
                    d.flagBits               = f.generalPurposeFlagBits;
                    d.internalFileAttributes = 0;
                    d.localHeaderOffset      = 0;
                    d.time                   = f.lastModTime;
                    d.uncompressedSize       = f.uncompressedSize;

                    dirEntryList.Add(d);
                }

                var dirEntryListStartPos = fw.BaseStream.BaseStream.Position;
                foreach (var d in dirEntryList)
                {
                    fw.Write(new Signature()
                    {
                        signature = stringCentralDir2
                    });
                    fw.Write(d);
                }
                var dirEntryListEndPos = fw.BaseStream.BaseStream.Position;

                End e = new End();
                e.byteSizeOfCentralDirectory = (uint)(dirEntryListEndPos - dirEntryListStartPos);
                e.centralDirRecordsOnDisk    = (short)dirEntryList.Count;
                e.centralDirStartDisk        = 0;
                e.comment       = new byte[0];
                e.commentLength = 0;
                e.diskNumber    = 0;
                e.offsetOfStartOfCentralDirectory = (uint)dirEntryListStartPos;
                e.totalNumOfCentralDirRecords     = (short)dirEntryList.Count;

                fw.Write(new Signature()
                {
                    signature = stringEndArchive2
                });
                fw.Write(e);
            }
        }