Esempio n. 1
0
        static void Main(string[] args)
        {
            ICollection<ValidationResult> listValidationResults = new List<ValidationResult>();
           
            var c = new User { Id = 12, Name = "" };

            bool valid = Validator.TryValidateObject(c,new ValidationContext(c), listValidationResults,true);
            if (!valid)
            {
                foreach (ValidationResult res in listValidationResults)
                {
                    Console.WriteLine(res.ErrorMessage);
                }

            }  


            Console.ReadLine();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var t = new Test();

            var a = new User();
            a.Value = 9;
            a.Name = "1234567";
            a.Status = 'S';

            t.User = a;

            var db = new DbFramework(typeof(Test));
            db.SetRules();
            var script = db.GetScript(true);

            Validator.ValidateObj(t);

            Console.ReadKey();
        }
Esempio n. 3
0
        private static void AddUser(string firstName, string lastName, string pseudonim, string email, int phone)
        {
            using (var context = new BookDBDataContext())
            {
                if (context.Users.FirstOrDefault(user => user.Email == email) == null)
                {

                    User temp = new User()
                    {
                        FirstName = firstName,
                        LastName = lastName,
                        Pseudonim = pseudonim,
                        Email = email,
                        Phone = phone
                    };

                    context.Users.InsertOnSubmit(temp);
                    context.SubmitChanges();
                }
            }
        }
Esempio n. 4
0
        public static void LoanBookToUser(User user, Book book)
        {
            using (var context = new BookDBDataContext())
            {
                bool alreadyLoaned = (from bu in context.BookUsers
                                  where bu.UserID == user.ID
                                    && bu.BookCopy.Book.ID == book.ID
                                    && bu.ReturnDate >= DateTime.Now.Date
                                  select 1).Count() > 0;

                if (alreadyLoaned == true)
                {
                    throw new ArgumentException("You have already loaned this book!");
                }

                BookCopy availableCopy = (from bu in context.BookUsers
                                          where bu.BookCopy.BookID == book.ID
                                          && bu.ReturnDate == null
                                          select bu.BookCopy).FirstOrDefault();

                var avail = (from bc in context.BookCopies
                             where bc.BookID == book.ID
                                 && bc.BookUsers.Count() == 0
                             select bc).FirstOrDefault();

                if (availableCopy == null)
                {
                    throw new ArgumentException("There is no available copy of this book!");
                }

            }
        }
Esempio n. 5
0
 partial void DeleteUser(User instance);
Esempio n. 6
0
 partial void UpdateUser(User instance);
Esempio n. 7
0
 partial void InsertUser(User instance);
Esempio n. 8
0
        public static void test ()
        {
            //Schema schema = Schema.Parse ("schema json");

            SpecificDatumWriter<User> w = new SpecificDatumWriter<User> (User._SCHEMA);
            User input = new User ();
            input.name = "mm";
            input.favorite_color = "red";
            input.favorite_number = 11;

            MemoryStream stream = new MemoryStream ();
            w.Write (input, new BinaryEncoder (stream));

            stream.Seek (0, SeekOrigin.Begin);

            SpecificDatumReader<User> r = new SpecificDatumReader<User> (User._SCHEMA, User._SCHEMA);
            User output = r.Read (null, new BinaryDecoder (stream));
            Console.WriteLine (output.name);
        }
Esempio n. 9
0
        //static void Test1()
        //{
        //    SocketClient _sc = new SocketClient("10.0.0.104", 11025);
        //    _sc.Sysinfo = s => Console.WriteLine(s);
        //    _sc.OnAMFMsgReceived = d =>
        //    {
        //        //Console.WriteLine("Message Received");
        //        var src = d.GetData();
        //        if (src != null)
        //        {
        //            var reqv = src as ReqResVO;
        //            if (reqv != null)
        //            {
        //                Console.WriteLine("ReqResVO action:{0}, command:{1}",reqv.action,reqv.command);
        //                var rdv = reqv.data as ResultDataVO;
        //                if (rdv != null)
        //                {
        //                    var nv = rdv.data as NotifyVO;
        //                    if (nv != null)
        //                    {
        //                        //Console.WriteLine(nv.eventName);
        //                    }
        //                    else
        //                    {
        //                        var nlv = rdv.data as NotifyListVO;
        //                        if (nlv != null)
        //                        {
        //                            //Console.WriteLine(nlv.);
        //                        }
        //                    }
        //                }
        //            }
        //            else
        //            {
        //                var nv = src as NotifyVO;
        //                if (nv != null)
        //                {
        //                    Console.WriteLine(nv.eventName);
        //                }
        //            }
        //        }
        //    };
        //    _sc.Connect();
        //    //Dictionary<string, string> msg = new Dictionary<string, string>();
        //    //msg.Add("accountName", "super1");
        //    //msg.Add("accountPassword", "");
        //    _sc.Start();
        //}
        //static void Test2()
        //{
        //    SocketClient _sc = new SocketClient("10.0.0.104", 11025);
        //    _sc.Sysinfo = s => Console.WriteLine(s);
        //    _sc.OnDataReceived = d =>
        //    {
        //        Console.WriteLine("Message Received...");
        //        JObject Jo = JObject.Parse(d);
        //        //var rawo = JsonConvert.DeserializeObject(d);
        //        //var js = JsonSerializer.Create();
        //        //js.MissingMemberHandling = MissingMemberHandling.Ignore;
        //        //js.TypeNameHandling = TypeNameHandling.All;
        //        //Console.WriteLine(Jo.);
        //        var nv = Jo.ToObject<NotifyVO>();
        //        if (nv.eventName != null)
        //        {
        //            Console.WriteLine("NotifyVO eventName::{0}", nv.eventName);
        //        }
        //        else
        //        {
        //            var reqv = Jo.ToObject<ReqResVO>();
        //            Console.WriteLine("ReqResVO action:{0}, command:{1}", reqv.action, reqv.command);
        //            var rdv = JObject.FromObject(reqv.data).ToObject<ResultDataVO>();
        //            var needCallback = true;
        //            var nfv = JObject.FromObject(rdv.data).ToObject<NotifyVO>();
        //            if (nfv.eventName != null)
        //            {
        //                Console.WriteLine("NotifyVO eventName::{0}", nfv.eventName);
        //                needCallback = false;
        //                //if (Test.NotifyEvents.ContainsKey(nv.eventName)) Test.NotifyEvents[nv.eventName](nv.data);
        //            }
        //            //var jlo = JObject.FromObject()
        //            var nlv = JObject.FromObject(rdv.data).ToObject<NotifyListVO>();
        //            if (nlv.notifyVOList != null)
        //            {
        //                Console.WriteLine("NotifyListVO");
        //                needCallback = false;
        //                //if (Test.NotifyEvents.ContainsKey(nv.eventName)) Test.NotifyEvents[nv.eventName](nv.data);
        //            }
        //            //var key = reqv.action + "#" + reqv.command;
        //            //if (Test.CallBackEvents.ContainsKey(key) && needCallback)
        //            //{
        //            //    Debug.Log("key:" + key);
        //            //    //Test.CallBackEvents[key](rdv.data);
        //            //}
        //        }
        //    };
        //    _sc.Connect();
        //    _sc.Start();
        //    Hashtable ht = new Hashtable()
        //    {
        //        {Conf.ACCOUNT_NAME, "super1"},
        //        {Conf.ACCOUNT_PASSWORD, ""}
        //    };
        //    //NetCtrl.SocketClient.Send(Conf.USER_FACADE, Conf.LOGIN_ACCOUNT, ht);
        //    _sc.Send(Conf.USER_FACADE, Conf.LOGIN_ACCOUNT, ht);
        //}
        static void Test3()
        {
            GSTest gst = new GSTest();

            gst.Connect();

            User a = new User() { ID = 123, Name = "王老吉" };
            User b = new User() { ID = 222, Name = "周润发" };

            gst.Send(new List<User>() { a, b });
        }