Exemple #1
0
        static void Main(string[] args)
        {
            CustomReader reader1 = new CustomReader("../../../file.bin", BaseIO.ByteOrder.LittleEndian);

            byte[] arr1 = reader1.ReadBytes(4);
            Console.WriteLine("Little Endian:");
            foreach (var item in arr1)
            {
                Console.WriteLine(item.ToString("X"));
            }
            reader1.Close();


            CustomReader reader2 = new CustomReader("../../../file.bin", BaseIO.ByteOrder.BigEndian);

            byte[] arr2 = reader2.ReadBytes(4);
            Console.WriteLine("Big Endian:");
            foreach (var item in arr2)
            {
                Console.WriteLine(item.ToString("X"));
            }
            reader2.Close();

            CustomWriter writer1 = new CustomWriter("../../../le.bin", BaseIO.ByteOrder.LittleEndian);

            byte[] ar = { 0x31, 0x32, 0x33 };
            writer1.WriteBytes(ar);
            writer1.Close();

            CustomWriter writer2 = new CustomWriter("../../../be.bin", BaseIO.ByteOrder.BigEndian);

            writer2.WriteBytes(ar);
            writer2.Close();
        }
        /// <summary>
        /// </summary>
        /// <param name="path"></param>
        /// <param name="customReader">custom stream reader</param>
        /// <param name="customWriter"></param>
        public StringListFile(string path, CustomReader customReader = null, CustomWriter customWriter = null)
        {
            _path         = path;
            _customReader = customReader;
            _customWriter = customWriter;

            if (File.Exists(path))
            {
                TextReader reader;
                if (_customReader != null)
                {
                    reader = _customReader(path);
                }
                else
                {
                    reader = new StreamReader(path);
                }

                using (reader)
                {
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        m_List.Add(line);
                    }
                }
            }
        }
Exemple #3
0
 /// <summary>
 /// Reuse same text writer on this stream.
 /// </summary>
 /// <returns>stream writer</returns>
 public TextWriter GetWriter()
 {
     if (Writer == null)
     {
         Writer = new CustomWriter(this);
     }
     return(Writer);
 }
Exemple #4
0
            public CustomPositionValueMaskReader(Vector3F[] positions, float[] initialValues, OneAxisBounds valueRange) : base(positions.Length)
            {
                this.positions     = positions;
                this.initialValues = initialValues;
                ValueRange         = valueRange;
                writer             = new CustomWriter(this);

                values = new float[initialValues.Length];
                Array.Copy(initialValues, values, values.Length);
            }
        public XmlWriter CreateMemWriter(XmlWriterUtils utils, Stream writerStream, XmlWriterSettings settings)
        {
            XmlWriterSettings wSettings = settings.Clone();

            wSettings.CloseOutput        = false;
            wSettings.OmitXmlDeclaration = true;
            wSettings.CheckCharacters    = false;
            XmlWriter w = null;

            switch (utils.WriterType)
            {
            case WriterType.UTF8Writer:
                wSettings.Encoding = Encoding.UTF8;
                w = WriterHelper.Create(writerStream, wSettings, overrideAsync: true, async: utils.Async);
                break;

            case WriterType.UnicodeWriter:
                wSettings.Encoding = Encoding.Unicode;
                w = WriterHelper.Create(writerStream, wSettings, overrideAsync: true, async: utils.Async);
                break;

            case WriterType.WrappedWriter:
                XmlWriter ww = WriterHelper.Create(writerStream, wSettings, overrideAsync: true, async: utils.Async);
                w = WriterHelper.Create(ww, wSettings, overrideAsync: true, async: utils.Async);
                break;

            case WriterType.CharCheckingWriter:
                XmlWriter         cw  = WriterHelper.Create(writerStream, wSettings, overrideAsync: true, async: utils.Async);
                XmlWriterSettings cws = settings.Clone();
                cws.CheckCharacters = true;
                w = WriterHelper.Create(cw, cws, overrideAsync: true, async: utils.Async);
                break;

            case WriterType.CustomWriter:
                wSettings.Async = utils.Async;
                w = new CustomWriter(writerStream, wSettings);
                break;

            case WriterType.UTF8WriterIndent:
                wSettings.Encoding = Encoding.UTF8;
                wSettings.Indent   = true;
                w = WriterHelper.Create(writerStream, wSettings, overrideAsync: true, async: utils.Async);
                break;

            case WriterType.UnicodeWriterIndent:
                wSettings.Encoding = Encoding.Unicode;
                wSettings.Indent   = true;
                w = WriterHelper.Create(writerStream, wSettings, overrideAsync: true, async: utils.Async);
                break;

            default:
                throw new Exception("Unknown writer type");
            }
            return(w);
        }
 public void UpdateProperties(CustomWriter cr)
 {
     //Update properties in every write
     lstCustomWriter.Remove(cr);
     _pendingWrites--;
     _totalWrites++;
     _totalBytesWritten += cr._fileData.Count();
     Console.WriteLine("Total Bytes Writtern: {0}", _totalBytesWritten);
     Console.WriteLine("Total Writes: {0}", _totalWrites);
     Console.WriteLine("Pending Writes: {0}\n", _pendingWrites);
 }
        public Packet Packet(short id)
        {
            Packet p = new Packet(id);

            using (MemoryStream ms = new MemoryStream())
                using (CustomWriter w = new CustomWriter(ms))
                {
                    w.Write(Id);
                    w.Write(MatchRunning);
                    w.Write(MatchType);
                    w.Write(Mods);
                    w.Write(Name);
                    w.Write(Password);
                    w.Write(BeatmapName);
                    w.Write(BeatmapId);
                    w.Write(BeatmapMd5);

                    for (int i = 0; i < 16; i++)
                    {
                        w.Write(Slots[i].Status);
                    }

                    for (int i = 0; i < 16; i++)
                    {
                        w.Write(Slots[i].Team);
                    }

                    for (int i = 0; i < 16; i++)
                    {
                        if ((Slots[i].Status & 124) != 0 && Slots[i].User != null)
                        {
                            w.Write(Slots[i].User.Id);
                        }
                    }

                    w.Write(Host);
                    w.Write(Gamemode);
                    w.Write(ScoreType);
                    w.Write(TeamType);
                    w.Write(FreeMod);

                    if (FreeMod)
                    {
                        for (int i = 0; i < 16; i++)
                        {
                            w.Write(Slots[i].Mods);
                        }
                    }

                    p.Data = ms.ToArray();
                }
            return(p);
        }
        public void RunWriteScheduler()
        {
            //Initialize files and their content
            //Interface reference is type casted to CustomWriter class
            CustomWriter cr1 = (CustomWriter)Write("cr1", Encoding.ASCII.GetBytes("1234567898"));
            CustomWriter cr2 = (CustomWriter)Write("cr2", Encoding.ASCII.GetBytes("this a first model for custom writer"));
            CustomWriter cr3 = (CustomWriter)Write("cr3", Encoding.ASCII.GetBytes("abcdefghijklmnopqrstuvwxyz"));
            CustomWriter cr4 = (CustomWriter)Write("cr4", Encoding.ASCII.GetBytes("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"));
            CustomWriter cr5 = (CustomWriter)Write("cr5", Encoding.ASCII.GetBytes("abcdefgh123456890ABCDEFGHI"));

            lstCustomWriter.Add(cr1);
            lstCustomWriter.Add(cr2);
            lstCustomWriter.Add(cr3);
            lstCustomWriter.Add(cr4);
            lstCustomWriter.Add(cr5);


            //Initializing properties
            _pendingWrites     = lstCustomWriter.Count;
            _totalWrites       = 0;
            _totalBytesWritten = 0;

            //we are assuming that there is a file already written
            cr1.Write(cr1._fileName, cr1._fileData);
            UpdateProperties(cr1);

            //we will process the file which has minimum byte count in comparision with totalBytesWritten/totalWrites
            //we are optimizing through writing smallest files first
            while (lstCustomWriter.Count != 0)
            {
                //just to ensure we have a variable in tempCr
                var tempCr = lstCustomWriter.First();
                foreach (var cr in lstCustomWriter)
                {
                    if (cr._fileData.Count() < (this.TotalBytesWritten / this.TotalWrites))
                    {
                        tempCr = cr;
                    }
                    else
                    {
                        if (tempCr._fileData.Count() > cr._fileData.Count())
                        {
                            tempCr = cr;
                        }
                    }
                }
                tempCr.Write(tempCr._fileName, tempCr._fileData);
                UpdateProperties(tempCr);
            }
        }
Exemple #9
0
        public void CheckDesignDataContext()
        {
            var type = typeof(ClassWithDataContext);
            var xaml = $@"
<{type.Name} xmlns='clr-namespace:{type.Namespace}'
xmlns:d='http://schemas.microsoft.com/expression/blend/2008'
xmlns:mc='http://schemas.openxmlformats.org/markup-compatibility/2006'
mc:Ignorable='d'
d:DataContext='value'>
</{type.Name}>";

            foreach (var designMode in new[] { true, false })
            {
                foreach (var useDirective in new[] { true, false })
                {
                    ClassWithDataContext res;
                    var settings = new XamlXmlReaderSettings {
                        LocalAssembly = type.Assembly
                    };
                    var rdr = new XamlXmlReader(new StringReader(xaml), new CustomContext()
                    {
                        IsDesignMode = designMode,
                        NamespaceMap = useDirective ? null : ("clr-namespace:" + typeof(ClassWithDataContext).Namespace)
                    }, settings);
                    if (useDirective)
                    {
                        var writer = new CustomWriter(rdr.SchemaContext)
                        {
                            IsDesignMode = designMode
                        };
                        XamlServices.Transform(rdr, writer);
                        res = (ClassWithDataContext)writer.Result;
                    }
                    else
                    {
                        res = (ClassWithDataContext)XamlServices.Load(rdr);
                    }

                    if (designMode)
                    {
                        Assert.AreEqual("value", res.DataContext);
                    }
                    else
                    {
                        Assert.IsNull(res.DataContext);
                    }
                }
            }
        }
 public void saveFields(CustomWriter w, int SaveVersion)
 {
     item.saveFields(w, SaveVersion); w.write(_Quantity);
 }
Exemple #11
0
		/// <summary>
		/// Reuse same text writer on this stream.
		/// </summary>
		/// <returns>stream writer</returns>
		public TextWriter GetWriter()
		{
			if (Writer == null)
				Writer = new CustomWriter(this);
			return Writer;
		}
Exemple #12
0
 public ChainedProgressMonitor(TestSingleThreadSynchronizationContext ctx) : base(ctx)
 {
     Log = underlyingLog = new CustomWriter(ctx);
 }
        /// <summary>
        /// Gets a CustomWriter for a given type
        /// </summary>
        private CustomWriter GetCustomWriter( Type type )
        {
            CustomWriter writer;
            if ( !m_TypeIds.TryGetValue( type, out writer ) )
            {
                int typeId = ( int )TypeId.Other + m_Writers.Count;

                writer = new CustomWriter( type, typeId, CustomTypeWriterCache.Instance.GetWriter( type ) );

                m_Writers.Add( writer );
                m_TypeIds[ type ] = writer;
            }
            return writer;
        }
Exemple #14
0
        public static void RegisterType <T>(CustomReader reader, CustomWriter writer)
        {
            var type = typeof(T);

            _customSerializers[type] = new CustomSerializer(reader, writer);
        }
Exemple #15
0
 public CustomSerializer(CustomReader reader, CustomWriter writer)
 {
     Read  = reader;
     Write = writer;
 }
 public void Register(CustomWriter writer)
 {
 }
Exemple #17
0
 private void EWriter_Test(CustomWriter writer)
 {
 }
Exemple #18
0
 public void saveFields(CustomWriter w, int SaveVersion)
 {
 }