Beispiel #1
0
        /**
         * this method requests a resource to be added to the meeting, by sending
         * out a RecommendationRequest Context Message to the local InfoAgent
         * */
        private void m_btnReq_Click(object sender, System.EventArgs e)
        {
            MeetingRequestMsg mtgReq = new MeetingRequestMsg();

            mtgReq.MeetingID         = strSelectedMtg;
            mtgReq.MeetingTopic      = mDAO.GetMeetingTopic(strSelectedMtg);
            mtgReq.Sender            = me.Name;
            mtgReq.SenderUrl         = strMyUrl;
            mtgReq.m_lstParticipants = pDAO.GetParticipants(strSelectedMtg);
            RecommendationRequestCtxMsg recReqCtxMsg = new RecommendationRequestCtxMsg(mtgReq);

            recReqCtxMsg.Type = enuContextMsgType.RecommendationRequest;

            string strS = recReqCtxMsg.ToXml();

            myctx.ClearParameters();
            myctx.MethodName = "RequestRecommendation";
            myctx.AddParameter(Serializer.Serialize(strS));

            Object objRes = null;

            try
            {
                objRes = myexec.Execute(myctx);
            }
            catch (Exception ex)
            {
                string strExceptionMsg = ex.Message;
            }
        }
        /**
         * this method sends a resource
         * first, it checks to see if any new resource request messages have arrived
         * into the ContextMessageDAO.  If so, then for each resource request, it
         * sends a resource response to the sender.  For each selected resource in the GUI,
         * it adds the resource to the resource response.  Next, it creates an Executor / Executor
         * Context to communicate with the InfoAgent that sent the message.  It then calls the Recommend
         * method on that InfoAgent that requested the resource, passing the selected resources (serialized)
         * in the parameter
         * */
        private void m_btnSend_Click(object sender, System.EventArgs e)
        {
            //first i check for resource request messages
            ArrayList   lstNew = cmDAO.GetNewReceivedContextMessages();
            IEnumerator it     = lstNew.GetEnumerator();

            while (it.MoveNext())
            {
                if (it.Current is RecommendationRequestCtxMsg)
                {
                    RecommendationRequestCtxMsg  recReq     = (RecommendationRequestCtxMsg)it.Current;
                    RecommendationResponseCtxMsg respctxmsg = new RecommendationResponseCtxMsg(recReq);

                    ResourceMsg msg = new ResourceMsg();
                    msg.MeetingID = recReq.MeetingID;
                    msg.Sender    = respctxmsg.Sender;
                    msg.SenderUrl = respctxmsg.SenderUrl;

                    foreach (string strSel in m_boxResources.SelectedItems)
                    {
                        foreach (Resource r in lstResources)
                        {
                            if (r.ID == strSel)
                            {
                                msg.m_lstResources.Add(r);
                            }
                        }
                    }

                    respctxmsg.ResourceMessage = msg;

                    string strResponse     = Serializer.Serialize(respctxmsg.ToXml());
                    string strInfoagenturl = recReq.SenderUrl;

                    ProxyGenRequest pxyreq = new ProxyGenRequest();
                    pxyreq.ProxyPath   = "";
                    pxyreq.ServiceName = "InfoAgent";
                    pxyreq.WsdlUrl     = strInfoagenturl;

                    ProxyPolicyMutator mymutator = new ProxyPolicyMutator();
                    mymutator.ProxyName = pxyreq.ServiceName;

                    // Ensure the name of the file generated is unique
                    string strMySuffix = "";
                    int    nMyCode     = Guid.NewGuid().GetHashCode();
                    if (nMyCode < 0)
                    {
                        nMyCode = nMyCode * -1;
                    }
                    strMySuffix        = nMyCode.ToString();
                    pxyreq.ServiceName = pxyreq.ServiceName + "_" + strMySuffix;

                    ProxyGen myPxyGen = new ProxyGen();
                    myPxyGen.Mutator = mymutator;

                    string strMyAssembly = "";
                    try
                    {
                        strMyAssembly = myPxyGen.GenerateAssembly(pxyreq);
                    }
                    catch (Exception excep)
                    {
                        string strString = excep.Message;
                    }

                    ExecContext myctx = new ExecContext();
                    myctx.ServiceName = pxyreq.Namespace + "." + mymutator.ProxyName;
                    myctx.Assembly    = strMyAssembly;

                    Executor myexec = new Executor();
                    myexec.Settings.ExpectSignedResponse = false;
                    myexec.Settings.SigningCertificate   = cert;

                    myctx.MethodName = "Recommend";
                    myctx.AddParameter(strResponse);

                    object objectRes = null;

                    try
                    {
                        objectRes = myexec.Execute(myctx);
                    }
                    catch (Exception exc)
                    {
                        string strBsg = exc.Message;
                        return;
                    }
                }
            }
        }