BVB Source Codes

SuperSocket v1.6.6 Show DynamicCommand.cs Source code

Return Download SuperSocket v1.6.6: download DynamicCommand.cs Source code - Download SuperSocket v1.6.6 Source code - Type:.cs
  1. 锘縰sing System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.Scripting;
  6. using Microsoft.Scripting.Hosting;
  7. using SuperSocket.SocketBase;
  8. using SuperSocket.SocketBase.Command;
  9. using SuperSocket.SocketBase.Protocol;
  10. using SuperSocket.SocketBase.Metadata;
  11.  
  12. namespace SuperSocket.Dlr
  13. {
  14.     class DynamicCommand<TAppSession, TRequestInfo> : ICommand<TAppSession, TRequestInfo>, ICommandFilterProvider
  15.         where TAppSession : IAppSession, IAppSession<TAppSession, TRequestInfo>, new()
  16.         where TRequestInfo : IRequestInfo
  17.     {
  18.         private Action<TAppSession, TRequestInfo> m_DynamicExecuteCommand;
  19.  
  20.         private IEnumerable<CommandFilterAttribute> m_Filters;
  21.  
  22.         public DynamicCommand(ScriptRuntime scriptRuntime, IScriptSource source)
  23.         {
  24.             Source = source;
  25.  
  26.             Name = source.Name;
  27.  
  28.             var scriptEngine = scriptRuntime.GetEngineByFileExtension(source.LanguageExtension);
  29.             var scriptScope = scriptEngine.CreateScope();
  30.  
  31.             var scriptSource = scriptEngine.CreateScriptSourceFromString(source.GetScriptCode(), SourceCodeKind.File);
  32.             var compiledCode = scriptSource.Compile();
  33.             compiledCode.Execute(scriptScope);
  34.  
  35.             Action<TAppSession, TRequestInfo> dynamicMethod;
  36.             if (!scriptScope.TryGetVariable<Action<TAppSession, TRequestInfo>>("execute", out dynamicMethod))
  37.                 throw new Exception("Failed to find a command execution method in source: " + source.Tag);
  38.  
  39.             Func<IEnumerable<CommandFilterAttribute>> filtersAction;
  40.  
  41.             if (scriptScope.TryGetVariable<Func<IEnumerable<CommandFilterAttribute>>>("getFilters", out filtersAction))
  42.                 m_Filters = filtersAction();
  43.  
  44.             CompiledTime = DateTime.Now;
  45.  
  46.             m_DynamicExecuteCommand = dynamicMethod;
  47.         }
  48.  
  49.         #region ICommand<TAppSession,TRequestInfo> Members
  50.  
  51.         public virtual void ExecuteCommand(TAppSession session, TRequestInfo requestInfo)
  52.         {
  53.             m_DynamicExecuteCommand(session, requestInfo);
  54.         }
  55.  
  56.         #endregion
  57.  
  58.         public IScriptSource Source { get; private set; }
  59.  
  60.         public DateTime CompiledTime { get; private set; }
  61.  
  62.         #region ICommand Members
  63.  
  64.         public string Name { get; private set; }
  65.  
  66.         #endregion
  67.  
  68.         public override string ToString()
  69.         {
  70.             return Source.Tag;
  71.         }
  72.  
  73.         public IEnumerable<CommandFilterAttribute> GetFilters()
  74.         {
  75.             return m_Filters;
  76.         }
  77.     }
  78. }
  79.  
downloadDynamicCommand.cs Source code - Download SuperSocket v1.6.6 Source code
Related Source Codes/Software:
Students' basic information input program v2.0 - 1, the program is based on. net4.0 framework and d... 2016-08-19
Student information input system v2.0 - 1, the program is based on. net4.0 framework and d... 2016-08-19
Baidu handwriting input source v1.0 - Baidu handwriting input method source code, no nee... 2016-08-19
Rui bao tong v1.0 JAVA version of B2B e-commerce system - Rainbow B2B system developed using the popular JAV... 2016-08-19
HTML + javascript lottery system v2.1.1 HTA - Technology QQ:838341952 HTML+JS lottery system sta... 2016-08-19
Cloud on the CMS (SyCms) v1.95 - Add menus and blocks the system style functionalit... 2016-08-19
1.0 housing, rental housing sale platform - Rent housing rent out platform is a very typical r... 2016-08-19
Deng Xi v2.4 website help system - Deng Xi website help system is a very useful help ... 2016-08-19
Address book v1.0 FaLiang three layer - This Demo is a three layer address book source cod... 2016-08-19
Ray speed v7.0 wage query system - To modify the software to conduct a comprehensive ... 2016-08-19
MTStatusBarOverlay - A custom iOS status bar overlay seen in Apps like ... 2017-05-12
blueprint - Reverse engineer server configuration ... 2017-05-12
PullToRefresh - A simple iPhone TableViewController for adding the... 2017-05-12
mrjob - Run MapReduce jobs on Hadoop or Amazon Web Service... 2017-05-11
wax - Wax is now being maintained by alibaba ... 2017-05-11
ledisdb - a high performance NoSQL powered by Go ... 2017-05-11
d3-cloud - Create word clouds in JavaScript. ... 2017-05-11
react-makes-you-sad - Here's a flowchart to make you happy again! 2017-05-11
flat-surface-shader - Flat Surface Shader for rendering lit triangles to... 2017-05-11
flat-surface-shader - Flat Surface Shader for rendering lit triangles to... 2017-05-11

 Back to top