Plan.cs 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT License.
  3. // See the LICENSE file in the project root for more information.
  4. using System.Collections.Generic;
  5. namespace System.Reactive.Joins
  6. {
  7. /// <summary>
  8. /// Represents an execution plan for join patterns.
  9. /// </summary>
  10. /// <typeparam name="TResult">The type of the results produced by the plan.</typeparam>
  11. public abstract class Plan<TResult>
  12. {
  13. internal Plan()
  14. {
  15. }
  16. internal abstract ActivePlan Activate(Dictionary<object, IJoinObserver> externalSubscriptions,
  17. IObserver<TResult> observer, Action<ActivePlan> deactivate);
  18. internal static JoinObserver<TSource> CreateObserver<TSource>(
  19. Dictionary<object, IJoinObserver> externalSubscriptions, IObservable<TSource> observable, Action<Exception> onError)
  20. {
  21. JoinObserver<TSource> observer;
  22. if (!externalSubscriptions.TryGetValue(observable, out var nonGeneric))
  23. {
  24. observer = new JoinObserver<TSource>(observable, onError);
  25. externalSubscriptions.Add(observable, observer);
  26. }
  27. else
  28. {
  29. observer = (JoinObserver<TSource>)nonGeneric;
  30. }
  31. return observer;
  32. }
  33. }
  34. internal class Plan<T1, TResult> : Plan<TResult>
  35. {
  36. internal Pattern<T1> Expression { get; }
  37. internal Func<T1, TResult> Selector { get; }
  38. internal Plan(Pattern<T1> expression, Func<T1, TResult> selector)
  39. {
  40. Expression = expression;
  41. Selector = selector;
  42. }
  43. internal override ActivePlan Activate(Dictionary<object, IJoinObserver> externalSubscriptions,
  44. IObserver<TResult> observer, Action<ActivePlan> deactivate)
  45. {
  46. var onError = new Action<Exception>(observer.OnError);
  47. var firstJoinObserver = CreateObserver(externalSubscriptions, Expression.First, onError);
  48. var activePlan = default(ActivePlan<T1>);
  49. activePlan = new ActivePlan<T1>(firstJoinObserver,
  50. first =>
  51. {
  52. TResult result;
  53. try
  54. {
  55. result = Selector(first);
  56. }
  57. catch (Exception exception)
  58. {
  59. observer.OnError(exception);
  60. return;
  61. }
  62. observer.OnNext(result);
  63. },
  64. () =>
  65. {
  66. firstJoinObserver.RemoveActivePlan(activePlan);
  67. deactivate(activePlan);
  68. });
  69. firstJoinObserver.AddActivePlan(activePlan);
  70. return activePlan;
  71. }
  72. }
  73. internal class Plan<T1, T2, TResult> : Plan<TResult>
  74. {
  75. internal Pattern<T1, T2> Expression { get; }
  76. internal Func<T1, T2, TResult> Selector { get; }
  77. internal Plan(Pattern<T1, T2> expression, Func<T1, T2, TResult> selector)
  78. {
  79. Expression = expression;
  80. Selector = selector;
  81. }
  82. internal override ActivePlan Activate(Dictionary<object, IJoinObserver> externalSubscriptions,
  83. IObserver<TResult> observer, Action<ActivePlan> deactivate)
  84. {
  85. var onError = new Action<Exception>(observer.OnError);
  86. var firstJoinObserver = CreateObserver(externalSubscriptions, Expression.First, onError);
  87. var secondJoinObserver = CreateObserver(externalSubscriptions, Expression.Second, onError);
  88. var activePlan = default(ActivePlan<T1, T2>);
  89. activePlan = new ActivePlan<T1, T2>(firstJoinObserver, secondJoinObserver,
  90. (first, second) =>
  91. {
  92. TResult result;
  93. try
  94. {
  95. result = Selector(first, second);
  96. }
  97. catch (Exception exception)
  98. {
  99. observer.OnError(exception);
  100. return;
  101. }
  102. observer.OnNext(result);
  103. },
  104. () =>
  105. {
  106. firstJoinObserver.RemoveActivePlan(activePlan);
  107. secondJoinObserver.RemoveActivePlan(activePlan);
  108. deactivate(activePlan);
  109. });
  110. firstJoinObserver.AddActivePlan(activePlan);
  111. secondJoinObserver.AddActivePlan(activePlan);
  112. return activePlan;
  113. }
  114. }
  115. internal class Plan<T1, T2, T3, TResult> : Plan<TResult>
  116. {
  117. internal Pattern<T1, T2, T3> Expression { get; }
  118. internal Func<T1, T2, T3, TResult> Selector { get; }
  119. internal Plan(Pattern<T1, T2, T3> expression, Func<T1, T2, T3, TResult> selector)
  120. {
  121. Expression = expression;
  122. Selector = selector;
  123. }
  124. internal override ActivePlan Activate(Dictionary<object, IJoinObserver> externalSubscriptions,
  125. IObserver<TResult> observer, Action<ActivePlan> deactivate)
  126. {
  127. var onError = new Action<Exception>(observer.OnError);
  128. var firstJoinObserver = CreateObserver(externalSubscriptions, Expression.First, onError);
  129. var secondJoinObserver = CreateObserver(externalSubscriptions, Expression.Second, onError);
  130. var thirdJoinObserver = CreateObserver(externalSubscriptions, Expression.Third, onError);
  131. var activePlan = default(ActivePlan<T1, T2, T3>);
  132. activePlan = new ActivePlan<T1, T2, T3>(firstJoinObserver, secondJoinObserver, thirdJoinObserver,
  133. (first, second, third) =>
  134. {
  135. TResult result;
  136. try
  137. {
  138. result = Selector(first, second, third);
  139. }
  140. catch (Exception exception)
  141. {
  142. observer.OnError(exception);
  143. return;
  144. }
  145. observer.OnNext(result);
  146. },
  147. () =>
  148. {
  149. firstJoinObserver.RemoveActivePlan(activePlan);
  150. secondJoinObserver.RemoveActivePlan(activePlan);
  151. thirdJoinObserver.RemoveActivePlan(activePlan);
  152. deactivate(activePlan);
  153. });
  154. firstJoinObserver.AddActivePlan(activePlan);
  155. secondJoinObserver.AddActivePlan(activePlan);
  156. thirdJoinObserver.AddActivePlan(activePlan);
  157. return activePlan;
  158. }
  159. }
  160. internal class Plan<T1, T2, T3, T4, TResult> : Plan<TResult>
  161. {
  162. internal Pattern<T1, T2, T3, T4> Expression { get; }
  163. internal Func<T1, T2, T3, T4, TResult> Selector { get; }
  164. internal Plan(Pattern<T1, T2, T3, T4> expression,
  165. Func<T1, T2, T3, T4, TResult> selector)
  166. {
  167. Expression = expression;
  168. Selector = selector;
  169. }
  170. internal override ActivePlan Activate(Dictionary<object, IJoinObserver> externalSubscriptions,
  171. IObserver<TResult> observer, Action<ActivePlan> deactivate)
  172. {
  173. var onError = new Action<Exception>(observer.OnError);
  174. var firstJoinObserver = CreateObserver(externalSubscriptions, Expression.First, onError);
  175. var secondJoinObserver = CreateObserver(externalSubscriptions, Expression.Second, onError);
  176. var thirdJoinObserver = CreateObserver(externalSubscriptions, Expression.Third, onError);
  177. var fourthJoinObserver = CreateObserver(externalSubscriptions, Expression.Fourth, onError);
  178. var activePlan = default(ActivePlan<T1, T2, T3, T4>);
  179. activePlan = new ActivePlan<T1, T2, T3, T4>(firstJoinObserver, secondJoinObserver, thirdJoinObserver, fourthJoinObserver,
  180. (first, second, third, fourth) =>
  181. {
  182. TResult result;
  183. try
  184. {
  185. result = Selector(first, second, third, fourth);
  186. }
  187. catch (Exception exception)
  188. {
  189. observer.OnError(exception);
  190. return;
  191. }
  192. observer.OnNext(result);
  193. },
  194. () =>
  195. {
  196. firstJoinObserver.RemoveActivePlan(activePlan);
  197. secondJoinObserver.RemoveActivePlan(activePlan);
  198. thirdJoinObserver.RemoveActivePlan(activePlan);
  199. fourthJoinObserver.RemoveActivePlan(activePlan);
  200. deactivate(activePlan);
  201. });
  202. firstJoinObserver.AddActivePlan(activePlan);
  203. secondJoinObserver.AddActivePlan(activePlan);
  204. thirdJoinObserver.AddActivePlan(activePlan);
  205. fourthJoinObserver.AddActivePlan(activePlan);
  206. return activePlan;
  207. }
  208. }
  209. internal class Plan<T1, T2, T3, T4, T5, TResult> : Plan<TResult>
  210. {
  211. internal Pattern<T1, T2, T3, T4, T5> Expression { get; }
  212. internal Func<T1, T2, T3, T4, T5, TResult> Selector { get; }
  213. internal Plan(Pattern<T1, T2, T3, T4, T5> expression,
  214. Func<T1, T2, T3, T4, T5, TResult> selector)
  215. {
  216. Expression = expression;
  217. Selector = selector;
  218. }
  219. internal override ActivePlan Activate(Dictionary<object, IJoinObserver> externalSubscriptions,
  220. IObserver<TResult> observer, Action<ActivePlan> deactivate)
  221. {
  222. var onError = new Action<Exception>(observer.OnError);
  223. var firstJoinObserver = CreateObserver(externalSubscriptions, Expression.First, onError);
  224. var secondJoinObserver = CreateObserver(externalSubscriptions, Expression.Second, onError);
  225. var thirdJoinObserver = CreateObserver(externalSubscriptions, Expression.Third, onError);
  226. var fourthJoinObserver = CreateObserver(externalSubscriptions, Expression.Fourth, onError);
  227. var fifthJoinObserver = CreateObserver(externalSubscriptions, Expression.Fifth, onError);
  228. var activePlan = default(ActivePlan<T1, T2, T3, T4, T5>);
  229. activePlan = new ActivePlan<T1, T2, T3, T4, T5>(firstJoinObserver, secondJoinObserver, thirdJoinObserver, fourthJoinObserver, fifthJoinObserver,
  230. (first, second, third, fourth, fifth) =>
  231. {
  232. TResult result;
  233. try
  234. {
  235. result = Selector(first, second, third, fourth, fifth);
  236. }
  237. catch (Exception exception)
  238. {
  239. observer.OnError(exception);
  240. return;
  241. }
  242. observer.OnNext(result);
  243. },
  244. () =>
  245. {
  246. firstJoinObserver.RemoveActivePlan(activePlan);
  247. secondJoinObserver.RemoveActivePlan(activePlan);
  248. thirdJoinObserver.RemoveActivePlan(activePlan);
  249. fourthJoinObserver.RemoveActivePlan(activePlan);
  250. fifthJoinObserver.RemoveActivePlan(activePlan);
  251. deactivate(activePlan);
  252. });
  253. firstJoinObserver.AddActivePlan(activePlan);
  254. secondJoinObserver.AddActivePlan(activePlan);
  255. thirdJoinObserver.AddActivePlan(activePlan);
  256. fourthJoinObserver.AddActivePlan(activePlan);
  257. fifthJoinObserver.AddActivePlan(activePlan);
  258. return activePlan;
  259. }
  260. }
  261. internal class Plan<T1, T2, T3, T4, T5, T6, TResult> : Plan<TResult>
  262. {
  263. internal Pattern<T1, T2, T3, T4, T5, T6> Expression { get; }
  264. internal Func<T1, T2, T3, T4, T5, T6, TResult> Selector { get; }
  265. internal Plan(Pattern<T1, T2, T3, T4, T5, T6> expression,
  266. Func<T1, T2, T3, T4, T5, T6, TResult> selector)
  267. {
  268. Expression = expression;
  269. Selector = selector;
  270. }
  271. internal override ActivePlan Activate(Dictionary<object, IJoinObserver> externalSubscriptions,
  272. IObserver<TResult> observer, Action<ActivePlan> deactivate)
  273. {
  274. var onError = new Action<Exception>(observer.OnError);
  275. var firstJoinObserver = CreateObserver(externalSubscriptions, Expression.First, onError);
  276. var secondJoinObserver = CreateObserver(externalSubscriptions, Expression.Second, onError);
  277. var thirdJoinObserver = CreateObserver(externalSubscriptions, Expression.Third, onError);
  278. var fourthJoinObserver = CreateObserver(externalSubscriptions, Expression.Fourth, onError);
  279. var fifthJoinObserver = CreateObserver(externalSubscriptions, Expression.Fifth, onError);
  280. var sixthJoinObserver = CreateObserver(externalSubscriptions, Expression.Sixth, onError);
  281. var activePlan = default(ActivePlan<T1, T2, T3, T4, T5, T6>);
  282. activePlan = new ActivePlan<T1, T2, T3, T4, T5, T6>(firstJoinObserver, secondJoinObserver, thirdJoinObserver,
  283. fourthJoinObserver, fifthJoinObserver, sixthJoinObserver,
  284. (first, second, third, fourth, fifth, sixth) =>
  285. {
  286. TResult result;
  287. try
  288. {
  289. result = Selector(first, second, third, fourth, fifth, sixth);
  290. }
  291. catch (Exception exception)
  292. {
  293. observer.OnError(exception);
  294. return;
  295. }
  296. observer.OnNext(result);
  297. },
  298. () =>
  299. {
  300. firstJoinObserver.RemoveActivePlan(activePlan);
  301. secondJoinObserver.RemoveActivePlan(activePlan);
  302. thirdJoinObserver.RemoveActivePlan(activePlan);
  303. fourthJoinObserver.RemoveActivePlan(activePlan);
  304. fifthJoinObserver.RemoveActivePlan(activePlan);
  305. sixthJoinObserver.RemoveActivePlan(activePlan);
  306. deactivate(activePlan);
  307. });
  308. firstJoinObserver.AddActivePlan(activePlan);
  309. secondJoinObserver.AddActivePlan(activePlan);
  310. thirdJoinObserver.AddActivePlan(activePlan);
  311. fourthJoinObserver.AddActivePlan(activePlan);
  312. fifthJoinObserver.AddActivePlan(activePlan);
  313. sixthJoinObserver.AddActivePlan(activePlan);
  314. return activePlan;
  315. }
  316. }
  317. internal class Plan<T1, T2, T3, T4, T5, T6, T7, TResult> : Plan<TResult>
  318. {
  319. internal Pattern<T1, T2, T3, T4, T5, T6, T7> Expression { get; }
  320. internal Func<T1, T2, T3, T4, T5, T6, T7, TResult> Selector { get; }
  321. internal Plan(Pattern<T1, T2, T3, T4, T5, T6, T7> expression,
  322. Func<T1, T2, T3, T4, T5, T6, T7, TResult> selector)
  323. {
  324. Expression = expression;
  325. Selector = selector;
  326. }
  327. internal override ActivePlan Activate(Dictionary<object, IJoinObserver> externalSubscriptions,
  328. IObserver<TResult> observer, Action<ActivePlan> deactivate)
  329. {
  330. var onError = new Action<Exception>(observer.OnError);
  331. var firstJoinObserver = CreateObserver(externalSubscriptions, Expression.First, onError);
  332. var secondJoinObserver = CreateObserver(externalSubscriptions, Expression.Second, onError);
  333. var thirdJoinObserver = CreateObserver(externalSubscriptions, Expression.Third, onError);
  334. var fourthJoinObserver = CreateObserver(externalSubscriptions, Expression.Fourth, onError);
  335. var fifthJoinObserver = CreateObserver(externalSubscriptions, Expression.Fifth, onError);
  336. var sixthJoinObserver = CreateObserver(externalSubscriptions, Expression.Sixth, onError);
  337. var seventhJoinObserver = CreateObserver(externalSubscriptions, Expression.Seventh, onError);
  338. var activePlan = default(ActivePlan<T1, T2, T3, T4, T5, T6, T7>);
  339. activePlan = new ActivePlan<T1, T2, T3, T4, T5, T6, T7>(firstJoinObserver, secondJoinObserver, thirdJoinObserver,
  340. fourthJoinObserver, fifthJoinObserver, sixthJoinObserver, seventhJoinObserver,
  341. (first, second, third, fourth, fifth, sixth, seventh) =>
  342. {
  343. TResult result;
  344. try
  345. {
  346. result = Selector(first, second, third, fourth, fifth, sixth, seventh);
  347. }
  348. catch (Exception exception)
  349. {
  350. observer.OnError(exception);
  351. return;
  352. }
  353. observer.OnNext(result);
  354. },
  355. () =>
  356. {
  357. firstJoinObserver.RemoveActivePlan(activePlan);
  358. secondJoinObserver.RemoveActivePlan(activePlan);
  359. thirdJoinObserver.RemoveActivePlan(activePlan);
  360. fourthJoinObserver.RemoveActivePlan(activePlan);
  361. fifthJoinObserver.RemoveActivePlan(activePlan);
  362. sixthJoinObserver.RemoveActivePlan(activePlan);
  363. seventhJoinObserver.RemoveActivePlan(activePlan);
  364. deactivate(activePlan);
  365. });
  366. firstJoinObserver.AddActivePlan(activePlan);
  367. secondJoinObserver.AddActivePlan(activePlan);
  368. thirdJoinObserver.AddActivePlan(activePlan);
  369. fourthJoinObserver.AddActivePlan(activePlan);
  370. fifthJoinObserver.AddActivePlan(activePlan);
  371. sixthJoinObserver.AddActivePlan(activePlan);
  372. seventhJoinObserver.AddActivePlan(activePlan);
  373. return activePlan;
  374. }
  375. }
  376. internal class Plan<T1, T2, T3, T4, T5, T6, T7, T8, TResult> : Plan<TResult>
  377. {
  378. internal Pattern<T1, T2, T3, T4, T5, T6, T7, T8> Expression { get; }
  379. internal Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult> Selector { get; }
  380. internal Plan(Pattern<T1, T2, T3, T4, T5, T6, T7, T8> expression,
  381. Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult> selector)
  382. {
  383. Expression = expression;
  384. Selector = selector;
  385. }
  386. internal override ActivePlan Activate(Dictionary<object, IJoinObserver> externalSubscriptions,
  387. IObserver<TResult> observer, Action<ActivePlan> deactivate)
  388. {
  389. var onError = new Action<Exception>(observer.OnError);
  390. var firstJoinObserver = CreateObserver(externalSubscriptions, Expression.First, onError);
  391. var secondJoinObserver = CreateObserver(externalSubscriptions, Expression.Second, onError);
  392. var thirdJoinObserver = CreateObserver(externalSubscriptions, Expression.Third, onError);
  393. var fourthJoinObserver = CreateObserver(externalSubscriptions, Expression.Fourth, onError);
  394. var fifthJoinObserver = CreateObserver(externalSubscriptions, Expression.Fifth, onError);
  395. var sixthJoinObserver = CreateObserver(externalSubscriptions, Expression.Sixth, onError);
  396. var seventhJoinObserver = CreateObserver(externalSubscriptions, Expression.Seventh, onError);
  397. var eighthJoinObserver = CreateObserver(externalSubscriptions, Expression.Eighth, onError);
  398. var activePlan = default(ActivePlan<T1, T2, T3, T4, T5, T6, T7, T8>);
  399. activePlan = new ActivePlan<T1, T2, T3, T4, T5, T6, T7, T8>(firstJoinObserver, secondJoinObserver, thirdJoinObserver,
  400. fourthJoinObserver, fifthJoinObserver, sixthJoinObserver, seventhJoinObserver, eighthJoinObserver,
  401. (first, second, third, fourth, fifth, sixth, seventh, eighth) =>
  402. {
  403. TResult result;
  404. try
  405. {
  406. result = Selector(first, second, third, fourth, fifth, sixth, seventh, eighth);
  407. }
  408. catch (Exception exception)
  409. {
  410. observer.OnError(exception);
  411. return;
  412. }
  413. observer.OnNext(result);
  414. },
  415. () =>
  416. {
  417. firstJoinObserver.RemoveActivePlan(activePlan);
  418. secondJoinObserver.RemoveActivePlan(activePlan);
  419. thirdJoinObserver.RemoveActivePlan(activePlan);
  420. fourthJoinObserver.RemoveActivePlan(activePlan);
  421. fifthJoinObserver.RemoveActivePlan(activePlan);
  422. sixthJoinObserver.RemoveActivePlan(activePlan);
  423. seventhJoinObserver.RemoveActivePlan(activePlan);
  424. eighthJoinObserver.RemoveActivePlan(activePlan);
  425. deactivate(activePlan);
  426. });
  427. firstJoinObserver.AddActivePlan(activePlan);
  428. secondJoinObserver.AddActivePlan(activePlan);
  429. thirdJoinObserver.AddActivePlan(activePlan);
  430. fourthJoinObserver.AddActivePlan(activePlan);
  431. fifthJoinObserver.AddActivePlan(activePlan);
  432. sixthJoinObserver.AddActivePlan(activePlan);
  433. seventhJoinObserver.AddActivePlan(activePlan);
  434. eighthJoinObserver.AddActivePlan(activePlan);
  435. return activePlan;
  436. }
  437. }
  438. internal class Plan<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult> : Plan<TResult>
  439. {
  440. internal Pattern<T1, T2, T3, T4, T5, T6, T7, T8, T9> Expression { get; }
  441. internal Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult> Selector { get; }
  442. internal Plan(Pattern<T1, T2, T3, T4, T5, T6, T7, T8, T9> expression,
  443. Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult> selector)
  444. {
  445. Expression = expression;
  446. Selector = selector;
  447. }
  448. internal override ActivePlan Activate(Dictionary<object, IJoinObserver> externalSubscriptions,
  449. IObserver<TResult> observer, Action<ActivePlan> deactivate)
  450. {
  451. var onError = new Action<Exception>(observer.OnError);
  452. var firstJoinObserver = CreateObserver(externalSubscriptions, Expression.First, onError);
  453. var secondJoinObserver = CreateObserver(externalSubscriptions, Expression.Second, onError);
  454. var thirdJoinObserver = CreateObserver(externalSubscriptions, Expression.Third, onError);
  455. var fourthJoinObserver = CreateObserver(externalSubscriptions, Expression.Fourth, onError);
  456. var fifthJoinObserver = CreateObserver(externalSubscriptions, Expression.Fifth, onError);
  457. var sixthJoinObserver = CreateObserver(externalSubscriptions, Expression.Sixth, onError);
  458. var seventhJoinObserver = CreateObserver(externalSubscriptions, Expression.Seventh, onError);
  459. var eighthJoinObserver = CreateObserver(externalSubscriptions, Expression.Eighth, onError);
  460. var ninthJoinObserver = CreateObserver(externalSubscriptions, Expression.Ninth, onError);
  461. var activePlan = default(ActivePlan<T1, T2, T3, T4, T5, T6, T7, T8, T9>);
  462. activePlan = new ActivePlan<T1, T2, T3, T4, T5, T6, T7, T8, T9>(firstJoinObserver, secondJoinObserver, thirdJoinObserver,
  463. fourthJoinObserver, fifthJoinObserver, sixthJoinObserver, seventhJoinObserver, eighthJoinObserver, ninthJoinObserver,
  464. (first, second, third, fourth, fifth, sixth, seventh, eighth, ninth) =>
  465. {
  466. TResult result;
  467. try
  468. {
  469. result = Selector(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth);
  470. }
  471. catch (Exception exception)
  472. {
  473. observer.OnError(exception);
  474. return;
  475. }
  476. observer.OnNext(result);
  477. },
  478. () =>
  479. {
  480. firstJoinObserver.RemoveActivePlan(activePlan);
  481. secondJoinObserver.RemoveActivePlan(activePlan);
  482. thirdJoinObserver.RemoveActivePlan(activePlan);
  483. fourthJoinObserver.RemoveActivePlan(activePlan);
  484. fifthJoinObserver.RemoveActivePlan(activePlan);
  485. sixthJoinObserver.RemoveActivePlan(activePlan);
  486. seventhJoinObserver.RemoveActivePlan(activePlan);
  487. eighthJoinObserver.RemoveActivePlan(activePlan);
  488. ninthJoinObserver.RemoveActivePlan(activePlan);
  489. deactivate(activePlan);
  490. });
  491. firstJoinObserver.AddActivePlan(activePlan);
  492. secondJoinObserver.AddActivePlan(activePlan);
  493. thirdJoinObserver.AddActivePlan(activePlan);
  494. fourthJoinObserver.AddActivePlan(activePlan);
  495. fifthJoinObserver.AddActivePlan(activePlan);
  496. sixthJoinObserver.AddActivePlan(activePlan);
  497. seventhJoinObserver.AddActivePlan(activePlan);
  498. eighthJoinObserver.AddActivePlan(activePlan);
  499. ninthJoinObserver.AddActivePlan(activePlan);
  500. return activePlan;
  501. }
  502. }
  503. internal class Plan<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult> : Plan<TResult>
  504. {
  505. internal Pattern<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> Expression { get; }
  506. internal Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult> Selector { get; }
  507. internal Plan(Pattern<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> expression,
  508. Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult> selector)
  509. {
  510. Expression = expression;
  511. Selector = selector;
  512. }
  513. internal override ActivePlan Activate(Dictionary<object, IJoinObserver> externalSubscriptions,
  514. IObserver<TResult> observer, Action<ActivePlan> deactivate)
  515. {
  516. var onError = new Action<Exception>(observer.OnError);
  517. var firstJoinObserver = CreateObserver(externalSubscriptions, Expression.First, onError);
  518. var secondJoinObserver = CreateObserver(externalSubscriptions, Expression.Second, onError);
  519. var thirdJoinObserver = CreateObserver(externalSubscriptions, Expression.Third, onError);
  520. var fourthJoinObserver = CreateObserver(externalSubscriptions, Expression.Fourth, onError);
  521. var fifthJoinObserver = CreateObserver(externalSubscriptions, Expression.Fifth, onError);
  522. var sixthJoinObserver = CreateObserver(externalSubscriptions, Expression.Sixth, onError);
  523. var seventhJoinObserver = CreateObserver(externalSubscriptions, Expression.Seventh, onError);
  524. var eighthJoinObserver = CreateObserver(externalSubscriptions, Expression.Eighth, onError);
  525. var ninthJoinObserver = CreateObserver(externalSubscriptions, Expression.Ninth, onError);
  526. var tenthJoinObserver = CreateObserver(externalSubscriptions, Expression.Tenth, onError);
  527. var activePlan = default(ActivePlan<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>);
  528. activePlan = new ActivePlan<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(firstJoinObserver, secondJoinObserver, thirdJoinObserver,
  529. fourthJoinObserver, fifthJoinObserver, sixthJoinObserver, seventhJoinObserver, eighthJoinObserver, ninthJoinObserver, tenthJoinObserver,
  530. (first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth) =>
  531. {
  532. TResult result;
  533. try
  534. {
  535. result = Selector(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth);
  536. }
  537. catch (Exception exception)
  538. {
  539. observer.OnError(exception);
  540. return;
  541. }
  542. observer.OnNext(result);
  543. },
  544. () =>
  545. {
  546. firstJoinObserver.RemoveActivePlan(activePlan);
  547. secondJoinObserver.RemoveActivePlan(activePlan);
  548. thirdJoinObserver.RemoveActivePlan(activePlan);
  549. fourthJoinObserver.RemoveActivePlan(activePlan);
  550. fifthJoinObserver.RemoveActivePlan(activePlan);
  551. sixthJoinObserver.RemoveActivePlan(activePlan);
  552. seventhJoinObserver.RemoveActivePlan(activePlan);
  553. eighthJoinObserver.RemoveActivePlan(activePlan);
  554. ninthJoinObserver.RemoveActivePlan(activePlan);
  555. tenthJoinObserver.RemoveActivePlan(activePlan);
  556. deactivate(activePlan);
  557. });
  558. firstJoinObserver.AddActivePlan(activePlan);
  559. secondJoinObserver.AddActivePlan(activePlan);
  560. thirdJoinObserver.AddActivePlan(activePlan);
  561. fourthJoinObserver.AddActivePlan(activePlan);
  562. fifthJoinObserver.AddActivePlan(activePlan);
  563. sixthJoinObserver.AddActivePlan(activePlan);
  564. seventhJoinObserver.AddActivePlan(activePlan);
  565. eighthJoinObserver.AddActivePlan(activePlan);
  566. ninthJoinObserver.AddActivePlan(activePlan);
  567. tenthJoinObserver.AddActivePlan(activePlan);
  568. return activePlan;
  569. }
  570. }
  571. internal class Plan<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult> : Plan<TResult>
  572. {
  573. internal Pattern<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> Expression { get; }
  574. internal Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult> Selector { get; }
  575. internal Plan(Pattern<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> expression,
  576. Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult> selector)
  577. {
  578. Expression = expression;
  579. Selector = selector;
  580. }
  581. internal override ActivePlan Activate(Dictionary<object, IJoinObserver> externalSubscriptions,
  582. IObserver<TResult> observer, Action<ActivePlan> deactivate)
  583. {
  584. var onError = new Action<Exception>(observer.OnError);
  585. var firstJoinObserver = CreateObserver(externalSubscriptions, Expression.First, onError);
  586. var secondJoinObserver = CreateObserver(externalSubscriptions, Expression.Second, onError);
  587. var thirdJoinObserver = CreateObserver(externalSubscriptions, Expression.Third, onError);
  588. var fourthJoinObserver = CreateObserver(externalSubscriptions, Expression.Fourth, onError);
  589. var fifthJoinObserver = CreateObserver(externalSubscriptions, Expression.Fifth, onError);
  590. var sixthJoinObserver = CreateObserver(externalSubscriptions, Expression.Sixth, onError);
  591. var seventhJoinObserver = CreateObserver(externalSubscriptions, Expression.Seventh, onError);
  592. var eighthJoinObserver = CreateObserver(externalSubscriptions, Expression.Eighth, onError);
  593. var ninthJoinObserver = CreateObserver(externalSubscriptions, Expression.Ninth, onError);
  594. var tenthJoinObserver = CreateObserver(externalSubscriptions, Expression.Tenth, onError);
  595. var eleventhJoinObserver = CreateObserver(externalSubscriptions, Expression.Eleventh, onError);
  596. var activePlan = default(ActivePlan<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>);
  597. activePlan = new ActivePlan<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(firstJoinObserver, secondJoinObserver, thirdJoinObserver,
  598. fourthJoinObserver, fifthJoinObserver, sixthJoinObserver, seventhJoinObserver, eighthJoinObserver, ninthJoinObserver, tenthJoinObserver, eleventhJoinObserver,
  599. (first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh) =>
  600. {
  601. TResult result;
  602. try
  603. {
  604. result = Selector(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh);
  605. }
  606. catch (Exception exception)
  607. {
  608. observer.OnError(exception);
  609. return;
  610. }
  611. observer.OnNext(result);
  612. },
  613. () =>
  614. {
  615. firstJoinObserver.RemoveActivePlan(activePlan);
  616. secondJoinObserver.RemoveActivePlan(activePlan);
  617. thirdJoinObserver.RemoveActivePlan(activePlan);
  618. fourthJoinObserver.RemoveActivePlan(activePlan);
  619. fifthJoinObserver.RemoveActivePlan(activePlan);
  620. sixthJoinObserver.RemoveActivePlan(activePlan);
  621. seventhJoinObserver.RemoveActivePlan(activePlan);
  622. eighthJoinObserver.RemoveActivePlan(activePlan);
  623. ninthJoinObserver.RemoveActivePlan(activePlan);
  624. tenthJoinObserver.RemoveActivePlan(activePlan);
  625. eleventhJoinObserver.RemoveActivePlan(activePlan);
  626. deactivate(activePlan);
  627. });
  628. firstJoinObserver.AddActivePlan(activePlan);
  629. secondJoinObserver.AddActivePlan(activePlan);
  630. thirdJoinObserver.AddActivePlan(activePlan);
  631. fourthJoinObserver.AddActivePlan(activePlan);
  632. fifthJoinObserver.AddActivePlan(activePlan);
  633. sixthJoinObserver.AddActivePlan(activePlan);
  634. seventhJoinObserver.AddActivePlan(activePlan);
  635. eighthJoinObserver.AddActivePlan(activePlan);
  636. ninthJoinObserver.AddActivePlan(activePlan);
  637. tenthJoinObserver.AddActivePlan(activePlan);
  638. eleventhJoinObserver.AddActivePlan(activePlan);
  639. return activePlan;
  640. }
  641. }
  642. internal class Plan<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult> : Plan<TResult>
  643. {
  644. internal Pattern<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> Expression { get; }
  645. internal Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult> Selector { get; }
  646. internal Plan(Pattern<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> expression,
  647. Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult> selector)
  648. {
  649. Expression = expression;
  650. Selector = selector;
  651. }
  652. internal override ActivePlan Activate(Dictionary<object, IJoinObserver> externalSubscriptions,
  653. IObserver<TResult> observer, Action<ActivePlan> deactivate)
  654. {
  655. var onError = new Action<Exception>(observer.OnError);
  656. var firstJoinObserver = CreateObserver(externalSubscriptions, Expression.First, onError);
  657. var secondJoinObserver = CreateObserver(externalSubscriptions, Expression.Second, onError);
  658. var thirdJoinObserver = CreateObserver(externalSubscriptions, Expression.Third, onError);
  659. var fourthJoinObserver = CreateObserver(externalSubscriptions, Expression.Fourth, onError);
  660. var fifthJoinObserver = CreateObserver(externalSubscriptions, Expression.Fifth, onError);
  661. var sixthJoinObserver = CreateObserver(externalSubscriptions, Expression.Sixth, onError);
  662. var seventhJoinObserver = CreateObserver(externalSubscriptions, Expression.Seventh, onError);
  663. var eighthJoinObserver = CreateObserver(externalSubscriptions, Expression.Eighth, onError);
  664. var ninthJoinObserver = CreateObserver(externalSubscriptions, Expression.Ninth, onError);
  665. var tenthJoinObserver = CreateObserver(externalSubscriptions, Expression.Tenth, onError);
  666. var eleventhJoinObserver = CreateObserver(externalSubscriptions, Expression.Eleventh, onError);
  667. var twelfthJoinObserver = CreateObserver(externalSubscriptions, Expression.Twelfth, onError);
  668. var activePlan = default(ActivePlan<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>);
  669. activePlan = new ActivePlan<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(firstJoinObserver, secondJoinObserver, thirdJoinObserver,
  670. fourthJoinObserver, fifthJoinObserver, sixthJoinObserver, seventhJoinObserver, eighthJoinObserver, ninthJoinObserver, tenthJoinObserver, eleventhJoinObserver,
  671. twelfthJoinObserver,
  672. (first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth) =>
  673. {
  674. TResult result;
  675. try
  676. {
  677. result = Selector(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth);
  678. }
  679. catch (Exception exception)
  680. {
  681. observer.OnError(exception);
  682. return;
  683. }
  684. observer.OnNext(result);
  685. },
  686. () =>
  687. {
  688. firstJoinObserver.RemoveActivePlan(activePlan);
  689. secondJoinObserver.RemoveActivePlan(activePlan);
  690. thirdJoinObserver.RemoveActivePlan(activePlan);
  691. fourthJoinObserver.RemoveActivePlan(activePlan);
  692. fifthJoinObserver.RemoveActivePlan(activePlan);
  693. sixthJoinObserver.RemoveActivePlan(activePlan);
  694. seventhJoinObserver.RemoveActivePlan(activePlan);
  695. eighthJoinObserver.RemoveActivePlan(activePlan);
  696. ninthJoinObserver.RemoveActivePlan(activePlan);
  697. tenthJoinObserver.RemoveActivePlan(activePlan);
  698. eleventhJoinObserver.RemoveActivePlan(activePlan);
  699. twelfthJoinObserver.RemoveActivePlan(activePlan);
  700. deactivate(activePlan);
  701. });
  702. firstJoinObserver.AddActivePlan(activePlan);
  703. secondJoinObserver.AddActivePlan(activePlan);
  704. thirdJoinObserver.AddActivePlan(activePlan);
  705. fourthJoinObserver.AddActivePlan(activePlan);
  706. fifthJoinObserver.AddActivePlan(activePlan);
  707. sixthJoinObserver.AddActivePlan(activePlan);
  708. seventhJoinObserver.AddActivePlan(activePlan);
  709. eighthJoinObserver.AddActivePlan(activePlan);
  710. ninthJoinObserver.AddActivePlan(activePlan);
  711. tenthJoinObserver.AddActivePlan(activePlan);
  712. eleventhJoinObserver.AddActivePlan(activePlan);
  713. twelfthJoinObserver.AddActivePlan(activePlan);
  714. return activePlan;
  715. }
  716. }
  717. internal class Plan<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult> : Plan<TResult>
  718. {
  719. internal Pattern<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> Expression { get; }
  720. internal Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult> Selector { get; }
  721. internal Plan(Pattern<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> expression,
  722. Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult> selector)
  723. {
  724. Expression = expression;
  725. Selector = selector;
  726. }
  727. internal override ActivePlan Activate(Dictionary<object, IJoinObserver> externalSubscriptions,
  728. IObserver<TResult> observer, Action<ActivePlan> deactivate)
  729. {
  730. var onError = new Action<Exception>(observer.OnError);
  731. var firstJoinObserver = CreateObserver(externalSubscriptions, Expression.First, onError);
  732. var secondJoinObserver = CreateObserver(externalSubscriptions, Expression.Second, onError);
  733. var thirdJoinObserver = CreateObserver(externalSubscriptions, Expression.Third, onError);
  734. var fourthJoinObserver = CreateObserver(externalSubscriptions, Expression.Fourth, onError);
  735. var fifthJoinObserver = CreateObserver(externalSubscriptions, Expression.Fifth, onError);
  736. var sixthJoinObserver = CreateObserver(externalSubscriptions, Expression.Sixth, onError);
  737. var seventhJoinObserver = CreateObserver(externalSubscriptions, Expression.Seventh, onError);
  738. var eighthJoinObserver = CreateObserver(externalSubscriptions, Expression.Eighth, onError);
  739. var ninthJoinObserver = CreateObserver(externalSubscriptions, Expression.Ninth, onError);
  740. var tenthJoinObserver = CreateObserver(externalSubscriptions, Expression.Tenth, onError);
  741. var eleventhJoinObserver = CreateObserver(externalSubscriptions, Expression.Eleventh, onError);
  742. var twelfthJoinObserver = CreateObserver(externalSubscriptions, Expression.Twelfth, onError);
  743. var thirteenthJoinObserver = CreateObserver(externalSubscriptions, Expression.Thirteenth, onError);
  744. var activePlan = default(ActivePlan<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>);
  745. activePlan = new ActivePlan<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(firstJoinObserver, secondJoinObserver, thirdJoinObserver,
  746. fourthJoinObserver, fifthJoinObserver, sixthJoinObserver, seventhJoinObserver, eighthJoinObserver, ninthJoinObserver, tenthJoinObserver, eleventhJoinObserver,
  747. twelfthJoinObserver, thirteenthJoinObserver,
  748. (first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth, thirteenth) =>
  749. {
  750. TResult result;
  751. try
  752. {
  753. result = Selector(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth, thirteenth);
  754. }
  755. catch (Exception exception)
  756. {
  757. observer.OnError(exception);
  758. return;
  759. }
  760. observer.OnNext(result);
  761. },
  762. () =>
  763. {
  764. firstJoinObserver.RemoveActivePlan(activePlan);
  765. secondJoinObserver.RemoveActivePlan(activePlan);
  766. thirdJoinObserver.RemoveActivePlan(activePlan);
  767. fourthJoinObserver.RemoveActivePlan(activePlan);
  768. fifthJoinObserver.RemoveActivePlan(activePlan);
  769. sixthJoinObserver.RemoveActivePlan(activePlan);
  770. seventhJoinObserver.RemoveActivePlan(activePlan);
  771. eighthJoinObserver.RemoveActivePlan(activePlan);
  772. ninthJoinObserver.RemoveActivePlan(activePlan);
  773. tenthJoinObserver.RemoveActivePlan(activePlan);
  774. eleventhJoinObserver.RemoveActivePlan(activePlan);
  775. twelfthJoinObserver.RemoveActivePlan(activePlan);
  776. thirteenthJoinObserver.RemoveActivePlan(activePlan);
  777. deactivate(activePlan);
  778. });
  779. firstJoinObserver.AddActivePlan(activePlan);
  780. secondJoinObserver.AddActivePlan(activePlan);
  781. thirdJoinObserver.AddActivePlan(activePlan);
  782. fourthJoinObserver.AddActivePlan(activePlan);
  783. fifthJoinObserver.AddActivePlan(activePlan);
  784. sixthJoinObserver.AddActivePlan(activePlan);
  785. seventhJoinObserver.AddActivePlan(activePlan);
  786. eighthJoinObserver.AddActivePlan(activePlan);
  787. ninthJoinObserver.AddActivePlan(activePlan);
  788. tenthJoinObserver.AddActivePlan(activePlan);
  789. eleventhJoinObserver.AddActivePlan(activePlan);
  790. twelfthJoinObserver.AddActivePlan(activePlan);
  791. thirteenthJoinObserver.AddActivePlan(activePlan);
  792. return activePlan;
  793. }
  794. }
  795. internal class Plan<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult> : Plan<TResult>
  796. {
  797. internal Pattern<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> Expression { get; }
  798. internal Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult> Selector { get; }
  799. internal Plan(Pattern<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> expression,
  800. Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult> selector)
  801. {
  802. Expression = expression;
  803. Selector = selector;
  804. }
  805. internal override ActivePlan Activate(Dictionary<object, IJoinObserver> externalSubscriptions,
  806. IObserver<TResult> observer, Action<ActivePlan> deactivate)
  807. {
  808. var onError = new Action<Exception>(observer.OnError);
  809. var firstJoinObserver = CreateObserver(externalSubscriptions, Expression.First, onError);
  810. var secondJoinObserver = CreateObserver(externalSubscriptions, Expression.Second, onError);
  811. var thirdJoinObserver = CreateObserver(externalSubscriptions, Expression.Third, onError);
  812. var fourthJoinObserver = CreateObserver(externalSubscriptions, Expression.Fourth, onError);
  813. var fifthJoinObserver = CreateObserver(externalSubscriptions, Expression.Fifth, onError);
  814. var sixthJoinObserver = CreateObserver(externalSubscriptions, Expression.Sixth, onError);
  815. var seventhJoinObserver = CreateObserver(externalSubscriptions, Expression.Seventh, onError);
  816. var eighthJoinObserver = CreateObserver(externalSubscriptions, Expression.Eighth, onError);
  817. var ninthJoinObserver = CreateObserver(externalSubscriptions, Expression.Ninth, onError);
  818. var tenthJoinObserver = CreateObserver(externalSubscriptions, Expression.Tenth, onError);
  819. var eleventhJoinObserver = CreateObserver(externalSubscriptions, Expression.Eleventh, onError);
  820. var twelfthJoinObserver = CreateObserver(externalSubscriptions, Expression.Twelfth, onError);
  821. var thirteenthJoinObserver = CreateObserver(externalSubscriptions, Expression.Thirteenth, onError);
  822. var fourteenthJoinObserver = CreateObserver(externalSubscriptions, Expression.Fourteenth, onError);
  823. var activePlan = default(ActivePlan<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>);
  824. activePlan = new ActivePlan<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(
  825. firstJoinObserver, secondJoinObserver, thirdJoinObserver,
  826. fourthJoinObserver, fifthJoinObserver, sixthJoinObserver,
  827. seventhJoinObserver, eighthJoinObserver, ninthJoinObserver,
  828. tenthJoinObserver, eleventhJoinObserver,
  829. twelfthJoinObserver, thirteenthJoinObserver,
  830. fourteenthJoinObserver,
  831. (first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth, thirteenth, fourteenth) =>
  832. {
  833. TResult result;
  834. try
  835. {
  836. result = Selector(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth, thirteenth, fourteenth);
  837. }
  838. catch (Exception exception)
  839. {
  840. observer.OnError(exception);
  841. return;
  842. }
  843. observer.OnNext(result);
  844. },
  845. () =>
  846. {
  847. firstJoinObserver.RemoveActivePlan(activePlan);
  848. secondJoinObserver.RemoveActivePlan(activePlan);
  849. thirdJoinObserver.RemoveActivePlan(activePlan);
  850. fourthJoinObserver.RemoveActivePlan(activePlan);
  851. fifthJoinObserver.RemoveActivePlan(activePlan);
  852. sixthJoinObserver.RemoveActivePlan(activePlan);
  853. seventhJoinObserver.RemoveActivePlan(activePlan);
  854. eighthJoinObserver.RemoveActivePlan(activePlan);
  855. ninthJoinObserver.RemoveActivePlan(activePlan);
  856. tenthJoinObserver.RemoveActivePlan(activePlan);
  857. eleventhJoinObserver.RemoveActivePlan(activePlan);
  858. twelfthJoinObserver.RemoveActivePlan(activePlan);
  859. thirteenthJoinObserver.RemoveActivePlan(activePlan);
  860. fourteenthJoinObserver.RemoveActivePlan(activePlan);
  861. deactivate(activePlan);
  862. });
  863. firstJoinObserver.AddActivePlan(activePlan);
  864. secondJoinObserver.AddActivePlan(activePlan);
  865. thirdJoinObserver.AddActivePlan(activePlan);
  866. fourthJoinObserver.AddActivePlan(activePlan);
  867. fifthJoinObserver.AddActivePlan(activePlan);
  868. sixthJoinObserver.AddActivePlan(activePlan);
  869. seventhJoinObserver.AddActivePlan(activePlan);
  870. eighthJoinObserver.AddActivePlan(activePlan);
  871. ninthJoinObserver.AddActivePlan(activePlan);
  872. tenthJoinObserver.AddActivePlan(activePlan);
  873. eleventhJoinObserver.AddActivePlan(activePlan);
  874. twelfthJoinObserver.AddActivePlan(activePlan);
  875. thirteenthJoinObserver.AddActivePlan(activePlan);
  876. fourteenthJoinObserver.AddActivePlan(activePlan);
  877. return activePlan;
  878. }
  879. }
  880. internal class Plan<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult> : Plan<TResult>
  881. {
  882. internal Pattern<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> Expression { get; }
  883. internal Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult> Selector { get; }
  884. internal Plan(Pattern<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> expression,
  885. Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult> selector)
  886. {
  887. Expression = expression;
  888. Selector = selector;
  889. }
  890. internal override ActivePlan Activate(Dictionary<object, IJoinObserver> externalSubscriptions,
  891. IObserver<TResult> observer, Action<ActivePlan> deactivate)
  892. {
  893. var onError = new Action<Exception>(observer.OnError);
  894. var firstJoinObserver = CreateObserver(externalSubscriptions, Expression.First, onError);
  895. var secondJoinObserver = CreateObserver(externalSubscriptions, Expression.Second, onError);
  896. var thirdJoinObserver = CreateObserver(externalSubscriptions, Expression.Third, onError);
  897. var fourthJoinObserver = CreateObserver(externalSubscriptions, Expression.Fourth, onError);
  898. var fifthJoinObserver = CreateObserver(externalSubscriptions, Expression.Fifth, onError);
  899. var sixthJoinObserver = CreateObserver(externalSubscriptions, Expression.Sixth, onError);
  900. var seventhJoinObserver = CreateObserver(externalSubscriptions, Expression.Seventh, onError);
  901. var eighthJoinObserver = CreateObserver(externalSubscriptions, Expression.Eighth, onError);
  902. var ninthJoinObserver = CreateObserver(externalSubscriptions, Expression.Ninth, onError);
  903. var tenthJoinObserver = CreateObserver(externalSubscriptions, Expression.Tenth, onError);
  904. var eleventhJoinObserver = CreateObserver(externalSubscriptions, Expression.Eleventh, onError);
  905. var twelfthJoinObserver = CreateObserver(externalSubscriptions, Expression.Twelfth, onError);
  906. var thirteenthJoinObserver = CreateObserver(externalSubscriptions, Expression.Thirteenth, onError);
  907. var fourteenthJoinObserver = CreateObserver(externalSubscriptions, Expression.Fourteenth, onError);
  908. var fifteenthJoinObserver = CreateObserver(externalSubscriptions, Expression.Fifteenth, onError);
  909. var activePlan = default(ActivePlan<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>);
  910. activePlan = new ActivePlan<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(
  911. firstJoinObserver, secondJoinObserver, thirdJoinObserver,
  912. fourthJoinObserver, fifthJoinObserver, sixthJoinObserver,
  913. seventhJoinObserver, eighthJoinObserver, ninthJoinObserver,
  914. tenthJoinObserver, eleventhJoinObserver,
  915. twelfthJoinObserver, thirteenthJoinObserver,
  916. fourteenthJoinObserver, fifteenthJoinObserver,
  917. (first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth, thirteenth, fourteenth, fifteenth) =>
  918. {
  919. TResult result;
  920. try
  921. {
  922. result = Selector(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth, thirteenth, fourteenth, fifteenth);
  923. }
  924. catch (Exception exception)
  925. {
  926. observer.OnError(exception);
  927. return;
  928. }
  929. observer.OnNext(result);
  930. },
  931. () =>
  932. {
  933. firstJoinObserver.RemoveActivePlan(activePlan);
  934. secondJoinObserver.RemoveActivePlan(activePlan);
  935. thirdJoinObserver.RemoveActivePlan(activePlan);
  936. fourthJoinObserver.RemoveActivePlan(activePlan);
  937. fifthJoinObserver.RemoveActivePlan(activePlan);
  938. sixthJoinObserver.RemoveActivePlan(activePlan);
  939. seventhJoinObserver.RemoveActivePlan(activePlan);
  940. eighthJoinObserver.RemoveActivePlan(activePlan);
  941. ninthJoinObserver.RemoveActivePlan(activePlan);
  942. tenthJoinObserver.RemoveActivePlan(activePlan);
  943. eleventhJoinObserver.RemoveActivePlan(activePlan);
  944. twelfthJoinObserver.RemoveActivePlan(activePlan);
  945. thirteenthJoinObserver.RemoveActivePlan(activePlan);
  946. fourteenthJoinObserver.RemoveActivePlan(activePlan);
  947. fifteenthJoinObserver.RemoveActivePlan(activePlan);
  948. deactivate(activePlan);
  949. });
  950. firstJoinObserver.AddActivePlan(activePlan);
  951. secondJoinObserver.AddActivePlan(activePlan);
  952. thirdJoinObserver.AddActivePlan(activePlan);
  953. fourthJoinObserver.AddActivePlan(activePlan);
  954. fifthJoinObserver.AddActivePlan(activePlan);
  955. sixthJoinObserver.AddActivePlan(activePlan);
  956. seventhJoinObserver.AddActivePlan(activePlan);
  957. eighthJoinObserver.AddActivePlan(activePlan);
  958. ninthJoinObserver.AddActivePlan(activePlan);
  959. tenthJoinObserver.AddActivePlan(activePlan);
  960. eleventhJoinObserver.AddActivePlan(activePlan);
  961. twelfthJoinObserver.AddActivePlan(activePlan);
  962. thirteenthJoinObserver.AddActivePlan(activePlan);
  963. fourteenthJoinObserver.AddActivePlan(activePlan);
  964. fifteenthJoinObserver.AddActivePlan(activePlan);
  965. return activePlan;
  966. }
  967. }
  968. internal class Plan<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TResult> : Plan<TResult>
  969. {
  970. internal Pattern<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> Expression { get; }
  971. internal Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TResult> Selector { get; }
  972. internal Plan(Pattern<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> expression,
  973. Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TResult> selector)
  974. {
  975. Expression = expression;
  976. Selector = selector;
  977. }
  978. internal override ActivePlan Activate(Dictionary<object, IJoinObserver> externalSubscriptions,
  979. IObserver<TResult> observer, Action<ActivePlan> deactivate)
  980. {
  981. var onError = new Action<Exception>(observer.OnError);
  982. var firstJoinObserver = CreateObserver(externalSubscriptions, Expression.First, onError);
  983. var secondJoinObserver = CreateObserver(externalSubscriptions, Expression.Second, onError);
  984. var thirdJoinObserver = CreateObserver(externalSubscriptions, Expression.Third, onError);
  985. var fourthJoinObserver = CreateObserver(externalSubscriptions, Expression.Fourth, onError);
  986. var fifthJoinObserver = CreateObserver(externalSubscriptions, Expression.Fifth, onError);
  987. var sixthJoinObserver = CreateObserver(externalSubscriptions, Expression.Sixth, onError);
  988. var seventhJoinObserver = CreateObserver(externalSubscriptions, Expression.Seventh, onError);
  989. var eighthJoinObserver = CreateObserver(externalSubscriptions, Expression.Eighth, onError);
  990. var ninthJoinObserver = CreateObserver(externalSubscriptions, Expression.Ninth, onError);
  991. var tenthJoinObserver = CreateObserver(externalSubscriptions, Expression.Tenth, onError);
  992. var eleventhJoinObserver = CreateObserver(externalSubscriptions, Expression.Eleventh, onError);
  993. var twelfthJoinObserver = CreateObserver(externalSubscriptions, Expression.Twelfth, onError);
  994. var thirteenthJoinObserver = CreateObserver(externalSubscriptions, Expression.Thirteenth, onError);
  995. var fourteenthJoinObserver = CreateObserver(externalSubscriptions, Expression.Fourteenth, onError);
  996. var fifteenthJoinObserver = CreateObserver(externalSubscriptions, Expression.Fifteenth, onError);
  997. var sixteenthJoinObserver = CreateObserver(externalSubscriptions, Expression.Sixteenth, onError);
  998. var activePlan = default(ActivePlan<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>);
  999. activePlan = new ActivePlan<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(
  1000. firstJoinObserver, secondJoinObserver, thirdJoinObserver,
  1001. fourthJoinObserver, fifthJoinObserver, sixthJoinObserver,
  1002. seventhJoinObserver, eighthJoinObserver, ninthJoinObserver,
  1003. tenthJoinObserver, eleventhJoinObserver,
  1004. twelfthJoinObserver, thirteenthJoinObserver,
  1005. fourteenthJoinObserver, fifteenthJoinObserver,
  1006. sixteenthJoinObserver,
  1007. (first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth, thirteenth, fourteenth, fifteenth, sixteenth) =>
  1008. {
  1009. TResult result;
  1010. try
  1011. {
  1012. result = Selector(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth, thirteenth, fourteenth, fifteenth, sixteenth);
  1013. }
  1014. catch (Exception exception)
  1015. {
  1016. observer.OnError(exception);
  1017. return;
  1018. }
  1019. observer.OnNext(result);
  1020. },
  1021. () =>
  1022. {
  1023. firstJoinObserver.RemoveActivePlan(activePlan);
  1024. secondJoinObserver.RemoveActivePlan(activePlan);
  1025. thirdJoinObserver.RemoveActivePlan(activePlan);
  1026. fourthJoinObserver.RemoveActivePlan(activePlan);
  1027. fifthJoinObserver.RemoveActivePlan(activePlan);
  1028. sixthJoinObserver.RemoveActivePlan(activePlan);
  1029. seventhJoinObserver.RemoveActivePlan(activePlan);
  1030. eighthJoinObserver.RemoveActivePlan(activePlan);
  1031. ninthJoinObserver.RemoveActivePlan(activePlan);
  1032. tenthJoinObserver.RemoveActivePlan(activePlan);
  1033. eleventhJoinObserver.RemoveActivePlan(activePlan);
  1034. twelfthJoinObserver.RemoveActivePlan(activePlan);
  1035. thirteenthJoinObserver.RemoveActivePlan(activePlan);
  1036. fourteenthJoinObserver.RemoveActivePlan(activePlan);
  1037. fifteenthJoinObserver.RemoveActivePlan(activePlan);
  1038. sixteenthJoinObserver.RemoveActivePlan(activePlan);
  1039. deactivate(activePlan);
  1040. });
  1041. firstJoinObserver.AddActivePlan(activePlan);
  1042. secondJoinObserver.AddActivePlan(activePlan);
  1043. thirdJoinObserver.AddActivePlan(activePlan);
  1044. fourthJoinObserver.AddActivePlan(activePlan);
  1045. fifthJoinObserver.AddActivePlan(activePlan);
  1046. sixthJoinObserver.AddActivePlan(activePlan);
  1047. seventhJoinObserver.AddActivePlan(activePlan);
  1048. eighthJoinObserver.AddActivePlan(activePlan);
  1049. ninthJoinObserver.AddActivePlan(activePlan);
  1050. tenthJoinObserver.AddActivePlan(activePlan);
  1051. eleventhJoinObserver.AddActivePlan(activePlan);
  1052. twelfthJoinObserver.AddActivePlan(activePlan);
  1053. thirteenthJoinObserver.AddActivePlan(activePlan);
  1054. fourteenthJoinObserver.AddActivePlan(activePlan);
  1055. fifteenthJoinObserver.AddActivePlan(activePlan);
  1056. sixteenthJoinObserver.AddActivePlan(activePlan);
  1057. return activePlan;
  1058. }
  1059. }
  1060. }