Inheritance: AbstractRecord
Esempio n. 1
0
    private void handleFacebookUser(string sessionKey, string userId )
    {
        log.Debug("Handling facebook user",userId);

            facebookApi = new FacebookAPI();

            facebookApi.IsDesktopApplication = false;
            facebookApi.ApplicationKey = apikey;
            facebookApi.Secret = apisecret;

            facebookApi.SessionKey = sessionKey;
            facebookApi.UserId = userId;

            facebookApi.ConnectToFacebook();

            FacebookId = facebookApi.GetLoggedInUser();
            Collection<Facebook.Entity.User> fb_users = facebookApi.GetUserInfo(facebook_id);
            log.Debug("Got Facebook users fb_users",fb_users);
            fb_user = fb_users[0];
            log.Debug("Facebook user fb_user",fb_user);

            IRecordList<DreamFolk> dreamFolk = DataProvider.LoadList<DreamFolk>(new FilterInfo("FacebookId",FacebookId));
            log.Debug("Got dreamFolk folk with FacebookId",FacebookId,dreamFolk);

            DreamFolk dreamPerson = null;
            if ( dreamFolk.Count > 0 ) dreamPerson = dreamFolk[0];

            if ( dreamPerson == null )
            {
                log.Warn("Creating new dreamPerson from Main.Current");
                dreamPerson = new DreamFolk(Main.Current.FbUser);
                dreamPerson.Save(true);
            }
            /*
            else if ( dreamPerson.Birthday != Main.Current.FbUser.Birthday )
            {
                log.Warn("Updating birthday dreamPerson from Main.Current");
                dreamPerson.Birthday = (DateTime)Main.Current.FbUser.Birthday;
                dreamPerson.Save(true);
            }
            else if ( !dreamPerson.Updated )
            */
            else
            {
                log.Warn("Updating dreamPerson");
                dreamPerson.update(fb_user);
                dreamPerson.Updated = true;
                dreamPerson.Save(true);
            }

            CurrentDreamFriend = dreamPerson;
            Now.Friends = CurrentDreamFriend.Friends;
    }
Esempio n. 2
0
        public override void PostInitialize()
        {
            base.PostInitialize ();

            log.Debug("PostInit BEGIN");

            Pane tones = this.Find<Pane>("Tones");
            Pane seals = this.Find<Pane>("Seals");
            Pane guides = this.Find<Pane>("Guides");
            Pane allies = this.Find<Pane>("Allies");
            Pane secrets = this.Find<Pane>("Secret");
            Pane focus = this.Find<Pane>("Focus");

            DreamFriend = (DreamFolk)this.Record;

            Repeater<DreamFolk> toneList = Find<Repeater<DreamFolk>>("toneList");
            if ( toneList != null && DreamFriend != null  && DreamFriend.Tones.Count > 0)
            {
                tones.AppendClass("clearfix");
                toneList.DataSource = DreamFriend.Tones;
                toneList.DataBind();
            }
            else
                tones.AppendClass("none");

            Repeater<DreamFolk> sealList = Find<Repeater<DreamFolk>>("sealList");
            if ( sealList != null && DreamFriend != null  && DreamFriend.Seals.Count > 0)
            {
                seals.AppendClass("clearfix");
                sealList.DataSource = DreamFriend.Seals;
                sealList.DataBind();
            }
            else
                seals.AppendClass("none");

            Repeater<DreamFolk> guideList = Find<Repeater<DreamFolk>>("guideList");
            if ( guideList != null && DreamFriend != null  && DreamFriend.Guides.Count > 0)
            {
                guides.AppendClass("clearfix");
                guideList.DataSource = DreamFriend.Guides;
                guideList.DataBind();
            }
            else
                guides.AppendClass("none");

            Repeater<DreamFolk> alliesList = Find<Repeater<DreamFolk>>("alliesList");
            if ( alliesList != null && DreamFriend != null && DreamFriend.Allies.Count > 0)
            {
                allies.AppendClass("clearfix");
                alliesList.DataSource = DreamFriend.Allies;
                alliesList.DataBind();
            }
            else
                allies.AppendClass("none");

            Repeater<DreamFolk> secretList = Find<Repeater<DreamFolk>>("secretList");
            if ( secretList != null && DreamFriend != null && DreamFriend.Occults.Count > 0)
            {
                secrets.AppendClass("clearfix");
                secretList.DataSource = DreamFriend.Occults;
                secretList.DataBind();
            }
            else
                secrets.AppendClass("none");

            Repeater<DreamFolk> focusList = Find<Repeater<DreamFolk>>("focusList");
            if ( focusList != null && DreamFriend != null && DreamFriend.FocusList.Count > 0)
            {
                focus.AppendClass("clearfix");
                focusList.DataSource = DreamFriend.FocusList;
                focusList.DataBind();
            }
            else
                focus.AppendClass("none");

            log.Debug("PostInit END");
        }
Esempio n. 3
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();
            }
    }
Esempio n. 4
0
        public override void PostInitialize()
        {
            //UnDataBindWidget();
            //this.Record = Main.Current.CurrentDreamFriend;
            //this.DataBindWidget();

            FacebookAPI api = Main.Current.FacebookApi;
            if( api == null )
                return;
            Collection<string> friends = api.GetFriendIds();
            //			IRecordList<RStuff.Model.Member> members = DataProvider.LoadList<RStuff.Model.Member>(
            //            	new FilterInfo( "FacebookId", friends, FilterOperation.In ) );
            //            Repeater<RStuff.Model.Member> friendList = Find<Repeater<RStuff.Model.Member>>("friendList");
            //            friendList.DataSource = members;
            //            friendList.DataBind();

            IRecordList<DreamFolk> dreamFolk = DataProvider.LoadList<DreamFolk>(new FilterInfo("FacebookId",Main.Current.FacebookId));
            DreamFolk dreamPerson = null;
            if ( dreamFolk.Count > 0 ) dreamPerson = dreamFolk[0];

            if ( dreamPerson == null )
            {
                log.Warn("Creating new dreamPerson");
                dreamPerson = new DreamFolk(Main.Current.FbUser);
                dreamPerson.Save(true);
            }
            else if ( dreamPerson.Birthday != Main.Current.FbUser.Birthday )
            {
                log.Warn("Updating dreamPerson's birthday");
                dreamPerson.Birthday = (DateTime)Main.Current.FbUser.Birthday;
                dreamPerson.Save(true);
            }

            DreamFolk dreamFriend = null;
            Label label;
            Collection<Facebook.Entity.User> fb_users;
            Pane pane, detailPane;
            bool dreamPersonChanged = false;
            int count = 0;
            int added = 0;

            foreach(string friend in friends)
            {
                //if ( count++ > 2 ) break;

                dreamFriend = dreamPerson.GetFriend(friend);
                if ( dreamFriend == null )
                {
                    log.Warn("dreamFriend not found, going to create new one, friend is", friend);
                    fb_users = Main.Current.FacebookApi.GetUserInfo(friend);
                    Facebook.Entity.User fb_user = fb_users[0];
                    log.Debug(fb_user);

                    dreamFriend = new DreamFolk(fb_user);
                    dreamFriend.Save(true);

                    log.Warn("Created new dreamFriend");

                    dreamPerson.Friends.Add(dreamFriend);
                    //dreamPerson.Save();
                    dreamPersonChanged = true;

                    added++;
                }
                else if ( !dreamFriend.Updated )
                {
                    log.Warn("Updating dreamFriend");

                    fb_users = Main.Current.FacebookApi.GetUserInfo(dreamFriend.FacebookId);
                    Facebook.Entity.User fb_user = fb_users[0];
                    log.Debug(fb_user);

                    //dreamFriend.Birthday = dreamFriend.Birthday;
                    dreamFriend.update(fb_user);

                    dreamFriend.Updated = true;
                    dreamFriend.Save(true);

                    count++;
                }
                //else
                //	log.Warn("DreamFriend is current and up todate",dreamFriend.FirstName);

                /*
                pane = this.RootContext.CreateWidget<Pane>(this);
                pane.AppendClass("dream-person");

                pane.OnClick += delegate( object sender, ClickEventArgs ea )
                {
                    DreamFolk dreamFolkFriend = (DreamFolk)ea.Source.Record;
                    this.RootContext.RawCmd("parent.location='http://www.facebook.com/profile.php?id=" + dreamFolkFriend.FacebookId + "';");
                };
                pane.Record = dreamFriend;
                pane.DataBindWidget();

                label = this.RootContext.CreateWidget<Label>(pane);
                label.Text = dreamFriend.FirstName;
                label.AppendClass("label-name");

                if ( dreamFriend.PictureSmallUrl != null )
                {
                    label = this.RootContext.CreateWidget<Label>(pane);
                    label.Text = "<img src=\"" + dreamFriend.PictureSmallUrl + "\" class=person>";
                }
                else if ( dreamFriend.PictureUrl != null )
                {
                    label = this.RootContext.CreateWidget<Label>(pane);
                    label.Text = "<img src=\"" + dreamFriend.PictureUrl + "\" class=person>";
                }
                else if ( dreamFriend.PictureBigUrl != null )
                {
                    label = this.RootContext.CreateWidget<Label>(pane);
                    label.Text = "<img src=\"" + dreamFriend.PictureBigUrl + "\" class=person>";
                }

                DateTime bday = dreamFriend.Birthday;
                //label.Text = date.ToString("d");
                if ( bday.Year == 1900 || bday.Year == DateTime.Now.Year )
                {
                    detailPane = this.RootContext.CreateWidget<Pane>(pane);
                    detailPane.AppendClass("dream-detail");

                    label = this.RootContext.CreateWidget<Label>(detailPane);
                    label.Text = "<img src=\"/Images/tone0.gif\" title=\"Unknown\" class=tone>";
                    label.AppendClass("label-tone");

                    label = this.RootContext.CreateWidget<Label>(detailPane);
                    label.Text = "<img src=\"/Images/glyph0.gif\" title=\"Unknown\" class=seal>";
                    label.AppendClass("label-glyph");

                    label = this.RootContext.CreateWidget<Label>(detailPane);
                    label.Text = "<a target=\"_parent\" href=\"http://apps.facebook.com/dreamspell/index.aspx?invite=1\" style=\"background-color:#3B5998;border-color:#D9DFEA #0E1F5B #0E1F5B #D9DFEA;border-style:solid;border-width:1px;color:white;margin-right:5px;padding:3px 15px;line-height:24px\">Invite!</a>";
                }
                else
                {
                    //DreamSpellUtil.Calc(bday);

                    detailPane = this.RootContext.CreateWidget<Pane>(pane);
                    detailPane.AppendClass("dream-detail");

                    label = this.RootContext.CreateWidget<Label>(detailPane);
                    label.Text = "<img src=\"/Images/tone" + dreamFriend.Tone + ".gif\" title=\""+ dreamFriend.Tone.Name +"\" class=tone>";
                    label.AppendClass("label-tone");

                    label = this.RootContext.CreateWidget<Label>(detailPane);
                    label.Text = "<img src=\"/Images/glyph" + dreamFriend.Seal + ".gif\" title=\""+ (dreamFriend.Seal == null ? "Unknown" : dreamFriend.Seal.Name) +"\" class=seal>";
                    label.AppendClass("label-glyph");

                    label = this.RootContext.CreateWidget<Label>(detailPane);
                    //label.Text = bday.ToString("d");
                    label.Text = dreamFriend.GetName();
                    label.AppendClass("label-dreamspell-name");

                    //break;

                }
                */

            }

            if ( dreamPersonChanged )
            {
                log.Debug("dreamPersonChanged, saving");
                dreamPerson.Save(true);
            }
            log.Debug("Added " + added + " new dream friends");
            log.Debug("Updated " + count + " dream friends");

            Repeater<DreamFolk> friendList = this.Find<Repeater<DreamFolk>>("Friends");
            //if ( friendList != null && Main.Current.CurrentDreamFriend != null && Main.Current.CurrentDreamFriend.Friends.Count > 0)
            if ( friendList != null && Main.Current.CurrentDreamFriend.Friends.Count > 1)
            {
                log.Warn("Going to unbind and rebind friendList, friend count " + dreamFolk.Count);
                log.Warn("Going to unbind and rebind friendList, CurrentDreamFriend.friend count " + Main.Current.CurrentDreamFriend.Friends.Count);
                friendList.UnDataBindWidget();
                //friendList.DataSource = Main.Current.CurrentDreamFriend.Friends;
                friendList.DataSource = Main.Current.CurrentDreamFriend.Friends;
                friendList.DataBind();

                //foreach (DreamFolk d in Main.Current.CurrentDreamFriend.Friends)
                //	log.Debug(d.FirstName);
            }
            else
                log.Error("Skipped unbind and rebind of frinedList");
        }