예제 #1
0
        // Simple scenario to show how an agent could execute a WS described using
        // DAML
        private object DemoExecuteService(DamlProcess process, DAMLParameter zipcode)
        {
            object objRes = null;

            // Ensure zipcode.Type matches to System.String in .NET world
            if (zipcode.Type == enuDAMLType.stringType && process.Inputs[0].Range.IndexOf("#string") != -1)
            {
                DynamicPxy.WeatherRetriever wr = new DynamicPxy.WeatherRetriever();
                Type PxyType = wr.GetType();

                // Even though we pass zipcode.data which is an object it is
                // dynamically cast to string
                MethodInfo mInfo = PxyType.GetMethod(process.Name);
                if (mInfo != null)
                {
                    objRes = mInfo.Invoke(wr, new object[] { zipcode.Data });
                }
            }
            else
            {
                MessageBox.Show("Input type mismatch on process execute");
            }

            return(objRes);
        }
예제 #2
0
        // Hook into combo box selection change event
        // to retrieve details on process
        private void cmbProcess_TextChanged(object sender, System.EventArgs e)
        {
            string strEvent = e.ToString();

            // If no text selected then exit
            if (this.cmbProcess.Text == "")
            {
                return;
            }

            // otherwise go get data and display
            DamlProcess    process     = new DamlProcess();
            enuProcessType processType = enuProcessType.AtomicProcess;

            if (rdoAtomic.Checked)
            {
                processType = enuProcessType.AtomicProcess;
            }
            else if (rdoSimple.Checked)
            {
                processType = enuProcessType.SimpleProcess;
            }
            else
            {
                processType = enuProcessType.CompositeProcess;
            }

            // Do query
            process = m_processModel.GetProcessData(cmbProcess.Text, processType);

            LoadProcessData(process, ref tvwDetails);
        }
예제 #3
0
        public frmMain()
        {
            m_demoProcess = new DamlProcess();

            // Can only execute Atomic processes
            m_demoProcess.ProcessType = enuProcessType.AtomicProcess;
            m_demoProcess.Name        = "GetWeather";

            // Inputs necessary
            RdfProperty input = new RdfProperty();

            input.Name          = "zipcode";
            input.Domain        = "#WeatherRetriever";
            input.Range         = "http://www.w3.org/2000/10/XMLSchema#string";
            input.SubPropertyOf = "http://www.daml.org/services/daml-s/2001/10/Process.daml#input";
            input.SameValueAs   = "";

            m_demoProcess.AddInput(input);

            // Conditional output
            // WS returns complex type (class instance) this maps to DAML "Thing"
            RdfProperty condOutput = new RdfProperty();

            condOutput.Name          = "CurrentWeather";
            condOutput.Domain        = "#WeatherRetriever";
            condOutput.Range         = "http://www.daml.org/2001/03/daml+oil#Thing";
            condOutput.SubPropertyOf = "http://www.daml.org/services/daml-s/2001/10/Process.daml#conditionalOutput";

            m_demoProcess.AddConditionalOutput(condOutput);

            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }
        public static string GenerateDaml(string strWsdlUrl)
        {
            // Read in Service Description from url
            ServiceDescription svcDesc = ServiceDescription.Read(Wsdl2DamlGen.GetHttpStream(strWsdlUrl));

            ServiceCollection svcColl = svcDesc.Services;

            // Get the services in the service Description collection
            // Expect only one
            // for the first one create a DamlProcess instance (atomic process)
            // for each method in the web service

            if (svcColl.Count == 0)
            {
                return("");
            }

            Service svc = svcColl[0];

            // Generate assembly in memory representing web service proxy
            // use reflection on it to get method data, inputs, outputs etc
            // For each method we create a Daml atomic process
            // and add data for its inputs, and outputs at least
            // no provision to add data on preconditions etc.
            // since more information would be needed than we get from
            // the wsdl
            Assembly proxyAssembly = GenerateAssembly(ref svcDesc);

            if (proxyAssembly == null)
            {
                throw new Exception("Error generating in memory web service proxy assembly");
            }

            string strServiceName = Wsdl2DamlGen.AUTO_GEN_NAMESPACE + "." + svc.Name;

            DamlProcessModelWriter damlWriter = new DamlProcessModelWriter();

            // Get all the types defined in the assembly
            Type[] arrTypes = proxyAssembly.GetTypes();
            // Get the type representing the web service
            Type proxyType = proxyAssembly.GetType(strServiceName, true);

            // Ask for all its methods, these are our daml atomic process
            // We only want the public instance methods declared at this type's level
            // we are not interested in any inherited methods
            MethodInfo[] arrMethods = proxyType.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);

            for (int i = 0; i < arrMethods.Length; i++)
            {
                // Get the current method
                MethodInfo currMethod = arrMethods[i];
                // Get the parameters expected by this method
                ParameterInfo[] arrParams = currMethod.GetParameters();
                // Get the return type of this method
                Type returnType = currMethod.ReturnType;

                // Flags whether we ignore or process this method
                bool bIgnoreMethod = false;

                // Ignore constructors and async methods
                if (currMethod.IsConstructor || currMethod.ReturnType == typeof(System.IAsyncResult))
                {
                    continue;
                }

                for (int j = 0; j < arrParams.Length; j++)
                {
                    if (arrParams[j].ParameterType == typeof(System.IAsyncResult))
                    {
                        bIgnoreMethod = true;
                        break;
                    }
                }

                if (bIgnoreMethod)
                {
                    continue;
                }

                // We do not want any of the async methods
                // filter based on paramters
                // Basically any method that expects or returns
                // System.IAsyncResult
                // neither do we want the constructor(s)

                DamlProcess process = new DamlProcess();
                process.Name = currMethod.Name;

                // Get the input and output types and add them to the process
                for (int x = 0; x < arrParams.Length; x++)
                {
                    RdfProperty input = new RdfProperty();

                    // Set the name of the input
                    input.Name = arrParams[x].Name;
                    // Set domain - name of methd
                    input.Domain = process.Name;
                    // Set subproperty - set as a subProperty of Process Inputs
                    input.SubPropertyOf = DamlConstants.PROCESS_INPUT_URI;

                    // Map .NET type to DamlTypes - strings, decimals, daml+oil#Thing
                    input.Range = "http://www.daml.org/2001/03/daml+oil#Thing";

                    process.AddInput(input);

                    // Create input restriction
                    DamlRestriction restriction = new DamlRestriction();
                    // Set the cardinality
                    restriction.Cardinality = 1;
                    // Set the owner
                    restriction.Owner = input.Domain;
                    // Specify the property to which the restriction applies
                    restriction.OnProperty = "#" + input.Name;

                    // Add restriction to process
                    process.AddRestriction(enuIOPEType.Input, new DamlRestriction[] { restriction });
                }

                // Add output to process
                if (returnType.FullName != (typeof(void).FullName))
                {
                    RdfProperty output = new RdfProperty();

                    // Set the name of the input
                    output.Name = process.Name + "Out";
                    // Set domain - name of methd
                    output.Domain = process.Name;
                    // Set subproperty - set as a subProperty of Process Inputs
                    output.SubPropertyOf = DamlConstants.PROCESS_OUTPUT_URI;

                    // Map .NET type to DamlTypes - strings, decimals, daml+oil#Thing
                    output.Range = "http://www.daml.org/2001/03/daml+oil#Thing";

                    process.AddOutput(output);
                }

                // Add the process to the process model writer
                damlWriter.AddDamlProcess(process);
            }

            return(damlWriter.ToXml());
        }
예제 #5
0
        private void LoadProcessData(DamlProcess process, ref TreeView tview)
        {
            // Clear treeview
            tview.Nodes.Clear();

            if (!process.HasData)
            {
                tview.Nodes.Add("No Details");
                return;
            }

            // Add nodes...

            // Inputs...
            if (process.HasInputs)
            {
                TreeNode      Node    = new TreeNode("Inputs");
                RdfProperty[] arrData = process.Inputs;

                for (int i = 0; i < arrData.Length; i++)
                {
                    Node.Nodes.Add(arrData[i].Name + " -> " + arrData[i].Range);
                }

                tview.Nodes.Add(Node);
            }

            if (process.HasParameters)
            {
                TreeNode      Node    = new TreeNode("Parameters");
                RdfProperty[] arrData = process.Parameters;

                for (int i = 0; i < arrData.Length; i++)
                {
                    Node.Nodes.Add(arrData[i].Name + " -> " + arrData[i].Range);
                }

                tview.Nodes.Add(Node);
            }

            if (process.HasOutputs)
            {
                TreeNode      Node    = new TreeNode("Outputs");
                RdfProperty[] arrData = process.Outputs;

                for (int i = 0; i < arrData.Length; i++)
                {
                    Node.Nodes.Add(arrData[i].Name + " -> " + arrData[i].Range);
                }

                tview.Nodes.Add(Node);
            }

            if (process.HasConditionalOutputs)
            {
                TreeNode      Node    = new TreeNode("ConditionalOutputs");
                RdfProperty[] arrData = process.ConditionalOutputs;

                for (int i = 0; i < arrData.Length; i++)
                {
                    Node.Nodes.Add(arrData[i].Name + " -> " + arrData[i].Range);
                }

                tview.Nodes.Add(Node);
            }

            if (process.HasCoOutputs)
            {
                TreeNode      Node    = new TreeNode("CoOutputs");
                RdfProperty[] arrData = process.CoOutputs;

                for (int i = 0; i < arrData.Length; i++)
                {
                    Node.Nodes.Add(arrData[i].Name + " -> " + arrData[i].Range);
                }

                tview.Nodes.Add(Node);
            }

            if (process.HasEffects)
            {
                TreeNode      Node    = new TreeNode("Effects");
                RdfProperty[] arrData = process.Effects;

                for (int i = 0; i < arrData.Length; i++)
                {
                    Node.Nodes.Add(arrData[i].Name + " -> " + arrData[i].Range);
                }

                tview.Nodes.Add(Node);
            }

            if (process.HasCoConditions)
            {
                TreeNode      Node    = new TreeNode("CoConditions");
                RdfProperty[] arrData = process.CoConditions;

                for (int i = 0; i < arrData.Length; i++)
                {
                    Node.Nodes.Add(arrData[i].Name + " -> " + arrData[i].Range);
                }

                tview.Nodes.Add(Node);
            }

            if (process.HasPreconditions)
            {
                TreeNode      Node    = new TreeNode("Preconditions");
                RdfProperty[] arrData = process.Preconditions;

                for (int i = 0; i < arrData.Length; i++)
                {
                    Node.Nodes.Add(arrData[i].Name + " -> " + arrData[i].Range);
                }

                tview.Nodes.Add(Node);
            }

            if (process.HasSubProcesses)
            {
                TreeNode      Node    = new TreeNode("SubProcesses");
                DamlProcess[] arrData = process.SubProcesses;

                for (int i = 0; i < arrData.Length; i++)
                {
                    Node.Nodes.Add(arrData[i].Name + " -> " + arrData[i].ProcessType.ToString());
                }

                tview.Nodes.Add(Node);
            }

            // Expand inputs
            tview.Nodes[0].Expand();
        }