Esempio n. 1
0
        public ActionResult Culture()
        {
            CustomCultureInfo customCultureInfo = Thread.CurrentThread.CurrentCulture as CustomCultureInfo;
            CultureModel      model             = new CultureModel();

            model.TimezoneHour           = 0;
            model.CurrentCultureDateTime = DateTimeExtensions.GetCustomCultureDateTime();
            model.PricipleDateTime       = DateTimeExtensions.GetUserThreadPricipleDateTime();
            if (customCultureInfo != null)
            {
                model.TimezoneHour = customCultureInfo.UtcHours;
            }

            model.Messages.Add(System.Web.HttpContext.Current.Items["culture-begin"] as string);
            model.Messages.Add(System.Web.HttpContext.Current.Items["culture-end"] as string);

            model.Messages.Add($"Home-UtcHours:{customCultureInfo?.UtcHours}  : {DateTime.Now}");
            model.Messages.Add($"CurrentPrincipal-Name:{Thread.CurrentPrincipal.Identity.Name}  : {DateTime.Now}");

            CustomPrincipal customPrincipal = User as CustomPrincipal;

            if (customPrincipal != null)
            {
                model.Messages.Add($"MyFormsIdentity:{customPrincipal.Identity.Name}  : {customPrincipal.TimeZoneHour}");
                model.UserDataTimezoneHour = customPrincipal.TimeZoneHour;
            }
            model.UserNo = User.Identity?.Name;
            return(View(model));
        }
Esempio n. 2
0
        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            int timeZoneHour = 8;
            //CurrentCulture Version
            HttpCookie timeZoneHourCookie = System.Web.HttpContext.Current.Request.Cookies["timezoneHour"];

            if (timeZoneHourCookie != null)
            {
                timeZoneHour = Convert.ToInt32(timeZoneHourCookie.Value);
                var culture = CustomCultureInfo.Create(Thread.CurrentThread.CurrentCulture.Name, timeZoneHour);
                culture.NumberFormat.CurrencySymbol = "R";
                System.Web.HttpContext.Current.Items.Add("culture-begin", $"Global:{culture.UtcHours}:{DateTime.Now}");
                Thread.CurrentThread.CurrentCulture = culture;

                //if (timeZoneHourCookie.Value == "2")
                //    System.Threading.Thread.Sleep(10000);
                System.Web.HttpContext.Current.Items.Add("culture-end", $"Global:{culture.UtcHours}:{DateTime.Now}");
            }

            //CustomPrincipal Version 20190209 參考此版使用在專案上
            if (Request.IsAuthenticated)
            {
                FormsIdentity id = (FormsIdentity)User.Identity;
                Context.User = new CustomPrincipal(User.Identity, id.Ticket.UserData);
            }
            //else
            //{
            //    //兩者都要指定,CurrentPrincipal才有作用
            //    Thread.CurrentPrincipal = new CustomPrincipal(new GenericIdentity("kimxinfo-without-formidentity"), 0);
            //    Context.User = Thread.CurrentPrincipal;
            //}
        }
Esempio n. 3
0
        static void CustomCultureMultiThreadRandowLab()
        {
            System.Console.WriteLine("CustomCultureMultiThreadRandowLab-Start");
            Random rnd   = new Random();
            var    tasks = new List <Task <int> >();

            for (int ctr = 1; ctr <= 20; ctr++)
            {
                tasks.Add(Task.Factory.StartNew(
                              () =>
                {
                    int s = 0;
                    for (int n = 0; n <= 999; n++)
                    {
                        lock (rndLock)
                        {
                            s = rnd.Next(24);
                            System.Threading.Thread.Sleep(1 * s);
                            CustomCultureInfo.Create("en", s);
                        }
                    }
                    return(CustomCultureInfo._dict.Count);
                }));
            }
            Task.WaitAll(tasks.ToArray());
            System.Console.WriteLine(CustomCultureInfo._dict.Count);
            System.Console.WriteLine("CustomCultureMultiThreadRandowLab-End");
        }
Esempio n. 4
0
        public MessengerBuddy(uint uint_1, string string_4, string string_5, string string_6, string string_7)
        {
            this.uint_0   = uint_1;
            this.string_0 = string_4;
            this.string_1 = string_5;
            this.string_2 = string_6;
            double timestamp;

            if (double.TryParse(string_7, NumberStyles.Any, CustomCultureInfo.GetCustomCultureInfo(), out timestamp))
            {
                this.string_3 = GoldTree.TimestampToDate(timestamp).ToString();
            }
            else
            {
                this.string_3 = GoldTree.TimestampToDate(GoldTree.GetUnixTimestamp()).ToString();
            }
            this.bool_0 = false;
        }
Esempio n. 5
0
        public MessengerBuddy(uint mUserId, string mUsername, string mLook, string mMotto, string mLastOnline, int mRelation)
        {
            this.UserId   = mUserId;
            this.Username = mUsername;
            this.Look     = mLook;
            this.Motto    = mMotto;
            double timestamp;

            if (double.TryParse(mLastOnline, NumberStyles.Any, CustomCultureInfo.GetCustomCultureInfo(), out timestamp))
            {
                this.LastOnline = Essential.TimestampToDate(timestamp).ToString();
            }
            else
            {
                this.LastOnline = Essential.TimestampToDate(Essential.GetUnixTimestamp()).ToString();
            }
            this.bool_0             = false;
            this.RelationshipStatus = mRelation;
        }
Esempio n. 6
0
        static void CustomCurrentCultureLab()
        {
            Thread.CurrentThread.CurrentCulture = CustomCultureInfo.Create(Thread.CurrentThread.CurrentCulture.Name, 0);
            System.Console.WriteLine($"UTC :          {DateTimeExtensions.GetCustomCultureDateTime()}");

            Thread.CurrentThread.CurrentCulture = CustomCultureInfo.Create(Thread.CurrentThread.CurrentCulture.Name, 2);
            System.Console.WriteLine($"South Africa : {DateTimeExtensions.GetCustomCultureDateTime()}");

            Thread.CurrentThread.CurrentCulture = CustomCultureInfo.Create(Thread.CurrentThread.CurrentCulture.Name, 4);
            System.Console.WriteLine($"Dubai :        {DateTimeExtensions.GetCustomCultureDateTime()}");

            Thread.CurrentThread.CurrentCulture = CustomCultureInfo.Create(Thread.CurrentThread.CurrentCulture.Name, 8);
            System.Console.WriteLine($"Taiwan :       {DateTimeExtensions.GetCustomCultureDateTime()}");

            ShowCultureFormat(new CultureInfo("en"));
            ShowCultureFormat(new CultureInfo("en-US"));
            ShowCultureFormat(new CultureInfo("en-ZA"));
            ShowCultureFormat(new CultureInfo("ar-AE"));//Arabic (United Arab Emirates) (ar-AE) - 杜拜
            //foreach (var item in CultureInfo.GetCultures(CultureTypes.SpecificCultures).Where(o => o.Name.StartsWith("ar-")))
            //{
            //    System.Console.WriteLine($"{item.Name} : {item.DisplayName} : {item.EnglishName}");
            //}
        }
        public void Handle(GameClient session, ClientMessage message)
        {
            ServerMessage response = new ServerMessage(950u);

            session.GetHabbo().GetUserDataFactory().UpdateFriendStream();

            int streamCount = session.GetHabbo().GetUserDataFactory().GetFriendStream().Rows.Count;

            response.AppendInt32(streamCount);

            DataTable dataTable_ = session.GetHabbo().GetUserDataFactory().GetFriendStream();

            foreach (DataRow row in dataTable_.Rows)
            {
                int type = (int)row["type"];

                if (type >= 0 && type <= 4)
                {
                    uint id = (uint)row["id"];

                    int  likes   = 0;
                    bool canlike = false;

                    using (DatabaseClient @class = GoldTree.GetDatabase().GetClient())
                    {
                        likes = @class.ReadInt32("SELECT COUNT(friend_stream_id) FROM friend_stream_likes WHERE friend_stream_id = '" + id + "' LIMIT 1");

                        DataRow datarow = @class.ReadDataRow("SELECT id FROM friend_stream_likes WHERE friend_stream_id = '" + id + "' AND userid = '" + session.GetHabbo().Id + "' LIMIT 1");

                        if (datarow == null)
                        {
                            canlike = true;
                        }
                        else
                        {
                            canlike = false;
                        }
                    }

                    uint   userid   = (uint)row["userid"];
                    string username = GoldTree.GetGame().GetClientManager().GetNameById(userid);

                    string gender = (string)row["gender"].ToString().ToLower();
                    string look   = (string)row["look"];

                    int time = (int)((GoldTree.GetUnixTimestamp() - (double)row["time"]) / 60);

                    string data = (string)row["data"];

                    response.AppendUInt(id);
                    response.AppendInt32(type);

                    response.AppendStringWithBreak(userid.ToString());
                    response.AppendStringWithBreak(username);

                    response.AppendStringWithBreak(gender);
                    response.AppendStringWithBreak("http://goldtreehotel.net/r63/c_images/friendstream/head.gif?figure=" + look);
                    //response.AppendStringWithBreak("http://goldtreehotel.net/r63/c_images/album1584/ADM.gif");

                    response.AppendInt32(time);

                    if (type == 0)
                    {
                        string data_extra = (string)row["data_extra"];

                        uint friend_id = uint.Parse(data, CustomCultureInfo.GetCustomCultureInfo());

                        if (session.GetHabbo().Id == friend_id || session.GetHabbo().GetMessenger().UserInFriends(friend_id))
                        {
                            response.AppendInt32(0);
                        }
                        else
                        {
                            response.AppendInt32(5);
                        }
                        response.AppendInt32(likes);
                        response.AppendBoolean(canlike);
                        response.AppendStringWithBreak(data);
                        response.AppendStringWithBreak(data_extra);
                    }
                    else if (type == 1)
                    {
                        response.AppendInt32(2);
                        response.AppendInt32(likes);
                        response.AppendBoolean(canlike);

                        uint roomId;

                        RoomData RoomData;

                        if (uint.TryParse(data, out roomId))
                        {
                            RoomData = GoldTree.GetGame().GetRoomManager().method_12(roomId);
                        }
                        else
                        {
                            RoomData = GoldTree.GetGame().GetRoomManager().method_12(0);
                        }

                        if (RoomData != null)
                        {
                            response.AppendStringWithBreak(RoomData.Id.ToString()); //data
                            response.AppendStringWithBreak(RoomData.Name);          //extra data
                        }
                        else
                        {
                            response.AppendStringWithBreak("");
                            response.AppendStringWithBreak("Room deleted");
                        }
                    }
                    else if (type == 2)
                    {
                        response.AppendInt32(3);
                        response.AppendInt32(likes);
                        response.AppendBoolean(canlike);
                        response.AppendStringWithBreak(data);
                    }
                    else if (type == 3)
                    {
                        response.AppendInt32(4);
                        response.AppendInt32(likes);
                        response.AppendBoolean(canlike);
                        response.AppendStringWithBreak(data);
                    }
                }
            }

            session.SendMessage(response);
        }