Ejemplo n.º 1
0
        public void ProcessRequest(HttpRequest request, Org.Reddragonit.EmbeddedWebServer.Interfaces.Site site)
        {
            bool isComplete = false;

            try
            {
                if (Domain.AllDomainNames.Count == 0)
                {
                    throw new Exception("No Domains have been created");
                }

                if (Context.AllContextNames.Count < 2)
                {
                    throw new Exception("You need a minimum of 2 contexts");
                }

                if (SipProfile.AllSipProfileNames.Count < 2)
                {
                    throw new Exception("You need a minimum of 2 sip profiles");
                }

                User usr = User.Create(request.Parameters["UserName"],
                                       request.Parameters["FirstName"],
                                       request.Parameters["LastName"],
                                       request.Parameters["Password"],
                                       null,
                                       null,
                                       UserRight.All.ToArray());
                if (usr == null)
                {
                    throw new Exception("Unable to create primary user");
                }
                else
                {
                    usr.AllowedDomains = Domain.LoadAll().ToArray();
                    usr.Update();
                }

                foreach (string c in Context.AllContextNames)
                {
                    CoreGenerator.RegenerateContextFile(c);
                }
                foreach (SipProfile sp in SipProfile.LoadAll())
                {
                    CoreGenerator.RegenerateSIPProfile(sp);
                }
                foreach (Domain d in Domain.LoadAll())
                {
                    CoreGenerator.RegenerateDomainFile(d);
                }

                isComplete = true;
            }
            catch (Exception e)
            {
                request.ResponseWriter.WriteLine(e.Message);
            }
            if (!isComplete)
            {
                request.ResponseStatus = HttpStatusCodes.Forbidden;
            }
            else
            {
                request.ResponseStatus = HttpStatusCodes.OK;
                EventController.TriggerEvent(new SetupCompleteEvent());
            }
            request.SendResponse();
        }