Пример #1
0
        public void Test_get_property_thows_exception(
            string text)
        {
            var obj = DynamicXml.Parse(text);

            Assert.Catch(typeof(RuntimeBinderException), () => { var _ = obj.b; });
        }
Пример #2
0
        public static void ParseXMLtoDynamic()
        {
            //string xml = @"<?xml version=""1.0"" encoding=""utf - 8""?><entry xml:base=""http://sp-devbox2013/_api/"" xmlns=""http://www.w3.org/2005/Atom"" xmlns:d=""http://schemas.microsoft.com/ado/2007/08/dataservices"" xmlns:m=""http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"" xmlns:georss=""http://www.georss.org/georss"" xmlns:gml=""http://www.opengis.net/gml""><id>http://sp-devbox2013/_api/Web/GetUserById(79)</id><category term=""SP.User"" scheme=""http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"" /><link rel=""edit"" href=""Web/GetUserById(79)"" /><link rel=""http://schemas.microsoft.com/ado/2007/08/dataservices/related/Groups"" type=""application/atom+xml;type=feed"" title=""Groups"" href=""Web/GetUserById(79)/Groups"" /><title /><updated>2016-12-20T03:01:16Z</updated><author><name /></author><content type=""application/xml""><m:properties><d:Id m:type=""Edm.Int32"">79</d:Id><d:IsHiddenInUI m:type=""Edm.Boolean"">false</d:IsHiddenInUI><d:LoginName>i:0#.w|rbvhsp\hm-common</d:LoginName><d:Title>HM ComUser1</d:Title><d:PrincipalType m:type=""Edm.Int32"">1</d:PrincipalType><d:Email>[email protected]</d:Email><d:IsSiteAdmin m:type=""Edm.Boolean"">false</d:IsSiteAdmin><d:UserId m:type=""SP.UserIdInfo""><d:NameId>s-1-5-21-3464779960-3153506264-3595381425-1199</d:NameId><d:NameIdIssuer>urn:office:idp:activedirectory</d:NameIdIssuer></d:UserId></m:properties></content></entry>";
            string xml2 = @"<?xml version=""1.0"" encoding=""utf - 8""?><feed xml:base=""http://sp-devbox2013/_api/"" xmlns=""http://www.w3.org/2005/Atom"" xmlns:d=""http://schemas.microsoft.com/ado/2007/08/dataservices"" xmlns:m=""http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"" xmlns:georss=""http://www.georss.org/georss"" xmlns:gml=""http://www.opengis.net/gml""><id>b9e52242-fd4c-4eeb-8de0-c8306a0d0d94</id><title /><updated>2016-12-20T02:17:00Z</updated><entry m:etag=""&quot;1&quot;""><id>8d2da3cf-1041-43be-8b7f-0ba122662ed5</id><category term=""SP.Data.EmployeeShiftTimeListItem"" scheme=""http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"" /><link rel=""edit"" href=""Web/Lists(guid'eb7118bf-17ed-47e7-89c9-e92d0ad8b196')/Items(1)"" /><link rel=""http://schemas.microsoft.com/ado/2007/08/dataservices/related/FirstUniqueAncestorSecurableObject"" type=""application/atom+xml;type=entry"" title=""FirstUniqueAncestorSecurableObject"" href=""Web/Lists(guid'eb7118bf-17ed-47e7-89c9-e92d0ad8b196')/Items(1)/FirstUniqueAncestorSecurableObject"" /><link rel=""http://schemas.microsoft.com/ado/2007/08/dataservices/related/RoleAssignments"" type=""application/atom+xml;type=feed"" title=""RoleAssignments"" href=""Web/Lists(guid'eb7118bf-17ed-47e7-89c9-e92d0ad8b196')/Items(1)/RoleAssignments"" /><link rel=""http://schemas.microsoft.com/ado/2007/08/dataservices/related/AttachmentFiles"" type=""application/atom+xml;type=feed"" title=""AttachmentFiles"" href=""Web/Lists(guid'eb7118bf-17ed-47e7-89c9-e92d0ad8b196')/Items(1)/AttachmentFiles"" /><link rel=""http://schemas.microsoft.com/ado/2007/08/dataservices/related/ContentType"" type=""application/atom+xml;type=entry"" title=""ContentType"" href=""Web/Lists(guid'eb7118bf-17ed-47e7-89c9-e92d0ad8b196')/Items(1)/ContentType"" /><link rel=""http://schemas.microsoft.com/ado/2007/08/dataservices/related/FieldValuesAsHtml"" type=""application/atom+xml;type=entry"" title=""FieldValuesAsHtml"" href=""Web/Lists(guid'eb7118bf-17ed-47e7-89c9-e92d0ad8b196')/Items(1)/FieldValuesAsHtml"" /><link rel=""http://schemas.microsoft.com/ado/2007/08/dataservices/related/FieldValuesAsText"" type=""application/atom+xml;type=entry"" title=""FieldValuesAsText"" href=""Web/Lists(guid'eb7118bf-17ed-47e7-89c9-e92d0ad8b196')/Items(1)/FieldValuesAsText"" /><link rel=""http://schemas.microsoft.com/ado/2007/08/dataservices/related/FieldValuesForEdit"" type=""application/atom+xml;type=entry"" title=""FieldValuesForEdit"" href=""Web/Lists(guid'eb7118bf-17ed-47e7-89c9-e92d0ad8b196')/Items(1)/FieldValuesForEdit"" /><link rel=""http://schemas.microsoft.com/ado/2007/08/dataservices/related/File"" type=""application/atom+xml;type=entry"" title=""File"" href=""Web/Lists(guid'eb7118bf-17ed-47e7-89c9-e92d0ad8b196')/Items(1)/File"" /><link rel=""http://schemas.microsoft.com/ado/2007/08/dataservices/related/Folder"" type=""application/atom+xml;type=entry"" title=""Folder"" href=""Web/Lists(guid'eb7118bf-17ed-47e7-89c9-e92d0ad8b196')/Items(1)/Folder"" /><link rel=""http://schemas.microsoft.com/ado/2007/08/dataservices/related/ParentList"" type=""application/atom+xml;type=entry"" title=""ParentList"" href=""Web/Lists(guid'eb7118bf-17ed-47e7-89c9-e92d0ad8b196')/Items(1)/ParentList"" /><title /><updated>2016-12-20T02:17:00Z</updated><author><name /></author><content type=""application/xml""><m:properties><d:FileSystemObjectType m:type=""Edm.Int32"">0</d:FileSystemObjectType><d:Id m:type=""Edm.Int32"">1</d:Id><d:ContentTypeId>0x010082B4587A9EFA47FCB1ADA5A1D1B8F0950090E4637C7267DB4BA42BD9C8C9CAE567</d:ContentTypeId><d:Title m:null=""true"" /><d:EmployeeId m:type=""Edm.Int32"">1</d:EmployeeId><d:StadaDate m:type=""Edm.DateTime"">2016-11-20T17:00:00Z</d:StadaDate><d:ShiftId m:type=""Edm.Int32"">1</d:ShiftId><d:IsValid m:type=""Edm.Boolean"">true</d:IsValid><d:ID m:type=""Edm.Int32"">1</d:ID><d:Modified m:type=""Edm.DateTime"">2016-12-19T12:11:08Z</d:Modified><d:Created m:type=""Edm.DateTime"">2016-12-19T12:11:08Z</d:Created><d:AuthorId m:type=""Edm.Int32"">53</d:AuthorId><d:EditorId m:type=""Edm.Int32"">53</d:EditorId><d:OData__UIVersionString>1.0</d:OData__UIVersionString><d:Attachments m:type=""Edm.Boolean"">false</d:Attachments><d:GUID m:type=""Edm.Guid"">0a16f7c5-fa5b-41fa-a54f-3883485cf4ef</d:GUID></m:properties></content></entry></feed>";
            //string xml = @"<Students>
            //    <Student ID=""100"">
            //        <Name>Arul</Name>
            //        <Mark>90</Mark>
            //    </Student>
            //    <Student>
            //        <Name>Arul2</Name>
            //        <Mark>80</Mark>
            //    </Student>
            //</Students>";

            dynamic data = DynamicXml.Parse(xml2);

            //var id = students.Student[0].ID;
            //var name1 = students.Student[1].Name;

            //foreach (var std in students.Student)
            //{
            //    Console.WriteLine(std.Mark);
            //}
        }
Пример #3
0
        public string Test_conversion(
            string text)
        {
            var obj = DynamicXml.Parse(text);

            return(JsonConvert.SerializeObject(obj));
        }
Пример #4
0
        public string Test_get_text_property(
            string text)
        {
            var obj = DynamicXml.Parse(text);

            return(obj.a._text);
        }
Пример #5
0
        public string Test_change_text_property_name(
            string text)
        {
            var obj = DynamicXml.Parse(text, new DynamicXmlOptions {
                TextFieldName = "__text"
            });

            return(obj.a.__text);
        }
Пример #6
0
        public void Test_get_property_returns_null_and_not_thows_exception(
            string text)
        {
            var obj = DynamicXml.Parse(text, new DynamicXmlOptions {
                ThrowOnGet = false
            });

            Assert.That(obj.b, Is.Null);
        }
        public override async Task <object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger, CancellationToken cancellationToken)
        {
            if (type == typeof(DynamicObject) || type == typeof(object))
            {
                string textContent = await content.ReadAsStringAsync();

                return(DynamicXml.Parse(textContent));
            }
            return(base.ReadFromStreamAsync(type, readStream, content, formatterLogger, cancellationToken));
        }
Пример #8
0
        public static void Main()
        {
            dynamic person = DynamicXml.Parse(
                @"<Person>
                <FirstName>Inigo</FirstName>
                <LastName>Montoya</LastName>
               </Person>");

            Console.WriteLine(
                $"{ person.FirstName } { person.LastName }");
        }
Пример #9
0
        private object DeserializeXml(string xmlText, Type type)
        {
            if (type == typeof(object))
            {
                return(DynamicXml.Parse(xmlText));
            }
            var serializer = new DataContractSerializer(type);

            using (var reader = new StringReader(xmlText))
            {
                var xmlReader = XmlReader.Create(reader);
                return(serializer.ReadObject(xmlReader));
            }
        }
Пример #10
0
        public static dynamic GetDynamicFromXml(string xml)
        {
            if (String.IsNullOrEmpty(xml))
            {
                return("");
            }

            try
            {
                dynamic model = new ExpandoObject();
                var     xDoc  = XDocument.Parse(xml);
                DynamicXml.Parse(model, xDoc.Elements().First());
                return(model);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Пример #11
0
        static async Task <DynamicXml> SendTestMessageAndReadDynamicAsync(string requestUri, int numberParamter1, TestRequestMessage testRequestMessage, string scenario, bool boolParameter2, string textParameter3, HttpStatusCode expectedStatusCode = HttpStatusCode.OK)
        {
            DynamicXml          graph;
            HttpResponseMessage response = await SendTestMessageAsync(requestUri, numberParamter1, testRequestMessage, scenario, boolParameter2, textParameter3);

            if (response.IsSuccessStatusCode)
            {
                var text = await response.Content.ReadAsStringAsync();

                graph = DynamicXml.Parse(text);
            }
            else
            {
                var text = await response.Content.ReadAsStringAsync();

                Trace.WriteLine(text);
                graph = null;
            }
            Assert.AreEqual(expectedStatusCode, response.StatusCode, $"Expected status code {expectedStatusCode} but got {response.StatusCode}");

            return(graph);
        }
Пример #12
0
        protected override void _GetCredentials(List <Credential> credentials)
        {
            const uint dwMaxClient = 2;
            var        hClient     = IntPtr.Zero;
            uint       dwCurVersion;

            if (Wlanapi.WlanOpenHandle(dwMaxClient, IntPtr.Zero, out dwCurVersion, ref hClient) !=
                Win32ErrorCode.ERROR_SUCCESS)
            {
                return;
            }

            IntPtr pIfvectorPtr;

            if (Wlanapi.WlanEnumInterfaces(hClient, IntPtr.Zero, out pIfvectorPtr) != Win32ErrorCode.ERROR_SUCCESS)
            {
                return;
            }

            var pIfvector = new Wlanapi.WLAN_INTERFACE_INFO_LIST(pIfvectorPtr);

            for (uint i = 0; i < pIfvector.DwNumberOfItems; i++)
            {
                IntPtr pProfilevectorPtr;
                Wlanapi.WlanGetProfileList(hClient, pIfvector.InterfaceInfo[i].InterfaceGuid,
                                           IntPtr.Zero, out pProfilevectorPtr);

                var pProfilevector = new Wlanapi.WLAN_PROFILE_INFO_LIST(pProfilevectorPtr);
                for (uint j = 0; j < pProfilevector.DwNumberOfItems; j++)
                {
                    var  pProfileXml     = "";
                    var  dwFlags         = Wlanapi.WlanProfileGetPlaintextKey;
                    uint dwGrantedAccess = 0;

                    if (Wlanapi.WlanGetProfile(hClient, ref pIfvector.InterfaceInfo[i].InterfaceGuid,
                                               pProfilevector.ProfileInfo[j].StrProfileName, IntPtr.Zero, ref pProfileXml, ref dwFlags,
                                               ref dwGrantedAccess) == Win32ErrorCode.ERROR_SUCCESS)
                    {
                        try
                        {
                            var wlanProfile =
                                DynamicXml.Parse(XDocument.Parse(pProfileXml).Elements().First()).WLANProfile;

                            var sharedKey = wlanProfile.MSM.security.sharedKey;
                            credentials.Add(new Credential(TargetTypes.WLan)
                            {
                                Username = wlanProfile.SSIDConfig.SSID.name,
                                Password = sharedKey != null ? sharedKey.keyMaterial : "",
                                Extra    =
                                    "Authentication: " + wlanProfile.MSM.security.authEncryption.authentication + " | " +
                                    "Encryption: " + wlanProfile.MSM.security.authEncryption.encryption + " | " +
                                    (sharedKey != null ? "KeyType: " + sharedKey.keyType ?? "none" + " | " : "") +
                                    "ConnectionType: " + wlanProfile.connectionType
                            });
                        }
                        catch
                        {
                        }
                    }
                }

                if (pProfilevectorPtr != IntPtr.Zero)
                {
                    Wlanapi.WlanFreeMemory(pProfilevectorPtr);
                }
            }

            if (pIfvectorPtr != IntPtr.Zero)
            {
                Wlanapi.WlanFreeMemory(pIfvectorPtr);
            }
        }
Пример #13
0
 public object Parse(string media, Type type)
 {
     return(DynamicXml.Parse(media));
 }
Пример #14
0
 public dynamic AsExpando()
 {
     return(DynamicXml.Parse(_root));
 }
        public IApiResponseParsingResult ParseResponse(ParseApiResponse message)
        {
            var responseType = ApiResponseType.Unknown;

            try
            {
                object response;

                var responseXml = DynamicXml.Parse(message.Data);
                responseType = responseXml.GetName();

                switch (responseType)
                {
                case ApiResponseType.CompetitorProfile:
                    response = CompetitorProfile.Parse(responseXml);
                    break;

                case ApiResponseType.FixtureChanges:
                    response = FixtureChangeList.Parse(responseXml);
                    break;

                case ApiResponseType.FixturesFixture:
                    response = FixtureList.Parse(responseXml);
                    break;

                case ApiResponseType.MatchSummary:
                    response = MatchSummary.Parse(responseXml);
                    break;

                case ApiResponseType.MarketDescriptions:
                    response = MarketDescriptionList.Parse(responseXml);
                    break;

                case ApiResponseType.MatchTimeline:
                    response = MatchTimeline.Parse(responseXml);
                    break;

                case ApiResponseType.PlayerProfile:
                    response = PlayerProfile.Parse(responseXml);
                    break;

                case ApiResponseType.RaceTournamentInfo:
                case ApiResponseType.SimpleTournamentInfo:
                case ApiResponseType.StandardTournamentInfo:
                case ApiResponseType.TournamentInfo:
                    response = TournamentInfo.Parse(responseXml);
                    break;

                case ApiResponseType.Response:
                    response = Response.Parse(responseXml);
                    break;

                case ApiResponseType.Schedule:
                    response = Schedule.Parse(responseXml);
                    break;

                case ApiResponseType.SportCategories:
                    response = SportCategoriesList.Parse(responseXml);
                    break;

                case ApiResponseType.Sports:
                    response = SportList.Parse(responseXml);
                    break;

                case ApiResponseType.SportTournaments:
                    response = SportTournamentList.Parse(responseXml);
                    break;

                case ApiResponseType.Tournaments:
                    response = TournamentList.Parse(responseXml);
                    break;

                case ApiResponseType.VenueSummary:
                    response = VenueSummary.Parse(responseXml);
                    break;

                default:
                    throw new NotSupportedException(
                              $"Message of specified type ['{responseType}'] can not be parsed.");
                }

                return(new ApiResponseParsed
                {
                    Language = message.Language,
                    Response = response,
                    RequestId = message.RequestId,
                    EventId = message.EventId,
                    ProductType = message.ProductType
                });
            }
            catch (Exception e)
            {
                throw;
                //return new ApiResponseParsingFailed(
                //    failureReason: e,
                //    requestId: message.RequestId,
                //    responseData: message.Data,
                //    responseType: responseType
                //);
            }
        }
Пример #16
0
        public void sub_nodes_attriute()
        {
            var xml = DynamicXml.Parse("<x><y z='hi'></y></x>");

            Assert.Equal("hi", xml.y.z);
        }
Пример #17
0
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            if (_settings.Enabled)
            {
                try
                {
                    var pathAndQuery = request.RequestUri.PathAndQuery;
                    if (_whenMatcher != null)
                    {
                        var match = _whenMatcher.Match(pathAndQuery);
                        if (match.Success)
                        {
                            var scenario = _mockEngine.FindScenario(pathAndQuery, request.Method.Method);

                            if (scenario == null)
                            {
                                return(await base.SendAsync(request, cancellationToken));
                            }

                            var dynamicParameters = new ExpandoObject();

                            var headers = new DynamicNameValueCollection();
                            headers.AddHeaders(request.Headers);
                            dynamicParameters.AddProperty("Headers", headers);

                            dynamicParameters.AddProperty("Request", request);

                            foreach (var pathParameter in scenario.PathParameters)
                            {
                                dynamicParameters.AddProperty(pathParameter.Key, pathParameter.Value);
                            }

                            foreach (var property in request.Properties)
                            {
                                dynamicParameters.AddProperty(property.Key, property.Value);
                            }

                            var parameters = request.RequestUri.ParseQueryString();

                            foreach (string parameterName in parameters)
                            {
                                dynamicParameters.AddProperty(parameterName, parameters[parameterName]);
                            }

                            if (request.Content.Headers.ContentType != null)
                            {
                                var contentType = request.Content.Headers.ContentType.MediaType;
                                if (contentType == "application/xml" || contentType == "text/xml")
                                {
                                    if (scenario.RequestType == typeof(DynamicObject))
                                    {
                                        var content = await request.Content.ReadAsStringAsync();

                                        if (!string.IsNullOrWhiteSpace(content))
                                        {
                                            dynamicParameters.AddProperty(scenario.RequestParameterName, DynamicXml.Parse(content));
                                        }
                                    }
                                    else
                                    {
                                        var contentGraph = await request.Content.ReadAsAsync(scenario.RequestType);

                                        dynamicParameters.AddProperty(scenario.RequestParameterName, contentGraph);
                                    }
                                }
                                else if (contentType == "application/yaml")
                                {
                                    // TBD: Note that I should be able to do this with the YamlMediaTypeFormatter
                                    // but it is currently being ignored
                                    var content = await request.Content.ReadAsStringAsync();

                                    if (scenario.RequestType == typeof(DynamicObject))
                                    {
                                        dynamicParameters.AddProperty(scenario.RequestParameterName, content.DeserializeYaml <object>());
                                    }
                                    else
                                    {
                                        dynamicParameters.AddProperty(scenario.RequestParameterName, content.DeserializeYaml(scenario.RequestType));
                                    }
                                }
                                else
                                {
                                    var contentGraph = await request.Content.ReadAsAsync(scenario.RequestType);

                                    dynamicParameters.AddProperty(scenario.RequestParameterName, contentGraph);
                                }
                            }
                            var result = _mockEngine.Invoke(scenario.Name, dynamicParameters);
                            if (result.Success)
                            {
                                var response = new HttpResponseMessage(result.StatusCode)
                                {
                                    ReasonPhrase = result.ReasonPhrase
                                };
                                response.RequestMessage = request;
                                if (result.Content != null)
                                {
                                    Type contentType = result.Content.GetType();
                                    if (WillAcceptType(request.Headers.Accept, "application/xml"))
                                    {
                                        response.Content = new StringContent(SerializeAsXml(result.Content, Encoding.UTF8), Encoding.UTF8, "application/xml");
                                    }
                                    else if (WillAcceptType(request.Headers.Accept, "application/json"))
                                    {
                                        response.Content = new ObjectContent(contentType, result.Content, new JsonMediaTypeFormatter(), "application/json");
                                    }
                                    else if (WillAcceptType(request.Headers.Accept, "application/yaml") || WillAcceptType(request.Headers.Accept, "*/*"))
                                    {
                                        response.Content = new ObjectContent(contentType, result.Content, new YamlMediaTypeFormatter(), "application/yaml");
                                    }
                                    else
                                    {
                                        response.Content      = new StringContent("response media type is not supported");
                                        response.StatusCode   = HttpStatusCode.UnsupportedMediaType;
                                        response.ReasonPhrase = "response media type is not supported";
                                    }
                                }
                                return(response);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Trace.WriteLine(e);
                    var reasonPhrase = e.Message.Replace("\n", " ").Replace("\r", " "); //cannot contain new lines
                    var response     = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                    {
                        ReasonPhrase = reasonPhrase
                    };
                    response.RequestMessage = request;
                    response.Content        = new StringContent(e.ToString(), Encoding.UTF8, "text/plain");
                    return(response);
                }
            }
            return(await base.SendAsync(request, cancellationToken));
        }
Пример #18
0
        public void attributes()
        {
            var xml = DynamicXml.Parse("<x y='hi'></x>");

            Assert.Equal("hi", xml.y);
        }
Пример #19
0
        public void sub_nodes()
        {
            var xml = DynamicXml.Parse("<x><y>hi</y></x>");

            Assert.Equal("hi", xml.y);
        }
Пример #20
0
        public void collections()
        {
            var xml = DynamicXml.Parse("<x><y>hi</y><y>ya</y></x>");

            Assert.Equal(2, xml.y.Count);
        }