public void CreateInstances()
        {
            var f = new MyFormatter();

            Assert.IsTrue(f.CreateInline() is InlineCategoriesDocument, "#1");
            Assert.IsTrue(f.CreateReferenced() is ReferencedCategoriesDocument, "#2");
        }
示例#2
0
 public MyCommand(IWpfTextView textView, MyFormatter formatter, ITextDocument document, ITextBufferUndoManager undoManager)
 {
     _textView    = textView;
     _formatter   = formatter;
     _document    = document;
     _undoManager = undoManager;
 }
示例#3
0
    public static void TestParseWithAssumeUniversal()
    {
        var formatter  = new MyFormatter();
        var dateBefore = DateTime.Now.ToString();
        var dateAfter  = DateTimeOffset.ParseExact(dateBefore, "G", formatter, DateTimeStyles.AssumeUniversal);

        Assert.Equal(dateBefore, dateAfter.DateTime.ToString());
    }
示例#4
0
文件: Client.cs 项目: emaha/Voter
        // Отправка пакета по сокету
        private void SendPacket(TcpClient client, Packet pack)
        {
            NetworkStream stream = client.GetStream();

            byte[] buf = MyFormatter.Serialize(pack);

            stream.Write(buf, 0, buf.Length);
        }
示例#5
0
    public static void TestParseExact_String_String_FormatProvider_DateTimeStyles_CustomFormatProvider()
    {
        var    formatter  = new MyFormatter();
        string dateBefore = DateTime.Now.ToString();

        DateTime dateAfter = DateTime.ParseExact(dateBefore, "G", formatter, DateTimeStyles.AdjustToUniversal);

        Assert.Equal(dateBefore, dateAfter.ToString());
    }
示例#6
0
        public static void Run <T>(this ITestOutputHelper helper) where T : NSpec.nspec
        {
            var spec      = typeof(T);
            var finder    = new SpecFinder(new[] { spec });
            var tags      = new Tags().Parse(spec.Name);
            var builder   = new ContextBuilder(finder, tags, new DefaultConventions());
            var formatter = new MyFormatter(helper);
            var runner    = new ContextRunner(tags, formatter, false);
            var contexts  = builder.Contexts().Build();
            var results   = runner.Run(contexts);

            //assert that there aren't any failures
            results.Failures().Count().Should().Be(0);
        }
        public void TestInitialize()
        {
            myFormatter = new MyFormatter();
            a1          = new ClassA("Ala", 3.12f, new DateTime(2019, 12, 24, 8, 12, 0));
            b1          = new ClassB("ma", 4.12f, new DateTime(2019, 12, 25, 8, 15, 0));
            c1          = new ClassC("kota", 5.12f, new DateTime(2019, 12, 26, 8, 20, 0));
            a1.ClassB   = b1;
            a1.ClassC   = c1;

            b1.ClassA = a1;
            b1.ClassC = c1;

            c1.ClassB = b1;
            c1.ClassA = a1;
        }
示例#8
0
        // Обработка сокетов
        private void ManageClients()
        {
            lock (mutex)     {
                foreach (TcpClient client in clients)
                {
                    NetworkStream stream = client.GetStream();
                    if (stream.DataAvailable)
                    {
                        byte[] buf = new byte[4096];
                        stream.Read(buf, 0, 4096);
                        Packet data = (Packet)MyFormatter.Deserialize(buf);

                        switch (data.Command)
                        {
                        case CommandType.Message:
                            Console.WriteLine(data.GetMessage());

                            break;

                        case CommandType.Collection:

                            break;

                        case CommandType.Choice:
                            int choice = data.getChoice();
                            vManager.Vote(choice);
                            break;

                        case CommandType.Stats:
                            Console.WriteLine("StatRequest");
                            Packet pack = new Packet();
                            pack.Command = CommandType.Stats;
                            pack.Data    = (Object)vManager.currentVoteBox;

                            SendPacket(client, pack);
                            break;

                        default:

                            break;
                        }
                    }

                    // На всякий случай спим, чтобы не напрягать процессор
                    Thread.Sleep(100);
                }
            }
        }
示例#9
0
文件: Client.cs 项目: emaha/Voter
        private void Loop()
        {
            while (!isExit)
            {
                if (stream.DataAvailable)
                {
                    byte[] buf = new byte[4096];

                    try {
                        stream.Read(buf, 0, 4096);
                    } catch (Exception ex) {
                        isExit = true;
                        Console.WriteLine(ex.Message);
                    }
                    Packet pack = (Packet)MyFormatter.Deserialize(buf);

                    switch (pack.Command)
                    {
                    case CommandType.Message:
                        Console.WriteLine(pack.GetMessage());
                        break;

                    case CommandType.Collection:
                        VoteBox voteBox = pack.GetVoteBox();
                        PrintVoteBox(voteBox);
                        TakeChoice(voteBox);
                        RequestStats();
                        break;

                    //вприципе тоже самое что и collection
                    case CommandType.Stats:
                        PrintStats(pack.Data);
                        isExit = true;
                        break;

                    default:

                        break;
                    }
                }

                Thread.Sleep(10);
            }
        }
示例#10
0
        public void Test1()
        {
            MyFormatter serializer = new MyFormatter();
            Class3      c3         = new Class3(DateTime.Now, null);
            Class2      c2         = new Class2("content", c3);
            Class1      c1         = new Class1(20, c2);

            c3.refC1 = c1;
            CustomSerialization.CreateFile(c1, "sample.dat");
            Class1 c1Copy = (Class1)CustomSerialization.ReadFile("sample.dat");

            c2.contentString = "zmiana";
            Assert.IsNotNull(c1Copy.refC2);
            Assert.IsNotNull(c1Copy.refC2.refC3);
            Assert.AreEqual(c1, c1.refC2.refC3.refC1);
            c1Copy.contentInt = 10;
            Assert.AreEqual(10, c1Copy.contentInt);
            Assert.AreEqual(10, c1Copy.refC2.refC3.refC1.contentInt);
        }
示例#11
0
        /// <summary>
        /// Write a CSV file and and use delegate method to format the lines
        /// </summary>
        /// <example>
        /// public static string CvsComplexFormatter(object line, int lineCounter, string columnSeparator)
        /// {
        ///     var elements = new List&lt;string&gt;();
        ///     var complex = (CommonUtils.MathLib.FFT.Complex) line;
        ///
        ///     elements.Add(String.Format("{0,4}", lineCounter));
        ///     elements.Add(String.Format("{0,12:N6}", complex.Re));
        ///     elements.Add(String.Format("{0,12:N6}", complex.Im));
        ///
        ///     return string.Join(columnSeparator, elements);
        /// }
        ///
        /// Complex[] spectrum = SpectrogramUtils.padded_FFT(ref signal);
        /// List&lt;object&gt; lines = spectrum.Cast&lt;object&gt;().ToList();
        /// IOUtils.WriteCSV("output.csv", lines, CvsComplexFormatter);
        /// </example>
        /// <param name="filePath">file path</param>
        /// <param name="lines">a list of objects</param>
        /// <param name="formatter">a formatter delegate method</param>
        public static void WriteCSV(string filePath, List <object> lines, MyFormatter formatter)
        {
            int        lineCounter = 0;
            TextWriter pw          = new StreamWriter(filePath, false, _isoLatin1Encoding);

            // rows and columns
            if (lines != null)
            {
                foreach (var line in lines)
                {
                    lineCounter++;

                    // write data
                    var columns = formatter(line, lineCounter, columnSeparator);
                    pw.Write("{0}\r\n", columns);
                }
            }
            pw.Close();
        }
示例#12
0
 public static void TestParseWithAssumeUniversal()
 {
     var formatter = new MyFormatter();
     var dateBefore = DateTime.Now.ToString();
     var dateAfter = DateTimeOffset.ParseExact(dateBefore, "G", formatter, DateTimeStyles.AssumeUniversal);
     Assert.Equal(dateBefore, dateAfter.DateTime.ToString());
 }
示例#13
0
        public static void ParseExact_String_String_FormatProvider_DateTimeStyles_CustomFormatProvider()
        {
            var formatter = new MyFormatter();
            string dateBefore = DateTime.Now.ToString();

            DateTime dateAfter = DateTime.ParseExact(dateBefore, "G", formatter, DateTimeStyles.AdjustToUniversal);
            Assert.Equal(dateBefore, dateAfter.ToString());
        }
		public void CreateInstances ()
		{
			var f = new MyFormatter ();
			Assert.IsTrue (f.CreateInline () is InlineCategoriesDocument, "#1");
			Assert.IsTrue (f.CreateReferenced () is ReferencedCategoriesDocument, "#2");
		}