Esempio n. 1
0
        protected override void OnExecute()
        {
            var authentication = this.CommandContext.GetAuthentication(this);
            var accessible     = this.GetObject(authentication, this.Path);

            if (this.MemberIDToAdd != string.Empty)
            {
                this.Invoke(authentication, accessible, () => accessible.AddAccessMember(authentication, this.MemberIDToAdd, this.AccessType));
            }
            else if (this.MemberIDToSet != string.Empty)
            {
                this.Invoke(authentication, accessible, () => accessible.SetAccessMember(authentication, this.MemberIDToSet, this.AccessType));
            }
            else if (this.MemberIDToRemove != string.Empty)
            {
                this.Invoke(authentication, accessible, () => accessible.RemoveAccessMember(authentication, this.MemberIDToRemove));
            }
            else if (this.Information == true)
            {
                var accessInfo = this.Invoke(authentication, accessible, () => accessible.AccessInfo);
                var prop       = accessInfo.ToDictionary();
                var text       = TextSerializer.Serialize(prop, this.FormatType);
                this.Out.WriteLine(text);
            }
            else
            {
                this.Invoke(authentication, accessible, () => accessible.SetPrivate(authentication));
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            string str = "Wally     M065201011161";

            Console.WriteLine("Text='" + str + "'");
            Console.WriteLine("-----");

            var serializer = new TextSerializer <Dog>();

            Console.WriteLine("Deserialized:");
            var deserialized = serializer.Deserialize(str);

            foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(deserialized))
            {
                string name  = descriptor.Name;
                object value = descriptor.GetValue(deserialized);
                Console.WriteLine("{0}={1}", name, value);
            }

            Console.WriteLine("-----");

            Console.WriteLine("Serialized:");
            var serialized = serializer.Serialize(deserialized);

            Console.WriteLine(serialized);
        }
Esempio n. 3
0
        ////////////////////////////////////////
        // StringToString

        public static string StringToString(string text, bool formatted) => JsonException.Wrap(() =>
        {
            using (StringWriter writer = new StringWriter(CultureInfo.InvariantCulture))
            {
                TextSerializer.Serialize(new TokenItemizer(new StringTokenizer(text)), Constants.GetIndent(formatted), writer);
                return(writer.ToString());
            }
        });
Esempio n. 4
0
        public void Length_Failure()
        {
            string str = "10charlong";

            var serializer   = new TextSerializer <StringClass>();
            var deserialized = serializer.Deserialize(str);

            Assert.AreEqual(str, deserialized.Value);
            Assert.AreEqual(str, serializer.Serialize(deserialized));

            string str2 = "not10charlong";

            deserialized.Value = str2;
            Assert.AreNotEqual(str, deserialized.Value);
            Assert.AreEqual(str2.Substring(0, 10), serializer.Serialize(deserialized));
            Assert.AreNotEqual(str2, serializer.Serialize(deserialized));
        }
Esempio n. 5
0
        public void Info(string tableName)
        {
            var table     = this.GetTable(tableName);
            var tableInfo = table.Dispatcher.Invoke(() => table.TableInfo);
            var props     = tableInfo.ToDictionary(true);
            var text      = TextSerializer.Serialize(props);

            this.Out.WriteLine(text);
        }
Esempio n. 6
0
        public void DateTimeTest()
        {
            string original = "20141017 18:30:00";

            var serializer   = new TextSerializer <SimpleDateTime>();
            var deserialized = serializer.Deserialize(original);

            Assert.AreEqual(new DateTime(2014, 10, 17, 18, 30, 0), deserialized.Value);
            Assert.AreEqual(original, serializer.Serialize(deserialized));
        }
Esempio n. 7
0
        public void String_Success()
        {
            string str = "asdf      ";

            var serializer   = new TextSerializer <SimpleString>();
            var deserialized = serializer.Deserialize(str);

            Assert.AreEqual("asdf", deserialized.Value);
            Assert.AreEqual(str, serializer.Serialize(deserialized));
        }
Esempio n. 8
0
        public void Bool_Success()
        {
            string str = "1";

            var serializer   = new TextSerializer <SimpleBool>();
            var deserialized = serializer.Deserialize(str);

            Assert.AreEqual(true, deserialized.Value);
            Assert.AreEqual(str, serializer.Serialize(deserialized));
        }
Esempio n. 9
0
        public void Double_Success()
        {
            string str = "12.3      ";

            var serializer   = new TextSerializer <SimpleDouble>();
            var deserialized = serializer.Deserialize(str);

            Assert.AreEqual(12.3, deserialized.Value);
            Assert.AreEqual(str, serializer.Serialize(deserialized));
        }
Esempio n. 10
0
        public void Float_Success()
        {
            string str = "12.3      ";

            var serializer   = new TextSerializer <SimpleFloat>();
            var deserialized = serializer.Deserialize(str);

            Assert.AreEqual(12.3, deserialized.Value, 0.001);
            Assert.AreEqual(str, serializer.Serialize(deserialized));
        }
        public void TextAlignmentRight_Success()
        {
            string original = "       abc";

            var serializer   = new TextSerializer <StringClassRight>();
            var deserialized = serializer.Deserialize(original);

            Assert.AreEqual("abc", deserialized.Value);
            Assert.AreEqual(original, serializer.Serialize(deserialized));
        }
Esempio n. 12
0
        public void Long_Success()
        {
            string str = "1234      ";

            var serializer   = new TextSerializer <SimpleLong>();
            var deserialized = serializer.Deserialize(str);

            Assert.AreEqual((long)1234, deserialized.Value);
            Assert.AreEqual(str, serializer.Serialize(deserialized));
        }
Esempio n. 13
0
 public void Serialize(TextSerializer serializer)
 {
     if (Token == null)
     {
         serializer.Serialize(true);
         serializer.Serialize(Name);
         foreach (var child in Children())
         {
             serializer.Serialize(true);
             child.Serialize(serializer);
         }
         serializer.Serialize(false);
     }
     else
     {
         serializer.Serialize(false);
         Token.Serialize(serializer);
     }
 }
Esempio n. 14
0
        protected override void OnExecute()
        {
            var authentication = this.CommandContext.GetAuthentication(this);
            var drive          = this.CommandContext.Drive;
            var provider       = this.GetObject(authentication, this.AbsolutePath);
            var info           = this.Invoke(provider, () => provider.Info);
            var text           = TextSerializer.Serialize(info, this.FormatType);

            this.Out.WriteLine(text);
        }
Esempio n. 15
0
        public void Length_Success()
        {
            string str = "10charlong";

            var serializer   = new TextSerializer <StringClass>();
            var deserialized = serializer.Deserialize(str);

            Assert.AreEqual(str, deserialized.Value);
            Assert.AreEqual(str, serializer.Serialize(deserialized));
        }
Esempio n. 16
0
        public void Char_Success()
        {
            string str = "a";

            var serializer   = new TextSerializer <SimpleChar>();
            var deserialized = serializer.Deserialize(str);

            Assert.AreEqual('a', deserialized.Value);
            Assert.AreEqual(str, serializer.Serialize(deserialized));
        }
Esempio n. 17
0
        public void Ushort_Success()
        {
            string str = "1234      ";

            var serializer   = new TextSerializer <SimpleUshort>();
            var deserialized = serializer.Deserialize(str);

            Assert.AreEqual((ushort)1234, deserialized.Value);
            Assert.AreEqual(str, serializer.Serialize(deserialized));
        }
Esempio n. 18
0
        //public void AddValue(string name, string value)
        //{
        //    _currentElement.Add(new XElement(name, new XAttribute("value", value)));
        //}

        public void AddValue <T>(string name, T value)
        {
            string textValue = _textSerializer.Serialize(value);

            // save null as empty string
            if (textValue == null)
            {
                textValue = "";
            }
            _currentElement.Add(new XElement(name, new XAttribute("value", textValue)));
        }
Esempio n. 19
0
        public void InheritanceSerialization_Success()
        {
            var    serializer = new TextSerializer <DerivedClass>();
            string str        = "a";

            var d = serializer.Deserialize(str);

            Assert.AreEqual('a', d.Value);
            var s = serializer.Serialize(d);

            Assert.AreEqual(str, s);
        }
Esempio n. 20
0
        void Authenticate()
        {
            string datastring = _serializer.Serialize(new { apikey = _apiKey });
            var    response   = _http.Post("/login", datastring);

            if (response.Succeeded)
            {
                var responseObject = _serializer.DynamicDeserialize(response.ResponseData);
                _http.AddBearerAuthentication((string)responseObject.token);
                IsAuthenticated = true;
            }
        }
Esempio n. 21
0
        public void SaveToFile <T>(string filePath, T item)
        {
            var text = _serializer.Serialize(item);

            if (_files.FileExists(filePath))
            {
                _files.Replace(filePath, text);
            }
            else
            {
                _files.Create(filePath, text);
            }
        }
Esempio n. 22
0
        public void Composite_Success()
        {
            string str = "C0000583420141102 16:31:420023267.47";

            var serializer = new TextSerializer <Account>();
            var account    = serializer.Deserialize(str);

            Assert.AreEqual('C', account.Type);
            Assert.AreEqual("5834", account.Number);
            Assert.AreEqual(new DateTime(2014, 11, 2, 16, 31, 42), account.Opened);
            Assert.AreEqual(23267.47m, account.Amount);

            Assert.AreEqual(str, serializer.Serialize(account));
        }
Esempio n. 23
0
        private void ReadWriteTest <T>(T initial)
        {
            var serializer = new TextSerializer();

            T source = initial;
            T result = default(T);

            using (var stream = new MemoryStream())
            {
                var writer = new StreamWriter(stream);

                serializer.Serialize(writer, initial);
                writer.Flush();

                var reader = new StreamReader(stream);
                result = (T)serializer.Deserialize(reader, typeof(T));
            }

            Assert.Equals(source, initial);
        }
Esempio n. 24
0
        protected override void OnExecute()
        {
            var authentication = this.CommandContext.GetAuthentication(this);
            var lockable       = this.GetObject(authentication, this.GetAbsolutePath(this.Path));

            if (this.Information == true)
            {
                var lockInfo = this.Invoke(authentication, lockable, () => lockable.LockInfo);
                var prop     = lockInfo.ToDictionary();
                var text     = TextSerializer.Serialize(prop, this.FormatType);
                this.Out.WriteLine(text);
            }
            else
            {
                if (this.Comment == string.Empty)
                {
                    throw new ArgumentException($"'{this.GetDescriptor(nameof(this.Comment)).DisplayPattern}' 가 필요합니다.");
                }
                this.Invoke(authentication, lockable, () => lockable.Lock(authentication, this.Comment));
            }
        }
Esempio n. 25
0
        protected override void OnExecute()
        {
            var authentication = this.CommandContext.GetAuthentication(this);
            var user           = this.GetUser(authentication, this.UserID);

            if (this.Information == true)
            {
                var banInfo = user.Dispatcher.Invoke(() => user.BanInfo);
                var prop    = banInfo.ToDictionary();
                var text    = TextSerializer.Serialize(prop, this.FormatType);
                this.Out.WriteLine(text);
            }
            else
            {
                if (this.Comment == string.Empty)
                {
                    throw new ArgumentException($"'{this.GetDescriptor(nameof(this.Comment)).DisplayPattern}' 가 필요합니다.");
                }
                user.Dispatcher.Invoke(() => user.Ban(authentication, this.Comment));
            }
        }
Esempio n. 26
0
        public void Save()
        {
            using var context = new TextSerializationContext()
                                .Marshal <RenderingObject, RenderObjectInfo>(from => new RenderObjectInfo()
            {
                Path   = from.ResourceName,
                Region = from.Bounds,
                Origin = new Origin { X = from.Origin.X, Y = from.Origin.Y }
            })
                                .Marshal <BaseAction, string>(_ => null)
                                .Marshal <IGameAI, AIFactory>(ai => ai.GetFactory())
                                .Unmarshal <AIFactory, IGameAI>(factory => factory.Get())
                                .Unmarshal <RenderObjectInfo, RenderingObject>(from => new RenderingObject(GameContext.Content.GetSprite(from), from.Path));

            var textSerializer = new TextSerializer(context);

            using (Stream stream = File.Create("save.txt"))
            {
                var entities = GameContext.EntitySets.Serializable.GetEntities().ToArray();
                textSerializer.Serialize(stream, entities);
            }
        }
Esempio n. 27
0
 private Action<Stream> GetTextContents(object model)
 {
     ISerializer textSerializer = new TextSerializer();
     return stream => textSerializer.Serialize("text/html", model, stream);
 }
        public static void AppendLine(this StringBuilder sb, object value, TextSerializerType type)
        {
            var text = TextSerializer.Serialize(value, type);

            sb.AppendLine(text);
        }
Esempio n. 29
0
 public static void StringToString(TextReader reader, TextWriter writer, bool formatted) => JsonException.Wrap(() =>
 {
     TextSerializer.Serialize(new TokenItemizer(new StreamTokenizer(reader)), Constants.GetIndent(formatted), writer);
 });
Esempio n. 30
0
 public void Serialize(TextSerializer serializer)
 {
     serializer.Serialize(Name);
     serializer.Serialize(Text);
 }
Esempio n. 31
0
 public static void ObjectToString(object value, TextWriter writer, bool formatted) => JsonException.Wrap(() =>
 {
     TextSerializer.Serialize(new ObjectItemizer(value), Constants.GetIndent(formatted), writer);
 });