/// <summary> /// Updates avatar represented by control's Value. /// </summary> private void UpdateAvatar() { // Try to get avatar info AvatarInfo avatar = null; if (avatarID > 0) { avatar = AvatarInfoProvider.GetAvatarInfoWithoutBinary(avatarID); } if (rdbMode.SelectedValue == AvatarInfoProvider.AVATAR) { // If some new picture was uploaded if (IsNewPictureUploaded()) { avatar = StoreUploadedPicture(avatarID, EditedUser); } // If some predefined avatar was selected else if (!string.IsNullOrEmpty(hiddenAvatarGuid.Value)) { DeleteCustomAvatar(avatar); Guid guid = ValidationHelper.GetGuid(hiddenAvatarGuid.Value, Guid.NewGuid()); avatar = AvatarInfoProvider.GetAvatarInfoWithoutBinary(guid); hiddenAvatarGuid.Value = String.Empty; } } if (ValidationHelper.GetBoolean(hiddenDeleteAvatar.Value, false)) { // Avatar has to be deleted DeleteCustomAvatar(avatar); hiddenDeleteAvatar.Value = String.Empty; avatar = null; } // Update avatar id avatarID = (avatar != null) ? avatar.AvatarID : 0; if (EditedUser != null) { // Save avatar type for user given by basic form EditedUser.UserSettings.UserAvatarType = rdbMode.SelectedValue; EditedUser.UserAvatarID = avatarID; UserInfoProvider.SetUserInfo(EditedUser); ShowUserAvatar(EditedUser); } else if (avatarID > 0) { ShowAvatar(avatarID); } else { HideAvatar(); } }
public WeaponsEngineer() : base() { Types.Add(UpgradeType.Crew); Name = "Weapons Engineer"; Cost = 3; Avatar = new AvatarInfo(Faction.None, new Vector2(60, 1)); UpgradeAbilities.Add(new Abilities.WeaponsEngineerAbility()); }
public Rage() : base() { Types.Add(UpgradeType.Elite); Name = "Rage"; Cost = 1; UpgradeAbilities.Add(new RageAbility()); Avatar = new AvatarInfo(Faction.Scum, new Vector2(53, 1)); }
public VeteranInstincts() : base() { Types.Add(UpgradeType.Elite); Name = "Veteran Instincts"; Cost = 1; Avatar = new AvatarInfo(Faction.Imperial, new Vector2(56, 0)); UpgradeAbilities.Add(new VeteranInstinctsAbility()); }
public AttanniMindlink() : base() { Types.Add(UpgradeType.Elite); Name = "Attanni Mindlink"; Cost = 1; Avatar = new AvatarInfo(Faction.Scum, new Vector3(70, 1)); UpgradeAbilities.Add(new AttanniMindlinkAbility()); }
public K4SecurityDroid() : base() { Types.Add(UpgradeType.Crew); Name = "K4 Security Droid"; Cost = 3; Avatar = new AvatarInfo(Faction.Scum, new Vector2(65, 5)); UpgradeAbilities.Add(new K4SecurityDroidAbility()); }
public Deadeye() : base() { Types.Add(UpgradeType.Elite); Name = "Deadeye"; Cost = 1; Avatar = new AvatarInfo(Faction.Rebel, new Vector2(38, 3)); UpgradeAbilities.Add(new DeadeyeAbility()); }
public Bombardier() : base() { Types.Add(UpgradeType.Crew); Name = "Bombardier"; Cost = 1; Avatar = new AvatarInfo(Faction.None, new Vector2(23, 1)); UpgradeAbilities.Add(new BombardierAbility()); }
public FleetOfficer() : base() { IsHidden = true; Types.Add(UpgradeType.Crew); Name = "Fleet Officer"; Cost = 3; Avatar = new AvatarInfo(Faction.Imperial, new Vector2(19, 1)); }
public FlightInstructor() : base() { Types.Add(UpgradeType.Crew); Name = "Flight Instructor"; Cost = 4; Avatar = new AvatarInfo(Faction.Imperial, new Vector2(32, 1)); UpgradeAbilities.Add(new FlightInstructorAbility()); }
public OutlawTech() : base() { Types.Add(UpgradeType.Crew); Name = "Outlaw Tech"; Cost = 2; Avatar = new AvatarInfo(Faction.Scum, new Vector2(50, 4)); UpgradeAbilities.Add(new OutlawTechAbility()); }
/// <summary> /// Deletes avatar. Called when the "Delete avatar" button is pressed. /// Expects the CreateAvatar method to be run first. /// </summary> private bool DeleteAvatar() { // Get the avatar AvatarInfo deleteAvatar = AvatarInfoProvider.GetAvatarInfo("MyNewAvatar"); // Delete the avatar AvatarInfoProvider.DeleteAvatarInfo(deleteAvatar); return(deleteAvatar != null); }
public AdrenalineRush() : base() { Types.Add(UpgradeType.Elite); Name = "Adrenaline Rush"; Cost = 1; Avatar = new AvatarInfo(Faction.Imperial, new Vector2(37, 1)); UpgradeAbilities.Add(new AdrenalineRushAbility()); }
public ReconSpecialist() : base() { Types.Add(UpgradeType.Crew); Name = "Recon Specialist"; Cost = 3; Avatar = new AvatarInfo(Faction.None, new Vector2(42, 3)); UpgradeAbilities.Add(new ReconSpecialistAbility()); }
public Gunner() : base() { Types.Add(UpgradeType.Crew); Name = "Gunner"; Cost = 5; Avatar = new AvatarInfo(Faction.None, new Vector2(61, 1)); UpgradeAbilities.Add(new GunnerAbility()); }
public Navigator() : base() { Types.Add(UpgradeType.Crew); Name = "Navigator"; Cost = 3; Avatar = new AvatarInfo(Faction.Imperial, new Vector2(10, 1)); UpgradeAbilities.Add(new NavigatorAbility()); }
public MercenaryCopilot() : base() { Types.Add(UpgradeType.Crew); Name = "Mercenary Copilot"; Cost = 2; Avatar = new AvatarInfo(Faction.Scum, new Vector2(46, 2)); UpgradeAbilities.Add(new MercenaryCopilotAbility()); }
public Fearlessness() : base() { Types.Add(UpgradeType.Elite); Name = "Fearlessness"; Cost = 1; Avatar = new AvatarInfo(Faction.Scum, new Vector2(80, 0)); UpgradeAbilities.Add(new FearlessnessAbility()); }
public FleetOfficer() : base() { UpgradeInfo = new UpgradeCardInfo( "Fleet Officer", UpgradeType.Crew, cost: 3 ); Avatar = new AvatarInfo(Faction.Imperial, new Vector2(19, 1)); }
public void Choose(AvatarInfo choose) { if (avatar_choose != null) { avatar_choose.NotChoose(); } avatar_choose = choose; image_choose = choose.image_avatar.sprite; }
public CrackShot() : base() { Types.Add(UpgradeType.Elite); Name = "Crack Shot"; Cost = 1; Avatar = new AvatarInfo(Faction.Scum, new Vector2(43, 1)); UpgradeAbilities.Add(new CrackShotAbility()); }
public override void InitSync(AvatarInfo info) { if (info != null) { var gc = GCPlayerCmd.CreateBuilder(); gc.AvatarInfo = info; var cmd = gc.Build(); NetworkAttribute(cmd); } }
public Bistan() : base() { Types.Add(UpgradeType.Crew); Name = "Bistan"; Cost = 2; isUnique = true; Avatar = new AvatarInfo(Faction.Rebel, new Vector2(43, 6)); UpgradeAbilities.Add(new BistanAbility()); }
public AdrenalineRush() : base() { UpgradeInfo = new UpgradeCardInfo( "Adrenaline Rush", UpgradeType.Talent, cost: 1, abilityType: typeof(Abilities.FirstEdition.AdrenalineRushAbility) ); Avatar = new AvatarInfo(Faction.Imperial, new Vector2(37, 1)); }
public CrackShot() : base() { UpgradeInfo = new UpgradeCardInfo( "Crack Shot", UpgradeType.Talent, cost: 1, abilityType: typeof(Abilities.FirstEdition.CrackShotAbility) ); Avatar = new AvatarInfo(Faction.Scum, new Vector2(43, 1)); }
public WeaponsEngineer() : base() { UpgradeInfo = new UpgradeCardInfo( "Weapons Engineer", UpgradeType.Crew, cost: 3, abilityType: typeof(Abilities.FirstEdition.WeaponsEngineerAbility) ); Avatar = new AvatarInfo(Faction.None, new Vector2(60, 1)); }
public Rage() : base() { UpgradeInfo = new UpgradeCardInfo( "Rage", UpgradeType.Talent, cost: 1, abilityType: typeof(Abilities.FirstEdition.RageAbility) ); Avatar = new AvatarInfo(Faction.Scum, new Vector2(53, 1)); }
public MercenaryCopilot() : base() { UpgradeInfo = new UpgradeCardInfo( "Mercenary Copilot", UpgradeType.Crew, cost: 2, abilityType: typeof(Abilities.FirstEdition.MercenaryCopilotAbility) ); Avatar = new AvatarInfo(Faction.Scum, new Vector2(46, 2)); }
public VeteranInstincts() : base() { UpgradeInfo = new UpgradeCardInfo( "Veteran Instincts", UpgradeType.Talent, cost: 1, abilityType: typeof(Abilities.FirstEdition.VeteranInstinctsAbility) ); Avatar = new AvatarInfo(Faction.Imperial, new Vector2(56, 0)); }
public LeeboCrew() : base() { Types.Add(UpgradeType.Crew); Name = "Leebo"; Cost = 2; isUnique = true; Avatar = new AvatarInfo(Faction.Rebel, new Vector2(31, 1)); UpgradeAbilities.Add(new LeeboAbility()); }
public override bool init() { base.init(); mTeleportTime = -teleportCD + 1.5f; Transform parent = cachedTransform.parent; GameObject poolObj = GenericHelper.FindChildByName(parent.gameObject, "Pool", true); GameObject avatarObj = GenericHelper.FindChildByName(poolObj, "Avatar_Alice", true); avatarInfo = new AvatarInfo(avatarObj); return true; }
/// <summary> /// Creates avatar. Called when the "Create avatar" button is pressed. /// </summary> private bool CreateAvatar() { // Create new avatar object AvatarInfo newAvatar = new AvatarInfo(Server.MapPath("~\\CMSAPIExamples\\Code\\Community\\Avatars\\Files\\avatar_man.jpg")); // Set the properties newAvatar.AvatarName = "MyNewAvatar"; newAvatar.AvatarType = AvatarInfoProvider.GetAvatarTypeString(AvatarTypeEnum.All); newAvatar.AvatarIsCustom = false; // Save the avatar AvatarInfoProvider.SetAvatarInfo(newAvatar); return true; }
/// <summary> /// Constructor. /// </summary> public UserInfo() { AvatarUri = new AvatarInfo(); }
/// <summary> /// Creates a new avatar object. /// </summary> /// <param name="ui"> Username of given user is used for avatar name.</param> private AvatarInfo CreateAvatar(UserInfo ui = null) { AvatarInfo ai = new AvatarInfo(uplFilePicture.PostedFile, SettingsKeyInfoProvider.GetIntValue(SiteContext.CurrentSiteName + ".CMSAvatarWidth"), SettingsKeyInfoProvider.GetIntValue(SiteContext.CurrentSiteName + ".CMSAvatarHeight"), SettingsKeyInfoProvider.GetIntValue(SiteContext.CurrentSiteName + ".CMSAvatarMaxSideSize")); if ((MembershipContext.AuthenticatedUser != null) && AuthenticationHelper.IsAuthenticated() && PortalContext.ViewMode.IsLiveSite()) { ai.AvatarName = AvatarInfoProvider.GetUniqueAvatarName(GetString("avat.custom") + " " + ((ui != null) ? ui.UserName : MembershipContext.AuthenticatedUser.UserName)); } else { ai.AvatarName = AvatarInfoProvider.GetUniqueAvatarName(ai.AvatarFileName.Substring(0, ai.AvatarFileName.LastIndexOfCSafe("."))); } ai.AvatarIsCustom = true; ai.AvatarGUID = Guid.NewGuid(); ai.AvatarType = AvatarTypeEnum.User.ToString(); return ai; }
/// <summary> /// Deletes given custom avatar. Does nothing when given avatar is not custom. /// </summary> /// <param name="avatar">Avatar to delete.</param> private static void DeleteCustomAvatar(AvatarInfo avatar) { // Delete avatar if some exists and is custom if ((avatar != null) && (avatar.AvatarIsCustom)) { AvatarInfoProvider.DeleteAvatarFile(avatar.AvatarGUID.ToString(), avatar.AvatarFileExtension, false, false); AvatarInfoProvider.DeleteAvatarInfo(avatar); } }
/// <summary> /// Save information about an avatar's appearance /// </summary> /// <param name="avatarID"></param> /// <param name="isTrial"></param> /// <param name="defaultTexture"></param> /// <param name="faceTextures"></param> /// <param name="visualParams"></param> void Avatars_OnAvatarAppearance( object sender, AvatarAppearanceEventArgs e) { List<byte> visualParams = e.VisualParams; // Create an entry in the avatar information dictionary. if (visualParams.Count > 32) { AvatarInfo info = new AvatarInfo(); info.gender = visualParams[31]; info.height = visualParams[32]; // We are only getting 218 parameters. // info.leglen = visualParams[691]; information[e.AvatarID] = info; // Check if a wrong voice has already been assigned, and reassign // if necessary. Talker.voices.CheckGender(e.AvatarID, info); } }
/// <summary> /// Updates picture of current user. /// </summary> /// <param name="ui">User info object</param> public void UpdateUserPicture(UserInfo ui) { AvatarInfo ai = null; if (ui != null) { // Check if some avatar should be deleted if (hiddenDeleteAvatar.Value == "true") { DeleteOldUserPicture(ui); } // If some file was uploaded if ((uplFilePicture.PostedFile != null) && (uplFilePicture.PostedFile.ContentLength > 0) && ImageHelper.IsImage(Path.GetExtension(uplFilePicture.PostedFile.FileName))) { // Check if this user has some avatar and if so check if is custom ai = AvatarInfoProvider.GetAvatarInfoWithoutBinary(ui.UserAvatarID); bool isCustom = false; if ((ai != null) && ai.AvatarIsCustom) { isCustom = true; } if (isCustom) { AvatarInfoProvider.UploadAvatar(ai, uplFilePicture.PostedFile, SettingsKeyProvider.GetIntValue(CMSContext.CurrentSiteName + ".CMSAvatarWidth"), SettingsKeyProvider.GetIntValue(CMSContext.CurrentSiteName + ".CMSAvatarHeight"), SettingsKeyProvider.GetIntValue(CMSContext.CurrentSiteName + ".CMSAvatarMaxSideSize")); } // Old avatar is not custom, so crate new custom avatar else { ai = new AvatarInfo(uplFilePicture.PostedFile, SettingsKeyProvider.GetIntValue(CMSContext.CurrentSiteName + ".CMSAvatarWidth"), SettingsKeyProvider.GetIntValue(CMSContext.CurrentSiteName + ".CMSAvatarHeight"), SettingsKeyProvider.GetIntValue(CMSContext.CurrentSiteName + ".CMSAvatarMaxSideSize")); ai.AvatarName = AvatarInfoProvider.GetUniqueAvatarName(GetString("avat.custom") + " " + ui.UserName); ai.AvatarType = AvatarTypeEnum.User.ToString(); ai.AvatarIsCustom = true; ai.AvatarGUID = Guid.NewGuid(); } AvatarInfoProvider.SetAvatarInfo(ai); // Update user info ui.UserAvatarID = ai.AvatarID; UserInfoProvider.SetUserInfo(ui); plcImageActions.Visible = true; } // If predefined was chosen else if (!string.IsNullOrEmpty(hiddenAvatarGuid.Value)) { // Delete old picture DeleteOldUserPicture(ui); Guid guid = ValidationHelper.GetGuid(hiddenAvatarGuid.Value, Guid.NewGuid()); ai = AvatarInfoProvider.GetAvatarInfoWithoutBinary(guid); // Update user info if (ai != null) { ui.UserAvatarID = ai.AvatarID; UserInfoProvider.SetUserInfo(ui); } plcImageActions.Visible = true; } else { plcImageActions.Visible = false; } } }
/// <summary> /// Clears default user avatars which is assigned to avatarinfo. /// </summary> private static void ClearDefaultUserAvatars(AvatarInfo ai) { if (ai.DefaultUserAvatar) { AvatarInfoProvider.ClearDefaultAvatar(DefaultAvatarTypeEnum.User); } if (ai.DefaultMaleUserAvatar) { AvatarInfoProvider.ClearDefaultAvatar(DefaultAvatarTypeEnum.Male); } if (ai.DefaultFemaleUserAvatar) { AvatarInfoProvider.ClearDefaultAvatar(DefaultAvatarTypeEnum.Female); } }
protected void Page_Load(object sender, EventArgs e) { imgAvatar.Visible = false; avatarId = QueryHelper.GetInteger("avatarid", 0); if (QueryHelper.GetInteger("saved", 0) == 1) { lblInfo.Visible = true; lblInfo.Text = GetString("general.changessaved"); } // new avatar if (avatarId == 0) { CurrentMaster.Title.TitleText = GetString("avat.newavatar"); CurrentMaster.Title.TitleImage = GetImageUrl("Objects/CMS_Avatar/new.png"); drpAvatarType.AutoPostBack = false; } // Edit avatar else { CurrentMaster.Title.TitleText = GetString("avat.properties"); CurrentMaster.Title.TitleImage = GetImageUrl("Objects/CMS_Avatar/object.png"); drpAvatarType.AutoPostBack = true; } CurrentMaster.Title.HelpTopicName = "avatars_edit"; CurrentMaster.Title.HelpName = "helpTopic"; // initializes breadcrumbs string[,] pageTitleTabs = new string[2, 3]; pageTitleTabs[0, 0] = GetString("avat.title"); pageTitleTabs[0, 1] = "~/CMSModules/Avatars/Avatar_List.aspx"; pageTitleTabs[0, 2] = ""; pageTitleTabs[1, 0] = GetString("avat.newavatar"); pageTitleTabs[1, 1] = ""; pageTitleTabs[1, 2] = ""; lblSharedInfo.Text = String.Format(GetString("avat.convertinfo") + "<br /><br />", "<a href=\"javascript:" + Page.ClientScript.GetPostBackEventReference(this, "shared") + "\">" + GetString("General.clickhere") + "</a>"); valAvatarName.ErrorMessage = GetString("avat.requiresname"); btnOk.Text = GetString("general.ok"); if (!RequestHelper.IsPostBack()) { // Fill the drop down list DataHelper.FillListControlWithEnum(typeof(AvatarTypeEnum), drpAvatarType, "avat.type", AvatarInfoProvider.GetAvatarTypeString); } if (avatarId > 0) { plcImage.Visible = true; ai = AvatarInfoProvider.GetAvatarInfoWithoutBinary(avatarId); if (ai != null) { if (ai.AvatarIsCustom) { lblSharedInfo.Visible = true; } pageTitleTabs[1, 0] = HTMLHelper.HTMLEncode(!string.IsNullOrEmpty(ai.AvatarName) ? ai.AvatarName : ai.AvatarFileName.Substring(0, ai.AvatarFileName.LastIndexOf("."))); // Load avatars data if (!RequestHelper.IsPostBack()) { txtAvatarName.Text = ai.AvatarName; drpAvatarType.SelectedValue = ai.AvatarType.ToLower(); chkDefaultUserAvatar.Checked = ai.DefaultUserAvatar; chkDefaultMaleUserAvatar.Checked = ai.DefaultMaleUserAvatar; chkDefaultFemaleUserAvatar.Checked = ai.DefaultFemaleUserAvatar; chkDefaultGroupAvatar.Checked = ai.DefaultGroupAvatar; imgAvatar.AlternateText = HTMLHelper.HTMLEncode(ai.AvatarName); } imgAvatar.Visible = true; imgAvatar.ImageUrl = ResolveUrl("~/CMSModules/Avatars/CMSPages/GetAvatar.aspx?maxsidesize=250&avatarguid=" + ai.AvatarGUID); // Display default avatar options, only for global avatars if (!ai.AvatarIsCustom) { switch (AvatarInfoProvider.GetAvatarTypeEnum(drpAvatarType.SelectedValue)) { case AvatarTypeEnum.User: plcDefaultUserAvatar.Visible = true; break; case AvatarTypeEnum.Group: plcDefaultGroupAvatar.Visible = true; break; case AvatarTypeEnum.All: plcDefaultGroupAvatar.Visible = true; plcDefaultUserAvatar.Visible = true; break; } } } } // Set up page title control CurrentMaster.Title.Breadcrumbs = pageTitleTabs; }
/// <summary> /// Upload avatars defined in dataset. /// </summary> public static void UploadAvatars() { try { if (!DataHelper.DataSourceIsEmpty(ds)) { foreach (DataRow dr in ds.Tables[0].Rows) { string userPicture = ValidationHelper.GetString(dr["UserPicture"], string.Empty); int userId = ValidationHelper.GetInteger(dr["UserSettingsUserID"], 0); if ((userPicture.Contains("/")) && (userId > 0)) { string[] values = userPicture.Split('/'); if ((values != null) && (values.Length == 2)) { string realFileName = values[0]; string fileName = values[0]; string path = mAvatarsPath + realFileName; if (File.Exists(path)) { AvatarInfo ai = new AvatarInfo(path); ai.AvatarIsCustom = true; ai.AvatarType = "user"; AvatarInfoProvider.SetAvatarInfo(ai); UserSettingsInfo ui = new UserSettingsInfo(dr); ui.UserAvatarID = ai.AvatarID; UserSettingsInfoProvider.SetUserSettingsInfo(ui); } } } } } } catch (Exception ex) { EventLogProvider evp = new EventLogProvider(); evp.LogEvent("Avatar upgrade", "Update", ex); } }
public override bool init() { base.init(); _lastAvatarTime = -avatarCD; Transform parent = cachedTransform.parent; GameObject poolObj = GenericHelper.FindChildByName(parent.gameObject, "Pool", true); GameObject avatarRoot = GenericHelper.FindChildByName(poolObj, "Avatar_DK", true); Transform trans = avatarRoot.transform; Transform t; for (int i = 0, max = trans.childCount; i < max; ++i) { t = trans.GetChild(i); avatarPool[i] = new AvatarInfo(t.gameObject); } return true; }
protected void Page_Load(object sender, EventArgs e) { imgAvatar.Visible = false; avatarId = QueryHelper.GetInteger("avatarid", 0); if ((QueryHelper.GetInteger("saved", 0) == 1) && !URLHelper.IsPostback()) { ShowChangesSaved(); } // new avatar if (avatarId == 0) { PageTitle.TitleText = GetString("avat.newavatar"); drpAvatarType.AutoPostBack = false; } // Edit avatar else { PageTitle.TitleText = GetString("avat.properties"); drpAvatarType.AutoPostBack = true; } // initializes breadcrumbs BreadcrumbItem breadCrumb = new BreadcrumbItem() { Text = GetString("avat.newavatar"), RedirectUrl = "", }; lblSharedInfo.Text = String.Format(GetString("avat.convertinfo") + "<br /><br />", "<a href=\"javascript:" + Page.ClientScript.GetPostBackEventReference(this, "shared") + "\">" + GetString("General.clickhere") + "</a>"); valAvatarName.ErrorMessage = GetString("avat.requiresname"); if (!RequestHelper.IsPostBack()) { // Fill the drop down list ControlsHelper.FillListControlWithEnum<AvatarTypeEnum>(drpAvatarType, "avat.type", useStringRepresentation: true); } if (avatarId > 0) { plcImage.Visible = true; ai = AvatarInfoProvider.GetAvatarInfoWithoutBinary(avatarId); // Set edited object EditedObject = ai; if (ai != null) { if (ai.AvatarIsCustom) { lblSharedInfo.Visible = true; } breadCrumb.Text = HTMLHelper.HTMLEncode(!string.IsNullOrEmpty(ai.AvatarName) ? ai.AvatarName : ai.AvatarFileName.Substring(0, ai.AvatarFileName.LastIndexOfCSafe("."))); // Load avatars data if (!RequestHelper.IsPostBack()) { txtAvatarName.Text = ai.AvatarName; drpAvatarType.SelectedValue = ai.AvatarType.ToLowerCSafe(); chkDefaultUserAvatar.Checked = ai.DefaultUserAvatar; chkDefaultMaleUserAvatar.Checked = ai.DefaultMaleUserAvatar; chkDefaultFemaleUserAvatar.Checked = ai.DefaultFemaleUserAvatar; chkDefaultGroupAvatar.Checked = ai.DefaultGroupAvatar; imgAvatar.AlternateText = HTMLHelper.HTMLEncode(ai.AvatarName); } imgAvatar.Visible = true; imgAvatar.ImageUrl = ResolveUrl("~/CMSModules/Avatars/CMSPages/GetAvatar.aspx?maxsidesize=250&avatarguid=" + ai.AvatarGUID); // Display default avatar options, only for global avatars if (!ai.AvatarIsCustom) { switch (AvatarInfoProvider.GetAvatarTypeEnum(drpAvatarType.SelectedValue)) { case AvatarTypeEnum.User: plcDefaultUserAvatar.Visible = true; break; case AvatarTypeEnum.Group: plcDefaultGroupAvatar.Visible = true; break; case AvatarTypeEnum.All: plcDefaultGroupAvatar.Visible = true; plcDefaultUserAvatar.Visible = true; break; } } } } PageBreadcrumbs.Items.Add(new BreadcrumbItem() { Text = GetString("avat.title"), RedirectUrl = ResolveUrl("~/CMSModules/Avatars/Avatar_List.aspx"), }); PageBreadcrumbs.Items.Add(breadCrumb); }
/// <summary> /// Returns the output data dependency based on the given attachment record. /// </summary> /// <param name="ai">Avatar object</param> protected CMSCacheDependency GetOutputDataDependency(AvatarInfo ai) { if (ai == null) { return null; } return CacheHelper.GetCacheDependency(ai.GetDependencyCacheKeys()); }
/// <summary> /// Clears default group avatar which is assigned to avatarinfo. /// </summary> private static void ClearDefaultGroupAvatar(AvatarInfo ai) { if (ai.DefaultGroupAvatar) { AvatarInfoProvider.ClearDefaultAvatar(DefaultAvatarTypeEnum.Group); } }
/// <summary> /// Creates new avatar object /// </summary> private AvatarInfo CreateNewAvatar() { AvatarInfo ai = new AvatarInfo(uplFilePicture.PostedFile, SettingsKeyInfoProvider.GetIntValue(site.SiteName + ".CMSGroupAvatarWidth"), SettingsKeyInfoProvider.GetIntValue(site.SiteName + ".CMSGroupAvatarHeight"), SettingsKeyInfoProvider.GetIntValue(site.SiteName + ".CMSGroupAvatarMaxSideSize")); if (CommunityContext.CurrentGroup != null) { ai.AvatarName = AvatarInfoProvider.GetUniqueAvatarName(GetString("avat.custom") + " " + CommunityContext.CurrentGroup.GroupName); } else { ai.AvatarName = AvatarInfoProvider.GetUniqueAvatarName(ai.AvatarFileName.Substring(0, ai.AvatarFileName.LastIndexOfCSafe("."))); } ai.AvatarType = AvatarTypeEnum.Group.ToString(); ai.AvatarIsCustom = true; ai.AvatarGUID = Guid.NewGuid(); return ai; }
/// <summary> /// OK click event handler. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { if ((uploadAvatar.PostedFile == null) && (ai == null)) { ShowError(GetString("avat.fileinputerror")); } else { SiteInfo site = SiteContext.CurrentSite; int width = 0; int height = 0; int sidesize = 0; // Get resize values if (drpAvatarType.SelectedValue != "all") { // Get right settings key string siteName = ((site != null) ? (site.SiteName + ".") : ""); string prefix = "CMSAvatar"; if (drpAvatarType.SelectedValue == "group") { prefix = "CMSGroupAvatar"; } width = SettingsKeyInfoProvider.GetIntValue(siteName + prefix + "Width"); height = SettingsKeyInfoProvider.GetIntValue(siteName + prefix + "Height"); sidesize = SettingsKeyInfoProvider.GetIntValue(siteName + prefix + "MaxSideSize"); } // Check if avatar name is unique string newAvatarName = txtAvatarName.Text.Trim(); AvatarInfo avatarWithSameName = AvatarInfoProvider.GetAvatarInfoWithoutBinary(newAvatarName); if (avatarWithSameName != null) { if (ai != null) { // Check unique avatar name of existing avatar if (avatarWithSameName.AvatarID != ai.AvatarID) { ShowError(GetString("avat.uniqueavatarname")); return; } } // Check unique avatar name of new avatar else { ShowError(GetString("avat.uniqueavatarname")); return; } } // Process form in these cases: // 1 - creating new avatar and uploaded file is not empty and it is image file // 2 - updating existing avatar and not uploading new image file // 3 - updating existing avatar and uploading image file if (((ai == null) && (uploadAvatar.PostedFile != null) && (uploadAvatar.PostedFile.ContentLength > 0) && (ImageHelper.IsImage(Path.GetExtension(uploadAvatar.PostedFile.FileName)))) || ((ai != null) && ((uploadAvatar.PostedFile == null) || (uploadAvatar.PostedFile.ContentLength == 0))) || ((ai != null) && (uploadAvatar.PostedFile != null) && (uploadAvatar.PostedFile.ContentLength > 0) && (ImageHelper.IsImage(Path.GetExtension(uploadAvatar.PostedFile.FileName))))) { if (ai == null) { switch (drpAvatarType.SelectedValue) { case "user": ai = new AvatarInfo(uploadAvatar.PostedFile, width, height, sidesize); break; case "group": ai = new AvatarInfo(uploadAvatar.PostedFile, width, height, sidesize); break; case "all": ai = new AvatarInfo(uploadAvatar.PostedFile, 0, 0, 0); break; default: ai = new AvatarInfo(uploadAvatar.PostedFile, 0, 0, 0); break; } ai.AvatarIsCustom = false; ai.AvatarGUID = Guid.NewGuid(); } else if ((uploadAvatar.PostedFile != null) && (uploadAvatar.PostedFile.ContentLength > 0) && (ImageHelper.IsMimeImage(uploadAvatar.PostedFile.ContentType))) { AvatarInfoProvider.DeleteAvatarFile(ai.AvatarGUID.ToString(), ai.AvatarFileExtension, false, false); AvatarInfoProvider.UploadAvatar(ai, uploadAvatar.PostedFile, width, height, sidesize); } // Set new avatar name ai.AvatarName = newAvatarName; imgAvatar.Visible = true; imgAvatar.ImageUrl = ResolveUrl("~/CMSModules/Avatars/CMSPages/GetAvatar.aspx?maxsidesize=250&avatarguid=" + ai.AvatarGUID); // If there was avatar type change clear possible default avatar settings if (ai.AvatarType != drpAvatarType.SelectedValue) { if (drpAvatarType.SelectedValue == "group") { // Clear default user's avatar ClearDefaultUserAvatars(ai); } else if (drpAvatarType.SelectedValue == "user") { //Clear group avatar ClearDefaultGroupAvatar(ai); } // "all" option is doesn't have to clear anything } // Set new type ai.AvatarType = drpAvatarType.SelectedValue; // If user uncheck if (ai.DefaultUserAvatar && (!chkDefaultUserAvatar.Checked || ai.AvatarIsCustom)) { AvatarInfoProvider.ClearDefaultAvatar(DefaultAvatarTypeEnum.User, true); } // If male uncheck if (ai.DefaultMaleUserAvatar && (!chkDefaultMaleUserAvatar.Checked || ai.AvatarIsCustom)) { AvatarInfoProvider.ClearDefaultAvatar(DefaultAvatarTypeEnum.Male, true); } // If female uncheck if (ai.DefaultFemaleUserAvatar && (!chkDefaultFemaleUserAvatar.Checked || ai.AvatarIsCustom)) { AvatarInfoProvider.ClearDefaultAvatar(DefaultAvatarTypeEnum.Female, true); } // If group uncheck if (ai.DefaultGroupAvatar && (!chkDefaultGroupAvatar.Checked || ai.AvatarIsCustom)) { AvatarInfoProvider.ClearDefaultAvatar(DefaultAvatarTypeEnum.Group, true); } // If avatar is not global, can't be default any default avatar if (ai.AvatarIsCustom) { // Set all default avatar options to false ai.DefaultUserAvatar = ai.DefaultMaleUserAvatar = ai.DefaultFemaleUserAvatar = ai.DefaultGroupAvatar = false; } else { // Set new default avatar settings ai.DefaultUserAvatar = chkDefaultUserAvatar.Checked; ai.DefaultMaleUserAvatar = chkDefaultMaleUserAvatar.Checked; ai.DefaultFemaleUserAvatar = chkDefaultFemaleUserAvatar.Checked; ai.DefaultGroupAvatar = chkDefaultGroupAvatar.Checked; // If this avatar is becoming to be new default avatar. Clear the mark from others avatar ClearDefaultUserAvatars(ai); ClearDefaultGroupAvatar(ai); } AvatarInfoProvider.SetAvatarInfo(ai); avatarId = ai.AvatarID; URLHelper.Redirect("Avatar_Edit.aspx?saved=1&avatarid=" + avatarId); } else { // If given file is not valid if ((uploadAvatar.PostedFile != null) && (uploadAvatar.PostedFile.ContentLength > 0) && !ImageHelper.IsImage(Path.GetExtension(uploadAvatar.PostedFile.FileName))) { ShowError(GetString("avat.filenotvalid")); } else { // If posted file is not given ShowError(GetString("avat.fileinputerror")); } } } }
/// <summary> /// Replaces existing avatar by the new one /// </summary> /// <param name="ai">Existing avatar info</param> private void ReplaceExistingAvatar(AvatarInfo ai) { AvatarInfoProvider.UploadAvatar(ai, uplFilePicture.PostedFile, SettingsKeyInfoProvider.GetIntValue(site.SiteName + ".CMSGroupAvatarWidth"), SettingsKeyInfoProvider.GetIntValue(site.SiteName + ".CMSGroupAvatarHeight"), SettingsKeyInfoProvider.GetIntValue(site.SiteName + ".CMSGroupAvatarMaxSideSize")); }
/// <summary> /// Gets and bulk updates avatars. Called when the "Get and bulk update avatars" button is pressed. /// Expects the CreateAvatar method to be run first. /// </summary> private bool GetAndBulkUpdateAvatars() { // Prepare the parameters string where = "AvatarName LIKE N'MyNewAvatar%'"; // Get the data DataSet avatars = AvatarInfoProvider.GetAvatars(where, null); if (!DataHelper.DataSourceIsEmpty(avatars)) { // Loop through the individual items foreach (DataRow avatarDr in avatars.Tables[0].Rows) { // Create object from DataRow AvatarInfo modifyAvatar = new AvatarInfo(avatarDr); // Update the properties modifyAvatar.AvatarName = modifyAvatar.AvatarName.ToUpper(); // Save the changes AvatarInfoProvider.SetAvatarInfo(modifyAvatar); } return true; } return false; }
/// <summary> /// Updates picture of current group. /// </summary> /// <param name="gi">Group info object</param> public void UpdateGroupPicture(GroupInfo gi) { AvatarInfo ai = null; if (gi != null) { // Delete avatar if needed if (hiddenDeleteAvatar.Value == "true") { DeleteOldGroupPicture(gi); } // If some file was uploaded if ((uplFilePicture.PostedFile != null) && (uplFilePicture.PostedFile.ContentLength > 0) && ImageHelper.IsImage(Path.GetExtension(uplFilePicture.PostedFile.FileName))) { // Check if this grou[ has some avatar and if so check if is custom ai = AvatarInfoProvider.GetAvatarInfoWithoutBinary(gi.GroupAvatarID); bool isCustom = false; if ((ai != null) && ai.AvatarIsCustom) { isCustom = true; } if (isCustom) { AvatarInfoProvider.UploadAvatar(ai, uplFilePicture.PostedFile, SettingsKeyProvider.GetIntValue(site.SiteName + ".CMSGroupAvatarWidth"), SettingsKeyProvider.GetIntValue(site.SiteName + ".CMSGroupAvatarHeight"), SettingsKeyProvider.GetIntValue(site.SiteName + ".CMSGroupAvatarMaxSideSize")); } else { // Delete old picture DeleteOldGroupPicture(gi); ai = new AvatarInfo(uplFilePicture.PostedFile, SettingsKeyProvider.GetIntValue(site.SiteName + ".CMSGroupAvatarWidth"), SettingsKeyProvider.GetIntValue(site.SiteName + ".CMSGroupAvatarHeight"), SettingsKeyProvider.GetIntValue(site.SiteName + ".CMSGroupAvatarMaxSideSize")); ai.AvatarName = AvatarInfoProvider.GetUniqueAvatarName(GetString("avat.custom") + " " + gi.GroupName); ai.AvatarType = AvatarTypeEnum.Group.ToString(); ai.AvatarIsCustom = true; ai.AvatarGUID = Guid.NewGuid(); } AvatarInfoProvider.SetAvatarInfo(ai); // Update group info gi.GroupAvatarID = ai.AvatarID; GroupInfoProvider.SetGroupInfo(gi); plcImageActions.Visible = true; } // If predefined was chosen else if (!string.IsNullOrEmpty(hiddenAvatarGuid.Value)) { // Delete old picture DeleteOldGroupPicture(gi); Guid guid = ValidationHelper.GetGuid(hiddenAvatarGuid.Value, Guid.NewGuid()); ai = AvatarInfoProvider.GetAvatarInfoWithoutBinary(guid); // Update group info if (ai != null) { gi.GroupAvatarID = ai.AvatarID; GroupInfoProvider.SetGroupInfo(gi); } plcImageActions.Visible = true; } else { plcImageActions.Visible = false; } } }