示例#1
0
 private static void ReadGeneric(object obj, int depth, ObjectDeserializer.ObjectReader reader)
 {
     while (reader.GetIndentation() == depth)
     {
         ObjectDeserializer.ReadComponent(obj, depth, reader);
     }
 }
示例#2
0
            public void Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer)
            {
                var dict = (Dictionary <string, string>)nestedObjectDeserializer(typeof(Dictionary <string, string>));

                // There should only be one item.
                Debug.Assert(dict.Count == 1);
                var kind = dict.Keys.ElementAt(0);

                Value = dict[kind];

                switch (kind.ToLowerInvariant())
                {
                case "arxiv":
                    Kind = BibliographyKind.arXiv;
                    break;

                case "doi":
                    Kind = BibliographyKind.DOI;
                    break;

                default:
                    Kind = BibliographyKind.URL;
                    break;
                }
            }
        /// <inheritdoc />
        public Request Deserialize(byte[] dataBytes)
        {
            var unpacked = MessagePackSerializer.Deserialize <Dictionary <string, byte[]> >(dataBytes);

            var request   = ObjectDeserializer.AsString(unpacked[nameof(Request.Type)]);
            var id        = ObjectDeserializer.AsGuid(unpacked[nameof(Request.Id)]);
            var timestamp = ObjectDeserializer.AsZonedDateTime(unpacked[nameof(Request.Timestamp)]);

            switch (request)
            {
            case nameof(Connect):
                return(new Connect(
                           ObjectDeserializer.AsClientId(unpacked),
                           ObjectDeserializer.AsString(unpacked[nameof(Connect.Authentication)]),
                           id,
                           timestamp));

            case nameof(Disconnect):
                return(new Disconnect(
                           ObjectDeserializer.AsClientId(unpacked),
                           ObjectDeserializer.AsSessionId(unpacked),
                           id,
                           timestamp));

            case nameof(DataRequest):
                return(new DataRequest(
                           this.querySerializer.Deserialize(unpacked[nameof(DataRequest.Query)]),
                           id,
                           timestamp));

            default:
                throw ExceptionFactory.InvalidSwitchArgument(request, nameof(request));
            }
        }
示例#4
0
        public void Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer)
        {
            var o = (DeserializeTemplate)nestedObjectDeserializer(typeof(DeserializeTemplate));

            Name      = o.Name;
            DebugInfo = new DebugInfo().MapDebugInfo(parser.Current.Start, parser.Current.End);
        }
 /// <summary>
 /// Search for Content
 /// </summary>
 /// <param name="parameters"></param>
 /// <returns></returns>
 public ContentSearchResponse ContentSearch(ContentSearchParameters parameters)
 {
     var query = GetQueryTranslator().Translate(parameters);
     var xml = _service.LoadContent(query);
     var results = new ObjectDeserializer().Deserialize<ContentSearchResponse>(xml);
     return results;
 }
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            Demo.USTViewer.BarkUST             bu  = new Demo.USTViewer.BarkUST();
            ObjectDeserializer <ProjectObject> DPO = new ObjectDeserializer <ProjectObject>();
            BasicFileInformation bfi = DPO.ReadBasicInformation(bu.GetCacheFile());

            if (bfi.SavePassword.Length > 0 || bfi.IntroduceText.Trim().Length > 0)
            {
                IntroduceSwap ISW = new IntroduceSwap(bfi);
                if (ISW.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
            }
            try
            {
                ProjectObject OOP = DPO.DeserializeFromFile(bu.GetCacheFile(), bfi, ObjectSerializer <ProjectObject> .SerializeType.JSON, true);
                LoadProject(ref OOP);
            }
            catch (Exception ew)
            {
                if (ew.Message == "Password Error or File Broken")
                {
                    MessageBox.Show("密码错误!");
                }
                else
                {
                    MessageBox.Show("未知错误!");
                }
            }
        }
示例#7
0
 public static void ReadFile(GameObject obj, ObjectDeserializer.ObjectReader reader)
 {
     ObjectDeserializer.PropertyData propertyData = reader.ReadTypeAndName();
     if (propertyData.type == "GameObject" && propertyData.name == obj.name)
     {
         ObjectDeserializer.ReadObject(obj, 1, reader);
     }
 }
        public void Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer)
        {
            var o = (DeserializeTemplate)nestedObjectDeserializer(typeof(DeserializeTemplate));

            _name       = o.Name;
            _attributes = o.Attributes;
            _edges      = o.Edges;
        }
示例#9
0
 static void AddDeserializer(Dictionary <string, ObjectDeserializer> deserializers, string name, ObjectDeserializer deserializer)
 {
     if (deserializers.ContainsKey(name))
     {
         // TODO throw
     }
     deserializers[name] = deserializer;
 }
示例#10
0
        public void Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer)
        {
            var o = (TransformTemplate)nestedObjectDeserializer(typeof(TransformTemplate));

            DebugInfo = new DebugInfo().MapDebugInfo(parser.Current.Start, parser.Current.End);
            Endpoint  = !string.IsNullOrWhiteSpace(o.context) ? new Uri(o.context) : null;
            Language  = !string.IsNullOrWhiteSpace(o.language) ? (LanguageCode?)Enum.Parse(typeof(LanguageCode), o.language.ToString(), true) : null;
        }
示例#11
0
        private void ReceiveCallback(IAsyncResult ar)
        {
            ExecuteFunction(delegate(IAsyncResult result)
            {
                StateObject state = (StateObject)result.AsyncState;

                // We may as well back off if no connection is available.
                if (!state.WorkSocket.IsConnected())
                {
                    //Logger.Warn("Client socket not connected during receive. Socket is being disposed.");
                    state.WorkSocket.Dispose(); // Bug: When the client is stopped using the Stop method this may be called faster then the stop method can do.

                    if (_clientSettings.ReconnectOnDisconnect)
                    {
                        Stop();
                        Start();
                    }

                    return;
                }

                int bytesRead = state.WorkSocket.EndReceive(result);

                // if (bytesRead <= 0) return;  // The return can prevent the client from listening.

                state.InboundStringBuilder.Append(Encoding.GetEncoding(Constants.Encoding).GetString(state.ReceiveBuffer, 0, bytesRead));
                string content = state.InboundStringBuilder.ToString();

                while (content.IndexOf(_clientSettings.Splitter, StringComparison.Ordinal) > -1)
                {
                    var strParts = content.Split(new string[] { _clientSettings.Splitter },
                                                 StringSplitOptions.RemoveEmptyEntries);

                    var type = typeof(TReceive);
                    if (type == typeof(String))
                    {
                        OnReceiveEvent(strParts[0] + _clientSettings.Splitter as TReceive);
                    }
                    else
                    {
                        // Convert it to the specific object.
                        var obj = ObjectDeserializer <TReceive> .Deserialize(Encoding.GetEncoding(Constants.Encoding).GetBytes(strParts[0]));
                        OnReceiveEvent(obj);
                    }

                    state.ReceiveBuffer = new byte[state.ReceiveBufferSize];
                    state.InboundStringBuilder.Clear();

                    content = content.Remove(0, strParts[0].Length);
                    content = content.Remove(0, _clientSettings.Splitter.Length);

                    state.InboundStringBuilder.Append(content);
                }

                _state.WorkSocket.BeginReceive(_state.ReceiveBuffer, 0, _state.ReceiveBufferSize, 0, ReceiveCallback, _state);
            }, ar);
        }
示例#12
0
        public User GetUser(string username)
        {
            string listId         = KeysDictionary.UserInformation(username);
            string serializedUser = redis.Get <string>(listId);

            User user = ObjectDeserializer.DeserializeUser(serializedUser);

            return(user);
        }
示例#13
0
 private static void ReadParticleSystem(ParticleSystem particleSystem, int depth, ObjectDeserializer.ObjectReader reader)
 {
     while (reader.GetIndentation() == depth)
     {
         ObjectDeserializer.PropertyData propertyData = reader.ReadProperty();
         if (propertyData.type == "Generic" && (propertyData.name == "InitialModule" || propertyData.name == "EmissionModule" || propertyData.name == "ShapeModule"))
         {
             ObjectDeserializer.ReadParticleSystemModule(particleSystem, propertyData.name, depth + 1, reader);
         }
     }
 }
示例#14
0
文件: Centroid.cs 项目: cofiem/egret
        public void Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer)
        {
            parser.Consume <SequenceStart>();

            // the interval type converter consumes one scalar token per invocation
            this.StartSeconds = (Interval)nestedObjectDeserializer.Invoke(typeof(Interval));

            this.LowHertz = (Interval)nestedObjectDeserializer.Invoke(typeof(Interval));

            parser.Consume <SequenceEnd>();
        }
示例#15
0
            public void Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer)
            {
                var comment = parser.Allow <Comment>();

                if (comment != null)
                {
                    Comment = comment.Value;
                }

                Value = (T)nestedObjectDeserializer(typeof(T));
            }
示例#16
0
        public void Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer)
        {
            var o = (DeserializeTemplate)nestedObjectDeserializer(typeof(DeserializeTemplate));

            if (o == null)
            {
                return;
            }
            AddRange(o);
            DebugInfo = new DebugInfo().MapDebugInfo(parser.Current.Start, parser.Current.End);
        }
示例#17
0
    private static Bounds ReadBounds(int depth, ObjectDeserializer.ObjectReader reader)
    {
        Bounds result = default(Bounds);

        reader.GetIndentation();
        reader.ReadProperty();
        result.center = ObjectDeserializer.ReadVector3(depth + 1, reader);
        reader.GetIndentation();
        reader.ReadProperty();
        result.extents = ObjectDeserializer.ReadVector3(depth + 1, reader);
        return(result);
    }
        public void Can_Deserialize_Gallery()
        {
            var content = File.ReadAllText("Json\\Gallery.json");

            var item = new ObjectDeserializer().Deserialize<ItemResponse>(content).Content;

            Assert.AreEqual("world/gallery/2010/sep/17/pope-benedict-xvi-catholicism", item.Id);
            Assert.AreEqual("Pope Benedict XVI's UK visit: Day two", item.Fields.Headline);
            Assert.AreEqual(13, item.MediaAssets.Count());
            Assert.AreEqual(6, item.Tags.Count());
            Assert.AreEqual("gallery", item.MediaAssets[0].Rel);
        }
示例#19
0
        public void Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer)
        {
            var o = (dynamic)nestedObjectDeserializer(typeof(object));

            foreach (var item in o["content"])
            {
                this.Add(new ContentItem()
                {
                    SemanticKey = item[""]
                });
            }
        }
示例#20
0
            public void Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer)
            {
                parser.Consume <MappingStart>();
                Scalar node;

                while (parser.TryConsume(out node))
                {
                    AutoconfFilter thisFilter = (AutoconfFilter)nestedObjectDeserializer(typeof(AutoconfFilter));
                    thisFilter.name = node.Value;
                    filters.Add(thisFilter);
                }
                parser.Consume <MappingEnd>();
            }
示例#21
0
        public void Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer)
        {
            var o = (DeserializeTemplate)nestedObjectDeserializer(typeof(DeserializeTemplate));

            if (o == null)
            {
                return;
            }
            Name        = o.Name;
            Constraints = o.Constraints;
            Attributes  = o.Attributes;
            DebugInfo   = new DebugInfo().MapDebugInfo(parser.Current.Start, parser.Current.End);
        }
示例#22
0
        public void Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer)
        {
            var o = (TransformTemplate)nestedObjectDeserializer(typeof(TransformTemplate));

            if (o == null)
            {
                return;
            }
            DebugInfo = new DebugInfo().MapDebugInfo(parser.Current.Start, parser.Current.End);

            Name     = o.waarde;
            Location = o.locatie;
        }
示例#23
0
            void IYamlConvertible.Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer)
            {
                var devkey = (string?)nestedObjectDeserializer(typeof(string)) ?? "";

                string 正規表現パターン = $@"^(\d+),(\d+)$";  // \d は10進数数字
                var    m        = Regex.Match(devkey, 正規表現パターン, RegexOptions.IgnoreCase);

                if (m.Success && (3 <= m.Groups.Count))
                {
                    this.deviceId = int.Parse(m.Groups[1].Value);
                    this.key      = int.Parse(m.Groups[2].Value);
                }
            }
        public void Can_Deserialize_Sections()
        {
            var content = File.ReadAllText("Json\\sections.json");

            var response = new ObjectDeserializer().Deserialize<SectionSearchResponse>(content);

            Assert.IsNotNull(response.Results);
            Assert.AreEqual(40, response.Total  );
            var first = response.Results[0];
            Assert.AreEqual("news", first.Id);
            Assert.AreEqual("News", first.WebTitle);
            Assert.AreEqual("http://www.guardian.co.uk/news", first.WebUrl);
            Assert.AreEqual("http://content.guardianapis.com/news", first.ApiUrl);
        }
示例#25
0
        public void Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer)
        {
            var o = (DeserializeTemplate)nestedObjectDeserializer(typeof(DeserializeTemplate));

            if (o == null)
            {
                throw new Exception("No node schema start element found.");
            }

            Name       = o.Name;
            Attributes = o.Attributes;
            Edges      = o.Edges;
            DebugInfo  = new DebugInfo().MapDebugInfo(parser.Current.Start, parser.Current.End);
        }
示例#26
0
        /// <inheritdoc/>
        public void Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer)
        {
            if (expectedType != typeof(ResourceQuantity))
            {
                throw new ArgumentOutOfRangeException(nameof(expectedType));
            }

            if (parser?.Current is Scalar)
            {
                Value = ((Scalar)parser.Current).Value;
                parser.MoveNext();
                CustomInit();
            }
        }
示例#27
0
        public List <Post> GetNewsFeed(string username)
        {
            List <Post> posts  = new List <Post>();
            string      listId = KeysDictionary.UserNewsFeed(username);


            foreach (string postString in redis.GetRangeFromList(listId, 0, NewsFeedLength - 1))
            {
                Post post = ObjectDeserializer.DeserializeRating(postString);
                posts.Add(post);
            }

            return(posts);
        }
示例#28
0
        public string GetOldestPostId(string username)
        {
            string listId = KeysDictionary.UserNewsFeed(username);
            string obj    = redis.GetItemFromList(listId, 0);
            Post   p      = ObjectDeserializer.DeserializeRating(obj);

            if (p != null)
            {
                return(p.Id);
            }
            else
            {
                return(Int32.MaxValue.ToString());
            }
        }
示例#29
0
        public List <Picture> GetPlaceGallery(string placeId)
        {
            string listId    = KeysDictionary.PlaceGallery(placeId);
            int    listCount = (int)redis.GetListCount(listId);

            List <Picture> pictures = new List <Picture>();

            foreach (string placeString in redis.GetRangeFromList(listId, 0, listCount - 1))
            {
                Picture picture = ObjectDeserializer.DeserializePicture(placeString);
                pictures.Add(picture);
            }

            return(pictures);
        }
示例#30
0
        public void Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer)
        {
            var scalar = parser.Allow <Scalar>();

            if (scalar != null)
            {
                var parsedValue = scalar.Value;
                var data        = parsedValue.Split('=');
                name  = data[0];
                value = data[1];
            }
            else
            {
                Console.WriteLine(nestedObjectDeserializer(typeof(string)));
            }
        }
示例#31
0
 public void Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer)
 {
     if (parser.TryConsume <Scalar>(out var scalar))
     {
         this.patterns.Add(scalar.Value);
         return;
     }
     else if (parser.TryConsume <SequenceStart>(out var seq))
     {
         while (parser.TryConsume <Scalar>(out var member))
         {
             this.patterns.Add(member.Value);
         }
         parser.Consume <SequenceEnd>();
     }
 }
示例#32
0
    private void ReadPrefabOverrides(GameObject obj, BinaryReader reader)
    {
        int num = reader.ReadInt32();

        byte[] buffer = new byte[num];
        reader.Read(buffer, 0, num);
        using (MemoryStream memoryStream = new MemoryStream(buffer))
        {
            using (StreamReader streamReader = new StreamReader(memoryStream, Encoding.UTF8))
            {
                ObjectDeserializer.ObjectReader reader2 = new ObjectDeserializer.ObjectReader(streamReader, this.m_references);
                ObjectDeserializer.ReadFile(obj, reader2);
            }
        }
        obj.SendMessage("OnDataLoaded", SendMessageOptions.DontRequireReceiver);
    }
        void IYamlConvertible.Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer)
        {
            events.Clear();
            int num = 0;

            do
            {
                if (!parser.MoveNext())
                {
                    throw new InvalidOperationException("The parser has reached the end before deserialization completed.");
                }
                events.Add(parser.Current);
                num += parser.Current.NestingIncrease;
            }while (num > 0);
            Debug.Assert(num == 0);
        }
        public void Can_Deserialize_Reviews()
        {
            var content = File.ReadAllText("Json\\Reviews.json");

            var response = new ObjectDeserializer().Deserialize<ContentSearchResponse>(content);

            Assert.IsNotNull(response.Results);
            Assert.AreEqual(64472, response.Total);
            var first = response.Results[0];
            Assert.AreEqual("Arise Black Man: the Peter Tosh Story – review", first.WebTitle);
            Assert.AreEqual(null, first.Fields.StarRating);

            var second = response.Results[1];
            Assert.AreEqual("AfroCubism – review", second.WebTitle);
            Assert.AreEqual(4, second.Fields.StarRating);
        }
        public void Can_Deserialize_Search()
        {
            var content = File.ReadAllText("Json\\Results.json");
            var response = new ObjectDeserializer().Deserialize<ContentSearchResponse>(content);

            Assert.AreEqual(10, response.Results.Count());
            Assert.AreEqual(response.CurrentPage, 1);
            Assert.AreEqual(response.PageSize, 10);
            Assert.AreEqual(response.Pages, 23);
            Assert.AreEqual(response.Total, 225);
            Assert.AreEqual(response.UserTier, UserTiers.Approved);
            Assert.AreEqual(response.OrderBy, Orders.Relevance);

            var article = response.Results[0];
            Assert.AreEqual(2010, article.WebPublicationDate.Year);
            Assert.AreEqual("Joanna Newsom", article.Fields.Headline);
        }
示例#36
0
        /// <summary>
        /// Reads this object's state from a YAML parser.
        /// </summary>
        void IYamlConvertible.Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer)
        {
            events.Clear();

            int depth = 0;
            do
            {
                if (!parser.MoveNext())
                {
                    throw new InvalidOperationException("The parser has reached the end before deserialization completed.");
                }

                events.Add(parser.Current);
                depth += parser.Current.NestingIncrease;
            } while (depth > 0);

            Debug.Assert(depth == 0);
        }
 internal void ItemAsyncCallback(IAsyncResult result)
 {
     var cbp = (AsyncItemCallbackParameter)result.AsyncState;
     var item = new ObjectDeserializer().Deserialize<ItemResponse>(cbp.Delegate.EndInvoke(result));
     cbp.CallbackFunction.Invoke(item.Content);
 }
 static void AddDeserializer (Dictionary<string, ObjectDeserializer> deserializers,
                              string name,
                              ObjectDeserializer deserializer)
 {
     if (deserializers.ContainsKey (name)) {
         // TODO throw
     }
     deserializers[name] = deserializer;
 }
 internal void TagsAsyncCallback(IAsyncResult result)
 {
     var cbp = (AsyncTagsCallbackParameter)result.AsyncState;
     var results = new ObjectDeserializer().Deserialize<TagSearchResponse>(cbp.Delegate.EndInvoke(result));
     cbp.CallbackFunction.Invoke(results);
 }
 /// <summary>
 /// Retrieve an item of Content by id
 /// </summary>
 /// <param name="itemId"></param>
 /// <returns></returns>
 public Content Item(string itemId)
 {
     var query = GetQueryTranslator().Translate(itemId);
     var xml = _service.LoadContent(query);
     var results = new ObjectDeserializer().Deserialize<ItemResponse>(xml);
     return results.Content;
 }
示例#41
0
 void IYamlConvertible.Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer)
 {
     Load(parser, new DocumentLoadingState());
 }
        public void Can_Deserialize_Tags()
        {
            var content = File.ReadAllText("Json\\tags.json");

            var response = new ObjectDeserializer().Deserialize<TagSearchResponse>(content);

            Assert.IsNotNull(response.Results);
            Assert.AreEqual(10, response.Results.Count());
            var second = response.Results[1];
            Assert.AreEqual("Dick Vinegar", second.WebTitle);
            Assert.AreEqual("contributor", second.Type);
            Assert.AreEqual("profile/dick-vinegar", second.Id);
            Assert.AreEqual("http://content.guardianapis.com/profile/dick-vinegar", second.ApiUrl);
            Assert.AreEqual("http://www.guardian.co.uk/profile/dick-vinegar", second.WebUrl);
        }