public static Dictionary <string, GadgetSpec> GetAllDBGadgets(bool useCache)
        {
            // check cache first
            Dictionary <string, GadgetSpec> dbApps = useCache ? (Dictionary <string, GadgetSpec>)Cache.FetchObject(GADGET_SPEC_KEY) : null;

            if (dbApps == null)
            {
                dbApps = new Dictionary <string, GadgetSpec>();
                Profiles.ORNG.Utilities.DataIO data = new Profiles.ORNG.Utilities.DataIO();
                using (SqlDataReader dr = data.GetGadgets())
                {
                    while (dr.Read())
                    {
                        GadgetSpec spec           = new GadgetSpec(Convert.ToInt32(dr[0]), dr[1].ToString(), dr[2].ToString(), Convert.ToBoolean(dr[3]), false);
                        string     gadgetFileName = GetGadgetFileNameFromURL(dr[2].ToString());
                        dbApps.Add(gadgetFileName, spec);
                    }
                }

                // add to cache unless noCache is turned on
                if (useCache)
                {
                    // set it to not timeout
                    Cache.Set(GADGET_SPEC_KEY, dbApps, -1, null);
                }
            }

            return(dbApps);
        }
Beispiel #2
0
 public PreparedGadget(GadgetSpec gadgetSpec, OpenSocialManager openSocialManager, int moduleId, string securityToken)
 {
     this.gadgetSpec        = gadgetSpec;
     this.openSocialManager = openSocialManager;
     this.moduleId          = moduleId;
     this.securityToken     = securityToken;
 }
Beispiel #3
0
        public void RemovePersonalGadget(long Subject, string propertyURI)
        {
            GadgetSpec spec = OpenSocialManager.GetGadgetByPropertyURI(propertyURI);

            if (spec != null)
            {
                RemovePersonalGadget(Subject, spec.GetAppId());
            }
        }
 // OntologyGadgets
 public PreparedGadget(GadgetSpec gadgetSpec, OpenSocialManager openSocialManager, string view, string optParams)
 {
     this.gadgetSpec        = gadgetSpec;
     this.openSocialManager = openSocialManager;
     this.securityToken     = openSocialManager.GetSecurityToken(gadgetSpec.GetGadgetURL());
     this.view      = view;
     this.chromeId  = "gadgets-ontology-" + GetAppId();
     this.optParams = optParams == null || optParams.Trim() == string.Empty ? "{}" : optParams;
 }
Beispiel #5
0
 // OntologyGadgets
 public PreparedGadget(GadgetSpec gadgetSpec, OpenSocialManager openSocialManager, string view, string optParams, string chromeId)
 {
     this.gadgetSpec        = gadgetSpec;
     this.openSocialManager = openSocialManager;
     this.securityToken     = SocketSendReceive(openSocialManager.GetViewerURI(), openSocialManager.GetOwnerURI(), gadgetSpec.GetGadgetURL());
     this.view      = view;
     this.chromeId  = chromeId;
     this.optParams = optParams == null || optParams.Trim() == string.Empty ? "{}" : optParams;
 }
Beispiel #6
0
 internal void MergeWithUnrecognizedGadget(GadgetSpec unrecognizedGadget)
 {
     // basically just grab it's URL, but check some things first!
     if (this.GetFileName() == unrecognizedGadget.GetFileName() && !this.unrecognized && unrecognizedGadget.unrecognized)
     {
         this.openSocialGadgetURL = unrecognizedGadget.openSocialGadgetURL;
         this.enabled             = true;
     }
     else
     {
         throw new Exception("This merge is not allowed!");
     }
 }
Beispiel #7
0
 internal void MergeWithSandboxGadget(GadgetSpec sandboxGadget)
 {
     // basically just grab it's URL, but check some things first!
     if (this.GetFileName() == sandboxGadget.GetFileName() && !this.fromSandbox && sandboxGadget.fromSandbox)
     {
         this.openSocialGadgetURL = sandboxGadget.openSocialGadgetURL;
         this.enabled             = true;
     }
     else
     {
         throw new Exception("This merge is not allowed!");
     }
 }
        private List <PreparedGadget> GetSandboxGadgets(Dictionary <string, GadgetSpec> allDBGadgets, string requestAppId)
        {
            List <PreparedGadget> sandboxGadgets = new List <PreparedGadget>();
            // Add sandbox gadgets if there are any
            // Note that this block of code only gets executed after someone logs in with GadgetSandbox.aspx!
            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;
                // see if we have a gadget with the same file name in the DB, if so use its configuration
                if (allDBGadgets.ContainsKey(gadgetFileName))
                {
                    appId       = allDBGadgets[gadgetFileName].GetAppId();
                    name        = allDBGadgets[gadgetFileName].GetName();
                    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 gadgetSpec = new GadgetSpec(appId, name, openSocialGadgetURL, true, sandboxOnly);
                // only add ones that are visible in this context!
                int moduleId = 0;
                if (sandboxOnly || gadgetSpec.Show(viewerUri, ownerUri, page.AppRelativeVirtualPath.Substring(2).ToLower()))
                {
                    String securityToken = SocketSendReceive(viewerUri, ownerUri, gadgetSpec.GetGadgetURL());
                    sandboxGadgets.Add(new PreparedGadget(gadgetSpec, this, moduleId++, securityToken));
                }
            }
            return(sandboxGadgets);
        }
        private List <GadgetSpec> GetGadgetSpecifications()
        {
            DebugLogging.Log("OpenSocialManager GetAllDBGadgets " + !noCache);
            Dictionary <string, GadgetSpec> allDBGadgets = GetAllDBGadgets(!noCache);
            List <GadgetSpec> gadgetSpecs = new List <GadgetSpec>();

            // if someone used the sandbox to log in, grab those gadgets, and only those gadget.
            // if a gadget with the same file name is in the DB, merge it in so that we can inherit it's configuruation
            if (page.Session != null && (string)page.Session[ORNG_GADGETS] != null)
            {
                // Add sandbox gadgets if there are any
                // Note that this block of code only gets executed after someone logs in with GadgetSandbox.aspx!
                String   openSocialGadgetURLS = (string)page.Session[ORNG_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;
                    }
                    GadgetSpec sandboxGadget = new GadgetSpec(openSocialGadgetURL);
                    // see if we have a gadget with the same file name in the DB, if so use its configuration
                    if (allDBGadgets.ContainsKey(sandboxGadget.GetFileName()))
                    {
                        GadgetSpec gadget = allDBGadgets[sandboxGadget.GetFileName()];
                        gadget.MergeWithUnrecognizedGadget(sandboxGadget);
                        gadgetSpecs.Add(gadget);
                    }
                    else
                    {
                        gadgetSpecs.Add(sandboxGadget);
                    }
                }
            }
            else
            {
                // the normal use case
                // just add in the db gadgets
                gadgetSpecs.AddRange(allDBGadgets.Values);
            }
            return(gadgetSpecs);
        }
Beispiel #10
0
        // tool gadgets
        public PreparedGadget(GadgetSpec gadgetSpec, OpenSocialManager openSocialManager)
        {
            this.gadgetSpec        = gadgetSpec;
            this.openSocialManager = openSocialManager;
            this.securityToken     = SocketSendReceive(openSocialManager.GetViewerURI(), openSocialManager.GetOwnerURI(), gadgetSpec.GetGadgetURL());

            // look at the view requirements and what page we are on to set some things
            GadgetViewRequirements viewReqs = GetGadgetViewRequirements();

            if (viewReqs != null)
            {
                this.view      = viewReqs.GetView();
                this.chromeId  = viewReqs.GetChromeId();
                this.optParams = viewReqs.GetOptParams();
            }
            else  // must be a sandbox gadget
            {
                this.view      = "";
                this.chromeId  = "gadgets-test-" + gadgetSpec.GetAppId();
                this.optParams = "{}";
            }
        }
        // tool gadgets
        public PreparedGadget(GadgetSpec gadgetSpec, OpenSocialManager openSocialManager)
        {
            this.gadgetSpec        = gadgetSpec;
            this.openSocialManager = openSocialManager;
            this.securityToken     = openSocialManager.GetSecurityToken(gadgetSpec.GetGadgetURL());

            // look at the view requirements and what page we are on to set some things
            GadgetViewRequirements viewReqs = GetGadgetViewRequirements();

            if (viewReqs != null)
            {
                this.view      = viewReqs.GetView();
                this.chromeId  = viewReqs.GetChromeIdBase() + "-" + GetAppId();
                this.optParams = viewReqs.GetOptParams();
            }
            else  // must be a sandbox gadget
            {
                this.view      = "sandbox";
                this.chromeId  = "gadgets-sandbox-" + GetAppId();
                this.optParams = "{}";
            }
        }
        public static Dictionary<string, GadgetSpec> GetAllDBGadgets(bool useCache)
        {
            // check cache first
            Dictionary<string, GadgetSpec> dbApps = useCache ? (Dictionary<string, GadgetSpec>)Cache.FetchObject(ORNG_GADGET_SPEC_KEY) : null;
            if (dbApps == null)
            {
                dbApps = new Dictionary<string, GadgetSpec>();
                Profiles.ORNG.Utilities.DataIO data = new Profiles.ORNG.Utilities.DataIO();
                using (SqlDataReader dr = data.GetGadgets())
                {
                    while (dr.Read())
                    {
                        GadgetSpec spec = new GadgetSpec(Convert.ToInt32(dr[0]), dr[1].ToString(), dr[2].ToString(), Convert.ToBoolean(dr[3]));
                        dbApps.Add(spec.GetFileName(), spec);
                    }
                }

                // add to cache unless noCache is turned on
                if (useCache)
                {
                    // set it to not timeout
                    Cache.Set(ORNG_GADGET_SPEC_KEY, dbApps, -1, null);
                }
            }

            return dbApps;
        }
        public static Dictionary<string, GadgetSpec> GetAllDBGadgets(bool useCache)
        {
            // check cache first
            Dictionary<string, GadgetSpec> dbApps = useCache ? (Dictionary<string, GadgetSpec>)Cache.FetchObject(GADGET_SPEC_KEY) : null;
            if (dbApps == null)
            {
                dbApps = new Dictionary<string, GadgetSpec>();
                Profiles.ORNG.Utilities.DataIO data = new Profiles.ORNG.Utilities.DataIO();
                using (SqlDataReader dr = data.GetGadgets())
                {
                    while (dr.Read())
                    {
                        String channelsStr = dr[3].ToString();
                        String[] channels = channelsStr != null && channelsStr.Length > 0 ? channelsStr.Split(' ') : new string[0];
                        GadgetSpec spec = new GadgetSpec(Convert.ToInt32(dr[0]), dr[1].ToString(), dr[2].ToString(), channels, Convert.ToBoolean(dr[4]), false);
                        string gadgetFileName = GetGadgetFileNameFromURL(dr[2].ToString());
                        dbApps.Add(gadgetFileName, spec);
                    }
                }

                // add to cache unless noCache is turned on
                if (useCache)
                {
                    // set it to not timeout
                    Cache.Set(GADGET_SPEC_KEY, dbApps, -1);
                }
            }

            return dbApps;
        }
 private List<PreparedGadget> GetSandboxGadgets(Dictionary<string, GadgetSpec> allDBGadgets, string requestAppId)
 {
     List<PreparedGadget> sandboxGadgets = new List<PreparedGadget>();
     // Add sandbox gadgets if there are any
     // Note that this block of code only gets executed after someone logs in with GadgetSandbox.aspx!
     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;
         // see if we have a gadget with the same file name in the DB, if so use its configuration
         if (allDBGadgets.ContainsKey(gadgetFileName))
         {
             appId = allDBGadgets[gadgetFileName].GetAppId();
             name = allDBGadgets[gadgetFileName].GetName();
             channels = allDBGadgets[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 gadgetSpec = new GadgetSpec(appId, name, openSocialGadgetURL, channels, true, sandboxOnly);
         // only add ones that are visible in this context!
         int moduleId = 0;
         if (sandboxOnly || gadgetSpec.Show(viewerId, ownerId, page.AppRelativeVirtualPath.Substring(2).ToLower()))
         {
             String securityToken = SocketSendReceive(viewerId, ownerId, gadgetSpec.GetGadgetURL());
             sandboxGadgets.Add(new PreparedGadget(gadgetSpec, this, moduleId++, securityToken));
         }
     }
     return sandboxGadgets;
 }
 internal void MergeWithSandboxGadget(GadgetSpec sandboxGadget)
 {
     // basically just grab it's URL, but check some things first!
     if (this.GetFileName() == sandboxGadget.GetFileName() && !this.fromSandbox && sandboxGadget.fromSandbox)
     {
         this.openSocialGadgetURL = sandboxGadget.openSocialGadgetURL;
         this.enabled = true;
     }
     else
     {
         throw new Exception("This merge is not allowed!");
     }
 }
Beispiel #16
0
 internal void MergeWithUnrecognizedGadget(GadgetSpec unrecognizedGadget)
 {
     // basically just grab it's URL, but check some things first!
     if (this.GetFileName() == unrecognizedGadget.GetFileName() && !this.unrecognized && unrecognizedGadget.unrecognized)
     {
         this.openSocialGadgetURL = unrecognizedGadget.openSocialGadgetURL;
         this.enabled = true;
     }
     else
     {
         throw new Exception("This merge is not allowed!");
     }
 }
        private List<GadgetSpec> GetGadgetSpecifications()
        {
            DebugLogging.Log("OpenSocialManager GetAllDBGadgets " + !noCache);
            Dictionary<string, GadgetSpec> allDBGadgets = GetAllDBGadgets(!noCache);
            List<GadgetSpec> gadgetSpecs = new List<GadgetSpec>();

            // if someone used the sandbox to log in, grab those gadgets, and only those gadget.
            // if a gadget with the same file name is in the DB, merge it in so that we can inherit it's configuruation
            if (page.Session != null && (string)page.Session[ORNG_GADGETS] != null)
            {
                // Add sandbox gadgets if there are any
                // Note that this block of code only gets executed after someone logs in with GadgetSandbox.aspx!
                String openSocialGadgetURLS = (string)page.Session[ORNG_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;
                    GadgetSpec sandboxGadget = new GadgetSpec(openSocialGadgetURL);
                    // see if we have a gadget with the same file name in the DB, if so use its configuration
                    if (allDBGadgets.ContainsKey(sandboxGadget.GetFileName()))
                    {
                        GadgetSpec gadget = allDBGadgets[sandboxGadget.GetFileName()];
                        gadget.MergeWithUnrecognizedGadget(sandboxGadget);
                        gadgetSpecs.Add(gadget);
                    }
                    else
                    {
                        gadgetSpecs.Add(sandboxGadget);
                    }
                }
            }
            else
            {
                // the normal use case
                // just add in the db gadgets
                gadgetSpecs.AddRange(allDBGadgets.Values);
            }
            return gadgetSpecs;
        }