public OpenSocialHelper(int viewerId, int ownerId, Page page)
    {
        this.viewerId = viewerId;
        this.ownerId  = ownerId;
        this.isDebug  = page.Session != null && page.Session[OPENSOCIAL_DEBUG] != null && (bool)page.Session[OPENSOCIAL_DEBUG];
        this.noCache  = page.Session != null && page.Session[OPENSOCIAL_NOCACHE] != null && (bool)page.Session[OPENSOCIAL_NOCACHE];
        this.pageName = page.AppRelativeVirtualPath.Substring(2);

        if (ConfigUtil.GetConfigItem("OpenSocialURL") == null)
        {
            // do nothing
            return;
        }

        Random random = new Random();

        bool   gadgetLogin  = page.AppRelativeVirtualPath.EndsWith("gadgetlogin.aspx");
        String requestAppId = page.Request.QueryString["appId"];

        Dictionary <string, GadgetSpec> dbApps       = new Dictionary <string, GadgetSpec>();
        Dictionary <string, GadgetSpec> officialApps = new Dictionary <string, GadgetSpec>();
        // Load gadgets from the DB first
        IDataReader reader = null;

        try
        {
            Database db = DatabaseFactory.CreateDatabase();

            string sqlCommand = "select appId, name, url, channels, enabled from shindig_apps";
            // if a specific app is requested, only grab it
            if (requestAppId != null)
            {
                sqlCommand += " where appId = " + requestAppId;
            }
            DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand);
            reader = db.ExecuteReader(dbCommand);
            while (reader.Read())
            {
                GadgetSpec spec           = new GadgetSpec(Convert.ToInt32(reader[0]), reader[1].ToString(), reader[2].ToString(), reader[3].ToString());
                string     gadgetFileName = GetGadgetFileNameFromURL(reader[2].ToString());

                dbApps.Add(gadgetFileName, spec);
                if (requestAppId != null || Convert.ToBoolean(reader[4]))
                {
                    officialApps.Add(gadgetFileName, spec);
                }
            }
        }
        catch (Exception e)
        {
            throw new Exception(e.Message);
        }
        finally
        {
            if (reader != null)
            {
                reader.Close();
            }
        }


        // Add manual gadgets if there are any
        // Note that this block of code only gets executed after someone logs in with gadgetlogin.aspx!
        int moduleId = 0;

        if (page.Session != null && (string)page.Session[OPENSOCIAL_GADGETS] != null)
        {
            String   openSocialGadgetURLS = (string)page.Session[OPENSOCIAL_GADGETS];
            String[] urls = openSocialGadgetURLS.Split(Environment.NewLine.ToCharArray());
            for (int i = 0; i < urls.Length; i++)
            {
                String openSocialGadgetURL = urls[i];
                if (openSocialGadgetURL.Length == 0)
                {
                    continue;
                }
                int      appId          = 0; // if URL matches one in the DB, use DB provided appId, otherwise generate one
                string   gadgetFileName = GetGadgetFileNameFromURL(openSocialGadgetURL);
                string   name           = gadgetFileName;
                string[] channels       = new string[0];
                bool     sandboxOnly    = true;
                if (dbApps.ContainsKey(gadgetFileName))
                {
                    appId       = dbApps[gadgetFileName].GetAppId();
                    name        = dbApps[gadgetFileName].GetName();
                    channels    = dbApps[gadgetFileName].GetChannels();
                    sandboxOnly = false;
                }
                else
                {
                    CharEnumerator ce = openSocialGadgetURL.GetEnumerator();
                    while (ce.MoveNext())
                    {
                        appId += (int)ce.Current;
                    }
                }
                // if they asked for a specific one, only let it in
                if (requestAppId != null && Convert.ToInt32(requestAppId) != appId)
                {
                    continue;
                }
                GadgetSpec gadget = new GadgetSpec(appId, name, openSocialGadgetURL, channels, sandboxOnly);
                // only add ones that are visible in this context!
                if (sandboxOnly || gadget.Show(viewerId, ownerId, page.AppRelativeVirtualPath.Substring(2)))
                {
                    String securityToken = SocketSendReceive(viewerId, ownerId, "" + gadget.GetAppId());
                    gadgets.Add(new PreparedGadget(gadget, this, moduleId++, securityToken));
                }
            }
        }

        // if no manual one were added, use the ones from the DB
        if (gadgets.Count == 0)
        {
            // Load DB gadgets
            if (gadgetLogin)
            {
                officialApps = dbApps;
            }
            foreach (KeyValuePair <string, GadgetSpec> pair in officialApps)
            {
                GadgetSpec gadget = new GadgetSpec(pair.Value.GetAppId(), pair.Value.GetName(), pair.Value.GetGadgetURL(), pair.Value.GetChannels(), false);
                // only add ones that are visible in this context!
                if (gadgetLogin || gadget.Show(viewerId, ownerId, GetPageName()))
                {
                    String securityToken = SocketSendReceive(viewerId, ownerId, "" + gadget.GetAppId());
                    gadgets.Add(new PreparedGadget(gadget, this, moduleId++, securityToken));
                }
            }
        }
        // sort the gadgets
        gadgets.Sort();

        // trigger the javascript to render gadgets
        HtmlGenericControl body = (HtmlGenericControl)page.Master.FindControl("bodyMaster");

        if (body == null)
        {
            body = (HtmlGenericControl)page.Master.Master.FindControl("bodyMaster");
        }
        body.Attributes.Add("onload", "my.init();");
    }
 public int GetAppId()
 {
     return(gadgetSpec.GetAppId());
 }
Esempio n. 3
0
        private void DrawProfilesModule()
        {
            List <GenericListItem> gli = new List <GenericListItem>();
            bool canedit = false;

            Profile.Utilities.DataIO    data = new Profiles.Profile.Utilities.DataIO();
            List <List <SecurityItem> > si   = new List <List <SecurityItem> >();
            List <SecurityItem>         singlesi;

            this.Dropdown     = new List <GenericListItem>();
            this.PropertyList = data.GetPropertyList(this.BaseData, base.PresentationXML, "", true, true, false);

            this.Subject = Convert.ToInt64(Request.QueryString["subject"]);

            this.SecurityGroups = new XmlDocument();
            this.SecurityGroups.LoadXml(base.PresentationXML.DocumentElement.LastChild.OuterXml);

            litBackLink.Text = "<b>Edit Menu</b>";

            Profiles.ORNG.Utilities.DataIO orngData = new Profiles.ORNG.Utilities.DataIO();

            foreach (XmlNode group in this.PropertyList.SelectNodes("//PropertyList/PropertyGroup"))
            {
                singlesi = new List <SecurityItem>();

                foreach (XmlNode node in group.SelectNodes("Property"))
                {
                    if (node.SelectSingleNode("@EditExisting").Value == "false" &&
                        node.SelectSingleNode("@EditAddExisting").Value == "false" &&
                        node.SelectSingleNode("@EditAddNew").Value == "false" &&
                        node.SelectSingleNode("@EditDelete").Value == "false")
                    {
                        canedit = false;
                    }
                    else
                    {
                        canedit = true;
                    }

                    // treat ORNG items as "special", because they may not be available and they may be turned off
                    if (node.SelectSingleNode("@URI").Value.StartsWith(Profiles.ORNG.Utilities.OpenSocialManager.ORNG_ONTOLOGY_PREFIX))
                    {
                        GadgetSpec spec = OpenSocialManager.GetGadgetByPropertyURI(node.SelectSingleNode("@URI").Value);
                        if (spec != null && spec.RequiresRegitration() && !orngData.IsRegistered(this.Subject, spec.GetAppId()))
                        {
                            singlesi.Add(new SecurityItem(node.ParentNode.SelectSingleNode("@Label").Value, node.SelectSingleNode("@Label").Value,
                                                          node.SelectSingleNode("@URI").Value,
                                                          Convert.ToInt32(node.SelectSingleNode("@NumberOfConnections").Value),
                                                          Convert.ToInt32(node.SelectSingleNode("@ViewSecurityGroup").Value),
                                                          "Unavailable",
                                                          node.SelectSingleNode("@ObjectType").Value, canedit));
                            continue;
                        }
                        else if (spec != null && "0".Equals(node.SelectSingleNode("@NumberOfConnections").Value))
                        {
                            singlesi.Add(new SecurityItem(node.ParentNode.SelectSingleNode("@Label").Value, node.SelectSingleNode("@Label").Value,
                                                          node.SelectSingleNode("@URI").Value,
                                                          Convert.ToInt32(node.SelectSingleNode("@NumberOfConnections").Value),
                                                          Convert.ToInt32(node.SelectSingleNode("@ViewSecurityGroup").Value),
                                                          "Hidden",
                                                          node.SelectSingleNode("@ObjectType").Value, canedit));
                            continue;
                        }
                    }

                    singlesi.Add(new SecurityItem(node.ParentNode.SelectSingleNode("@Label").Value, node.SelectSingleNode("@Label").Value,
                                                  node.SelectSingleNode("@URI").Value,
                                                  Convert.ToInt32(node.SelectSingleNode("@NumberOfConnections").Value),
                                                  Convert.ToInt32(node.SelectSingleNode("@ViewSecurityGroup").Value),
                                                  this.SecurityGroups.SelectSingleNode("SecurityGroupList/SecurityGroup[@ID='" + node.SelectSingleNode("@ViewSecurityGroup").Value + "']/@Label").Value,
                                                  node.SelectSingleNode("@ObjectType").Value, canedit));
                }
                si.Add(singlesi);
            }

            foreach (XmlNode securityitem in this.SecurityGroups.SelectNodes("SecurityGroupList/SecurityGroup"))
            {
                this.Dropdown.Add(new GenericListItem(securityitem.SelectSingleNode("@Label").Value,
                                                      securityitem.SelectSingleNode("@ID").Value));

                gli.Add(new GenericListItem(securityitem.SelectSingleNode("@Label").Value, securityitem.SelectSingleNode("@Description").Value));
            }
            gli.Add(new GenericListItem("Unavailable", "This feature depends on automatically collected data that we do not have for your Profile."));

            repPropertyGroups.DataSource = si;
            repPropertyGroups.DataBind();

            BuildSecurityKey(gli);

            // OpenSocial.  Allows gadget developers to show test gadgets if you have them installed
            string            uri = this.BaseData.SelectSingleNode("rdf:RDF/rdf:Description/@rdf:about", base.Namespaces).Value;
            OpenSocialManager om  = OpenSocialManager.GetOpenSocialManager(uri, Page, true);

            if (om.IsVisible())
            {
                litGadget.Visible = true;
                string sandboxDivs = "";
                foreach (PreparedGadget gadget in om.GetSandboxGadgets())
                {
                    sandboxDivs += "<div id='" + gadget.GetChromeId() + "' class='gadgets-gadget-parent'></div>";
                }
                litGadget.Text = sandboxDivs;
                om.LoadAssets();
            }
        }