コード例 #1
0
ファイル: Client.cs プロジェクト: tuga1975/DeviceServer
 public void Serialise(Stream stream)
 {
     IPCHelper.Write(stream, ClientID);
     IPCHelper.Write(stream, Name);
     IPCHelper.Write(stream, Lifetime);
     IPCHelper.Write(stream, Version.ToString());
     IPCHelper.Write(stream, BindingMode.ToString());
     IPCHelper.Write(stream, SMSNumber);
     if (SupportedTypes == null)
     {
         IPCHelper.Write(stream, (int)-1);
     }
     else
     {
         SupportedTypes.Serialise(stream);
     }
     stream.Flush();
 }
コード例 #2
0
        private void CreateBindingOverrideMethod(List <ExpressionContainer> bindingExpressions, CodePropertyReferenceExpression localizationServiceReference, Dictionary <string, CodePropertyReferenceExpression> resourceReferences, params CodeMethodReferenceExpression[] preCallMethods)
        {
            CodeTypeReference listOfBindingObjectTypeReference = CodeGeneratorHelper.GetTypeReferenceFromName("List<BindingObject>");
            CodeTypeReference bindingObjectTypeReference       = CodeGeneratorHelper.GetTypeReferenceFromName("BindingObject");
            CodeTypeReference bindingExpressionTypeReference   = CodeGeneratorHelper.GetTypeReferenceFromName("BindingExpression");

            CodeMemberMethod method = new CodeMemberMethod
            {
                Attributes = MemberAttributes.Family | MemberAttributes.Override,
                Name       = NameGeneratorHelper.GET_BINDING_METHOD_NAME,
                ReturnType = listOfBindingObjectTypeReference
            };

            foreach (CodeMethodReferenceExpression preCallMethod in preCallMethods)
            {
                method.Statements.Add(new CodeMethodInvokeExpression(preCallMethod));
            }

            var variableCreationResult = CodeGeneratorHelper.CreateVariable(listOfBindingObjectTypeReference, "result");

            method.Statements.Add(variableCreationResult.Item1);
            CodeVariableReferenceExpression resultReference = variableCreationResult.Item2;

            // group binding expression by target object to simplify
            foreach (IGrouping <string, ExpressionContainer> groupedExpressions in bindingExpressions.GroupBy(x => x.TargetObject))
            {
                // create a variable for this binding object and build it with the Property of the view element
                variableCreationResult = CodeGeneratorHelper.CreateVariable(bindingObjectTypeReference, NameGeneratorHelper.GetBindingObjectName(), CodeGeneratorHelper.GetPropertyReference(groupedExpressions.Key));                //viewElementReferences[groupedExpressions.Key]);
                method.Statements.Add(variableCreationResult.Item1);

                CodeVariableReferenceExpression objectReference = variableCreationResult.Item2;
                method.Statements.Add(new CodeMethodInvokeExpression(resultReference, "Add", objectReference));


                foreach (ExpressionContainer expressionContainer in groupedExpressions)
                {
                    Expression expression = expressionContainer.Expression;
                    // create a binding expression for this
                    variableCreationResult = CodeGeneratorHelper.CreateVariable(bindingExpressionTypeReference, NameGeneratorHelper.GetBindingExpressionName(), new CodePrimitiveExpression(expressionContainer.TargetField),
                                                                                new CodePrimitiveExpression(expression.GetValue(BindingExpression.PATH)));
                    method.Statements.Add(variableCreationResult.Item1);

                    CodeVariableReferenceExpression expressionReference = variableCreationResult.Item2;

                    if (expression.Has(BindingExpression.MODE) && expression.Get <ModeExpression>(BindingExpression.MODE).Value != BindingMode.OneWay)
                    {
                        // Expression could only be of type ModeExpression
                        BindingMode mode = expression.Get <ModeExpression>(BindingExpression.MODE).Value;
                        method.Statements.Add(new CodeAssignStatement(new CodePropertyReferenceExpression(expressionReference, "Mode"),
                                                                      new CodeFieldReferenceExpression(new CodeTypeReferenceExpression("BindingMode"), mode.ToString())));
                    }
                    if (expression.Has(BindingExpression.UPDATE_EVENT) && !string.IsNullOrWhiteSpace(expression.GetValue(BindingExpression.UPDATE_EVENT)))
                    {
                        // Expression could only be of type Text
                        string updateEvent = expression.GetValue(BindingExpression.UPDATE_EVENT);
                        method.Statements.Add(new CodeAssignStatement(new CodePropertyReferenceExpression(expressionReference, "UpdateEvent"), new CodePrimitiveExpression(updateEvent)));
                    }
                    if (expression.Has(BindingExpression.CONVERTER))
                    {
                        // Expression could be type Resource or (Binding : not implemented for now)
                        Expression converterExpression = expression[BindingExpression.CONVERTER];
                        if (converterExpression.IsOfType(ExpressionType.Binding))
                        {
                            Log.LogError("Binding expression for converter is not implemented yet");
                            throw new NotImplementedException("Binding expression for converter is not implemented yet");
                        }
                        else if (converterExpression.IsOfType(ExpressionType.Resource))
                        {
                            string resourceKey = converterExpression.GetValue(ResourceExpression.KEY);
                            CodePropertyReferenceExpression resourceReference = resourceReferences[resourceKey];

                            method.Statements.Add(new CodeAssignStatement(new CodePropertyReferenceExpression(expressionReference, "Converter"), resourceReference));
                        }
                    }
                    if (expression.Has(BindingExpression.CONVERTER_PARAMETER))
                    {
                        // Expression could be of type Resource, Translation, Text or (Binding : not implemented for now)
                        Expression converterParameterExpression = expression[BindingExpression.CONVERTER_PARAMETER];
                        if (converterParameterExpression.IsOfType(ExpressionType.Binding))
                        {
                            Log.LogError("Binding expression for converter parameter is not implemented yet");
                            throw new NotImplementedException("Binding expression for converter parameter is not implemented yet");
                        }
                        else if (converterParameterExpression.IsOfType(ExpressionType.Resource))
                        {
                            string resourceKey = converterParameterExpression.GetValue(ResourceExpression.KEY);
                            CodePropertyReferenceExpression resourceReference = resourceReferences[resourceKey];

                            method.Statements.Add(new CodeAssignStatement(new CodePropertyReferenceExpression(expressionReference, "ConverterParameter"), resourceReference));
                        }
                        else if (converterParameterExpression.IsOfType(ExpressionType.Translation))
                        {
                            CodeMethodInvokeExpression valueReference = GenerateStatementToGetTranslation(localizationServiceReference, converterParameterExpression);
                            method.Statements.Add(new CodeAssignStatement(new CodePropertyReferenceExpression(expressionReference, "ConverterParameter"), valueReference));
                        }
                        else if (converterParameterExpression.IsOfType(ExpressionType.Value))
                        {
                            TextExpression textExpression = converterParameterExpression as TextExpression;
                            if (textExpression != null)
                            {
                                string converterParameterValue = textExpression.Value;
                                method.Statements.Add(new CodeAssignStatement(new CodePropertyReferenceExpression(expressionReference, "ConverterParameter"), new CodePrimitiveExpression(converterParameterValue)));
                            }
                            else
                            {
                                throw new InvalidOperationException("Can't get a textExpression from a ExpressionType.Value expression...");
                            }
                        }
                    }

                    if (!string.IsNullOrWhiteSpace(expressionContainer.CommandParameterTarget))
                    {
                        method.Statements.Add(new CodeAssignStatement(new CodePropertyReferenceExpression(expressionReference, "CommandParameter"),
                                                                      CodeGeneratorHelper.GetPropertyReference(expressionContainer.CommandParameterTarget)));
                    }

                    method.Statements.Add(new CodeMethodInvokeExpression(objectReference, "AddExpression", expressionReference));
                }
            }

            method.Statements.Add(new CodeMethodReturnStatement(resultReference));

            Methods.Add(method);
        }
コード例 #3
0
 public override string ToString()
 {
     return("[BindingRelationship:from:" + source.GetType() + ",to:" + target.GetType()
            + ",mode:" + mode.ToString() + "]");
     // + Json.jsonEncode(map);
 }