public override ExpressionResult Evaluate(IThreadContext context)
        {
            switch (this.Type)
            {
            case Constant.PI:
                return(new ExpressionResult {
                    NumberValue = Math.PI
                });

            case Constant.G:
                // return new ExpressionResult { NumberValue = 6.67408E-11 }; ;
                // The Andrew screws with physics constant
                return(new ExpressionResult {
                    NumberValue = 6.67384E-11
                });;

            case Constant.E:
                return(new ExpressionResult {
                    NumberValue = Math.E
                });

            case Constant.C:
                return(new ExpressionResult {
                    NumberValue = 299792458
                });

            default:
                Debug.Log($"Unrecognized numeric constant '{this._type}'");
                return(new ExpressionResult {
                    NumberValue = 0
                });
            }
        }
示例#2
0
        public override ExpressionResult Evaluate(IThreadContext context)
        {
            var string1 = this.GetExpression(0).Evaluate(context).TextValue;
            var string2 = this.GetExpression(1).Evaluate(context).TextValue;

            return(new ExpressionResult(string1.Split(string2.ToCharArray()).ToList()));
        }
示例#3
0
 private static void DumpRegisters(IThreadContext context, Logger output)
 {
     foreach (var register in context.GetTopLevelRegisters())
     {
         DumpRegister(register, output);
     }
 }
        public static ServiceCollection AddTextile(this ServiceCollection services, Action <ThreadClientOptions> configure)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            services.AddOptions();
            services.AddThreadContext();

            services.TryAddSingleton <IThreadClientFactory, ThreadClientFactory>();

            services.TryAddScoped <IThreadClient, ThreadClient>();

            services.TryAddSingleton <IPostConfigureOptions <ThreadContextOptions>, ThreadContextPostConfigureOptions>();

            services.AddAutoMapper(typeof(ThreadProfile));

            services.AddGrpcClient <API.APIClient>((serviceProvider, options) =>
            {
                IThreadContext context = serviceProvider.GetRequiredService <IThreadContext>();
                options.Address        = new Uri(context.Host);
            });

            services.Configure(configure);


            return(services);
        }
        /// <summary>
        /// Initializes this factory.
        /// </summary>
        /// <param name="factoryConfig">The configuration of this factory.</param>
        /// <param name="proxyConfig">An optional proxy configuration.</param>
        /// <param name="threadContext">For WPF applications, an instance of WpfThreadContext should be passed here.
        /// For console applications or Windows services an instance of SimpleThreadContext should be used instead.</param>
        protected void Initialize(IWcfClientFactoryConfig factoryConfig, IProxyConfig proxyConfig, IThreadContext threadContext)
        {
            _factoryConfig = factoryConfig;
            _proxyConfig   = proxyConfig;
            _threadContext = threadContext;

            VersionService = new VersionServiceManager(proxyConfig, factoryConfig.Host, factoryConfig.Port);
        }
示例#6
0
 /// <summary>
 /// Sets the optional synchronization context.
 /// Because most TWAIN-related things are happening on a different thread,
 /// this allows events to be raised on the thread associated with this context and
 /// may be useful if you want to handle them in the UI thread.
 /// </summary>
 /// <param name="context">Usually you want to use <see cref="SynchronizationContext.Current"/> while on the UI thread.</param>
 public void SetSynchronizationContext(SynchronizationContext context)
 {
     if (context == null)
     {
         _externalContext = null;
     }
     else
     {
         _externalContext = new UIThreadContext(context);
     }
 }
        public override ProgramInstruction Execute(IThreadContext context)
        {
            var stackFrame = context.PopStackFrame();

            while (context.CallStackSize > 0 && (stackFrame?.ReturnInstruction == null || !stackFrame.ReturnInstruction.StopBreakPropagation))
            {
                stackFrame = context.PopStackFrame();
            }

            return(stackFrame?.ReturnInstruction);
        }
示例#8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DispatcherHub" /> class.
        /// </summary>
        /// <param name="threadContext">The thread context.</param>
        /// <param name="listeners">The listeners.</param>
        /// <param name="eventDelayer">The event delayer.</param>
        /// <param name="work">The work.</param>
        public DispatcherHub(
            IThreadContext threadContext,
            IEnumerable <IListener> listeners,
            IDelayer <EventDispatcherData> eventDelayer,
            IUnitOfWork work)
        {
            Check.NotNull(() => work);
            this.syncListeners = Check.NotNull(() => listeners);

            // breaking the circular reference here.
            work.DispatcherHub = this;
            this.eventDelayer  = Check.NotNull(() => eventDelayer);
            this.threadContext = Check.NotNull(() => threadContext);
        }
        public override ExpressionResult Evaluate(IThreadContext context)
        {
            var    value = this.GetExpression(0).Evaluate(context).NumberValue;
            Double result;

            switch (this._opType)
            {
            case UnaryMathExpressionType.Exponential:
                result = Math.Exp(value);
                break;

            case UnaryMathExpressionType.HyperbolicSine:
                result = Math.Sinh(value);
                break;

            case UnaryMathExpressionType.HyperbolicCosine:
                result = Math.Cosh(value);
                break;

            case UnaryMathExpressionType.HyperbolicTangent:
                result = Math.Tanh(value);
                break;

            case UnaryMathExpressionType.HyperbolicArcSine:
                result = Math.Log(value + Math.Sqrt(Math.Pow(value, 2) + 1));
                break;

            case UnaryMathExpressionType.HyperbolicArcCosine:
                result = Math.Log(value + Math.Sqrt(Math.Pow(value, 2) - 1));
                break;

            case UnaryMathExpressionType.HyperbolicArcTangent:
                result = Math.Log((1 + value) / (1 - value)) / 2;
                break;

            default:
                Debug.LogWarning(
                    $"Unrecognized unary math operator: {this._op}"
                    );
                result = 0;
                break;
            }

            return(new ExpressionResult {
                NumberValue = result
            });
        }
示例#10
0
        public bool ExecuteContext(IThreadContext context)
        {
            bool successfulInvoke = false;

            lock (Lock)
            {
                successfulInvoke = context != null && _state == ThreadState.Suspended;
                if (successfulInvoke)
                {
                    Context = context;
                    _state  = ThreadState.Running;
                    ResumeEvent.Set();
                }
            }

            return(successfulInvoke);
        }
        public override ExpressionResult Evaluate(IThreadContext context)
        {
            //Debug.Log($"cr= {context.Craft.CraftScript.ActiveCommandPod.CurrentStage}");
            switch (_infoType)
            {
            case (StagingInformationType.Current):
                return(new ExpressionResult {
                    NumberValue = context.Craft.CraftScript.ActiveCommandPod.CurrentStage     /// from 0
                });

            case (StagingInformationType.Remain):
                return(new ExpressionResult {
                    NumberValue = context.Craft.CraftScript.ActiveCommandPod.NumStages
                });

            case (StagingInformationType.Parts):
                List <string> partlist      = new List <string>();
                int           selectedStage = (int)GetExpression(0).Evaluate(context).NumberValue;
                //Debug.Log($"selected stage= {selectedStage}");
                string partIdString;
                foreach (PartData part in context.Craft.CraftScript.Data.Assembly.Parts)
                {
                    //Debug.Log(part.ActivationStage);
                    if (part.ActivationStage == selectedStage && part.Config.SupportsActivation)
                    {
                        partIdString = (Convert.ToString(part.Id)).Trim();
                        Debug.Log($"match {selectedStage} {partIdString}");
                        partlist.Add(partIdString);
                    }
                    else if (part.ActivationStage == 0 && selectedStage == -1)
                    {
                        partIdString = (Convert.ToString(part.Id)).Trim();
                        partlist.Add(partIdString);
                    }
                }

                //}
                return(new ExpressionResult(partlist));

            default:
                return(new ExpressionResult {
                    NumberValue = -1
                });
            }
        }
示例#12
0
        /// <summary>
        /// Constructs a new <see cref="TwainSession"/>.
        /// </summary>
        /// <param name="config"></param>
        /// <exception cref="ArgumentNullException"></exception>
        public TwainSession(TwainConfig config)
        {
            Config = config ?? throw new ArgumentNullException(nameof(config));
            SetSynchronizationContext(SynchronizationContext.Current);
            switch (config.Platform)
            {
            case PlatformID.MacOSX:
            case PlatformID.Unix:
                _internalContext = new DispatcherLoop(this);
                break;

            default:
                _internalContext    = new WinMsgLoop(this);
                _callback32Delegate = new Callback32(Handle32BitCallback);
                break;
            }
            //CapReader = new CapReader(this);
            CapWriter = new CapWriter(config);
        }
示例#13
0
        public override ExpressionResult Evaluate(IThreadContext context)
        {
            var        selectedNodeExpression = this.GetExpression(0).Evaluate(context);
            IOrbitNode node;

            if (selectedNodeExpression.ExpressionType == ExpressionType.Number)
            {
                var craftId = (Int32)selectedNodeExpression.NumberValue;
                node = craftId >= 0 ? context.Craft.GetCraftNode(craftId) : context.Craft.CraftScript.CraftNode;
            }
            else
            {
                var nodeName = selectedNodeExpression.TextValue;
                if (nodeName != String.Empty)
                {
                    node = context.Craft.GetPlanet(nodeName) ??
                           (IOrbitNode)context.Craft.GetCraftNodeByName(nodeName);

                    if (node == null && Int32.TryParse(selectedNodeExpression.TextValue, out var craftId))
                    {
                        node = craftId >= 0 ? context.Craft.GetCraftNode(craftId) : context.Craft.CraftScript.CraftNode;
                    }
                }
                else
                {
                    node = context.Craft.CraftScript.CraftNode;
                }
            }

            if (node != null)
            {
                return(GetOrbitNodeProperty(node));
            }
            else
            {
                Debug.Log($"Craft or planet not found: {selectedNodeExpression.TextValue}");
                return(new ExpressionResult {
                    NumberValue = 0
                });
            }
        }
示例#14
0
        public void ExecuteContext(IThreadContext context)
        {
            bool successfulInvoke = false;

            while (successfulInvoke == false)
            {
                foreach (ThreadContainer thread in ThreadPool)
                {
                    successfulInvoke = thread.ExecuteContext(context);
                    if (successfulInvoke)
                    {
                        break;
                    }
                }

                if (!successfulInvoke)
                {
                    Thread.Sleep(250);
                }
            }
        }
示例#15
0
        public override ExpressionResult Evaluate(IThreadContext context)
        {
            switch (this._craftType)
            {
            case CraftType.Current:
                Debug.Log($"Returning current craft id: {context.Craft.CraftScript.CraftNode.NodeId}");
                return(new ExpressionResult {
                    NumberValue = context.Craft.CraftScript.CraftNode.NodeId
                });

            case CraftType.Target:
                if (context.Craft.Data.NavSphereTarget is CraftNode targetCraft)
                {
                    Debug.Log($"Returning target craft id: {targetCraft.NodeId}");
                    return(new ExpressionResult {
                        NumberValue = targetCraft.NodeId
                    });
                }

                break;

            case CraftType.Active when Game.InFlightScene:
                Debug.Log($"Returning active craft id: {Game.Instance.FlightScene.CraftNode.NodeId}");
                return(new ExpressionResult {
                    NumberValue = Game.Instance.FlightScene.CraftNode.NodeId
                });

            case CraftType.Active when !Game.InFlightScene:
                Debug.Log($"Unable to get Active Craft ID when not in flight scene.");
                break;

            default:
                Debug.Log($"Unrecognized craft type: {this._type}");
                break;
            }

            return(NoTargetResult);
        }
示例#16
0
        /// <summary>
        /// Clones the context from another thread
        /// </summary>
        /// <param name="context">The other thread context</param>
        public void CloneFrom(IThreadContext context)
        {
            X86ThreadContext source = (X86ThreadContext)context;

            // Stack
            createStacks();

            Memory.Memcpy(m_kernelStackStart, source.m_kernelStackStart, KernelStackSize + UserStackSize);

            int diffStack       = (int)source.m_stack - (int)source.m_stackStart;
            int diffKernelStack = (int)source.m_kernelStack - (int)source.m_kernelStackStart;

            m_stack       = (int *)((int)m_stackStart + diffStack);
            m_kernelStack = (int *)((int)m_kernelStackStart + diffKernelStack);

            // FPU context
            m_FPUContext = Heap.AlignedAlloc(16, 512);
            Memory.Memcpy(m_FPUContext, source.m_FPUContext, 512);

            // Update stack references within the system stack itself
            int diffRegs = (int)source.m_sysRegs - (int)source.m_stackStart;
            int diffESP  = source.m_sysRegs->ESP - (int)source.m_stackStart;

            m_sysRegs      = (RegsDirect *)((int)m_stackStart + diffRegs);
            m_sysRegs->ESP = (int)m_stackStart + diffESP;

            // Write stack
            m_stack = writeSchedulerStack(m_stack, (void *)m_sysRegs->ESP, UserspaceCS, UserspaceDS, (void *)m_sysRegs->EIP);
            RegsDirect *ptr = (RegsDirect *)m_stack;

            ptr->EBX = m_sysRegs->EBX;
            ptr->ECX = m_sysRegs->ECX;
            ptr->EDX = m_sysRegs->EDX;
            ptr->EBP = m_sysRegs->EBP;
            ptr->ESI = m_sysRegs->ESI;
            ptr->EDI = m_sysRegs->EDI;
        }
示例#17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UnitOfWorkQueueSender" /> class.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="factory">The factory.</param>
 /// <param name="serializer">The serializer.</param>
 public UnitOfWorkQueueSender(IThreadContext context, IQueueFactory factory, ITextSerializer serializer)
 {
     this.context    = Check.NotNull(() => context);
     this.factory    = Check.NotNull(() => factory);
     this.serializer = Check.NotNull(() => serializer);
 }
示例#18
0
		public ThreadVM(DnThread thread, IThreadContext context) {
			this.thread = thread;
			this.context = context;
		}
 /// <summary>
 /// Initializes this factory.
 /// </summary>
 /// <param name="factoryConfig">The configuration of this factory.</param>
 /// <param name="proxyConfig">An optional proxy configuration.</param>
 /// <param name="threadContext">For WPF applications, an instance of WpfThreadContext should be passed here.
 /// For console applications or Windows services an instance of SimpleThreadContext should be used instead.</param>
 protected void Initialize(IWcfClientFactoryConfig factoryConfig, IProxyConfig proxyConfig, IThreadContext threadContext)
 {
     _factoryConfig = factoryConfig;
     _proxyConfig   = proxyConfig;
     _threadContext = threadContext;
 }
示例#20
0
		public ThreadVM(DnThread thread, IThreadContext context) {
			Thread = thread;
			Context = context;
		}
示例#21
0
 /// <summary>
 /// Initializes a new instance with the specified configuration.
 /// </summary>
 /// <param name="threadContext"></param>
 /// <param name="mapper"></param>
 /// <param name="apiClient"></param>
 public ThreadClient(IThreadContext threadContext, IMapper mapper, API.APIClient apiClient)
 {
     this._threadContext = threadContext;
     this._mapper        = mapper;
     this._apiClient     = apiClient;
 }
示例#22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UnitOfWorkContext"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 public UnitOfWorkContext(IThreadContext context)
 {
     this.context = Check.NotNull(() => context);
 }
        public override ExpressionResult Evaluate(IThreadContext context)
        {
            var planetNameExpression = this.GetExpression(0).Evaluate(context);
            var planetName           = planetNameExpression.TextValue;

            if (!String.IsNullOrEmpty(planetName))
            {
                var planet = context.Craft.GetPlanet(planetName);

                if (planet != null)
                {
                    ExpressionResult result;
                    try {
                        switch (this._planetInformationType)
                        {
                        case PlanetInformation.SphereOfInfluenceDistance:
                            result = new ExpressionResult {
                                NumberValue = planet.SphereOfInfluence
                            };
                            break;

                        case PlanetInformation.SphereOfInfluenceExitDistance:
                            result = new ExpressionResult {
                                NumberValue = planet.SphereOfInfluenceExitDistance
                            };
                            break;

                        case PlanetInformation.RotationAngle:
                            result = new ExpressionResult {
                                NumberValue = planet.RotationAngle
                            };
                            break;

                        case PlanetInformation.AngularVelocity:
                            result = new ExpressionResult {
                                NumberValue = planet.PlanetData.AngularVelocity / Math.PI * 180
                            };
                            break;

                        case PlanetInformation.IsTerrainDataLoaded:
                            result = new ExpressionResult {
                                BoolValue = planet.TerrainDataLoaded
                            };
                            break;

                        case PlanetInformation.HasWater:
                            result = new ExpressionResult {
                                BoolValue = planet.PlanetData.HasWater
                            };
                            break;

                        case PlanetInformation.SeaLevel:
                            result = new ExpressionResult {
                                NumberValue = planet.PlanetData.SeaLevel
                            };
                            break;

                        case PlanetInformation.StructureNames:
                            result = new ExpressionResult(
                                planet.PlanetData.StructureNodes
                                .Select(n => n.Name)
                                .ToList()
                                );
                            break;

                        case PlanetInformation.StructureLocations:
                            result = new ExpressionResult(
                                planet.PlanetData.StructureNodes
                                .Select(n => $"({n.Latitude:R}, {n.Longitude:R}, {n.Elevation})")
                                .ToList()
                                );
                            break;

                        case PlanetInformation.StructureHeadings:
                            result = new ExpressionResult(
                                planet.PlanetData.StructureNodes
                                .Select(n => n.Heading.ToString("R"))
                                .ToList()
                                );
                            break;

                        case PlanetInformation.LaunchLocationNames:
                            result = new ExpressionResult(
                                planet.PlanetData.DefaultLaunchLocations
                                .Select(l => l.Name)
                                .ToList()
                                );
                            break;

                        case PlanetInformation.LaunchLocations:
                            result = new ExpressionResult(
                                planet.PlanetData.DefaultLaunchLocations
                                .Select(l => $"({l.Latitude}, {l.Longitude}, {l.LocationType})")
                                .ToList()
                                );
                            break;

                        case PlanetInformation.LaunchLocationHeadings:
                            result = new ExpressionResult(
                                planet.PlanetData.DefaultLaunchLocations
                                .Select(l => l.HeadingSimple?.ToString("R"))
                                .ToList()
                                );
                            break;

                        default:
                            Debug.LogWarning("Unrecognized planet information field: " + this._info);
                            return(new ExpressionResult {
                                NumberValue = 0
                            });
                        }
                    } catch (Exception ex) {
                        Debug.LogWarning($"An unexpected error occured getting planet information: {this._info} ({this._planetInformationType})");
                        Debug.LogError(ex);
                        return(new ExpressionResult {
                            NumberValue = 0
                        });
                    }

                    return(result);
                }
            }

            Debug.Log($"Craft or planet not found: {planetNameExpression.TextValue}");
            return(new ExpressionResult {
                NumberValue = 0
            });
        }
示例#24
0
 public ThreadVM(DnThread thread, IThreadContext context)
 {
     Thread  = thread;
     Context = context;
 }
示例#25
0
 public ThreadVM(DnThread thread, IThreadContext context)
 {
     this.Thread  = thread;
     this.Context = context;
 }
示例#26
0
 public override ProgramInstruction Execute(IThreadContext context)
 {
     this._parent.OnTransmitPhiloticParallaxMessage(this._message, context.GetLocalVariable("data")?.Value);
     return(null);
 }
 public ContextDownloader(IThreadContext threadContext)
 {
     _threadContext = threadContext;
 }
示例#28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AggregateEventContext"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 public AggregateEventContext(IThreadContext context)
 {
     this.context = Check.NotNull(() => context);
 }
 public ContextDownloader(IThreadContext threadContext)
 {
     _threadContext = threadContext;
 }