/// <summary>
        /// Format the RPC server as text.
        /// </summary>
        /// <param name="remove_comments">True to remove comments from the output.</param>
        /// <returns>The formatted RPC server.</returns>
        public string FormatAsText(bool remove_comments)
        {
            INdrFormatter formatter = DefaultNdrFormatter.Create(remove_comments
                ? DefaultNdrFormatterFlags.RemoveComments : DefaultNdrFormatterFlags.None);
            StringBuilder builder = new StringBuilder();

            if (!remove_comments)
            {
                builder.AppendLine($"// DllOffset: 0x{Offset:X}");
                builder.AppendLine($"// DllPath {FilePath}");
            }

            if (ComplexTypes.Any())
            {
                if (!remove_comments)
                {
                    builder.AppendLine("// Complex Types: ");
                }
                foreach (var type in ComplexTypes)
                {
                    builder.AppendLine(formatter.FormatComplexType(type));
                }
            }

            builder.AppendLine().AppendLine(formatter.FormatRpcServerInterface(Server));

            return(builder.ToString());
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates and adds a new complex type to the conceptual model.
 /// </summary>
 /// <param name="name">Type name for the new complex type.</param>
 /// <returns>A ModelComplexType corresponding to the new complex type.</returns>
 public ModelComplexType AddComplexType(string name)
 {
     try
     {
         if (!EntityTypes.Any(et => et.Name == name) &&
             !ComplexTypes.Any(ct => ct.Name == name))
         {
             ModelComplexType ct = new ModelComplexType(ParentFile, this, name);
             _modelComplexTypes.Add(name, ct);
             ct.NameChanged += new EventHandler <NameChangeArgs>(ct_NameChanged);
             ct.Removed     += new EventHandler(ct_Removed);
             return(ct);
         }
         else
         {
             throw new ArgumentException("A type with the name " + name + " already exist in the model.");
         }
     }
     catch (Exception ex)
     {
         try
         {
             if (!ex.Data.Contains("EDMXType"))
             {
                 ex.Data.Add("EDMXType", this.GetType().Name);
             }
             if (!ex.Data.Contains("EDMXObjectName"))
             {
                 ex.Data.Add("EDMXObjectName", this.ContainerName);
             }
         }
         catch { }
         throw;
     }
 }
        /// <summary>
        /// Format the RPC server as text.
        /// </summary>
        /// <param name="remove_comments">True to remove comments from the output.</param>
        /// <param name="cpp_format">Formating using C++ pseduo syntax.</param>
        /// <returns>The formatted RPC server.</returns>
        public string FormatAsText(bool remove_comments, bool cpp_format)
        {
            DefaultNdrFormatterFlags flags = remove_comments
                ? DefaultNdrFormatterFlags.RemoveComments : DefaultNdrFormatterFlags.None;
            INdrFormatter formatter = cpp_format ? CppNdrFormatter.Create(flags) : DefaultNdrFormatter.Create(flags);
            StringBuilder builder   = new StringBuilder();

            if (!remove_comments)
            {
                builder.AppendLine($"// DllOffset: 0x{Offset:X}");
                builder.AppendLine($"// DllPath {FilePath}");
                if (!string.IsNullOrWhiteSpace(ServiceName))
                {
                    builder.AppendLine($"// ServiceName: {ServiceName}");
                    builder.AppendLine($"// ServiceDisplayName: {ServiceDisplayName}");
                }

                if (EndpointCount > 0)
                {
                    builder.AppendLine($"// Endpoints: {EndpointCount}");
                    foreach (var ep in Endpoints)
                    {
                        builder.AppendLine($"// {ep.BindingString}");
                    }
                }
            }

            if (ComplexTypes.Any())
            {
                if (!remove_comments)
                {
                    builder.AppendLine("// Complex Types: ");
                }
                foreach (var type in ComplexTypes)
                {
                    builder.AppendLine(formatter.FormatComplexType(type));
                }
            }

            builder.AppendLine().AppendLine(formatter.FormatRpcServerInterface(Server));

            return(builder.ToString());
        }