コード例 #1
0
        public override void ProcessRequest(HttpContext context)
        {
            ISession sess = this.CurrentSession;

            PersistentUser   user   = sess.Get <PersistentUser>(new Guid(context.Request["UserID"]));
            PersistentClient client = sess.Get <PersistentClient>(new Guid(context.Request["ClientID"]));

            if (user == null || !user.HasAPIAccess)
            {
                throw new Exception("no api access");
            }

            if (client == null || !client.HasAPIAccess)
            {
                throw new Exception("no api access");
            }

            bool isActive  = bool.Parse(context.Request["IsActive"]);
            Guid profileID = new Guid(context.Request["ProfileID"]);

            PersistentProfile profile = sess.Get <PersistentProfile>(profileID);
            string            xml     = profile.ToPersistentXml();

            context.Response.Write(xml);
        }
コード例 #2
0
        public override void ProcessRequest(HttpContext context)
        {
            ISession s = this.CurrentSession;

            using (ITransaction t = s.BeginTransaction())
            {
                Console.WriteLine("fdsa");
                Guid userID   = new Guid(context.Request["UserID"]);
                Guid clientID = new Guid(context.Request["ClientID"]);

                PersistentUser   user   = s.Get <PersistentUser>(userID);
                PersistentClient client = s.Get <PersistentClient>(clientID);

                if (user == null || !user.HasAPIAccess)
                {
                    throw new Exception("no api access");
                }

                if (client == null || !client.HasAPIAccess)
                {
                    throw new Exception("no api access");
                }

                PersistentProfile profile = new PersistentProfile();

                string webUserID = context.Request["WebUserID"];

                profile.WebUserID   = new Guid(context.Request["WebUserID"]);
                profile.Description = context.Request["ProfileDescription"];
                profile.Name        = context.Request["ProfileName"];
                profile.Range       = context.Request["ProfileDomain"];
                profile.Domain      = context.Request["ProfileDomain"];
                profile.RunEvery    = new TimeSpan(24 * (int.Parse(context.Request["ProfileSchedule"])), 0, 0);            //30 days
                profile.RunAfter    = DateTime.Now;
                profile.HasRun      = false;

                profile.SetCreationInfo(userID);

                s.Save(profile);

                foreach (string h in profile.Range.Split(','))
                {
                    PersistentProfileHost host = new PersistentProfileHost(new Guid(context.Request["WebUserID"]));
                    host.ParentProfile       = profile;
                    host.IPv4Address         = Dns.GetHostEntry(h).AddressList[0].ToString();
                    host.VerifiedByFile      = true;
                    host.VerifiedByWhois     = true;
                    host.VerifiedOn          = DateTime.Now;
                    host.WasManuallyVerified = false;
                    host.IsVerified          = true;

                    s.Save(host);
                }

                try
                {
                    t.Commit();
                }
                catch (Exception ex)
                {
                    t.Rollback();

                    throw ex;
                }

                string xml = profile.ToPersistentXml();

                context.Response.Write(xml);
            }
        }