Пример #1
0
 //private void button1_Click(object sender, EventArgs e)
 //{
 //    getJsonClient<AddRelationJsonClient>(@"C:\Users\Administrator\SkyDrive\OtransModel");
 //    getJsonClient<ComfirmTrustJsonClient>(@"c:\users\administrator\skydrive\otransmodel");
 //    getJsonClient<LogChallengeJsonClient>(@"c:\users\administrator\skydrive\otransmodel");
 //    getJsonClient<LogInJsonClient>(@"c:\users\administrator\skydrive\otransmodel");
 //    getJsonClient<LogOutJsonClient>(@"c:\users\administrator\skydrive\otransmodel");
 //    getJsonClient<RegisterJsonClient>(@"c:\users\administrator\skydrive\otransmodel");
 //    getJsonClient<RemoveRelationJsonClient>(@"c:\users\administrator\skydrive\otransmodel");
 //    getJsonClient<TrustRemoveJsonClient>(@"c:\users\administrator\skydrive\otransmodel");
 //    getJsonClient<TrustRequestJsonClient>(@"c:\users\administrator\skydrive\otransmodel");
 //    getJsonClient<UpdateLocationJsonClient>(@"c:\users\administrator\skydrive\otransmodel");
 //    getJsonClient<ViewLocationJsonClient>(@"c:\users\administrator\skydrive\otransmodel");
 //}
 //private void button2_Click(object sender, EventArgs e)
 //{
 //    getJsonServer<GetRelationJsonServer>(@"C:\Users\Administrator\SkyDrive\OtransModel");
 //    getJsonServer<LogChallengeJsonServer>(@"C:\Users\Administrator\SkyDrive\OtransModel");
 //    getJsonServer<MemberJsonServer>(@"C:\Users\Administrator\SkyDrive\OtransModel");
 //    getJsonServer<MyTrustRequestDetailJsonServer>(@"C:\Users\Administrator\SkyDrive\OtransModel");
 //    getJsonServer<MyTrustRequestJsonServer>(@"C:\Users\Administrator\SkyDrive\OtransModel");
 //    getJsonServer<ViewLocationJsonServer>(@"C:\Users\Administrator\SkyDrive\OtransModel");
 //}
 private void button1_Click(object sender, EventArgs e)
 {
     CodeParameter cgp = new CodeParameter()
     {
         ServerFunction = "getObjectWithData",
         ClientFunction = "jsonData",
         Folder = @"c:\Model",
         Prefix = "OTrans",
         ClientProtocal = "JsonClient",
         ServerProtocal = "JsonServer"
     };
     CodeFactory.Generate(cgp, typeof(TestModel), JsonModelType.ServerClient);
 }
Пример #2
0
        public static void Generate(CodeParameter parm, Type type, JsonModelType modelType)
        {
            string name = type.Name;
            var properties = type.GetProperties();
            List<string> relation = new List<string>();
            StreamWriter msrw = File.CreateText(Path.Combine(parm.Folder, name + ".m"));
            msrw.WriteLine("#import \"" + name + ".h" + "\"");
            msrw.WriteLine("");
            msrw.WriteLine("@implementation " + name);
            WritePropertyM(msrw, properties);

            if (modelType == JsonModelType.Client)
                WriteClientCode(type, msrw, parm.ClientFunction);
            else if (modelType == JsonModelType.Server)
                WriteServerCode(type, relation, msrw, parm.ServerFunction);
            else if (modelType == JsonModelType.ServerClient)
            {
                WriteServerCode(type, relation, msrw, parm.ServerFunction);
                WriteClientCode(type, msrw, parm.ClientFunction);
            }
            msrw.WriteLine("");
            msrw.WriteLine("@end");
            msrw.Close();
            PropertyRelation(relation, properties);
            StreamWriter hsrw = File.CreateText(Path.Combine(parm.Folder, name + ".h"));

            if (modelType == JsonModelType.Client)
            {
                hsrw.WriteLine("#import \"" + parm.ClientProtocal + ".h\"");
            }
            else if (modelType == JsonModelType.Server)
            {
                hsrw.WriteLine("#import \"" + parm.ServerProtocal + ".h\"");
            }
            else if (modelType == JsonModelType.Client)
            {
                hsrw.WriteLine("#import \"" + parm.ClientProtocal + ".h\"");
                hsrw.WriteLine("#import \"" + parm.ServerProtocal + ".h\"");
            }

            foreach (string item in relation.Distinct().Where(x => x != type.Name))
            {
                hsrw.WriteLine("#import \"" + item + ".h\"");
            }
            hsrw.WriteLine("");
            string protocal = "";
            if (modelType == JsonModelType.Client)
            {
                protocal = "<" + parm.ClientProtocal + ">";
            }
            else if (modelType == JsonModelType.Server)
            {
                protocal = "<" + parm.ServerProtocal + ">";
            }
            else if (modelType == JsonModelType.Client)
            {
                protocal = "<" + parm.ClientProtocal + "," + parm.ServerProtocal + ">";
            }

            hsrw.WriteLine("@interface " + name + " : NSObject" + protocal);
            WritePropertyH(hsrw, properties);
            hsrw.WriteLine("");
            hsrw.WriteLine("@end");
            hsrw.Close();
        }