private static string GetAsynchronousBody(String serviceInterfaceName, MethodDefinition x)
        {

            StringBuilder sb = new StringBuilder();
            sb.AppendLine("using(System.ComponentModel.BackgroundWorker wrk = new System.ComponentModel.BackgroundWorker())");
            sb.AppendLine("{");
            if (x.ReturnType != null && x.ReturnType.Name != "void")
            {
                sb.Append("\t");
                sb.AppendLine(String.Format("var res = ({0})null;", x.ReturnType.FullName));
            }
            sb.Append("\t");
            sb.AppendLine("wrk.DoWork += (s, e) =>");
            sb.Append("\t");
            sb.AppendLine("{");
            sb.Append("\t");
            sb.Append("\t");
            if (x.ReturnType != null && x.ReturnType.Name != "void")
                sb.Append("res = ");

            sb.AppendFormat("{0}(", x.Name);
            foreach (var item in x.Parameters)
            {
                if (item != x.Parameters.First())
                    sb.Append(", ");
                sb.Append(item.Name);
            }
            sb.AppendLine(");");
            sb.Append("\t");
            sb.AppendLine("};");
            sb.Append("\t");
            sb.AppendLine("wrk.RunWorkerCompleted += (s, e) =>");
            sb.Append("\t");
            sb.AppendLine("{");
            sb.Append("\t");
            sb.Append("\t");
            sb.AppendLine("if (action != null)");
            sb.Append("\t");
            sb.Append("\t");
            sb.Append("\t");
            sb.Append("action(");
            if (x.ReturnType != null && x.ReturnType.Name != "void")
                sb.Append("res");
            sb.AppendLine(");");
            sb.Append("\t");
            sb.Append("\t");
            sb.AppendLine(String.Format("else if ({0}Completed != null)", x.Name));
            sb.Append("\t");
            sb.Append("\t");
            sb.Append("\t");
            sb.AppendFormat("{0}Completed(", x.Name);
            if (x.ReturnType != null && x.ReturnType.Name != "void")
                sb.Append("res");
            sb.AppendLine(");");
            sb.Append("\t");
            sb.Append("\t");
            sb.AppendLine("wrk.Dispose();");
            sb.Append("\t");
            sb.AppendLine("};");
            sb.Append("\t");
            sb.AppendLine("wrk.RunWorkerAsync();");
            sb.AppendLine("}");
            return sb.ToString();
        }
 private static string GetSynchronousBody(String serviceInterfaceName, MethodDefinition x)
 {
     StringBuilder sb = new StringBuilder();
     sb.AppendLine("System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();");
     sb.AppendLine("if (Logger.IsDebugEnabled)");
     sb.AppendLine("{");
     sb.Append("\t");
     sb.AppendFormat(@"Logger.Debug(""Method {0}.{1} started"");", serviceInterfaceName, x.Name);
     sb.AppendLine();
     sb.Append("\t");
     sb.AppendLine("timer.Start();");
     sb.AppendLine("}");
     sb.AppendFormat("{0} clt = null;", serviceInterfaceName);
     sb.AppendLine();
     sb.AppendLine("try");
     sb.AppendLine("{");
     sb.Append("\t");
     sb.AppendLine("if (Logger.IsDebugEnabled)");
     sb.Append("\t");
     sb.AppendLine("{");
     sb.Append("\t\t");
     sb.AppendLine(@"Logger.DebugFormat(""Creating client ({0})"", timer.Elapsed);");
     sb.Append("\t");
     sb.AppendLine("}");
     sb.Append("\t");
     sb.AppendLine("clt = CreateClient();");
     sb.Append("\t");
     sb.AppendLine("if (Logger.IsDebugEnabled)");
     sb.Append("\t");
     sb.AppendLine("{");
     sb.Append("\t\t");
     sb.AppendFormat(@"Logger.DebugFormat(""Calling client.{0} ({{0}})"", timer.Elapsed);", x.Name);
     sb.AppendLine();
     sb.Append("\t");
     sb.AppendLine("}");
     sb.Append("\t");
     if (x.ReturnType != null && x.ReturnType.Name != "void")
         sb.Append("return ");
     sb.AppendFormat("clt.{0}(", x.Name);
     foreach (var item in x.Parameters)
     {
         if (item != x.Parameters.First())
             sb.Append(", ");
         sb.Append(item.Name);
     }
     sb.AppendLine(");");
     sb.AppendLine("}");
     sb.AppendLine("finally");
     sb.AppendLine("{");
     sb.Append("\t");
     sb.AppendLine("if (Logger.IsDebugEnabled)");
     sb.Append("\t");
     sb.AppendLine("{");
     sb.Append("\t\t");
     sb.AppendLine(@"Logger.DebugFormat(""Closing client ({0})"", timer.Elapsed);");
     sb.Append("\t");
     sb.AppendLine("}");
     sb.Append("\t");
     sb.AppendLine("CloseClient(clt);");
     sb.Append("\t");
     sb.AppendLine("if (Logger.IsDebugEnabled)");
     sb.Append("\t");
     sb.AppendLine("{");
     sb.Append("\t\t");
     sb.AppendFormat(@"Logger.DebugFormat(""Method {0}.{1} finished ({{0}})"", timer.Elapsed);", serviceInterfaceName, x.Name);
     sb.AppendLine();
     sb.Append("\t");
     sb.AppendLine("}");
     sb.Append("}");
     return sb.ToString();
 }
        private static string GetSynchronousBody(String serviceInterfaceName, string baseNamespace, MethodDefinition x)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat(@"return {0}.Business.Factory.{1}ProviderFactory
                .CreateProvider(DataMode)
                .{2}", baseNamespace, serviceInterfaceName, x.Name);
            sb.Append("(");

            if (x.Parameters.Length > 0)
            {
                for (int i = 0; i < x.Parameters.Length - 1; i++)
                {
                    sb.Append(x.Parameters[i].Name);
                    sb.Append(", ");
                }
                sb.Append(x.Parameters[x.Parameters.Length - 1].Name);
            }
            sb.Append(");");
            return sb.ToString();
        }