コード例 #1
0
 public O2P(PocoSetting setting = null)
 {
     Setting = setting ?? new PocoSetting();
     //   Source = Media.Http;
     ClassList = new List <ClassTemplate>();
     MetaData  = new MetaDataInfo();
 }
コード例 #2
0
ファイル: MetaDataReader.cs プロジェクト: yuka1984/odata2poco
        private async Task <MetaDataInfo> LoadMetaDataHttpAsync()
        {
            string url = ServiceUrl.TrimEnd('/') + "/$metadata";

            using (var client = new WebClient())
            {
                //credintial
                if (!string.IsNullOrEmpty(User))
                {
                    //_token = Convert.ToBase64String(Encoding.ASCII.GetBytes(User + ":" + Password));
                    client.Headers[HttpRequestHeader.Authorization] = string.Format("Basic {0}", Token);
                }

                var content = await client.DownloadStringTaskAsync(url);

                if (!string.IsNullOrEmpty(content))
                {
                    content = Helper.PrettyXml(content);
                    GetServiceHttpHeader(client);
                    var metaData = new MetaDataInfo
                    {
                        MetaDataAsString = content,
                        MetaDataVersion  = Helper.GetMetadataVersion(content),
                        ServiceHeader    = GetServiceHttpHeader(client),
                        //ServiceVersion = null,
                        ServiceUrl      = ServiceUrl,
                        SchemaNamespace = "",
                        MediaType       = Media.Http
                    };
                    metaData.ServiceVersion = GetServiceVersion(metaData.ServiceHeader);
                    return(metaData);
                }
                return(new MetaDataInfo());
            }
        }
コード例 #3
0
ファイル: MetaDataReader.cs プロジェクト: yuka1984/odata2poco
        internal static async Task <MetaDataInfo> LoadMetaDataFileAsync(string fname)
        {
            IFile dataFile = await FileSystem.Current.GetFileFromPathAsync(fname);

            if (dataFile == null)
            {
                throw new FileNotFoundException("File not found: " + fname);
            }

            var content = await dataFile.ReadAllTextAsync();

            Debug.WriteLine(content);
            if (!string.IsNullOrEmpty(content))
            {
                var metaData = new MetaDataInfo
                {
                    MetaDataAsString = content,
                    MetaDataVersion  = Helper.GetMetadataVersion(content),
                    ServiceUrl       = fname,
                    SchemaNamespace  = Helper.GetNameSpace(content),
                    MediaType        = Media.Xml
                };
                Debug.WriteLine(content);
                return(metaData);
            }
            return(new MetaDataInfo());
        }
コード例 #4
0
ファイル: PocoFactory.cs プロジェクト: moh-hassan/odata2poco
 public static IPocoClassGenerator GeneratePoco(MetaDataInfo metadata,PocoSetting setting=null)
 {
     if(string.IsNullOrEmpty(metadata.MetaDataAsString))
         throw new XmlException("Metaddata is empty");
     var generator = Create(metadata);
     return new PocoClassGeneratorCs(generator, setting??new PocoSetting() );
 }
コード例 #5
0
        public static async Task <MetaDataInfo> LoadMetaDataHttpAsync(OdataConnectionString odataConnString)
        {
            // to avoid the Error Message://An error occurred while sending the request.-->
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
                                                   | SecurityProtocolType.Tls11
                                                   | SecurityProtocolType.Tls;



            var client  = new CustomeHttpClient(odataConnString);
            var content = await client.ReadMetaDataAsync();

            var metaData = new MetaDataInfo
            {
                MetaDataAsString = content,
                MetaDataVersion  = Helper.GetMetadataVersion(content),
                ServiceUrl       = client.ServiceUri.OriginalString,
                SchemaNamespace  = Helper.GetNameSpace(content),
                MediaType        = Media.Http,
            };

            if (client.Response != null)
            {
                foreach (var entry in client.Response.Headers)
                {
                    string value = entry.Value.FirstOrDefault();
                    string key   = entry.Key;
                    metaData.ServiceHeader.Add(key, value);
                }
            }

            metaData.ServiceVersion = Helper.GetServiceVersion(metaData.ServiceHeader);
            return(metaData);
        }
コード例 #6
0
        private static IPocoGenerator Create(MetaDataInfo metadata, PocoSetting setting)
        {
            if (string.IsNullOrEmpty(metadata.MetaDataAsString))
            {
                throw new InvalidOperationException("No Metadata available");
            }

            var metaDataVersion = metadata.MetaDataVersion;

            switch (metaDataVersion)
            {
            case ODataVersion.V4:
                return(new Poco(metadata, setting));

            case ODataVersion.V1:
            case ODataVersion.V2:
            case ODataVersion.V3:
                return(new V3.Poco(metadata, setting));

            //throw new NotImplementedException();

            default:
                throw new NotSupportedException(string.Format("OData Version '{0}' is not supported", metaDataVersion));
            }
        }
コード例 #7
0
        public static IPocoClassGenerator GeneratePoco(MetaDataInfo metadata, PocoSetting setting = null)
        {
            if (string.IsNullOrEmpty(metadata.MetaDataAsString))
            {
                throw new XmlException("Metaddata is empty");
            }
            var generator = Create(metadata);

            return(new PocoClassGeneratorCs(generator, setting ?? new PocoSetting()));
        }
コード例 #8
0
ファイル: MetaDataReader.cs プロジェクト: yuka1984/odata2poco
        public static async Task <MetaDataInfo> LoadMetaDataHttpAsync(Uri serviceUri, string user, string password)
        {
            string url = serviceUri.AbsoluteUri.TrimEnd('/') + "/$metadata";

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Add("User-Agent", "OData2Poco in Codeplex");
                //credintial
                if (!string.IsNullOrEmpty(user))
                {
                    var token = Convert.ToBase64String(Encoding.UTF8.GetBytes(user + ":" + password));
                    Debug.WriteLine(token);
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", token);
                }

                using (HttpResponseMessage response = await client.GetAsync(url))
                {
                    //   Debug.WriteLine(await response.Content.ReadAsStringAsync());
                    //response.EnsureSuccessStatusCode();
                    if (response.IsSuccessStatusCode)
                    {
                        var content = await response.Content.ReadAsStringAsync();

                        //Debug.WriteLine(content);
                        if (!string.IsNullOrEmpty(content))
                        {
                            // content = Helper.PrettyXml(content);
                            var metaData = new MetaDataInfo
                            {
                                MetaDataAsString = content,
                                MetaDataVersion  = Helper.GetMetadataVersion(content),
                                ServiceUrl       = serviceUri.OriginalString,
                                SchemaNamespace  = Helper.GetNameSpace(content),
                                MediaType        = Media.Http,
                                ServiceHeader    = new Dictionary <string, string>()
                            };
                            foreach (var entry in response.Headers)
                            {
                                string value = entry.Value.FirstOrDefault();
                                string key   = entry.Key;
                                //Debug.WriteLine(key +":" +value);
                                metaData.ServiceHeader.Add(key, value);
                            }
                            metaData.ServiceVersion = Helper.GetServiceVersion(metaData.ServiceHeader);
                            //Debug.WriteLine(metaData.MetaDataAsString);
                            return(metaData);
                        }
                    }
                    Debug.WriteLine(response.ReasonPhrase);
                    throw new WebException("Http Error " + (int)response.StatusCode + ": " + response.ReasonPhrase);
                }
            }
        }
コード例 #9
0
        public static  async Task<MetaDataInfo> LoadMetaDataHttpAsync(Uri serviceUri,string user ,string password)
        {
            string url = serviceUri.AbsoluteUri.TrimEnd('/') + "/$metadata";
            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Add("User-Agent", "OData2Poco in Codeplex");
                //credintial
                if (!string.IsNullOrEmpty(user))
                {
                    var token = Convert.ToBase64String(Encoding.UTF8.GetBytes(user + ":" + password));
                    Debug.WriteLine(token);
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", token);
                }

                using (HttpResponseMessage response = await client.GetAsync(url))
                {
                    //   Debug.WriteLine(await response.Content.ReadAsStringAsync());
                    //response.EnsureSuccessStatusCode();
                    if (response.IsSuccessStatusCode)
                    {
                        var content = await response.Content.ReadAsStringAsync();
                        //Debug.WriteLine(content);
                        if (!string.IsNullOrEmpty(content))
                        {
                           // content = Helper.PrettyXml(content);
                            var metaData = new MetaDataInfo
                            {
                                MetaDataAsString = content,
                                MetaDataVersion = Helper.GetMetadataVersion(content),
                                ServiceUrl = serviceUri.OriginalString,
                                SchemaNamespace = Helper.GetNameSpace(content),
                                MediaType = Media.Http,
                                ServiceHeader = new Dictionary<string, string>()
                            };
                            foreach (var entry in response.Headers)
                            {
                                string value = entry.Value.FirstOrDefault();
                                string key = entry.Key;
                                //Debug.WriteLine(key +":" +value);
                                metaData.ServiceHeader.Add(key, value);
                            }
                            metaData.ServiceVersion = Helper.GetServiceVersion(metaData.ServiceHeader);
                            //Debug.WriteLine(metaData.MetaDataAsString);
                            return metaData;
                        }

                    }
                    Debug.WriteLine(response.ReasonPhrase);
                    throw new WebException("Http Error " + (int)response.StatusCode + ": " + response.ReasonPhrase);
                }
            }
        }
コード例 #10
0
        /// <summary>
        /// Load Metadata from xml string
        /// </summary>
        /// <param name="xmlContent">xml string </param>
        /// <returns></returns>
        public static MetaDataInfo LoadMetaDataFromXml(string xmlContent)
        {
            var metaData = new MetaDataInfo
            {
                MetaDataAsString = xmlContent,
                MetaDataVersion  = Helper.GetMetadataVersion(xmlContent),
                ServiceUrl       = "",
                SchemaNamespace  = Helper.GetNameSpace(xmlContent),
                MediaType        = Media.Xml
            };

            return(metaData);
        }
コード例 #11
0
        public static async Task <MetaDataInfo> LoadMetaDataHttpAsync(OdataConnectionString odataConnString)
        {
            // to avoid the Error Message://An error occurred while sending the request.-->
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
                                                   | SecurityProtocolType.Tls11
                                                   | SecurityProtocolType.Tls;


            var serviceUri = new Uri(odataConnString.ServiceUrl);

            using (var client = new HttpClient())
            {
                await new Authenticator(client).Authenticate(odataConnString);
                client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=utf-8");
                client.DefaultRequestHeaders.Add("User-Agent", "OData2Poco");
                string url = serviceUri.AbsoluteUri.TrimEnd('/') + "/$metadata";

                using (HttpResponseMessage response = await client.GetAsync(url))
                {
                    if (!response.IsSuccessStatusCode)
                    {
                        throw new HttpRequestException(
                                  $"Http Error {(int) response.StatusCode}: {response.ReasonPhrase}");
                    }
                    var content = await response.Content.ReadAsStringAsync();

                    if (string.IsNullOrEmpty(content))
                    {
                        throw new HttpRequestException(
                                  $"Http Error {(int) response.StatusCode}: {response.ReasonPhrase}");
                    }
                    var metaData = new MetaDataInfo
                    {
                        MetaDataAsString = content,
                        MetaDataVersion  = Helper.GetMetadataVersion(content),
                        ServiceUrl       = serviceUri.OriginalString,
                        SchemaNamespace  = Helper.GetNameSpace(content),
                        MediaType        = Media.Http,
                        ServiceHeader    = new Dictionary <string, string>()
                    };
                    foreach (var entry in response.Headers)
                    {
                        string value = entry.Value.FirstOrDefault();
                        string key   = entry.Key;
                        metaData.ServiceHeader.Add(key, value);
                    }
                    metaData.ServiceVersion = Helper.GetServiceVersion(metaData.ServiceHeader);
                    return(metaData);
                }
            }
        }
コード例 #12
0
ファイル: PocoFactory.cs プロジェクト: moh-hassan/odata2poco
        private static IPocoGenerator Create(MetaDataInfo metadata)
        {
            if (string.IsNullOrEmpty(metadata.MetaDataAsString)) throw new InvalidOperationException("No Metadata available");

            var metaDataVersion = metadata.MetaDataVersion;  
            switch (metaDataVersion)
            {
                case ODataVersion.V4:
                    return new Poco(metadata);

                case ODataVersion.V1:
                case ODataVersion.V2:
                case ODataVersion.V3:
                    return new V3.Poco(metadata);
                //throw new NotImplementedException();

                default:
                    throw new NotSupportedException(string.Format("OData Version '{0}' is not supported", metaDataVersion));
                  
            }
        }
コード例 #13
0
        private MetaDataInfo LoadMetaDataFile()
        {
            if (!File.Exists(ServiceUrl))
                throw new FileNotFoundException("File not found: " + ServiceUrl);


            using (var reader = File.OpenText(ServiceUrl))
            {
                var text = reader.ReadToEnd();
                var metaData = new MetaDataInfo
                {
                    MetaDataAsString = text,
                    MetaDataVersion = Helper.GetMetadataVersion(text),
                     ServiceHeader = new Dictionary<string, string>( ), //http only
                    ServiceVersion = "NA", //http only
                    ServiceUrl = ServiceUrl,
                    SchemaNamespace = "",
                     MediaType = Media.File
                };
                return metaData;
            }
        }
コード例 #14
0
        internal static async Task<MetaDataInfo> LoadMetaDataFileAsync(string fname)
        {
            IFile dataFile = await FileSystem.Current.GetFileFromPathAsync(fname);
            if (dataFile == null)
                throw new FileNotFoundException("File not found: " + fname);

            var content = await dataFile.ReadAllTextAsync();
            Debug.WriteLine(content);
            if (!string.IsNullOrEmpty(content))
            {
              var metaData = new MetaDataInfo
                {
                    MetaDataAsString = content,
                    MetaDataVersion = Helper.GetMetadataVersion(content),
                    ServiceUrl = fname,
                    SchemaNamespace = Helper.GetNameSpace(content),
                    MediaType = Media.Xml
                };
                Debug.WriteLine(content);
                return metaData;
            }
            return new MetaDataInfo();
        }
コード例 #15
0
ファイル: MetaDataReader.cs プロジェクト: yuka1984/odata2poco
        private async Task <MetaDataInfo> LoadMetaDataFileAsync()
        {
            if (!File.Exists(ServiceUrl))
            {
                throw new FileNotFoundException("File not found: " + ServiceUrl);
            }
            using (var reader = File.OpenText(ServiceUrl))
            {
                var text = await reader.ReadToEndAsync();

                var metaData = new MetaDataInfo
                {
                    MetaDataAsString = text,
                    MetaDataVersion  = Helper.GetMetadataVersion(text),
                    //ServiceHeader = null, //http only
                    //ServiceVersion = null, //http only
                    ServiceUrl      = ServiceUrl,
                    SchemaNamespace = "",
                    MediaType       = Media.File
                };
                return(metaData);
            }
        }
コード例 #16
0
ファイル: MetaDataReader.cs プロジェクト: yuka1984/odata2poco
        private MetaDataInfo LoadMetaDataFile()
        {
            if (!File.Exists(ServiceUrl))
            {
                throw new FileNotFoundException("File not found: " + ServiceUrl);
            }


            using (var reader = File.OpenText(ServiceUrl))
            {
                var text     = reader.ReadToEnd();
                var metaData = new MetaDataInfo
                {
                    MetaDataAsString = text,
                    MetaDataVersion  = Helper.GetMetadataVersion(text),
                    ServiceHeader    = new Dictionary <string, string>( ), //http only
                    ServiceVersion   = "NA",                               //http only
                    ServiceUrl       = ServiceUrl,
                    SchemaNamespace  = "",
                    MediaType        = Media.File
                };
                return(metaData);
            }
        }
コード例 #17
0
 /// <summary>
 /// Load Metadata from xml string
 /// </summary>
 /// <param name="xmlContent">xml string </param>
 /// <returns></returns>
 public static MetaDataInfo LoadMetaDataFromXml(string xmlContent)
 {
     var metaData = new MetaDataInfo
     {
         MetaDataAsString = xmlContent,
         MetaDataVersion = Helper.GetMetadataVersion(xmlContent),
         ServiceUrl = "",
         SchemaNamespace = Helper.GetNameSpace(xmlContent),
         MediaType = Media.Xml
     };
     //Debug.WriteLine(xmlContent);
     return metaData;
 }
コード例 #18
0
        private async Task<MetaDataInfo> LoadMetaDataHttpAsync()
        {
            string url = ServiceUrl.TrimEnd('/') + "/$metadata";
            using (var client = new WebClient())
            {
                //credintial
                if (!string.IsNullOrEmpty(User))
                {
                   
                    //_token = Convert.ToBase64String(Encoding.ASCII.GetBytes(User + ":" + Password));
                    client.Headers[HttpRequestHeader.Authorization] = string.Format("Basic {0}", Token);
                }

                var content = await client.DownloadStringTaskAsync(url);

                if (!string.IsNullOrEmpty(content))
                {
                    content = Helper.PrettyXml(content);
                    GetServiceHttpHeader(client);
                    var metaData = new MetaDataInfo
                    {
                        MetaDataAsString = content,
                        MetaDataVersion = Helper.GetMetadataVersion(content),
                        ServiceHeader = GetServiceHttpHeader(client),
                        //ServiceVersion = null,
                        ServiceUrl = ServiceUrl,
                        SchemaNamespace = "",
                        MediaType = Media.Http
                    };
                    metaData.ServiceVersion = GetServiceVersion(metaData.ServiceHeader);
                    return metaData;
                }
                return new MetaDataInfo();
            }
        }
コード例 #19
0
 private async Task<MetaDataInfo> LoadMetaDataFileAsync()
 {
     if (!File.Exists(ServiceUrl))
         throw new FileNotFoundException("File not found: " + ServiceUrl);
     using (var reader = File.OpenText(ServiceUrl))
     {
         var text = await reader.ReadToEndAsync();
         var metaData = new MetaDataInfo
         {
             MetaDataAsString = text,
             MetaDataVersion = Helper.GetMetadataVersion(text),
             //ServiceHeader = null, //http only
             //ServiceVersion = null, //http only
             ServiceUrl = ServiceUrl,
             SchemaNamespace = "",
             MediaType = Media.File
         };
         return metaData;
     }
 }
コード例 #20
0
ファイル: O2P.cs プロジェクト: moh-hassan/odata2poco
        /// <summary>
        /// 
        /// </summary>
        /// <param name="url"> can be : Url , filename or xml data</param>
        /// <param name="setting"></param>
        //public O2P(Uri url, PocoSetting setting = null)
        //{
        //    ServiceUri = url;
        //    Setting = setting ?? new PocoSetting();
        //    Source = Media.Http;
        //    ClassList = new List<ClassTemplate>();
        //    MetaData = new MetaDataInfo();
        //}
        //public O2P(Uri url, string user, string password, PocoSetting setting = null)
        //    : this(url)
        //{
        //    User = user;
        //    Password = password;
        //}

        //public O2P(string xmlContent, PocoSetting setting = null)
        //{
        //    _xmlContent = xmlContent;
        //    Setting = setting ?? new PocoSetting();
        //    Source = Media.Http;
        //    ClassList = new List<ClassTemplate>();
        //    MetaData = new MetaDataInfo();
        //}

        public O2P( PocoSetting setting = null)
        {
           
            Setting = setting ?? new PocoSetting();
         //   Source = Media.Http;
            ClassList = new List<ClassTemplate>();
            MetaData = new MetaDataInfo();
        }