示例#1
0
 public O2P(string url, string user, string password)
 {
     Url = url;
     User = user;
     Password = password;
     Setting = new PocoSetting();
 }
示例#2
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() );
 }
 //container for all classes
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="pocoGen"></param>
 /// <param name="setting"></param>
 private PocoClassGeneratorCs(IPocoGenerator pocoGen, PocoSetting setting)
 {
     PocoSetting = setting;
     _pocoGen    = pocoGen;
     ClassList   = pocoGen.GeneratePocoList();
     CodeText    = null;
 }
示例#4
0
 public O2P(string url, string user, string password)
 {
     Url      = url;
     User     = user;
     Password = password;
     Setting  = new PocoSetting();
 }
示例#5
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));
            }
        }
示例#6
0
 public O2P(PocoSetting setting = null)
 {
     Setting = setting ?? new PocoSetting();
     //   Source = Media.Http;
     ClassList = new List <ClassTemplate>();
     MetaData  = new MetaDataInfo();
 }
示例#7
0
 /// <summary>
 /// cto initialization
 /// </summary>
 /// <param name="pocoSetting">Seting parameters of generating code</param>
 /// <param name="model">The model containing all classes </param>
 public AssemplyManager(PocoSetting pocoSetting, IDictionary <string, ClassTemplate> model)
 {
     _pocoSetting      = pocoSetting;
     _model            = model;
     AssemplyReference = new List <string>();
     AddAssemply(DefaultAssemply);//add default assemplies
     AddAssemplyReferenceList();
 }
示例#8
0
        //todo
        internal static async Task <IPocoGenerator> GenerateModel(OdataConnectionString connectionString,
                                                                  PocoSetting setting)
        {
            var metaData = await MetaDataReader.LoadMetadataAsync(connectionString);

            IPocoGenerator generator = Create(metaData, setting);

            return(generator);
        }
示例#9
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()));
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="pocoGen"></param>
 /// <param name="setting"></param>
 public PocoClassGeneratorCs(IPocoGenerator pocoGen, PocoSetting setting = null)
 {
     PocoSetting = setting ?? new PocoSetting();
     _pocoGen = pocoGen;
     _classDictionary = new Dictionary<string, ClassTemplate>();
     Template = new FluentCsTextTemplate();
     var list = _pocoGen.GeneratePocoList(); //generate all classes from model
     if (list != null)
         foreach (var item in list) _classDictionary[item.Name] = item;
     //Console.WriteLine("PocoClassGeneratorCs constructor key: {0}", PocoSetting.AddKeyAttribute);
     CodeText = null;
 }
        //container for all classes
        /// <summary>
        ///     Constructor
        /// </summary>
        /// <param name="pocoGen"></param>
        /// <param name="setting"></param>
        public PocoClassGeneratorCs(IPocoGenerator pocoGen, PocoSetting setting = null)
        {
            PocoSetting = setting ?? new PocoSetting();
            _pocoGen    = pocoGen;
            //add jsonproperty to properties/classes that are renamed
            PocoSetting?.Attributes.Add("original"); //v3.2

            //initialize AttributeFactory to use pocosetting.Attributes
            AttributeFactory.Default.Init(PocoSetting);

            ClassList = _pocoGen.GeneratePocoList();
            //check reserved keywords
            ModelManager.RenameClasses(ClassList);
            Header   = GetHeader() ?? "";
            CodeText = null;
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="pocoGen"></param>
        /// <param name="setting"></param>
        public PocoClassGeneratorCs(IPocoGenerator pocoGen, PocoSetting setting = null)
        {
            PocoSetting      = setting ?? new PocoSetting();
            _pocoGen         = pocoGen;
            _classDictionary = new Dictionary <string, ClassTemplate>();
            Template         = new FluentCsTextTemplate();
            var list = _pocoGen.GeneratePocoList(); //generate all classes from model

            if (list != null)
            {
                foreach (var item in list)
                {
                    _classDictionary[item.Name] = item;
                }
            }
            //Console.WriteLine("PocoClassGeneratorCs constructor key: {0}", PocoSetting.AddKeyAttribute);
            CodeText = null;
        }
示例#13
0
        /// <summary>
        /// Generate code PocoSetting setting =null, Language lang = Language.CS
        /// </summary>
        /// <returns></returns>
        //public PocoClassGeneratorCs Generate()
        //{
        //    PocoSetting setting = new PocoSetting();
        //    return Generate(setting);
        //}

        public PocoClassGeneratorCs Generate(PocoSetting setting, Language lang = Language.CS)
        {
            Console.WriteLine("metadatareader generate key: {0}", setting.AddKeyAttribute);
            if (MetaData == null)
            {
                MetaData = LoadMetaData();
            }
            IPocoGenerator       pocoFactory = PocoFactory.Create(MetaData);
            PocoClassGeneratorCs generator;

            if (lang == Language.CS)
            {
                generator = new PocoClassGeneratorCs(pocoFactory, setting);                     //.GeneratePoco();
            }
            else //vb ,java,...
            {
                throw new NotImplementedException();
            }
            return(generator);
        }
示例#14
0
        /// <summary>
        ///     Constructor
        /// </summary>
        /// <param name="pocoGen"></param>
        /// <param name="setting"></param>
        public PocoClassGeneratorCs(IPocoGenerator pocoGen, PocoSetting setting = null)
        {
            PocoSetting = setting ?? new PocoSetting();
            //initialize AttributeFactory to use pocosetting.Attributes
            AttributeFactory.Default.Init(PocoSetting);
            _pocoGen  = pocoGen;
            PocoModel = new Dictionary <string, ClassTemplate>();
            Template  = new FluentCsTextTemplate();
            var list = _pocoGen.GeneratePocoList(); //generate all classes from model

            //check reserved keywords
            ModelManager.RenameClasses(list);
            if (list != null)
            {
                foreach (var item in list)
                {
                    PocoModel[item.Name] = item;
                }
            }

            CodeText = null;
        }
        /// <summary>
        /// Generate all attributes of the class
        /// </summary>
        /// <param name="setting"></param>
        /// <returns></returns>
        public List <string> GetAttributes(PocoSetting setting)
        {
            var list = new List <string>();

            //[Table("depts")]
            if (setting.AddTableAttribute)
            {
                if (EntitySetName != "")
                {
                    list.Add($"[Table(\"{EntitySetName}\")]");
                }
            }

            //in future may be extra attributes or even custom user defined attributes
            //[DataContract]
            //if (setting.AddDataMemberAttribute)
            //{

            //    list.Add(string.Format("[{0}]", "DataContract"));


            //}
            return(list);
        }
示例#16
0
 public O2P()
 {
     Setting = new PocoSetting();
 }
示例#17
0
 public PocoClassGeneratorVb(IPocoGenerator pocoFactory, PocoSetting setting)
 {
     throw new NotImplementedException();
 }
示例#18
0
 public O2P(string url)
 {
     Url     = url;
     Setting = new PocoSetting();
 }
        public static PocoClassGeneratorCs GenerateCsPocoClass(IPocoGenerator pocoGen, PocoSetting setting)
        {
            setting = setting ?? new PocoSetting();
            //add jsonproperty to properties/classes that are renamed
            setting.Attributes.Add("original"); //v3.2


            //initialize AttributeFactory to use pocosetting.Attributes
            AttributeFactory.Default.Init(setting);

            var generator = new PocoClassGeneratorCs(pocoGen, setting);

            //filter model
            var generatorClassList = generator.ClassList;

            if (setting.Include?.Count > 0)
            {
                generator.ClassList = ModelFilter.FilterList(generatorClassList, setting.Include).ToList();
            }

            //change case
            if (setting.EntityNameCase != CaseEnum.None)
            {
                ModelChangeCase.RenameClasses(generatorClassList, setting.EntityNameCase);
            }

            //check reserved keywords
            ModelManager.RenameReservedWords(generatorClassList);
            generator.Header = generator.GetHeader() ?? "";
            //CodeText = null;
            return(generator);
        }
示例#20
0
 public O2P()
 {
     Setting = new PocoSetting();
 }
示例#21
0
        /// <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();
        }
示例#22
0
        /// <summary>
        /// Generate code PocoSetting setting =null, Language lang = Language.CS
        /// </summary>
        /// <returns></returns>
        //public PocoClassGeneratorCs Generate()
        //{
        //    PocoSetting setting = new PocoSetting();
        //    return Generate(setting);
        //}

        public PocoClassGeneratorCs Generate(PocoSetting setting, Language lang = Language.CS)
        {
            Console.WriteLine("metadatareader generate key: {0}", setting.AddKeyAttribute);
            if (MetaData == null) MetaData = LoadMetaData();
            IPocoGenerator pocoFactory = PocoFactory.Create(MetaData);
            PocoClassGeneratorCs generator;
            if (lang == Language.CS) generator= new PocoClassGeneratorCs(pocoFactory, setting); //.GeneratePoco();
            else //vb ,java,...
                throw new NotImplementedException();
            return generator;

        }
示例#23
0
 /// <summary>
 /// Initialize in cto
 /// </summary>
 /// <param name="propertyTemplate"></param>
 /// <param name="pocoSetting"></param>
 public PropertyGenerator(PropertyTemplate propertyTemplate, PocoSetting pocoSetting)
 {
     _property = propertyTemplate;
     _setting  = pocoSetting ?? new PocoSetting();
 }
示例#24
0
 public O2P(string url)
 {
     Url = url;
     Setting = new PocoSetting();
 }