public static Property Clone(Property target) { Property prop = null; int id = target.PropertyId; PropertyBag bag = target.Owner; switch (target.PropertyType) { case (int)PropertyKind.WispObject: prop = new WispProperty(target.Name, id, ((WispProperty)target).Value, bag); break; case (int)PropertyKind.WispArray: prop = new WispArrayProperty(target.Name, id, ((WispArrayProperty)target).Value, bag); break; case (int)PropertyKind.Int32: prop = new Int32Property(target.Name, id, ((Int32Property)target).Value, bag); break; case (int)PropertyKind.String: prop = new StringProperty(target.Name, id, ((StringProperty)target).Value, bag); break; case (int)PropertyKind.Bool: prop = new BoolProperty(target.Name, id, ((BoolProperty)target).Value, bag); break; case (int)PropertyKind.Guid: prop = new GuidProperty(target.Name, id, ((GuidProperty)target).Value, bag); break; case (int)PropertyKind.Single: prop = new SingleProperty(target.Name, id, ((SingleProperty)target).Value, bag); break; case (int)PropertyKind.Int32Array: prop = new Int32ArrayProperty(target.Name, id, ((Int32ArrayProperty)target).Value, bag); break; case (int)PropertyKind.StringArray: prop = new StringArrayProperty(target.Name, id, ((StringArrayProperty)target).Value, bag); break; case (int)PropertyKind.DateTime: prop = new DateTimeProperty(target.Name, id, ((DateTimeProperty)target).Value, bag); break; case (int)PropertyKind.GuidArray: prop = new GuidArrayProperty(target.Name, id, ((GuidArrayProperty)target).Value, bag); break; case (int)PropertyKind.Double: prop = new DoubleProperty(target.Name, id, ((DoubleProperty)target).Value, bag); break; case (int)PropertyKind.Byte: prop = new ByteProperty(target.Name, id, ((ByteProperty)target).Value, bag); break; case (int)PropertyKind.Component: prop = new ComponentProperty(target.Name, id, ((ComponentProperty)target).Value, bag); break; case (int)PropertyKind.SingleArray: prop = new SingleArrayProperty(target.Name, id, ((SingleArrayProperty)target).Value, bag); break; case (int)PropertyKind.Int64: prop = new Int64Property(target.Name, id, ((Int64Property)target).Value, bag); break; case (int)PropertyKind.ComponentArray: prop = new ComponentArrayProperty(target.Name, id, ((ComponentArrayProperty)target).Value, bag); break; case (int)PropertyKind.DateTimeArray: prop = new DateTimeArrayProperty(target.Name, id, ((DateTimeArrayProperty)target).Value, bag); break; case (int)PropertyKind.ByteArray: prop = new ByteArrayProperty(target.Name, id, ((ByteArrayProperty)target).Value, bag); break; case (int)PropertyKind.DoubleArray: prop = new DoubleArrayProperty(target.Name, id, ((DoubleArrayProperty)target).Value, bag); break; case (int)PropertyKind.Int16Array: prop = new Int16ArrayProperty(target.Name, id, ((Int16ArrayProperty)target).Value, bag); break; case (int)PropertyKind.Int16: prop = new Int16Property(target.Name, id, ((Int16Property)target).Value, bag); break; case (int)PropertyKind.Int64Array: prop = new Int64ArrayProperty(target.Name, id, ((Int64ArrayProperty)target).Value, bag); break; case (int)PropertyKind.BoolArray: prop = new BoolArrayProperty(target.Name, id, ((BoolArrayProperty)target).Value, bag); break; } prop.Name = target.Name; return(prop); }
public virtual bool Save(bool serverRequiresAuth) { if (!serverRequiresAuth) { // no authorization means no accounts, which means no profiles. return(true); } if (LoginHistoryIP.Count != LoginHistoryTime.Count || LoginHistoryTime.Count != LogoffHistoryTime.Count) { Log1.Logger("Server").Error("Unable to save user's [" + Username + "] profile. Login History variables are not the same size."); return(false); } try { lock (m_Lock) { ProfileBase profile = ProfileBase.Create(Username, true); profile.SetPropertyValue("MaxCharacters", MaxCharacters); string[] curRoles = Roles.GetRolesForUser(Username); foreach (string role in UserRoles) { try { if (Array.IndexOf(curRoles, role) == -1) { Roles.AddUserToRole(Username, role); } } catch (Exception e) { Roles.CreateRole(role); Roles.AddUserToRole(Username, role); } } if (LoginHistoryIP.Count != LoginHistoryTime.Count || LoginHistoryTime.Count != LogoffHistoryTime.Count) { Log1.Logger("Server").Error("Unable to save user's [" + Username + "] login history to profile. Login History arrays are not the same size."); } else { string ips = ""; string logins = ""; string logouts = ""; for (int i = 0; i < LoginHistoryIP.Count; i++) { ips += LoginHistoryIP.ElementAt(i) + "|"; logins += LoginHistoryTime.ElementAt(i) + "|"; logouts += LogoffHistoryTime.ElementAt(i) + "|"; } ips = ips.Trim(char.Parse("|")); logins = logins.Trim(char.Parse("|")); logouts = logouts.Trim(char.Parse("|")); profile.SetPropertyValue("LoginHistoryIP", ips); profile.SetPropertyValue("LoginHistoryTime", logins); profile.SetPropertyValue("LogoffHistoryTime", logouts); long currentTimeSpent = (long)profile.GetPropertyValue("TotalTimeOnAccount"); Int64Property pl = AddedProperties.GetProperty("TotalTimeOnAccount") as Int64Property; if (pl != null) { pl.Value = currentTimeSpent + m_TotalSessionTime; Log1.Logger("Account").Info("Updating total account login time for [" + Username + "] from " + new TimeSpan(currentTimeSpent).ToString("g") + " to " + new TimeSpan(currentTimeSpent + m_TotalSessionTime).ToString("g")); } m_TotalSessionTime = 0; foreach (Property p in AddedProperties.AllProperties) { switch (p.Name) { case "LoginHistoryIP": case "LoginHistoryTime": case "LogoffHistoryTime": case "": continue; default: profile.SetPropertyValue(p.Name, p.PropertyValue()); break; } } Log1.Logger("Server").Debug("Saving [" + LoginHistoryIP.Count + "] login sessions for profile of [" + Username + "]."); } //profile.SetPropertyValue("Alias", Alias); profile.Save(); Log1.Logger("Server").Info("Saved profile info [" + Username + "]."); } } catch (Exception e) { Log1.Logger("Server").Error("Failed to save profile for user [" + Username + "]. " + e.Message); return(false); } return(true); }