Example #1
0
    public static void CreateFirstUser(string name, string mail, string password)
    {
        // Make sure that no first person exists already, as a security measure

        Swarmops.Logic.Swarm.Person personOne = null;
        bool personOneExists = false;

        try
        {
            personOne = Swarmops.Logic.Swarm.Person.FromIdentity(1);
            if (System.Diagnostics.Debugger.IsAttached)
            {
                if (personOne.CityName != "Duckville" || personOne.Mail != "*****@*****.**")
                // these values are returned in debug environments when no person is found
                {
                    personOneExists = true;
                }
                else
                {
                    personOne = null;
                }
            }
            else
            {
                personOneExists = true;
            }
        }
        catch (Exception)
        {
            // We expect this to throw.
        }

        if (personOneExists || personOne != null)
        {
            throw new InvalidOperationException("Cannot run initialization processes again when initialized.");
        }

        Swarmops.Logic.Swarm.Person newPerson = Swarmops.Logic.Swarm.Person.Create(HttpUtility.UrlDecode(name), HttpUtility.UrlDecode(mail),
                                                                                   HttpUtility.UrlDecode(password), string.Empty, string.Empty, string.Empty,
                                                                                   string.Empty, string.Empty, DateTime.MinValue, PersonGender.Unknown);

        newPerson.AddMembership(1, DateTime.MaxValue); // Add membership in Sandbox
        newPerson.AddRole(RoleType.SystemAdmin, 0, 0); // Add role System Admin
    }