game_machine 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +72 -0
- data/Rakefile +38 -0
- data/bin/game_machine +79 -0
- data/config/cluster.conf +65 -0
- data/config/config.example.yml +93 -0
- data/config/game_messages.proto +45 -0
- data/config/messages.proto +339 -0
- data/config/regions.example.yml +9 -0
- data/config/standalone.conf +36 -0
- data/db/do_not_delete +0 -0
- data/game_machine.gemspec +38 -0
- data/games/example/boot.rb +6 -0
- data/games/example/data/game_data.yml +13 -0
- data/games/example/lib/aggressive_npc.rb +176 -0
- data/games/example/lib/authentication_handler.rb +69 -0
- data/games/example/lib/chatbot.rb +61 -0
- data/games/example/lib/combat_controller.rb +145 -0
- data/games/example/lib/example_controller.rb +21 -0
- data/games/example/lib/game.rb +85 -0
- data/games/example/lib/models/attack.rb +9 -0
- data/games/example/lib/models/combat_update.rb +11 -0
- data/games/example/lib/models/player_command.rb +7 -0
- data/games/example/lib/models/user.rb +11 -0
- data/games/example/lib/models/vitals.rb +17 -0
- data/games/example/lib/npc.rb +111 -0
- data/games/example/lib/npc_group.rb +42 -0
- data/games/example/lib/npc_movement.rb +116 -0
- data/games/example/lib/player_manager.rb +58 -0
- data/games/example/lib/player_register.rb +80 -0
- data/games/example/lib/tracking_handler.rb +17 -0
- data/games/example/lib/zone_manager.rb +57 -0
- data/games/preload.rb +8 -0
- data/integration_tests/basic_spec.rb +68 -0
- data/integration_tests/bot_spec.rb +18 -0
- data/integration_tests/chat_spec.rb +45 -0
- data/integration_tests/distributed_spec.rb +34 -0
- data/integration_tests/entity_tracking_spec.rb +48 -0
- data/integration_tests/mono_spec.rb +16 -0
- data/integration_tests/objectdb_spec.rb +55 -0
- data/integration_tests/tcp_client_spec.rb +71 -0
- data/integration_tests/udp_client_spec.rb +61 -0
- data/integration_tests/udp_spec.rb +20 -0
- data/integration_tests/udt_client_spec.rb +23 -0
- data/integration_tests/udt_spec.rb +31 -0
- data/java/.gitignore +1 -0
- data/java/build.gradle +93 -0
- data/java/component.erb +396 -0
- data/java/gradle.properties +6 -0
- data/java/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/java/gradle/wrapper/gradle-wrapper.properties +6 -0
- data/java/gradlew +164 -0
- data/java/gradlew.bat +90 -0
- data/java/local_lib/protostuff-compiler-1.0.7-jarjar.jar +0 -0
- data/java/settings.gradle +2 -0
- data/java/src/main/java/com/game_machine/core/ActorFactory.java +25 -0
- data/java/src/main/java/com/game_machine/core/ActorUtil.java +39 -0
- data/java/src/main/java/com/game_machine/core/CommandProxy.java +9 -0
- data/java/src/main/java/com/game_machine/core/EntitySerializer.java +66 -0
- data/java/src/main/java/com/game_machine/core/EventStreamHandler.java +43 -0
- data/java/src/main/java/com/game_machine/core/GameMachineLoader.java +25 -0
- data/java/src/main/java/com/game_machine/core/Grid.java +195 -0
- data/java/src/main/java/com/game_machine/core/GridValue.java +30 -0
- data/java/src/main/java/com/game_machine/core/IActorFactory.java +7 -0
- data/java/src/main/java/com/game_machine/core/NetMessage.java +28 -0
- data/java/src/main/java/com/game_machine/core/UdpServer.java +97 -0
- data/java/src/main/java/com/game_machine/core/UdpServerHandler.java +90 -0
- data/java/src/main/resources/game_machine.java.stg +738 -0
- data/java/src/main/resources/logback.xml +14 -0
- data/java/src/main/resources/logging.properties +3 -0
- data/java/src/main/resources/protostuff.properties +7 -0
- data/lib/game_machine.rb +85 -0
- data/lib/game_machine/actor.rb +7 -0
- data/lib/game_machine/actor/base.rb +184 -0
- data/lib/game_machine/actor/builder.rb +108 -0
- data/lib/game_machine/actor/development.rb +31 -0
- data/lib/game_machine/actor/factory.rb +35 -0
- data/lib/game_machine/actor/mono_actor.rb +89 -0
- data/lib/game_machine/actor/ref.rb +81 -0
- data/lib/game_machine/actor/reloadable.rb +98 -0
- data/lib/game_machine/actor/system.rb +32 -0
- data/lib/game_machine/akka.rb +98 -0
- data/lib/game_machine/app_config.rb +49 -0
- data/lib/game_machine/application.rb +181 -0
- data/lib/game_machine/auth_handlers/base.rb +21 -0
- data/lib/game_machine/auth_handlers/public.rb +34 -0
- data/lib/game_machine/bot/chat.rb +66 -0
- data/lib/game_machine/bot/client.rb +54 -0
- data/lib/game_machine/client_manager.rb +204 -0
- data/lib/game_machine/clients.rb +4 -0
- data/lib/game_machine/clients/client.rb +45 -0
- data/lib/game_machine/clients/tcp_client.rb +25 -0
- data/lib/game_machine/clients/test_client.rb +151 -0
- data/lib/game_machine/clients/udp_client.rb +25 -0
- data/lib/game_machine/clients/udt_client.rb +34 -0
- data/lib/game_machine/cluster_monitor.rb +115 -0
- data/lib/game_machine/commands.rb +23 -0
- data/lib/game_machine/commands/base.rb +21 -0
- data/lib/game_machine/commands/chat_commands.rb +88 -0
- data/lib/game_machine/commands/datastore_commands.rb +60 -0
- data/lib/game_machine/commands/grid_commands.rb +35 -0
- data/lib/game_machine/commands/message_helper.rb +25 -0
- data/lib/game_machine/commands/misc_commands.rb +29 -0
- data/lib/game_machine/commands/navigation_commands.rb +24 -0
- data/lib/game_machine/commands/player_commands.rb +28 -0
- data/lib/game_machine/commands/proxy.rb +16 -0
- data/lib/game_machine/console.rb +3 -0
- data/lib/game_machine/console/build.rb +74 -0
- data/lib/game_machine/console/install.rb +92 -0
- data/lib/game_machine/console/server.rb +120 -0
- data/lib/game_machine/data_store.rb +52 -0
- data/lib/game_machine/data_stores/couchbase.rb +18 -0
- data/lib/game_machine/data_stores/mapdb.rb +49 -0
- data/lib/game_machine/data_stores/memory.rb +35 -0
- data/lib/game_machine/data_stores/redis.rb +46 -0
- data/lib/game_machine/endpoints.rb +6 -0
- data/lib/game_machine/endpoints/mono_gateway.rb +87 -0
- data/lib/game_machine/endpoints/tcp.rb +51 -0
- data/lib/game_machine/endpoints/tcp_handler.rb +75 -0
- data/lib/game_machine/endpoints/udp.rb +88 -0
- data/lib/game_machine/endpoints/udp_incoming.rb +113 -0
- data/lib/game_machine/endpoints/udp_outgoing.rb +46 -0
- data/lib/game_machine/game_loader.rb +46 -0
- data/lib/game_machine/game_systems.rb +14 -0
- data/lib/game_machine/game_systems/agents/controller.rb +118 -0
- data/lib/game_machine/game_systems/chat.rb +256 -0
- data/lib/game_machine/game_systems/chat_manager.rb +108 -0
- data/lib/game_machine/game_systems/chat_topic.rb +36 -0
- data/lib/game_machine/game_systems/devnull.rb +13 -0
- data/lib/game_machine/game_systems/entity_loader.rb +12 -0
- data/lib/game_machine/game_systems/entity_tracking.rb +133 -0
- data/lib/game_machine/game_systems/local_echo.rb +16 -0
- data/lib/game_machine/game_systems/objectdb_proxy.rb +61 -0
- data/lib/game_machine/game_systems/private_chat.rb +20 -0
- data/lib/game_machine/game_systems/region_manager.rb +91 -0
- data/lib/game_machine/game_systems/region_service.rb +94 -0
- data/lib/game_machine/game_systems/region_settings.rb +13 -0
- data/lib/game_machine/game_systems/remote_echo.rb +14 -0
- data/lib/game_machine/game_systems/stress_test.rb +21 -0
- data/lib/game_machine/grid.rb +60 -0
- data/lib/game_machine/grid_replicator.rb +31 -0
- data/lib/game_machine/handlers/authentication.rb +55 -0
- data/lib/game_machine/handlers/game.rb +63 -0
- data/lib/game_machine/handlers/request.rb +80 -0
- data/lib/game_machine/hashring.rb +48 -0
- data/lib/game_machine/helpers/game_message.rb +159 -0
- data/lib/game_machine/helpers/state_machine.rb +29 -0
- data/lib/game_machine/java_lib.rb +51 -0
- data/lib/game_machine/logger.rb +39 -0
- data/lib/game_machine/message_buffer.rb +58 -0
- data/lib/game_machine/message_queue.rb +63 -0
- data/lib/game_machine/model.rb +125 -0
- data/lib/game_machine/models.rb +3 -0
- data/lib/game_machine/models/player_status_update.rb +8 -0
- data/lib/game_machine/models/region.rb +9 -0
- data/lib/game_machine/mono_server.rb +20 -0
- data/lib/game_machine/navigation.rb +4 -0
- data/lib/game_machine/navigation/detour.rb +20 -0
- data/lib/game_machine/navigation/detour_navmesh.rb +53 -0
- data/lib/game_machine/navigation/detour_path.rb +53 -0
- data/lib/game_machine/navigation/path.rb +31 -0
- data/lib/game_machine/object_db.rb +67 -0
- data/lib/game_machine/protobuf.rb +6 -0
- data/lib/game_machine/protobuf/game_messages.rb +24 -0
- data/lib/game_machine/protobuf/generate.rb +113 -0
- data/lib/game_machine/protobuf_extensions/entity_helper.rb +11 -0
- data/lib/game_machine/reloadable_monitor.rb +26 -0
- data/lib/game_machine/restart_watcher.rb +17 -0
- data/lib/game_machine/ruby_extensions/nilclass.rb +10 -0
- data/lib/game_machine/ruby_extensions/string.rb +17 -0
- data/lib/game_machine/scheduler.rb +23 -0
- data/lib/game_machine/securerandom.rb +6 -0
- data/lib/game_machine/settings.rb +11 -0
- data/lib/game_machine/system_monitor.rb +19 -0
- data/lib/game_machine/system_stats.rb +24 -0
- data/lib/game_machine/uniqueid.rb +23 -0
- data/lib/game_machine/vector.rb +95 -0
- data/lib/game_machine/version.rb +3 -0
- data/lib/game_machine/write_behind_cache.rb +164 -0
- data/mono/bin/csharp/common.xslt +109 -0
- data/mono/bin/csharp/csharp.xslt +628 -0
- data/mono/bin/csharp/descriptor.proto +533 -0
- data/mono/bin/csharp/protobuf-net.dll +0 -0
- data/mono/bin/csharp/protobuf-net.pdb +0 -0
- data/mono/bin/csharp/protobuf-net.xml +2879 -0
- data/mono/bin/csharp/protogen.exe.config +3 -0
- data/mono/bin/csharp/protogen.pdb +0 -0
- data/mono/bin/csharp/protogen_csharp.exe +0 -0
- data/mono/bin/csharp/vb.xslt +745 -0
- data/mono/bin/csharp/xml.xslt +26 -0
- data/mono/server/Makefile +6 -0
- data/mono/server/NLog.config +12 -0
- data/mono/server/NLog.dll +0 -0
- data/mono/server/actor.cs +37 -0
- data/mono/server/build.bat +3 -0
- data/mono/server/cscompmgd.dll +0 -0
- data/mono/server/iactor.cs +11 -0
- data/mono/server/message_router.cs +67 -0
- data/mono/server/message_util.cs +29 -0
- data/mono/server/messages.cs +1888 -0
- data/mono/server/protobuf-net.dll +0 -0
- data/mono/server/proxy_client.cs +73 -0
- data/mono/server/proxy_server.cs +30 -0
- data/mono/server/test_actor.cs +33 -0
- data/pathfinding/bin/premake4 +0 -0
- data/pathfinding/include/mesh_loader.h +28 -0
- data/pathfinding/include/pathfind.h +167 -0
- data/pathfinding/main.cpp +39 -0
- data/pathfinding/mesh_loader.cpp +108 -0
- data/pathfinding/pathfind.cpp +174 -0
- data/pathfinding/pathfinder.cs +66 -0
- data/pathfinding/premake4.lua +109 -0
- data/script/server.sh +109 -0
- data/script/watch.sh +11 -0
- data/spec/actor/actor_spec.rb +73 -0
- data/spec/actor/builder_spec.rb +56 -0
- data/spec/actor/ref_spec.rb +83 -0
- data/spec/application_spec.rb +7 -0
- data/spec/client_manager_spec.rb +171 -0
- data/spec/commands/chat_commands_spec.rb +38 -0
- data/spec/commands/datastore_commands_spec.rb +91 -0
- data/spec/commands/grid_commands_spec.rb +37 -0
- data/spec/commands/navigation_commands_spec.rb +51 -0
- data/spec/commands/player_commands_spec.rb +48 -0
- data/spec/commands_spec.rb +38 -0
- data/spec/data_stores/mapdb_spec.rb +46 -0
- data/spec/data_stores/redis_spec.rb +44 -0
- data/spec/game_systems/agents/controller_spec.rb +84 -0
- data/spec/game_systems/agents/test_agent.rb +10 -0
- data/spec/game_systems/agents/test_agent_config.rb +29 -0
- data/spec/game_systems/chat_manager_spec.rb +66 -0
- data/spec/game_systems/chat_spec.rb +187 -0
- data/spec/game_systems/entity_tracking_spec.rb +64 -0
- data/spec/game_systems/region_manager_spec.rb +138 -0
- data/spec/grid_spec.rb +37 -0
- data/spec/handlers/authentication_spec.rb +36 -0
- data/spec/handlers/game_spec.rb +49 -0
- data/spec/handlers/request_spec.rb +65 -0
- data/spec/hashring_spec.rb +59 -0
- data/spec/integration_helper.rb +120 -0
- data/spec/java_grid_spec.rb +89 -0
- data/spec/message_buffer_spec.rb +67 -0
- data/spec/message_expectations.rb +47 -0
- data/spec/message_queue_spec.rb +23 -0
- data/spec/misc_spec.rb +71 -0
- data/spec/model_spec.rb +103 -0
- data/spec/mono_spec.rb +36 -0
- data/spec/mono_test.rb +18 -0
- data/spec/navigation/detour_navmesh_spec.rb +34 -0
- data/spec/navigation/detour_path_spec.rb +25 -0
- data/spec/spec_helper.rb +40 -0
- data/spec/udp_server_spec.rb +10 -0
- data/spec/write_behind_cache_spec.rb +109 -0
- data/web/app.rb +131 -0
- data/web/config/trinidad.yml +4 -0
- data/web/controllers/auth_controller.rb +19 -0
- data/web/controllers/base_controller.rb +16 -0
- data/web/controllers/index_controller.rb +7 -0
- data/web/controllers/log_controller.rb +47 -0
- data/web/controllers/messages_controller.rb +59 -0
- data/web/controllers/player_register_controller.rb +15 -0
- data/web/log/development.log +1339 -0
- data/web/tmp/restart.txt +0 -0
- data/web/views/game_messages.haml +45 -0
- data/web/views/index.haml +6 -0
- data/web/views/layout.haml +41 -0
- data/web/views/logs.haml +32 -0
- data/web/views/player_register.haml +22 -0
- data/web/views/player_registered.haml +2 -0
- data/web/views/register_layout.haml +22 -0
- data/web/views/restart.haml +35 -0
- metadata +576 -0
@@ -0,0 +1,164 @@
|
|
1
|
+
module GameMachine
|
2
|
+
class WriteBehindCache < Actor::Base
|
3
|
+
|
4
|
+
def self.max_writes_per_second
|
5
|
+
if @max_writes_per_second
|
6
|
+
@max_writes_per_second
|
7
|
+
else
|
8
|
+
@max_writes_per_second = Application.config.cache_writes_per_second
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.write_interval
|
13
|
+
if @write_interval
|
14
|
+
@write_interval
|
15
|
+
else
|
16
|
+
@write_interval = Application.config.cache_write_interval
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_accessor :write_interval, :max_writes_per_second
|
21
|
+
attr_reader :cache, :queue
|
22
|
+
|
23
|
+
def post_init(*args)
|
24
|
+
@write_interval = self.class.write_interval
|
25
|
+
@max_writes_per_second = self.class.max_writes_per_second
|
26
|
+
@store = DataStore.instance
|
27
|
+
@cache = {}
|
28
|
+
@updates = {}
|
29
|
+
@queue = []
|
30
|
+
@queue_map = {}
|
31
|
+
@last_write = current_time - (120 * 1000)
|
32
|
+
@scheduler = get_context.system.scheduler
|
33
|
+
@dispatcher = get_context.system.dispatcher
|
34
|
+
unless @write_interval == -1 && @max_writes_per_second == -1
|
35
|
+
schedule_queue_run
|
36
|
+
schedule_queue_stats
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def on_receive(message)
|
41
|
+
if message.is_a?(String)
|
42
|
+
handle_scheduled_message(message)
|
43
|
+
else
|
44
|
+
set_message(message)
|
45
|
+
if new_message?(message)
|
46
|
+
write(message)
|
47
|
+
elsif eligible_for_write?(message)
|
48
|
+
write(message)
|
49
|
+
else
|
50
|
+
enqueue(message.id)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def last_updated(message)
|
58
|
+
@updates.fetch(message.id,nil)
|
59
|
+
end
|
60
|
+
|
61
|
+
def new_message?(message)
|
62
|
+
@updates.has_key?(message.id) ? false : true
|
63
|
+
end
|
64
|
+
|
65
|
+
def eligible_for_write?(message)
|
66
|
+
return true if write_interval == -1
|
67
|
+
(current_time - last_updated(message)) > write_interval
|
68
|
+
end
|
69
|
+
|
70
|
+
def min_time_between_writes
|
71
|
+
1000.to_f / max_writes_per_second.to_f
|
72
|
+
end
|
73
|
+
|
74
|
+
def current_time
|
75
|
+
java.lang.System.currentTimeMillis
|
76
|
+
end
|
77
|
+
|
78
|
+
def queue_stats
|
79
|
+
if @queue.size > 10
|
80
|
+
GameMachine.logger.warn "Queued messages size = #{@queue.size}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def check_queue
|
85
|
+
return if @queue.empty?
|
86
|
+
if message = get_message(dequeue)
|
87
|
+
write(message)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def set_message(message)
|
92
|
+
@cache[message.id] = message
|
93
|
+
end
|
94
|
+
|
95
|
+
def get_message(message_id)
|
96
|
+
@cache.fetch(message_id,nil)
|
97
|
+
end
|
98
|
+
|
99
|
+
def busy?(message)
|
100
|
+
return false if max_writes_per_second == -1
|
101
|
+
(current_time - @last_write) < min_time_between_writes
|
102
|
+
end
|
103
|
+
|
104
|
+
def set_updated_at(message)
|
105
|
+
@updates[message.id] = @last_write
|
106
|
+
end
|
107
|
+
|
108
|
+
def enqueue(message_id)
|
109
|
+
unless @queue_map.fetch(message_id,nil)
|
110
|
+
@queue << message_id
|
111
|
+
@queue_map[message_id] = true
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def dequeue
|
116
|
+
if message_id = @queue.shift
|
117
|
+
@queue_map.delete(message_id)
|
118
|
+
message_id
|
119
|
+
else
|
120
|
+
nil
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
# If there are items in queue, write one of those and put
|
125
|
+
# the current message at the end of the queue
|
126
|
+
def swap_if_queued_exists(message)
|
127
|
+
if queued_message = get_message(dequeue)
|
128
|
+
enqueue(message)
|
129
|
+
queued_message
|
130
|
+
else
|
131
|
+
message
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def write(message)
|
136
|
+
if busy?(message)
|
137
|
+
enqueue(message.id)
|
138
|
+
else
|
139
|
+
message = swap_if_queued_exists(message)
|
140
|
+
@store.set(message.id, message.to_byte_array)
|
141
|
+
@last_write = current_time
|
142
|
+
set_updated_at(message)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def handle_scheduled_message(message)
|
147
|
+
if message == 'check_queue'
|
148
|
+
check_queue
|
149
|
+
elsif message == 'queue_stats'
|
150
|
+
queue_stats
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def schedule_queue_run
|
155
|
+
duration = JavaLib::Duration.create(500, java.util.concurrent.TimeUnit::MILLISECONDS)
|
156
|
+
@scheduler.schedule(duration, duration, get_self, "check_queue", @dispatcher, nil)
|
157
|
+
end
|
158
|
+
|
159
|
+
def schedule_queue_stats
|
160
|
+
duration = JavaLib::Duration.create(10, java.util.concurrent.TimeUnit::SECONDS)
|
161
|
+
@scheduler.schedule(duration, duration, get_self, "queue_stats", @dispatcher, nil)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
3
|
+
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
|
4
|
+
>
|
5
|
+
<!--
|
6
|
+
<xsl:template name="capitalizeFirst">
|
7
|
+
<xsl:param name="value"/>
|
8
|
+
<xsl:value-of select="translate(substring($value,1,1),$alpha,$ALPHA)"/>
|
9
|
+
<xsl:value-of select="substring($value,2)"/>
|
10
|
+
</xsl:template>
|
11
|
+
-->
|
12
|
+
<xsl:template match="*">
|
13
|
+
<xsl:message terminate="yes">
|
14
|
+
Node not handled: <xsl:for-each select="ancestor-or-self::*">/<xsl:value-of select="name()"/></xsl:for-each>
|
15
|
+
<xsl:for-each select="*">
|
16
|
+
; <xsl:value-of select="concat(name(),'=',.)"/>
|
17
|
+
</xsl:for-each>
|
18
|
+
</xsl:message>
|
19
|
+
</xsl:template>
|
20
|
+
<xsl:param name="fixCase"/>
|
21
|
+
<xsl:variable name="optionFixCase" select="$fixCase='true'"/>
|
22
|
+
|
23
|
+
<xsl:template name="escapeKeyword">
|
24
|
+
<xsl:param name="value"/>
|
25
|
+
<xsl:value-of select="$value"/>
|
26
|
+
</xsl:template>
|
27
|
+
|
28
|
+
<xsl:template name="toCamelCase">
|
29
|
+
<xsl:param name="value"/>
|
30
|
+
<xsl:param name="delimiter" select="'_'"/>
|
31
|
+
<xsl:param name="keepDelimiter" select="false()"/>
|
32
|
+
<xsl:variable name="segment" select="substring-before($value, $delimiter)"/>
|
33
|
+
<xsl:choose>
|
34
|
+
<xsl:when test="$segment != ''">
|
35
|
+
<xsl:value-of select="$segment"/><xsl:if test="$keepDelimiter"><xsl:value-of select="$delimiter"/></xsl:if>
|
36
|
+
<xsl:call-template name="toPascalCase">
|
37
|
+
<xsl:with-param name="value" select="substring-after($value, $delimiter)"/>
|
38
|
+
<xsl:with-param name="delimiter" select="$delimiter"/>
|
39
|
+
<xsl:with-param name="keepDelimiter" select="$keepDelimiter"/>
|
40
|
+
</xsl:call-template>
|
41
|
+
</xsl:when>
|
42
|
+
<xsl:otherwise>
|
43
|
+
<xsl:value-of select="$value"/>
|
44
|
+
</xsl:otherwise>
|
45
|
+
</xsl:choose>
|
46
|
+
</xsl:template>
|
47
|
+
|
48
|
+
<xsl:variable name="alpha" select="'abcdefghijklmnopqrstuvwxyz'"/>
|
49
|
+
<xsl:variable name="ALPHA" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
|
50
|
+
|
51
|
+
<xsl:template name="toPascalCase">
|
52
|
+
<xsl:param name="value"/>
|
53
|
+
<xsl:param name="delimiter" select="'_'"/>
|
54
|
+
<xsl:param name="keepDelimiter" select="false()"/>
|
55
|
+
<xsl:if test="$value != ''">
|
56
|
+
<xsl:variable name="segment" select="substring-before($value, $delimiter)"/>
|
57
|
+
<xsl:choose>
|
58
|
+
<xsl:when test="$segment != ''">
|
59
|
+
<xsl:value-of select="translate(substring($segment,1,1),$alpha,$ALPHA)"/><xsl:value-of select="substring($segment,2)"/><xsl:if test="$keepDelimiter"><xsl:value-of select="$delimiter"/></xsl:if>
|
60
|
+
<xsl:call-template name="toPascalCase">
|
61
|
+
<xsl:with-param name="value" select="substring-after($value, $delimiter)"/>
|
62
|
+
<xsl:with-param name="delimiter" select="$delimiter"/>
|
63
|
+
<xsl:with-param name="keepDelimiter" select="$keepDelimiter"/>
|
64
|
+
</xsl:call-template>
|
65
|
+
</xsl:when>
|
66
|
+
<xsl:otherwise>
|
67
|
+
<xsl:value-of select="translate(substring($value,1,1),$alpha,$ALPHA)"/><xsl:value-of select="substring($value,2)"/>
|
68
|
+
</xsl:otherwise>
|
69
|
+
</xsl:choose>
|
70
|
+
</xsl:if>
|
71
|
+
</xsl:template>
|
72
|
+
<xsl:template name="pascal">
|
73
|
+
<xsl:param name="value" select="name"/>
|
74
|
+
<xsl:param name="delimiter" select="'_'"/>
|
75
|
+
<xsl:call-template name="escapeKeyword">
|
76
|
+
<xsl:with-param name="value"><xsl:choose>
|
77
|
+
<xsl:when test="$optionFixCase"><xsl:variable name="dotted"><xsl:call-template name="toPascalCase">
|
78
|
+
<xsl:with-param name="value" select="$value"/>
|
79
|
+
<xsl:with-param name="delimiter" select="'.'"/>
|
80
|
+
<xsl:with-param name="keepDelimiter" select="true()"/>
|
81
|
+
</xsl:call-template></xsl:variable><xsl:call-template name="toPascalCase">
|
82
|
+
<xsl:with-param name="value" select="$dotted"/>
|
83
|
+
<xsl:with-param name="delimiter" select="$delimiter"/>
|
84
|
+
</xsl:call-template></xsl:when>
|
85
|
+
<xsl:otherwise><xsl:value-of select="$value"/></xsl:otherwise>
|
86
|
+
</xsl:choose></xsl:with-param></xsl:call-template>
|
87
|
+
</xsl:template>
|
88
|
+
|
89
|
+
<xsl:template name="PickNamespace"><xsl:param name="defaultNamespace"/><xsl:choose>
|
90
|
+
<xsl:when test="package"><xsl:call-template name="pascal">
|
91
|
+
<xsl:with-param name="value" select="package"/>
|
92
|
+
</xsl:call-template></xsl:when>
|
93
|
+
<xsl:when test="$defaultNamespace"><xsl:value-of select="$defaultNamespace"/></xsl:when>
|
94
|
+
<xsl:otherwise><xsl:variable name="trimmedName"><xsl:choose>
|
95
|
+
<xsl:when test="substring(name,string-length(name)-5,6)='.proto'"><xsl:value-of select="substring(name,1,string-length(name)-6)"/></xsl:when>
|
96
|
+
<xsl:otherwise><xsl:value-of select="name"/></xsl:otherwise>
|
97
|
+
</xsl:choose></xsl:variable><xsl:call-template name="pascal">
|
98
|
+
<xsl:with-param name="value" select="$trimmedName"/>
|
99
|
+
</xsl:call-template></xsl:otherwise>
|
100
|
+
</xsl:choose></xsl:template>
|
101
|
+
|
102
|
+
<xsl:template match="FieldDescriptorProto/options"/>
|
103
|
+
<xsl:template match="FileDescriptorProto/options"/>
|
104
|
+
<xsl:template match="DescriptorProto/options"/>
|
105
|
+
<xsl:template match="EnumValueDescriptorProto/options"/>
|
106
|
+
<xsl:template match="EnumDescriptorProto/options"/>
|
107
|
+
<xsl:template match="ServiceDescriptorProto/options"/>
|
108
|
+
<xsl:template match="MethodDescriptorProto/options"/>
|
109
|
+
</xsl:stylesheet>
|
@@ -0,0 +1,628 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<xsl:stylesheet version="1.0"
|
3
|
+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
4
|
+
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="xsl msxsl"
|
5
|
+
>
|
6
|
+
<xsl:import href="common.xslt"/>
|
7
|
+
<xsl:param name="help"/>
|
8
|
+
<xsl:param name="xml"/>
|
9
|
+
<xsl:param name="datacontract"/>
|
10
|
+
<xsl:param name="binary"/>
|
11
|
+
<xsl:param name="protoRpc"/>
|
12
|
+
<xsl:param name="observable"/>
|
13
|
+
<xsl:param name="preObservable"/>
|
14
|
+
<xsl:param name="partialMethods"/>
|
15
|
+
<xsl:param name="detectMissing"/>
|
16
|
+
<xsl:param name="lightFramework"/>
|
17
|
+
<xsl:param name="asynchronous"/>
|
18
|
+
<xsl:param name="clientProxy"/>
|
19
|
+
<xsl:param name="defaultNamespace"/>
|
20
|
+
<xsl:param name="import"/>
|
21
|
+
|
22
|
+
<xsl:key name="fieldNames" match="//FieldDescriptorProto" use="name"/>
|
23
|
+
<xsl:output method="text" indent="no" omit-xml-declaration="yes"/>
|
24
|
+
|
25
|
+
<xsl:variable name="optionXml" select="$xml='true'"/>
|
26
|
+
<xsl:variable name="optionDataContract" select="$datacontract='true'"/>
|
27
|
+
<xsl:variable name="optionBinary" select="$binary='true'"/>
|
28
|
+
<xsl:variable name="optionProtoRpc" select="$protoRpc='true'"/>
|
29
|
+
<xsl:variable name="optionObservable" select="$observable='true'"/>
|
30
|
+
<xsl:variable name="optionPreObservable" select="$preObservable='true'"/>
|
31
|
+
<xsl:variable name="optionPartialMethods" select="$partialMethods='true'"/>
|
32
|
+
<xsl:variable name="optionDetectMissing" select="$detectMissing='true'"/>
|
33
|
+
<xsl:variable name="optionFullFramework" select="not($lightFramework='true')"/>
|
34
|
+
<xsl:variable name="optionAsynchronous" select="$asynchronous='true'"/>
|
35
|
+
<xsl:variable name="optionClientProxy" select="$clientProxy='true'"/>
|
36
|
+
|
37
|
+
<xsl:template match="/">
|
38
|
+
<xsl:text disable-output-escaping="yes">//------------------------------------------------------------------------------
|
39
|
+
// <auto-generated>
|
40
|
+
// This code was generated by a tool.
|
41
|
+
//
|
42
|
+
// Changes to this file may cause incorrect behavior and will be lost if
|
43
|
+
// the code is regenerated.
|
44
|
+
// </auto-generated>
|
45
|
+
//------------------------------------------------------------------------------
|
46
|
+
</xsl:text><!--
|
47
|
+
--><xsl:apply-templates select="*"/><!--
|
48
|
+
--></xsl:template>
|
49
|
+
|
50
|
+
<xsl:template name="WriteUsings">
|
51
|
+
<xsl:param name="ns"/>
|
52
|
+
<xsl:if test="$ns != ''"><xsl:choose>
|
53
|
+
<xsl:when test="contains($ns,';')">
|
54
|
+
using <xsl:value-of select="substring-before($ns,';')"/>;<!--
|
55
|
+
--><xsl:call-template name="WriteUsings">
|
56
|
+
<xsl:with-param name="ns" select="substring-after($ns,';')"/>
|
57
|
+
</xsl:call-template>
|
58
|
+
</xsl:when>
|
59
|
+
<xsl:otherwise>
|
60
|
+
using <xsl:value-of select="$ns"/>;
|
61
|
+
</xsl:otherwise>
|
62
|
+
</xsl:choose></xsl:if></xsl:template>
|
63
|
+
|
64
|
+
<xsl:template match="FileDescriptorSet">
|
65
|
+
<xsl:if test="$help='true'">
|
66
|
+
<xsl:message terminate="yes">
|
67
|
+
CSharp template for protobuf-net.
|
68
|
+
Options:
|
69
|
+
General:
|
70
|
+
"help" - this page
|
71
|
+
Additional serializer support:
|
72
|
+
"xml" - enable explicit xml support (XmlSerializer)
|
73
|
+
"datacontract" - enable data-contract support (DataContractSerializer; requires .NET 3.0)
|
74
|
+
"binary" - enable binary support (BinaryFormatter; not supported on Silverlight)
|
75
|
+
Other:
|
76
|
+
"protoRpc" - enable proto-rpc client
|
77
|
+
"observable" - change notification (observer pattern) support
|
78
|
+
"preObservable" - pre-change notification (observer pattern) support (requires .NET 3.5)
|
79
|
+
"partialMethods" - provide partial methods for changes (requires C# 3.0)
|
80
|
+
"detectMissing" - provide *Specified properties to indicate whether fields are present
|
81
|
+
"lightFramework" - omit additional attributes not included in CF/Silverlight
|
82
|
+
"asynchronous" - emit asynchronous methods for use with WCF
|
83
|
+
"clientProxy" - emit asynchronous client proxy class
|
84
|
+
"import" - additional namespaces to import (semicolon delimited)
|
85
|
+
"fixCase" - change type/member names (types/properties become PascalCase; fields become camelCase)
|
86
|
+
</xsl:message>
|
87
|
+
</xsl:if>
|
88
|
+
|
89
|
+
<xsl:if test="$optionXml and $optionDataContract">
|
90
|
+
<xsl:message terminate="yes">
|
91
|
+
Invalid options: xml and data-contract serialization are mutually exclusive.
|
92
|
+
</xsl:message>
|
93
|
+
</xsl:if>
|
94
|
+
<xsl:if test="$optionXml">
|
95
|
+
// Option: xml serialization ([XmlType]/[XmlElement]) enabled
|
96
|
+
</xsl:if><xsl:if test="$optionDataContract">
|
97
|
+
// Option: data-contract serialization ([DataContract]/[DataMember]) enabled
|
98
|
+
</xsl:if><xsl:if test="$optionBinary">
|
99
|
+
// Option: binary serialization (ISerializable) enabled
|
100
|
+
</xsl:if><xsl:if test="$optionObservable">
|
101
|
+
// Option: observable (OnPropertyChanged) enabled
|
102
|
+
</xsl:if><xsl:if test="$optionPreObservable">
|
103
|
+
// Option: pre-observable (OnPropertyChanging) enabled
|
104
|
+
</xsl:if><xsl:if test="$partialMethods">
|
105
|
+
// Option: partial methods (On*Changing/On*Changed) enabled
|
106
|
+
</xsl:if><xsl:if test="$optionDetectMissing">
|
107
|
+
// Option: missing-value detection (*Specified/ShouldSerialize*/Reset*) enabled
|
108
|
+
</xsl:if><xsl:if test="not($optionFullFramework)">
|
109
|
+
// Option: light framework (CF/Silverlight) enabled
|
110
|
+
</xsl:if><xsl:if test="$optionProtoRpc">
|
111
|
+
// Option: proto-rpc enabled
|
112
|
+
</xsl:if>
|
113
|
+
<xsl:call-template name="WriteUsings">
|
114
|
+
<xsl:with-param name="ns" select="$import"/>
|
115
|
+
</xsl:call-template>
|
116
|
+
<xsl:apply-templates select="file/FileDescriptorProto"/>
|
117
|
+
</xsl:template>
|
118
|
+
|
119
|
+
|
120
|
+
<xsl:template match="FileDescriptorProto">
|
121
|
+
// Generated from: <xsl:value-of select="name"/>
|
122
|
+
|
123
|
+
<xsl:apply-templates select="dependency/string[.!='']"/>
|
124
|
+
<xsl:variable name="namespace"><xsl:call-template name="PickNamespace">
|
125
|
+
<xsl:with-param name="defaultNamespace" select="$defaultNamespace"/>
|
126
|
+
</xsl:call-template>
|
127
|
+
</xsl:variable>
|
128
|
+
<xsl:if test="string($namespace) != ''">
|
129
|
+
namespace <xsl:value-of select="translate($namespace,':-/\','__..')"/>
|
130
|
+
{</xsl:if>
|
131
|
+
<xsl:apply-templates select="message_type | enum_type | service"/>
|
132
|
+
<xsl:if test="string($namespace) != ''">
|
133
|
+
}</xsl:if></xsl:template>
|
134
|
+
|
135
|
+
<xsl:template match="FileDescriptorProto/dependency/string">
|
136
|
+
// Note: requires additional types generated from: <xsl:value-of select="."/></xsl:template>
|
137
|
+
|
138
|
+
|
139
|
+
<xsl:template name="camel">
|
140
|
+
<xsl:param name="value" select="name"/>
|
141
|
+
<xsl:param name="delimiter" select="'_'"/>
|
142
|
+
<xsl:choose>
|
143
|
+
<xsl:when test="$optionFixCase"><xsl:call-template name="toCamelCase">
|
144
|
+
<xsl:with-param name="value" select="$value"/>
|
145
|
+
<xsl:with-param name="delimiter" select="$delimiter"/>
|
146
|
+
</xsl:call-template></xsl:when>
|
147
|
+
<xsl:otherwise><xsl:value-of select="$value"/></xsl:otherwise>
|
148
|
+
</xsl:choose>
|
149
|
+
</xsl:template>
|
150
|
+
|
151
|
+
<xsl:template match="DescriptorProto">
|
152
|
+
[<xsl:if test="$optionFullFramework">global::System.Serializable, </xsl:if>global::ProtoBuf.ProtoContract(Name=@"<xsl:value-of select="name"/>")]
|
153
|
+
<xsl:if test="$optionDataContract">[global::System.Runtime.Serialization.DataContract(Name=@"<xsl:value-of select="name"/>")]
|
154
|
+
</xsl:if><xsl:if test="$optionXml">[global::System.Xml.Serialization.XmlType(TypeName=@"<xsl:value-of select="name"/>")]
|
155
|
+
</xsl:if><!--
|
156
|
+
-->public partial class <xsl:call-template name="pascal"/> : global::ProtoBuf.IExtensible<!--
|
157
|
+
--><xsl:if test="$optionBinary">, global::System.Runtime.Serialization.ISerializable</xsl:if><!--
|
158
|
+
--><xsl:if test="$optionObservable">, global::System.ComponentModel.INotifyPropertyChanged</xsl:if><!--
|
159
|
+
--><xsl:if test="$optionPreObservable">, global::System.ComponentModel.INotifyPropertyChanging</xsl:if>
|
160
|
+
{
|
161
|
+
public <xsl:call-template name="pascal"/>() {}
|
162
|
+
<xsl:apply-templates select="*"/><xsl:if test="$optionBinary">
|
163
|
+
protected <xsl:call-template name="pascal"/>(global::System.Runtime.Serialization.SerializationInfo info, global::System.Runtime.Serialization.StreamingContext context)
|
164
|
+
: this() { global::ProtoBuf.Serializer.Merge(info, this); }
|
165
|
+
void global::System.Runtime.Serialization.ISerializable.GetObjectData(global::System.Runtime.Serialization.SerializationInfo info, global::System.Runtime.Serialization.StreamingContext context)
|
166
|
+
{ global::ProtoBuf.Serializer.Serialize(info, this); }
|
167
|
+
</xsl:if><xsl:if test="$optionObservable">
|
168
|
+
public event global::System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
|
169
|
+
protected virtual void OnPropertyChanged(string propertyName)
|
170
|
+
{ if(PropertyChanged != null) PropertyChanged(this, new global::System.ComponentModel.PropertyChangedEventArgs(propertyName)); }
|
171
|
+
</xsl:if><xsl:if test="$optionPreObservable">
|
172
|
+
public event global::System.ComponentModel.PropertyChangingEventHandler PropertyChanging;
|
173
|
+
protected virtual void OnPropertyChanging(string propertyName)
|
174
|
+
{ if(PropertyChanging != null) PropertyChanging(this, new global::System.ComponentModel.PropertyChangingEventArgs(propertyName)); }
|
175
|
+
</xsl:if>
|
176
|
+
private global::ProtoBuf.IExtension extensionObject;
|
177
|
+
global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing)
|
178
|
+
{ return global::ProtoBuf.Extensible.GetExtensionObject(ref extensionObject, createIfMissing); }
|
179
|
+
}
|
180
|
+
</xsl:template>
|
181
|
+
|
182
|
+
<xsl:template match="DescriptorProto/name | DescriptorProto/extension_range | DescriptorProto/extension"/>
|
183
|
+
|
184
|
+
<xsl:template match="
|
185
|
+
FileDescriptorProto/message_type | FileDescriptorProto/enum_type | FileDescriptorProto/service
|
186
|
+
| DescriptorProto/enum_type | DescriptorProto/message_type
|
187
|
+
| DescriptorProto/nested_type | EnumDescriptorProto/value | ServiceDescriptorProto/method">
|
188
|
+
<xsl:apply-templates select="*"/>
|
189
|
+
</xsl:template>
|
190
|
+
|
191
|
+
<xsl:template match="DescriptorProto/field">
|
192
|
+
<xsl:apply-templates select="*"/>
|
193
|
+
<xsl:variable name="extName" select="concat('.',(ancestor::FileDescriptorProto/package)[1],'.',../name)"/>
|
194
|
+
<xsl:apply-templates select="//FieldDescriptorProto[extendee=$extName]"/>
|
195
|
+
</xsl:template>
|
196
|
+
|
197
|
+
<xsl:template match="EnumDescriptorProto">
|
198
|
+
[global::ProtoBuf.ProtoContract(Name=@"<xsl:value-of select="name"/>")]
|
199
|
+
<xsl:if test="$optionDataContract">[global::System.Runtime.Serialization.DataContract(Name=@"<xsl:value-of select="name"/>")]
|
200
|
+
</xsl:if>
|
201
|
+
<xsl:if test="$optionXml">[global::System.Xml.Serialization.XmlType(TypeName=@"<xsl:value-of select="name"/>")]
|
202
|
+
</xsl:if><!--
|
203
|
+
-->public enum <xsl:call-template name="pascal"/>
|
204
|
+
{
|
205
|
+
<xsl:apply-templates select="value"/>
|
206
|
+
}
|
207
|
+
</xsl:template>
|
208
|
+
|
209
|
+
<xsl:template match="EnumValueDescriptorProto">
|
210
|
+
<xsl:variable name="value"><xsl:choose>
|
211
|
+
<xsl:when test="number"><xsl:value-of select="number"/></xsl:when>
|
212
|
+
<xsl:otherwise>0</xsl:otherwise>
|
213
|
+
</xsl:choose></xsl:variable>
|
214
|
+
[global::ProtoBuf.ProtoEnum(Name=@"<xsl:value-of select="name"/>", Value=<xsl:value-of select="$value"/>)]<!--
|
215
|
+
--><xsl:if test="$optionDataContract">
|
216
|
+
[global::System.Runtime.Serialization.EnumMember(Value=@"<xsl:value-of select="name"/>")]</xsl:if><!--
|
217
|
+
--><xsl:if test="$optionXml">
|
218
|
+
[global::System.Xml.Serialization.XmlEnum(@"<xsl:value-of select="name"/>")]</xsl:if><!--
|
219
|
+
--><xsl:text disable-output-escaping="yes">
|
220
|
+
</xsl:text><xsl:call-template name="pascal"/><xsl:text xml:space="preserve"> = </xsl:text><xsl:value-of select="$value"/><xsl:if test="position()!=last()">,
|
221
|
+
</xsl:if>
|
222
|
+
</xsl:template>
|
223
|
+
|
224
|
+
<xsl:template match="FieldDescriptorProto" mode="field">
|
225
|
+
<xsl:variable name="field"><xsl:choose>
|
226
|
+
<xsl:when test="$optionFixCase"><xsl:call-template name="toCamelCase">
|
227
|
+
<xsl:with-param name="value" select="name"/>
|
228
|
+
</xsl:call-template></xsl:when>
|
229
|
+
<xsl:otherwise><xsl:value-of select="name"/></xsl:otherwise>
|
230
|
+
</xsl:choose></xsl:variable>
|
231
|
+
<xsl:call-template name="escapeKeyword">
|
232
|
+
<xsl:with-param name="value"><xsl:choose>
|
233
|
+
<xsl:when test="not(key('fieldNames',concat('_',$field)))"><xsl:value-of select="concat('_',$field)"/></xsl:when>
|
234
|
+
<xsl:when test="not(key('fieldNames',concat($field,'Field')))"><xsl:value-of select="concat($field,'Field')"/></xsl:when>
|
235
|
+
<xsl:otherwise><xsl:value-of select="concat('_',generate-id())"/></xsl:otherwise>
|
236
|
+
</xsl:choose></xsl:with-param>
|
237
|
+
</xsl:call-template>
|
238
|
+
</xsl:template>
|
239
|
+
|
240
|
+
<xsl:template name="escapeKeyword">
|
241
|
+
<xsl:param name="value"/>
|
242
|
+
<xsl:if test="contains($keywords,concat('|',$value,'|'))">@</xsl:if><xsl:value-of select="$value"/>
|
243
|
+
</xsl:template>
|
244
|
+
<xsl:variable name="keywords">|abstract|as|base|bool|break|byte|case|catch|char|checked|class|const|continue|decimal|default|delegate|do|double|else|enum|event|explicit|extern|false|finally|fixed|float|for|foreach|goto|if|implicit|in|int|interface|internal|is|lock|long|namespace|new|null|object|operator|out|override|params|private|protected|public|readonly|ref|return|sbyte|sealed|short|sizeof|stackalloc|static|string|struct|switch|this|throw|true|try|typeof|uint|ulong|unchecked|unsafe|ushort|using|virtual|void|volatile|while|</xsl:variable>
|
245
|
+
|
246
|
+
<xsl:template match="FieldDescriptorProto" mode="format">
|
247
|
+
<xsl:choose>
|
248
|
+
<xsl:when test="type='TYPE_DOUBLE' or type='TYPE_FLOAT'
|
249
|
+
or type='TYPE_FIXED32' or type='TYPE_FIXED64'
|
250
|
+
or type='TYPE_SFIXED32' or type='TYPE_SFIXED64'">FixedSize</xsl:when>
|
251
|
+
<xsl:when test="type='TYPE_GROUP'">Group</xsl:when>
|
252
|
+
<xsl:when test="not(type) or type='TYPE_INT32' or type='TYPE_INT64'
|
253
|
+
or type='TYPE_UINT32' or type='TYPE_UINT64'
|
254
|
+
or type='TYPE_ENUM'">TwosComplement</xsl:when>
|
255
|
+
<xsl:when test="type='TYPE_SINT32' or type='TYPE_SINT64'">ZigZag</xsl:when>
|
256
|
+
<xsl:otherwise>Default</xsl:otherwise>
|
257
|
+
</xsl:choose>
|
258
|
+
</xsl:template>
|
259
|
+
<xsl:template match="FieldDescriptorProto" mode="primitiveType">
|
260
|
+
<xsl:choose>
|
261
|
+
<xsl:when test="not(type)">struct</xsl:when>
|
262
|
+
<xsl:when test="type='TYPE_DOUBLE'">struct</xsl:when>
|
263
|
+
<xsl:when test="type='TYPE_FLOAT'">struct</xsl:when>
|
264
|
+
<xsl:when test="type='TYPE_INT64'">struct</xsl:when>
|
265
|
+
<xsl:when test="type='TYPE_UINT64'">struct</xsl:when>
|
266
|
+
<xsl:when test="type='TYPE_INT32'">struct</xsl:when>
|
267
|
+
<xsl:when test="type='TYPE_FIXED64'">struct</xsl:when>
|
268
|
+
<xsl:when test="type='TYPE_FIXED32'">struct</xsl:when>
|
269
|
+
<xsl:when test="type='TYPE_BOOL'">struct</xsl:when>
|
270
|
+
<xsl:when test="type='TYPE_STRING'">class</xsl:when>
|
271
|
+
<xsl:when test="type='TYPE_BYTES'">class</xsl:when>
|
272
|
+
<xsl:when test="type='TYPE_UINT32'">struct</xsl:when>
|
273
|
+
<xsl:when test="type='TYPE_SFIXED32'">struct</xsl:when>
|
274
|
+
<xsl:when test="type='TYPE_SFIXED64'">struct</xsl:when>
|
275
|
+
<xsl:when test="type='TYPE_SINT32'">struct</xsl:when>
|
276
|
+
<xsl:when test="type='TYPE_SINT64'">struct</xsl:when>
|
277
|
+
<xsl:when test="type='TYPE_ENUM'">struct</xsl:when>
|
278
|
+
<xsl:when test="type='TYPE_GROUP' or type='TYPE_MESSAGE'">none</xsl:when>
|
279
|
+
<xsl:otherwise>
|
280
|
+
<xsl:message terminate="yes">
|
281
|
+
Field type not implemented: <xsl:value-of select="type"/> (<xsl:value-of select="../../name"/>.<xsl:value-of select="name"/>)
|
282
|
+
</xsl:message>
|
283
|
+
</xsl:otherwise>
|
284
|
+
</xsl:choose>
|
285
|
+
</xsl:template>
|
286
|
+
<xsl:template match="FieldDescriptorProto" mode="type">
|
287
|
+
<xsl:choose>
|
288
|
+
<xsl:when test="not(type)">double</xsl:when>
|
289
|
+
<xsl:when test="type='TYPE_DOUBLE'">double</xsl:when>
|
290
|
+
<xsl:when test="type='TYPE_FLOAT'">float</xsl:when>
|
291
|
+
<xsl:when test="type='TYPE_INT64'">long</xsl:when>
|
292
|
+
<xsl:when test="type='TYPE_UINT64'">ulong</xsl:when>
|
293
|
+
<xsl:when test="type='TYPE_INT32'">int</xsl:when>
|
294
|
+
<xsl:when test="type='TYPE_FIXED64'">ulong</xsl:when>
|
295
|
+
<xsl:when test="type='TYPE_FIXED32'">uint</xsl:when>
|
296
|
+
<xsl:when test="type='TYPE_BOOL'">bool</xsl:when>
|
297
|
+
<xsl:when test="type='TYPE_STRING'">string</xsl:when>
|
298
|
+
<xsl:when test="type='TYPE_BYTES'">byte[]</xsl:when>
|
299
|
+
<xsl:when test="type='TYPE_UINT32'">uint</xsl:when>
|
300
|
+
<xsl:when test="type='TYPE_SFIXED32'">int</xsl:when>
|
301
|
+
<xsl:when test="type='TYPE_SFIXED64'">long</xsl:when>
|
302
|
+
<xsl:when test="type='TYPE_SINT32'">int</xsl:when>
|
303
|
+
<xsl:when test="type='TYPE_SINT64'">long</xsl:when>
|
304
|
+
<xsl:when test="type='TYPE_GROUP' or type='TYPE_MESSAGE' or type='TYPE_ENUM'"><xsl:call-template name="pascal">
|
305
|
+
<xsl:with-param name="value" select="substring-after(type_name,'.')"/>
|
306
|
+
</xsl:call-template></xsl:when>
|
307
|
+
<xsl:otherwise>
|
308
|
+
<xsl:message terminate="yes">
|
309
|
+
Field type not implemented: <xsl:value-of select="type"/> (<xsl:value-of select="../../name"/>.<xsl:value-of select="name"/>)
|
310
|
+
</xsl:message>
|
311
|
+
</xsl:otherwise>
|
312
|
+
</xsl:choose>
|
313
|
+
|
314
|
+
</xsl:template>
|
315
|
+
|
316
|
+
<xsl:template match="FieldDescriptorProto[default_value]" mode="defaultValue">
|
317
|
+
<xsl:choose>
|
318
|
+
<xsl:when test="type='TYPE_STRING'">@"<xsl:value-of select="default_value"/>"</xsl:when>
|
319
|
+
<xsl:when test="type='TYPE_ENUM'"><xsl:apply-templates select="." mode="type"/>.<xsl:call-template name="pascal">
|
320
|
+
<xsl:with-param name="value" select="default_value"/>
|
321
|
+
</xsl:call-template></xsl:when>
|
322
|
+
<xsl:when test="type='TYPE_BYTES'"> /*
|
323
|
+
<xsl:value-of select="default_value"/>
|
324
|
+
*/ null </xsl:when>
|
325
|
+
<xsl:otherwise>(<xsl:apply-templates select="." mode="type"/>)<xsl:value-of select="default_value"/></xsl:otherwise>
|
326
|
+
</xsl:choose>
|
327
|
+
</xsl:template>
|
328
|
+
|
329
|
+
<!--
|
330
|
+
We need to find the first enum value given .foo.bar.SomeEnum - but the enum itself
|
331
|
+
only knows about SomeEnum; we need to look at all parent DescriptorProto nodes, and
|
332
|
+
the FileDescriptorProto for the namespace.
|
333
|
+
|
334
|
+
This does an annoying up/down recursion... a bit expensive, but *generally* OK.
|
335
|
+
Could perhaps index the last part of the enum name to reduce overhead?
|
336
|
+
-->
|
337
|
+
<xsl:template name="GetFirstEnumValue">
|
338
|
+
<xsl:variable name="hunt" select="type_name"/>
|
339
|
+
<xsl:for-each select="//EnumDescriptorProto">
|
340
|
+
<xsl:variable name="fullName">
|
341
|
+
<xsl:for-each select="ancestor::FileDescriptorProto[package!='']">.<xsl:value-of select="package"/></xsl:for-each>
|
342
|
+
<xsl:for-each select="ancestor::DescriptorProto">.<xsl:value-of select="name"/></xsl:for-each>
|
343
|
+
<xsl:value-of select="'.'"/>
|
344
|
+
<xsl:call-template name="pascal"/>
|
345
|
+
</xsl:variable>
|
346
|
+
<xsl:if test="$fullName=$hunt"><xsl:value-of select="(value/EnumValueDescriptorProto)[1]/name"/></xsl:if>
|
347
|
+
</xsl:for-each>
|
348
|
+
</xsl:template>
|
349
|
+
|
350
|
+
<xsl:template match="FieldDescriptorProto[not(default_value)]" mode="defaultValue">
|
351
|
+
<xsl:choose>
|
352
|
+
<xsl:when test="type='TYPE_STRING'">""</xsl:when>
|
353
|
+
<xsl:when test="type='TYPE_MESSAGE'">null</xsl:when>
|
354
|
+
<xsl:when test="type='TYPE_BYTES'">null</xsl:when>
|
355
|
+
<xsl:when test="type='TYPE_ENUM'"><xsl:apply-templates select="." mode="type"/>.<xsl:call-template name="GetFirstEnumValue"/></xsl:when>
|
356
|
+
<xsl:otherwise>default(<xsl:apply-templates select="." mode="type"/>)</xsl:otherwise>
|
357
|
+
</xsl:choose>
|
358
|
+
</xsl:template>
|
359
|
+
|
360
|
+
<xsl:template match="FieldDescriptorProto" mode="checkDeprecated"><!--
|
361
|
+
--><xsl:if test="options/deprecated='true'">global::System.Obsolete, </xsl:if><!--
|
362
|
+
--></xsl:template>
|
363
|
+
<xsl:template match="FieldDescriptorProto[label='LABEL_OPTIONAL' or not(label)]">
|
364
|
+
<xsl:variable name="propType"><xsl:apply-templates select="." mode="type"/></xsl:variable>
|
365
|
+
<xsl:variable name="format"><xsl:apply-templates select="." mode="format"/></xsl:variable>
|
366
|
+
<xsl:variable name="primitiveType"><xsl:apply-templates select="." mode="primitiveType"/></xsl:variable>
|
367
|
+
<xsl:variable name="defaultValue"><xsl:apply-templates select="." mode="defaultValue"/></xsl:variable>
|
368
|
+
<xsl:variable name="field"><xsl:apply-templates select="." mode="field"/></xsl:variable>
|
369
|
+
<xsl:variable name="specified" select="$optionDetectMissing and ($primitiveType='struct' or $primitiveType='class')"/>
|
370
|
+
<xsl:variable name="fieldType"><xsl:value-of select="$propType"/><xsl:if test="$specified and $primitiveType='struct'">?</xsl:if></xsl:variable>
|
371
|
+
private <xsl:value-of select="concat($fieldType,' ',$field)"/><xsl:if test="not($specified)"> = <xsl:value-of select="$defaultValue"/></xsl:if>;
|
372
|
+
[<xsl:apply-templates select="." mode="checkDeprecated"/>global::ProtoBuf.ProtoMember(<xsl:value-of select="number"/>, IsRequired = false, Name=@"<xsl:value-of select="name"/>", DataFormat = global::ProtoBuf.DataFormat.<xsl:value-of select="$format"/>)]<!--
|
373
|
+
--><xsl:if test="not($specified)">
|
374
|
+
[global::System.ComponentModel.DefaultValue(<xsl:value-of select="$defaultValue"/>)]</xsl:if><!--
|
375
|
+
--><xsl:if test="$optionXml">
|
376
|
+
[global::System.Xml.Serialization.XmlElement(@"<xsl:value-of select="name"/>", Order = <xsl:value-of select="number"/>)]
|
377
|
+
</xsl:if><xsl:if test="$optionDataContract">
|
378
|
+
[global::System.Runtime.Serialization.DataMember(Name=@"<xsl:value-of select="name"/>", Order = <xsl:value-of select="number"/>, IsRequired = false)]
|
379
|
+
</xsl:if><xsl:call-template name="WriteGetSet">
|
380
|
+
<xsl:with-param name="fieldType" select="$fieldType"/>
|
381
|
+
<xsl:with-param name="propType" select="$propType"/>
|
382
|
+
<xsl:with-param name="name"><xsl:call-template name="pascal"/></xsl:with-param>
|
383
|
+
<xsl:with-param name="field" select="$field"/>
|
384
|
+
<xsl:with-param name="defaultValue" select="$defaultValue"/>
|
385
|
+
<xsl:with-param name="specified" select="$specified"/>
|
386
|
+
</xsl:call-template>
|
387
|
+
</xsl:template>
|
388
|
+
|
389
|
+
<xsl:template match="FieldDescriptorProto[label='LABEL_REQUIRED']">
|
390
|
+
<xsl:variable name="type"><xsl:apply-templates select="." mode="type"/></xsl:variable>
|
391
|
+
<xsl:variable name="format"><xsl:apply-templates select="." mode="format"/></xsl:variable>
|
392
|
+
<xsl:variable name="field"><xsl:apply-templates select="." mode="field"/></xsl:variable>
|
393
|
+
private <xsl:value-of select="concat($type, ' ', $field)"/>;
|
394
|
+
[<xsl:apply-templates select="." mode="checkDeprecated"/>global::ProtoBuf.ProtoMember(<xsl:value-of select="number"/>, IsRequired = true, Name=@"<xsl:value-of select="name"/>", DataFormat = global::ProtoBuf.DataFormat.<xsl:value-of select="$format"/>)]<!--
|
395
|
+
--><xsl:if test="$optionXml">
|
396
|
+
[global::System.Xml.Serialization.XmlElement(@"<xsl:value-of select="name"/>", Order = <xsl:value-of select="number"/>)]
|
397
|
+
</xsl:if><xsl:if test="$optionDataContract">
|
398
|
+
[global::System.Runtime.Serialization.DataMember(Name=@"<xsl:value-of select="name"/>", Order = <xsl:value-of select="number"/>, IsRequired = true)]
|
399
|
+
</xsl:if><xsl:call-template name="WriteGetSet">
|
400
|
+
<xsl:with-param name="fieldType" select="$type"/>
|
401
|
+
<xsl:with-param name="propType" select="$type"/>
|
402
|
+
<xsl:with-param name="name"><xsl:call-template name="pascal"/></xsl:with-param>
|
403
|
+
<xsl:with-param name="field" select="$field"/>
|
404
|
+
</xsl:call-template>
|
405
|
+
</xsl:template>
|
406
|
+
|
407
|
+
<xsl:template name="stripKeyword">
|
408
|
+
<xsl:param name="value"/>
|
409
|
+
<xsl:choose>
|
410
|
+
<xsl:when test="starts-with($value,'@')"><xsl:value-of select="substring-after($value,'@')"/></xsl:when>
|
411
|
+
<xsl:otherwise><xsl:value-of select="$value"/></xsl:otherwise>
|
412
|
+
</xsl:choose>
|
413
|
+
</xsl:template>
|
414
|
+
|
415
|
+
<xsl:template name="WriteGetSet">
|
416
|
+
<xsl:param name="fieldType"/>
|
417
|
+
<xsl:param name="propType"/>
|
418
|
+
<xsl:param name="name"/>
|
419
|
+
<xsl:param name="field"/>
|
420
|
+
<xsl:param name="specified" select="false()"/>
|
421
|
+
<xsl:param name="defaultValue"/>
|
422
|
+
<xsl:variable name="nameNoKeyword">
|
423
|
+
<xsl:call-template name="stripKeyword">
|
424
|
+
<xsl:with-param name="value" select="$name"/>
|
425
|
+
</xsl:call-template></xsl:variable>
|
426
|
+
public <xsl:value-of select="concat($propType,' ',$name)"/>
|
427
|
+
{
|
428
|
+
get { return <xsl:value-of select="$field"/> <xsl:if test="$specified">?? <xsl:value-of select="$defaultValue"/></xsl:if>; }
|
429
|
+
set { <xsl:if test="$optionPartialMethods">On<xsl:value-of select="$nameNoKeyword"/>Changing(value); </xsl:if><xsl:if test="$optionPreObservable">OnPropertyChanging(@"<xsl:value-of select="$nameNoKeyword"/>"); </xsl:if><xsl:value-of select="$field"/> = value; <xsl:if test="$optionObservable">OnPropertyChanged(@"<xsl:value-of select="$nameNoKeyword"/>"); </xsl:if><xsl:if test="$optionPartialMethods">On<xsl:value-of select="$nameNoKeyword"/>Changed();</xsl:if>}
|
430
|
+
}<xsl:if test="$optionPartialMethods">
|
431
|
+
partial void On<xsl:value-of select="$nameNoKeyword"/>Changing(<xsl:value-of select="$propType"/> value);
|
432
|
+
partial void On<xsl:value-of select="$nameNoKeyword"/>Changed();</xsl:if><xsl:if test="$specified">
|
433
|
+
[global::System.Xml.Serialization.XmlIgnore]
|
434
|
+
<xsl:if test="$optionFullFramework">[global::System.ComponentModel.Browsable(false)]</xsl:if>
|
435
|
+
public bool <xsl:value-of select="$nameNoKeyword"/>Specified
|
436
|
+
{
|
437
|
+
get { return this.<xsl:value-of select="$field"/> != null; }
|
438
|
+
set { if (value == (this.<xsl:value-of select="$field"/>== null)) this.<xsl:value-of select="$field"/> = value ? this.<xsl:value-of select="$name"/> : (<xsl:value-of select="$fieldType"/>)null; }
|
439
|
+
}
|
440
|
+
private bool ShouldSerialize<xsl:value-of select="$nameNoKeyword"/>() { return <xsl:value-of select="$nameNoKeyword"/>Specified; }
|
441
|
+
private void Reset<xsl:value-of select="$nameNoKeyword"/>() { <xsl:value-of select="$nameNoKeyword"/>Specified = false; }
|
442
|
+
</xsl:if>
|
443
|
+
</xsl:template>
|
444
|
+
<xsl:template match="FieldDescriptorProto[label='LABEL_REPEATED']">
|
445
|
+
<xsl:variable name="type"><xsl:apply-templates select="." mode="type"/></xsl:variable>
|
446
|
+
<xsl:variable name="format"><xsl:apply-templates select="." mode="format"/></xsl:variable>
|
447
|
+
<xsl:variable name="field"><xsl:apply-templates select="." mode="field"/></xsl:variable>
|
448
|
+
private <xsl:if test="not($optionXml)">readonly</xsl:if> global::System.Collections.Generic.List<<xsl:value-of select="$type" />> <xsl:value-of select="$field"/> = new global::System.Collections.Generic.List<<xsl:value-of select="$type"/>>();
|
449
|
+
[<xsl:apply-templates select="." mode="checkDeprecated"/>global::ProtoBuf.ProtoMember(<xsl:value-of select="number"/>, Name=@"<xsl:value-of select="name"/>", DataFormat = global::ProtoBuf.DataFormat.<xsl:value-of select="$format"/><xsl:if test="options/packed='true'">, Options = global::ProtoBuf.MemberSerializationOptions.Packed</xsl:if>)]<!--
|
450
|
+
--><xsl:if test="$optionDataContract">
|
451
|
+
[global::System.Runtime.Serialization.DataMember(Name=@"<xsl:value-of select="name"/>", Order = <xsl:value-of select="number"/>, IsRequired = false)]
|
452
|
+
</xsl:if><xsl:if test="$optionXml">
|
453
|
+
[global::System.Xml.Serialization.XmlElement(@"<xsl:value-of select="name"/>", Order = <xsl:value-of select="number"/>)]
|
454
|
+
</xsl:if>
|
455
|
+
public global::System.Collections.Generic.List<<xsl:value-of select="$type" />> <xsl:call-template name="pascal"/>
|
456
|
+
{
|
457
|
+
get { return <xsl:value-of select="$field"/>; }<!--
|
458
|
+
--><xsl:if test="$optionXml">
|
459
|
+
set { <xsl:value-of select="$field"/> = value; }</xsl:if>
|
460
|
+
}
|
461
|
+
</xsl:template>
|
462
|
+
|
463
|
+
<xsl:template match="ServiceDescriptorProto">
|
464
|
+
<xsl:if test="($optionClientProxy or $optionDataContract)">
|
465
|
+
[global::System.ServiceModel.ServiceContract(Name = @"<xsl:value-of select="name"/>")]</xsl:if>
|
466
|
+
public interface I<xsl:value-of select="name"/>
|
467
|
+
{
|
468
|
+
<xsl:apply-templates select="method"/>
|
469
|
+
}
|
470
|
+
|
471
|
+
<xsl:if test="$optionProtoRpc">
|
472
|
+
public class <xsl:value-of select="name"/>Client : global::ProtoBuf.ServiceModel.RpcClient
|
473
|
+
{
|
474
|
+
public <xsl:value-of select="name"/>Client() : base(typeof(I<xsl:value-of select="name"/>)) { }
|
475
|
+
<xsl:apply-templates select="method/MethodDescriptorProto" mode="protoRpc"/>
|
476
|
+
}
|
477
|
+
</xsl:if>
|
478
|
+
<xsl:apply-templates select="." mode="clientProxy"/>
|
479
|
+
|
480
|
+
</xsl:template>
|
481
|
+
|
482
|
+
<xsl:template match="MethodDescriptorProto">
|
483
|
+
<xsl:if test="($optionClientProxy or $optionDataContract)">
|
484
|
+
[global::System.ServiceModel.OperationContract(Name = @"<xsl:value-of select="name"/>")]
|
485
|
+
<xsl:if test="$optionFullFramework">[global::ProtoBuf.ServiceModel.ProtoBehavior]</xsl:if>
|
486
|
+
</xsl:if>
|
487
|
+
<xsl:apply-templates select="output_type"/><xsl:text xml:space="preserve"> </xsl:text><xsl:value-of select="name"/>(<xsl:apply-templates select="input_type"/> request);
|
488
|
+
<xsl:if test="$optionAsynchronous and ($optionClientProxy or $optionDataContract)">
|
489
|
+
[global::System.ServiceModel.OperationContract(AsyncPattern = true, Name = @"<xsl:value-of select="name"/>")]
|
490
|
+
global::System.IAsyncResult Begin<xsl:value-of select="name"/>(<xsl:apply-templates select="input_type"/> request, global::System.AsyncCallback callback, object state);
|
491
|
+
<xsl:apply-templates select="output_type"/> End<xsl:value-of select="name"/>(global::System.IAsyncResult ar);
|
492
|
+
</xsl:if>
|
493
|
+
</xsl:template>
|
494
|
+
|
495
|
+
<xsl:template match="MethodDescriptorProto" mode="protoRpc">
|
496
|
+
<xsl:apply-templates select="output_type"/><xsl:text xml:space="preserve"> </xsl:text><xsl:value-of select="name"/>(<xsl:apply-templates select="input_type"/> request)
|
497
|
+
{
|
498
|
+
return (<xsl:apply-templates select="output_type"/>) Send(@"<xsl:value-of select="name"/>", request);
|
499
|
+
}
|
500
|
+
</xsl:template>
|
501
|
+
|
502
|
+
<xsl:template match="MethodDescriptorProto/input_type | MethodDescriptorProto/output_type">
|
503
|
+
<xsl:value-of select="substring-after(.,'.')"/>
|
504
|
+
</xsl:template>
|
505
|
+
|
506
|
+
<xsl:template match="MethodDescriptorProto" mode="CompleteEvent">
|
507
|
+
<xsl:if test="$optionAsynchronous and $optionDataContract">
|
508
|
+
public partial class <xsl:value-of select="name"/>CompletedEventArgs : global::System.ComponentModel.AsyncCompletedEventArgs
|
509
|
+
{
|
510
|
+
private object[] results;
|
511
|
+
|
512
|
+
public <xsl:value-of select="name"/>CompletedEventArgs(object[] results, global::System.Exception exception, bool cancelled, object userState)
|
513
|
+
: base(exception, cancelled, userState)
|
514
|
+
{
|
515
|
+
this.results = results;
|
516
|
+
}
|
517
|
+
|
518
|
+
public <xsl:apply-templates select="output_type"/> Result
|
519
|
+
{
|
520
|
+
get {
|
521
|
+
base.RaiseExceptionIfNecessary();
|
522
|
+
return (<xsl:apply-templates select="output_type"/>)(this.results[0]);
|
523
|
+
}
|
524
|
+
}
|
525
|
+
}
|
526
|
+
</xsl:if>
|
527
|
+
</xsl:template>
|
528
|
+
|
529
|
+
<xsl:template match="ServiceDescriptorProto" mode="clientProxy">
|
530
|
+
<xsl:if test="$optionAsynchronous and $optionDataContract and $optionClientProxy">
|
531
|
+
<xsl:apply-templates select="method/MethodDescriptorProto" mode="CompleteEvent"/>
|
532
|
+
|
533
|
+
[global::System.Diagnostics.DebuggerStepThroughAttribute()]
|
534
|
+
public partial class <xsl:value-of select="name"/>Client : global::System.ServiceModel.ClientBase<I<xsl:value-of select="name"/>>, I<xsl:value-of select="name"/>
|
535
|
+
{
|
536
|
+
|
537
|
+
public <xsl:value-of select="name"/>Client()
|
538
|
+
{}
|
539
|
+
public <xsl:value-of select="name"/>Client(string endpointConfigurationName)
|
540
|
+
: base(endpointConfigurationName)
|
541
|
+
{}
|
542
|
+
public <xsl:value-of select="name"/>Client(string endpointConfigurationName, string remoteAddress)
|
543
|
+
: base(endpointConfigurationName, remoteAddress)
|
544
|
+
{}
|
545
|
+
public <xsl:value-of select="name"/>Client(string endpointConfigurationName, global::System.ServiceModel.EndpointAddress remoteAddress)
|
546
|
+
: base(endpointConfigurationName, remoteAddress)
|
547
|
+
{}
|
548
|
+
public <xsl:value-of select="name"/>Client(global::System.ServiceModel.Channels.Binding binding, global::System.ServiceModel.EndpointAddress remoteAddress)
|
549
|
+
: base(binding, remoteAddress)
|
550
|
+
{}
|
551
|
+
|
552
|
+
<xsl:apply-templates select="method/MethodDescriptorProto" mode="clientProxy"/>
|
553
|
+
}
|
554
|
+
</xsl:if>
|
555
|
+
</xsl:template>
|
556
|
+
|
557
|
+
<xsl:template match="MethodDescriptorProto" mode="clientProxy">
|
558
|
+
<xsl:if test="$optionAsynchronous and $optionDataContract and $optionClientProxy">
|
559
|
+
private BeginOperationDelegate onBegin<xsl:value-of select="name"/>Delegate;
|
560
|
+
private EndOperationDelegate onEnd<xsl:value-of select="name"/>Delegate;
|
561
|
+
private global::System.Threading.SendOrPostCallback on<xsl:value-of select="name"/>CompletedDelegate;
|
562
|
+
|
563
|
+
public event global::System.EventHandler<<xsl:value-of select="name"/>CompletedEventArgs> <xsl:value-of select="name"/>Completed;
|
564
|
+
|
565
|
+
public <xsl:apply-templates select="output_type"/><xsl:text xml:space="preserve"> </xsl:text><xsl:value-of select="name"/>(<xsl:apply-templates select="input_type"/> request)
|
566
|
+
{
|
567
|
+
return base.Channel.<xsl:value-of select="name"/>(request);
|
568
|
+
}
|
569
|
+
|
570
|
+
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
571
|
+
public global::System.IAsyncResult Begin<xsl:value-of select="name"/>(<xsl:apply-templates select="input_type"/> request, global::System.AsyncCallback callback, object asyncState)
|
572
|
+
{
|
573
|
+
return base.Channel.Begin<xsl:value-of select="name"/>(request, callback, asyncState);
|
574
|
+
}
|
575
|
+
|
576
|
+
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
577
|
+
public <xsl:apply-templates select="output_type"/> End<xsl:value-of select="name"/>(global::System.IAsyncResult result)
|
578
|
+
{
|
579
|
+
return base.Channel.End<xsl:value-of select="name"/>(result);
|
580
|
+
}
|
581
|
+
|
582
|
+
private global::System.IAsyncResult OnBegin<xsl:value-of select="name"/>(object[] inValues, global::System.AsyncCallback callback, object asyncState)
|
583
|
+
{
|
584
|
+
<xsl:apply-templates select="input_type"/> request = ((<xsl:apply-templates select="input_type"/>)(inValues[0]));
|
585
|
+
return this.Begin<xsl:value-of select="name"/>(request, callback, asyncState);
|
586
|
+
}
|
587
|
+
|
588
|
+
private object[] OnEnd<xsl:value-of select="name"/>(global::System.IAsyncResult result)
|
589
|
+
{
|
590
|
+
<xsl:apply-templates select="output_type"/> retVal = this.End<xsl:value-of select="name"/>(result);
|
591
|
+
return new object[] {
|
592
|
+
retVal};
|
593
|
+
}
|
594
|
+
|
595
|
+
private void On<xsl:value-of select="name"/>Completed(object state)
|
596
|
+
{
|
597
|
+
if ((this.<xsl:value-of select="name"/>Completed != null))
|
598
|
+
{
|
599
|
+
InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
|
600
|
+
this.<xsl:value-of select="name"/>Completed(this, new <xsl:value-of select="name"/>CompletedEventArgs(e.Results, e.Error, e.Cancelled, e.UserState));
|
601
|
+
}
|
602
|
+
}
|
603
|
+
|
604
|
+
public void <xsl:value-of select="name"/>Async(<xsl:apply-templates select="input_type"/> request)
|
605
|
+
{
|
606
|
+
this.<xsl:value-of select="name"/>Async(request, null);
|
607
|
+
}
|
608
|
+
|
609
|
+
public void <xsl:value-of select="name"/>Async(<xsl:apply-templates select="input_type"/> request, object userState)
|
610
|
+
{
|
611
|
+
if ((this.onBegin<xsl:value-of select="name"/>Delegate == null))
|
612
|
+
{
|
613
|
+
this.onBegin<xsl:value-of select="name"/>Delegate = new BeginOperationDelegate(this.OnBegin<xsl:value-of select="name"/>);
|
614
|
+
}
|
615
|
+
if ((this.onEnd<xsl:value-of select="name"/>Delegate == null))
|
616
|
+
{
|
617
|
+
this.onEnd<xsl:value-of select="name"/>Delegate = new EndOperationDelegate(this.OnEnd<xsl:value-of select="name"/>);
|
618
|
+
}
|
619
|
+
if ((this.on<xsl:value-of select="name"/>CompletedDelegate == null))
|
620
|
+
{
|
621
|
+
this.on<xsl:value-of select="name"/>CompletedDelegate = new global::System.Threading.SendOrPostCallback(this.On<xsl:value-of select="name"/>Completed);
|
622
|
+
}
|
623
|
+
base.InvokeAsync(this.onBegin<xsl:value-of select="name"/>Delegate, new object[] {
|
624
|
+
request}, this.onEnd<xsl:value-of select="name"/>Delegate, this.on<xsl:value-of select="name"/>CompletedDelegate, userState);
|
625
|
+
}
|
626
|
+
</xsl:if>
|
627
|
+
</xsl:template>
|
628
|
+
</xsl:stylesheet>
|