Exemple #1
0
        public override void Initialize()
        {
            base.Initialize();
            ImagedEntity entity = GetConcretEntity <ImagedEntity>();

            if (entity != null)
            {
                if (entity.Image_Id.HasValue && entity.Image_Id.Value > 0)
                {
                    int typeId     = entity.GetImageType().Id;
                    int imageValue = entity.Image_Id.Value;
                    if (ApplicationVM.LocalCache.AllImages.ContainsKey(typeId))
                    {
                        if (ApplicationVM.LocalCache.AllImages[typeId].ContainsKey(imageValue))
                        {
                            ImageVM = ApplicationVM.LocalCache.AllImages[typeId][imageValue];
                        }
                    }
                    if (ImageVM == null || !File.Exists(ImageVM.StaticImageFile))
                    {
                        var img = ApplicationVM.ChatClient.GetImage(imageValue);
                        if (img != null)
                        {
                            ImageVM = ApplicationVM.AddImage(img);
                            string dir = Path.GetDirectoryName(ImageVM.StaticImageFile);
                            if (!Directory.Exists(dir))
                            {
                                Directory.CreateDirectory(dir);
                            }
                            File.WriteAllBytes(ImageVM.StaticImageFile, img.TheImage);
                        }
                    }
                }
            }
        }
Exemple #2
0
        public void Register(string account, string pwd, int sex)
        {
            User newUser = ApplicationVM.ChatClient.Register(UserId, account, Utility.GetMD5String(pwd), sex);

            if (newUser != null)
            {
                if (newUser.Image_Id.HasValue)
                {
                    Image img   = ApplicationVM.ChatClient.GetImage(newUser.Image_Id.Value);
                    var   imgVM = ApplicationVM.AddImage(img);
                    File.WriteAllBytes(imgVM.GetAbsoluteFile(true), img.TheImage);
                }
                user         = newUser;
                ErrorMessage = string.Format(Resource.Messages.RegisterSucceeded, user.Id);
            }
            else
            {
                user         = null;
                ErrorMessage = Resource.Messages.RegisterFailed;
            }
        }