Ejemplo n.º 1
0
        public static string wmGetAWSObjectList(string sCloudID, string sObjectType)
        {
            awsMethods acAWS = new awsMethods();

            string sHTML = "";
            string sErr  = "";

            DataTable dt = acAWS.GetCloudObjectsAsDataTable(sCloudID, sObjectType, ref sErr);

            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    GetAssociatedEcosystems(ref dt, sObjectType);
                    sHTML = DrawTableForType(sObjectType, dt);
                }
                else
                {
                    sHTML = "No data returned from the Cloud Provider.";
                }
            }
            else
            {
                sHTML += "<div class=\"ui-widget\" style=\"margin-top: 10px;\">";
                sHTML += "<div style=\"padding: 10px;\" class=\"ui-state-highlight ui-corner-all\">";
                sHTML += "<span style=\"float: left; margin-right: .3em;\" class=\"ui-icon ui-icon-info\"></span>";
                sHTML += "<p>" + sErr + "</p>";
                sHTML += "</div>";
                sHTML += "</div>";
            }

            return(sHTML);
        }
Ejemplo n.º 2
0
        public static string wmGetCloudObjectList(string sCloudID, string sObjectType)
        {
            acUI.acUI  ui    = new acUI.acUI();
            awsMethods acAWS = new awsMethods();

            string sXML  = "";
            string sErr  = "";
            string sHTML = "";

            //get the cloud object type from the session
            Provider        p   = ui.GetSelectedCloudProvider();
            CloudObjectType cot = ui.GetCloudObjectType(p, sObjectType);

            if (cot != null)
            {
                if (string.IsNullOrEmpty(cot.ID))
                {
                    sErr = "Cannot find definition for requested object type [" + sObjectType + "]"; return(null);
                }
            }
            else
            {
                sErr = "GetCloudObjectType failed for [" + sObjectType + "]";
                return(null);
            }


            sXML = acAWS.GetCloudObjectsAsXML(sCloudID, cot, ref sErr, null);
            if (!string.IsNullOrEmpty(sErr))
            {
                return("GetCloudObjectsAsXML failed with error: " + sErr);
            }
            if (string.IsNullOrEmpty(sXML))
            {
                return("Cloud connection was successful, but the query returned no data.");
            }



            //try a few debugging things:
            //Peek at our object type definition
            sHTML += "<div class=\"ui-state-default\">Cloud Object Type Definition</div>";
            sHTML += "<div class=\"ui-widget-content\">";
            if (cot != null)
            {
                string sReq = "<span class=\"ui-widget-content ui-state-error\">required</span>";

                //product stuff
                sHTML += "<span class=\"property\">Product:</span> <span class=\"code\">" + (string.IsNullOrEmpty(cot.ParentProduct.Name) ? sReq : cot.ParentProduct.Name).ToString() + "</span><br />";
                sHTML += "<span class=\"property\">APIVersion:</span> <span class=\"code\">" + (string.IsNullOrEmpty(cot.ParentProduct.APIVersion) ? sReq : cot.ParentProduct.APIVersion).ToString() + "</span><br />";

                //type stuff
                sHTML += "<span class=\"property\">Name:</span> <span class=\"code\">" + (string.IsNullOrEmpty(cot.ID) ? sReq : cot.ID).ToString() + "</span>";
                sHTML += "<span class=\"property\">Label:</span> <span class=\"code\">" + cot.Label + "</span><br />";
                sHTML += "<span class=\"property\">API:</span> <span class=\"code\">" + cot.APICall + "</span>";
                sHTML += "<span class=\"property\">APIUrlPrefix:</span> <span class=\"code\">" + cot.ParentProduct.APIUrlPrefix.ToString() + "</span>";
                sHTML += "<span class=\"property\">APICall:</span> <span class=\"code\">" + cot.APICall.ToString() + "</span><br />";
                sHTML += "<span class=\"property\">APIRequestGroupFilter:</span> <span class=\"code\">" + (string.IsNullOrEmpty(cot.APIRequestGroupFilter) ? "N/A" : cot.APIRequestGroupFilter) + "</span><br />";
                sHTML += "<span class=\"property\">APIRequestRecordFilter:</span> <span class=\"code\">" + (string.IsNullOrEmpty(cot.APIRequestRecordFilter) ? "N/A" : cot.APIRequestRecordFilter) + "</span><br />";
                sHTML += "<span class=\"property\">XMLRecordXPath:</span> <span class=\"code\">" + (string.IsNullOrEmpty(cot.XMLRecordXPath) ? sReq : cot.XMLRecordXPath).ToString() + "</span><br />";

                sHTML += "<div class=\"properties\">";
                if (cot.Properties.Count > 0)
                {
                    foreach (CloudObjectTypeProperty cop in cot.Properties)
                    {
                        sHTML += "<div class=\"ui-state-default\">" + cop.Name + "</div>";
                        sHTML += "<div class=\"ui-widget-content ui-corner-bottom\">";
                        sHTML += "<span class=\"property\">Label: <span class=\"code\">" + (string.IsNullOrEmpty(cop.Label) ? "N/A" : cop.Label) + "</span></span>";
                        sHTML += "<span class=\"property\">XPath: <span class=\"code\">" + cop.XPath + "</span></span>";
                        sHTML += "<span class=\"property\">HasIcon: <span class=\"code\">" + cop.HasIcon + "</span></span>";
                        sHTML += "<span class=\"property\">IsID: <span class=\"code\">" + cop.IsID + "</span></span>";
                        sHTML += "<span class=\"property\">ShortList: <span class=\"code\">" + cop.ShortList + "</span></span>";
                        sHTML += "</div>";
                    }
                }
                else
                {
                    sHTML += "<span class=\"ui-widget-content ui-state-error\">At least one Property is required.</span>";
                }
                sHTML += "</div>";
            }
            else
            {
                sHTML = "<span class=\"ui-widget-content ui-state-error\">GetCloudObjectType failed for [" + sObjectType + "].</span>";
            }

            //end object type definition box
            sHTML += "</div>";

            sHTML += "<hr />";


            //API RESULTS
            sHTML += "<div class=\"ui-state-default\">API Results</div>";
            sHTML += "<div class=\"ui-widget-content\">";

            //this will return false if the object doesn't have enough information to form a call
            if (cot.IsValidForCalls())
            {
                //we have a complete enough object type to make a call.
                //can it be parsed?

                sXML = ui.RemoveNamespacesFromXML(sXML);
                XElement xDoc = XElement.Parse(sXML);
                if (xDoc == null)
                {
                    sHTML += "<span class=\"ui-widget-content ui-state-error\">Cloud Response XML document is invalid.</span>.";
                }
                else
                {
                    sHTML += "Result is valid XML.";
                }



                //test the record xpath
                sHTML += "<div>Checking Record Xpath [" + cot.XMLRecordXPath + "]... ";
                if (cot.XMLRecordXPath != "")
                {
                    XElement xe = xDoc.XPathSelectElement(cot.XMLRecordXPath);
                    if (xe == null)
                    {
                        sHTML += "<span class=\"ui-state-info\">Record XPath [" + cot.XMLRecordXPath + "] was not found.</span><br />";
                        sHTML += "<span class=\"ui-state-info\">(This may be a normal condition if the Cloud doesn't contain any objects of this type.)</span>";
                    }
                    else
                    {
                        sHTML += "Record XPath matched [" + xe.Nodes().Count() + "] items.";
                    }
                }
                else
                {
                    sHTML += "Record XPath is not defined.";
                }
                sHTML += "</div>";



                sHTML += "<div class=\"ui-state-default\"><span id=\"api_results_toggler\" class=\"ui-icon-circle-triangle-e ui-icon floatleft\"></span>Result XML</div>";
                sHTML += "<div id=\"api_results_div\" class=\"hidden\">";
                sHTML += "<pre><code>";
                sHTML += ui.FixBreaks(ui.SafeHTML(sXML));
                sHTML += "</code></pre>";
                sHTML += "</div>";
            }
            else
            {
                sHTML = "<span class=\"ui-widget-content ui-state-error\">Cloud Object Type definition for [" + sObjectType + "] is incomplete.</span>";
            }

            //end API RESULTS
            sHTML += "</div>";


            return(sHTML);
        }
Ejemplo n.º 3
0
        public static string wmGetEcosystemObjectByType(string sEcosystemID, string sType)
        {
            dataAccess dc    = new dataAccess();
            awsMethods acAWS = new awsMethods();

            acUI.acUI ui = new acUI.acUI();

            try
            {
                string sHTML = "";
                string sErr  = "";

                //So, we'll first get a distinct list of all clouds represented in this set
                //then for each cloud we'll get the objects.
                string sSQL = "select distinct cloud_id" +
                              " from ecosystem_object" +
                              " where ecosystem_id ='" + sEcosystemID + "'" +
                              " and ecosystem_object_type = '" + sType + "'";

                DataTable dtClouds = new DataTable();
                if (!dc.sqlGetDataTable(ref dtClouds, sSQL, ref sErr))
                {
                    return(sErr);
                }


                if (dtClouds.Rows.Count > 0)
                {
                    foreach (DataRow drCloud in dtClouds.Rows)
                    {
                        string sCloudID = drCloud["cloud_id"].ToString();

                        //get the cloud object rows
                        sSQL = "select eo.ecosystem_object_id, eo.ecosystem_object_type" +
                               " from ecosystem_object eo" +
                               " where eo.ecosystem_id ='" + sEcosystemID + "'" +
                               " and eo.ecosystem_object_type = '" + sType + "'" +
                               " and eo.cloud_id = '" + sCloudID + "'" +
                               " order by eo.ecosystem_object_type";

                        DataTable dtObjects = new DataTable();
                        if (!dc.sqlGetDataTable(ref dtObjects, sSQL, ref sErr))
                        {
                            return(sErr);
                        }


                        if (dtObjects.Rows.Count > 0)
                        {
                            //we only need to hit the API once... this result will contain all the objects
                            //and our DrawProperties will filter the DataTable on the ID.
                            DataTable dtAPIResults = acAWS.GetCloudObjectsAsDataTable(sCloudID, sType, ref sErr);

                            foreach (DataRow drObject in dtObjects.Rows)
                            {
                                //look up the cloud and get the name
                                Cloud c = new Cloud(sCloudID);
                                if (c.ID != null)
                                {
                                    //giving each section a guid so we can delete it on the client side after the ajax call.
                                    //not 100% the ecosystem_object_id will always be suitable as a javascript ID.
                                    string sGroupID = ui.NewGUID();

                                    sHTML += "<div class=\"ui-widget-content ui-corner-all ecosystem_item\" id=\"" + sGroupID + "\">";


                                    string sObjectID = drObject["ecosystem_object_id"].ToString();

                                    string sLabel = "Cloud: " + c.Name + " - " + sObjectID;

                                    sHTML += "<div class=\"ui-widget-header ecosystem_item_header\">";
                                    sHTML += "<div class=\"ecosystem_item_header_title\"><span>" + sLabel + "</span></div>";

                                    sHTML += "<div class=\"ecosystem_item_header_icons\">";

                                    sHTML += "<span class=\"ui-icon ui-icon-close ecosystem_item_remove_btn pointer\"" +
                                             " id_to_delete=\"" + drObject["ecosystem_object_id"].ToString() + "\"" +
                                             " id_to_remove=\"" + sGroupID + "\">";
                                    sHTML += "</span>";

                                    sHTML += "</div>";

                                    sHTML += "</div>";

                                    //the details section
                                    sHTML += "<div class=\"ecosystem_item_detail\">";

                                    if (dtAPIResults != null)
                                    {
                                        if (dtAPIResults.Rows.Count > 0)
                                        {
                                            sHTML += DrawAllProperties(dtAPIResults, sObjectID);
                                        }
                                    }


                                    //end detail section
                                    sHTML += "</div>";
                                    //end block
                                    sHTML += "</div>";
                                }
                            }
                        }
                        else
                        {
                            sHTML += "<span>This ecosystem does not contain any Cloud Objects.</span>";
                        }
                    }
                }



                return(sHTML);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }