Ejemplo n.º 1
0
 internal static string GetSignalCallbackMethodName(string idlSignalName)
 {
     return("On" + CodeBuilderCommon.GetSignalCompilableName(idlSignalName));
 }
Ejemplo n.º 2
0
        override protected void PostHandleSignal(IDLInterface idlIntf, IDLSignal idlSignal, CodeCompileUnit unit, CodeNamespace ns, CodeTypeDeclaration typeInterface)
        {
            string nsName, intf;
            int    lastDot = idlIntf.Name.LastIndexOf('.');

            intf   = idlIntf.Name.Substring(lastDot + 1);
            nsName = CodeBuilderCommon.GetNamespace(idlIntf.Name, new InterfaceVisitor());
            CodeFieldReferenceExpression fieldrefCallback = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), CodeBuilderCommon.callback);
            CodeFieldReferenceExpression fieldrefTarget   = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), CodeBuilderCommon.targetName);
            CodeNamespace nsClient      = this.GetClientNamespace(unit, idlIntf.Name);
            CodeNamespace nsClientTypes = nsClient;

            if (this.typedeclCallbackInterface == null) // If no callback interface yet
            {
                CodeTypeReference typerefInterface = new CodeTypeReference(typeInterface.Name);

                // Declare callback interface and hold onto it in field.
                // * public interface I<interface>Callback
                // * {
                string nsWCFName, intfWCF;
                nsWCFName = CodeBuilderCommon.GetNamespace(idlIntf.Name, this.visitorType);
                intfWCF   = CodeBuilderCommon.GetName(idlIntf.Name, null);
                string callbackInterfaceName = CodeBuilderCommon.GetSignalCallbackInterfaceName(intfWCF);
                typedeclCallbackInterface             = new CodeTypeDeclaration(callbackInterfaceName);
                typedeclCallbackInterface.Attributes  = MemberAttributes.Public;
                typedeclCallbackInterface.IsInterface = true;
                ns.Types.Add(typedeclCallbackInterface);

                // * class <interface>CallbackClient : I<interface>Callback
                string            wcfCallbackClientName    = CodeBuilderCommon.GetSignalCompilableName(intfWCF) + "CallbackClient";
                CodeTypeReference typerefCallbackInterface = new CodeTypeReference(typedeclCallbackInterface.Name);

                CodeAttributeDeclaration attribdeclServiceContract = new CodeAttributeDeclaration(CodeBuilderCommon.typerefServiceContract,
                                                                                                  new CodeAttributeArgument("CallbackContract", new CodeTypeOfExpression(typerefCallbackInterface))
                                                                                                  );
                typeInterface.CustomAttributes.Add(attribdeclServiceContract);

                //string scopedCallbackInterfaceName = CodeBuilderCommon.GetScopedName(nsWCFName, proxyInterfaceName);
                //typedeclCallbackClient = new CodeTypeDeclaration(CodeBuilderCommon.GetSignalCallbackName(intf));
                typedeclCallbackClient = new CodeTypeDeclaration(wcfCallbackClientName);
                CodeTypeReference typerefWCFCallbackInterface = new CodeTypeReference(typedeclCallbackInterface.Name);
                typedeclCallbackClient.BaseTypes.Add(typerefWCFCallbackInterface);

                nsClientTypes.Types.Add(typedeclCallbackClient);

                // * public class <interface>Proxy : Udbus.WCF.Client.CallbackProxy< <wcf_contracts.interface>, <interface>CallbackClient >
                this.typedeclProxy = new CodeTypeDeclaration(CodeBuilderCommon.GetSignalProxyName(intfWCF));
                CodeTypeReference typerefCallbackProxy  = new CodeTypeReference(typeof(Udbus.WCF.Client.CallbackProxy <,>));
                CodeTypeReference typerefCallbackClient = new CodeTypeReference(typedeclCallbackClient.Name);
                typerefCallbackProxy.TypeArguments.Add(typerefInterface);
                typerefCallbackProxy.TypeArguments.Add(typerefCallbackClient);
                this.typedeclProxy.BaseTypes.Add(typerefCallbackProxy);

                AddProxyConstructors(this.typedeclProxy);

                nsClientTypes.Types.Add(this.typedeclProxy);
            } // Ends if no callback interface yet

            // Add signal property to Proxy.
            CodeMemberProperty propProxySignal = CodeBuilderCommon.CreateSignalEventProperty(idlSignal);

            propProxySignal.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            CodePropertyReferenceExpression proprefProxyInterface     = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "ProxyInterface");
            CodePropertyReferenceExpression proprefProxyCallback      = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "Callback");
            CodePropertyReferenceExpression proprefProxyCallbackEvent = new CodePropertyReferenceExpression(proprefProxyCallback, propProxySignal.Name);

            propProxySignal.GetStatements.Add(new CodeMethodReturnStatement(proprefProxyCallbackEvent));
            propProxySignal.SetStatements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(proprefProxyCallbackEvent, CodeBinaryOperatorType.IdentityEquality, new CodePrimitiveExpression(null))
                                                                         , new CodeExpressionStatement(new CodeMethodInvokeExpression(proprefProxyInterface, CodeBuilderCommon.GetSignalRegisterFunction(idlSignal.Name)))
                                                                         ));
            propProxySignal.SetStatements.Add(new CodeAssignStatement(proprefProxyCallbackEvent, new CodePropertySetValueReferenceExpression()));
            this.typedeclProxy.Members.Add(propProxySignal);

            // Add callback method to callback interface.
            // * [System.ServiceModel.OperationContract(IsOneWay=true)]
            // * void On<signal>(<interface_ns>.<signal>Args args);
            CodeMemberMethod methodOnSignal = new CodeMemberMethod();

            methodOnSignal.Name = CodeBuilderCommon.GetSignalCallbackMethodName(idlSignal.Name);
            string signalArgsTypeName       = CodeBuilderCommon.GetSignalEventTypeName(idlSignal.Name);
            string scopedSignalArgsTypeName = CodeBuilderCommon.GetScopedName(nsName, signalArgsTypeName);
            CodeParameterDeclarationExpression paramdeclSignalArgs = new CodeParameterDeclarationExpression(scopedSignalArgsTypeName,
                                                                                                            CodeBuilderCommon.SignalArgsName);

            methodOnSignal.Parameters.Add(paramdeclSignalArgs);
            methodOnSignal.CustomAttributes.Add(CodeBuilderCommon.attribOperationContractOneWay);
            typedeclCallbackInterface.Members.Add(methodOnSignal);

            // Add registration method to wcf interface.
            // * [System.ServiceModel.OperationContract]
            // * void RegisterForStorageSpaceLow();
            CodeMemberMethod methodRegister = new CodeMemberMethod();

            methodRegister.Name = CodeBuilderCommon.GetSignalRegisterFunction(idlSignal.Name);
            methodRegister.CustomAttributes.Add(CodeBuilderCommon.attribOperationContract);
            typeInterface.Members.Add(methodRegister);

            // Add event to callback client implementation.

            // * private event System.EventHandler< <signal>Args > <signal>Event;
            CodeMemberEvent eventSignal = CodeBuilderCommon.CreateSignalEvent(idlSignal);

            typedeclCallbackClient.Members.Add(eventSignal);

            // * public virtual System.EventHandler< <signal>Args > <signal>
            // * {
            // *     get { return this.<signal>Event; }
            // *     set { this.<signal>Event = value; }
            // * }
            CodeMemberProperty propSignal = CodeBuilderCommon.CreateSignalEventProperty(idlSignal);

            propSignal.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            CodeEventReferenceExpression eventrefSignal = new CodeEventReferenceExpression(new CodeThisReferenceExpression(), eventSignal.Name);

            propSignal.GetStatements.Add(new CodeMethodReturnStatement(eventrefSignal));
            propSignal.SetStatements.Add(new CodeAssignStatement(eventrefSignal, new CodePropertySetValueReferenceExpression()));
            typedeclCallbackClient.Members.Add(propSignal);

            // * public void On<signal>(<ns>.<signal>Args args)
            // * {
            // *     if (this.<signal> != null)
            // *     {
            // *         this.<signal>(this, args);
            // *     }
            //}
            CodeMemberMethod methodSignal = new CodeMemberMethod();

            methodSignal.Name       = CodeBuilderCommon.GetSignalCallbackMethodName(idlSignal.Name);
            methodSignal.Attributes = MemberAttributes.Public;
            methodSignal.Parameters.Add(paramdeclSignalArgs);
            CodePropertyReferenceExpression proprefSignal = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), propSignal.Name);

            methodSignal.Statements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(eventrefSignal, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null))
                                                                   , new CodeExpressionStatement(new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), eventrefSignal.EventName, new CodeThisReferenceExpression(), new CodeArgumentReferenceExpression(paramdeclSignalArgs.Name)))
                                                                   ));
            typedeclCallbackClient.Members.Add(methodSignal);
        }
Ejemplo n.º 3
0
 internal static string GetSignalProxyName(string idlInterfaceName)
 {
     return(CodeBuilderCommon.GetSignalCompilableName(idlInterfaceName) + "Proxy");
 }