Ejemplo n.º 1
0
    public override void Initialize()
    {
        base.Initialize();



        log.Debug("**** Going to get new client of main ****", this.ClientId);
        string newClientId = RootContext.GetNewClientId(this);

        log.Debug("**** Going to set new client of main ****", this.ClientId, newClientId);
        this.ClientId = newClientId;
        log.Debug("**** Set new client of main ****", this.ClientId);

        log.Debug("**** INIT TIME ****", this.ClientId);
        log.Warn("**** WARN INIT TIME ****", this.ClientId);

        log.Debug("**** apikey:", apikey);
        log.Debug("**** apisecret:", apisecret);

        foreach (var item in HttpContext.Current.Request.Params)
        {
            log.Debug("request item", item, HttpContext.Current.Request[(string)item]);
        }

        InitializeServices();

        if (Glyphs == null)
        {
            Glyphs = DataProvider.LoadList <Glyph>();
        }
        if (Tones == null)
        {
            Tones = DataProvider.LoadList <Tone>();
        }

        if (Glyphs.Count == 0)
        {
            Glyph.InitDataBase();
            Glyphs = DataProvider.LoadList <Glyph>();
        }
        if (Tones.Count == 0)
        {
            Tone.InitDataBase();
            Tones = DataProvider.LoadList <Tone>();
        }

        log.Debug("Tones", Tones);
        log.Debug("Glyphs", Glyphs);

        Now            = new DreamFolk();
        Now.FacebookId = "Now";
        Now.Birthday   = DateTime.Now;
        log.Warn("Now is " + Now.GetName(), Now, DateTime.Now, Now.Birthday);

        Label l = this.Find <Label>();

        if (l == null)
        {
            l = this.CreateWidget <Label>();
        }
        l.Text = DateTime.Now.ToShortDateString();


        // check to see if force records needs to be recalc
        if (HttpContext.Current.Request["recalc"] == "1")
        {
            log.Warn("RECALCULATING BIRTHDAYS!");
            //DataHelper helper = new DataHelper();
            //new Thread (new ThreadStart (helper.Recalc)).Start();
            ThreadPool.QueueUserWorkItem(new WaitCallback(Recalc));
        }
        else
        {
            log.Warn("skppping recalc", HttpContext.Current.Request["recalc"]);
        }

//			DreamSpellUtil.Calc();
//			log.Debug("Year Seal: " + DreamSpellUtil.CalcYearSeal());
//			log.Debug("Year Tone: " + DreamSpellUtil.CalcYearTone());
//			log.Debug("Distance From Day Out Of Time: " + DreamSpellUtil.CalcDistanceFromDayOutOfTime());
//			log.Debug("Year Seal: " + DreamSpellUtil.CalcSeal());
//			log.Debug("Year Tone: " + DreamSpellUtil.CalcTone());
//			DreamSpellUtil.CalcOracle();
//			log.Debug("Guide: " + DreamSpellUtil.Guide);
//			log.Debug("Antiopde: " + DreamSpellUtil.Antipode);
//			log.Debug("Analog: " + DreamSpellUtil.Analog);
//			log.Debug("Occult: " + DreamSpellUtil.Occult);
//			log.Debug("Kin: " + DreamSpellUtil.Kin);

        log.Debug("This HttpContext.Request", HttpContext.Current.Request);

        bool isAdded = HttpContext.Current.Request["fb_sig_added"] == "1";

        string owner_fb_id = HttpContext.Current.Request["owner_fb_id"];

        string sessionKey = HttpContext.Current.Request["fb_sig_session_key"];

        string userId = HttpContext.Current.Request["fb_sig_user"];

        log.Debug("isAdded", isAdded);
        log.Debug("owner_fb_id", owner_fb_id);
        log.Debug("sessionKey", sessionKey);
        log.Debug("userId", userId);

        if (userId != "775949236")
        {
            log.Debug("User is not me", userId);
            //return;
        }
        else
        {
            log.Debug("User is me!");
        }
        //return;
        log.Debug("Checking for nullOrEmpty sessionKey", sessionKey);

        if (string.IsNullOrEmpty(sessionKey))
        {
            log.Debug("No sessionKey");
            //this.HttpContext.Response.Redirect(@"http://www.facebook.com/login.php?api_key=" + apikey + @"&v=1.0");
            //return;
            log.Warn("No facebook session 1");

            StarSummary starSummary = Find <StarSummary>("StarHeader");
            if (starSummary != null)
            {
                starSummary.Visible = false;
            }

            Pane me = Find <Pane>("Me");
            //me.AppendClass("none");
            log.Warn("No facebook session 2");

            Pane friends = Find <Pane>("Friends");
            //friends.AppendClass("none");

            TabPane tabPane = Find <TabPane>();
            if (tabPane != null)
            {
                foreach (Pane pane in tabPane.tabsByLabels.Values)
                {
                    log.Debug("looking at pane: " + pane.Id);
                    if (pane.Id == "Me" || pane.Id == "Friends")
                    {
                        log.Debug("found either Me or Friends, going apply None: " + pane.Id);
                        pane.AppendClass("none");

                        //HtmlElement li = pane.FindAncestor
                        //li.AppendClass("none");
                    }
                }

                /*
                 * foreach (Object obj in tabPane.tabsByLabels.Keys)
                 * {
                 *      if ( ! (obj is HtmlElement) )
                 *      {
                 *              log.Debug("obj is not an  htmlElement",obj);
                 *              continue;
                 *      }
                 *
                 *      HtmlElement li = (HtmlElement)obj;
                 *      log.Debug("looking at key: " + li.Id + " " + li.TagName + " " + li.ClassName);
                 *
                 *      if ( li.ClassName == "MeTab" || li.ClassName == "FriendsTab" )
                 *      {
                 *              li.AppendClass("none");
                 *
                 *              //HtmlElement li = pane.FindAncestor
                 *              //li.AppendClass("none");
                 *
                 *      }
                 *      else
                 *              li.AppendClass("no-top-margin");
                 * }
                 */
            }
        }
        else
        {
            log.Debug(sessionKey, userId);

            IsFaceBookSession = true;

            if (sessionKey != null && userId != null)
            {
                handleFacebookUser(sessionKey, userId);
            }
        }

        if (CurrentDreamFriend == null)
        {
            log.Debug("Setting CurrentDreamFriend to Now");
            CurrentDreamFriend = Now;
        }
        log.Debug("Going to bind CurrentDreamFriend", CurrentDreamFriend);

//			ConfirmButton button = this.RootContext.CreateWidget<ConfirmButton>(this);
//			button.Label = "Recalc";
//			button.OnClick += delegate { ThreadPool.QueueUserWorkItem(new WaitCallback(Recalc)); };

        //this.RootContext.CreateWidget<FriendList>(this);

        //this.Record = Now;
        this.Record = CurrentDreamFriend;
        this.DataBindWidget(this.Record);

        log.Debug("Binded CurrentDreamFriend");

        Pane       todayPane   = this.Find <Pane>("Today");
        Pane       mePane      = this.Find <Pane>("Me");
        Pane       friendsPane = this.Find <Pane>("Friends");
        FriendList friendList  = this.Find <FriendList>();

        if (todayPane != null)
        {
            log.Debug("Binding todayPane");
            todayPane.DataBindWidget(Now);
        }

        if (mePane != null)
        {
            log.Debug("Binding mePane");
            mePane.DataBindWidget(CurrentDreamFriend);
        }

        if (friendsPane != null && friendList != null)
        {
            log.Debug("Binding friendsPane");
            friendsPane.DataBindWidget(CurrentDreamFriend);
            log.Debug("Binding friendList");
            friendList.DataBindWidget(CurrentDreamFriend);
        }

        log.Debug("Creating starHeaderNow");
        StarSummary starHeaderNow = this.Find <StarSummary>("StarHeaderNow");

        if (starHeaderNow != null)
        {
            log.Debug("Binding starHeaderNow");
            starHeaderNow.Record = Now;
            starHeaderNow.DataBindWidget();
        }
    }