예제 #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() );
 }
예제 #3
0
 //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()));
        }
예제 #10
0
 /// <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;
 }
예제 #11
0
        //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;
        }
예제 #12
0
        /// <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;
        }
예제 #15
0
        /// <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();
 }
예제 #19
0
        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();
 }