Exemple #1
0
        private void AddLayer(int bodyID, int hue, bool asMount = false)
        {
            int   facing    = MirrorFacingForDraw(Facing);
            int   animation = 0;
            float frame     = 0;

            if (Entity is Mobile)
            {
                animation = (Entity as Mobile).Animation.ActionIndex;
                if (asMount)
                {
                    animation = patchMountAction(animation);
                }
                frame = (Entity as Mobile).Animation.AnimationFrame;
            }
            else if (Entity is Corpse)
            {
                animation = ActionTranslator.GetActionIndex(Entity, MobileAction.Death);
                frame     = (Entity as Corpse).Frame * BodyConverter.DeathAnimationFrameCount(Body);
            }

            int             frameCount;
            IAnimationFrame animframe = getFrame(bodyID, ref hue, facing, animation, frame, out frameCount);

            m_MobileLayers[m_LayerCount++] = new MobileViewLayer(bodyID, hue, animframe);
            m_FrameCount = frameCount;
        }
Exemple #2
0
        /// <summary>
        /// Process key press events
        /// </summary>
        /// <param name="keyPressed"></param>
        public override void ProcessKeyPress(int keyPressed)
        {
            _logger.Debug("MediaPortal1RemoteHandling - ProcessKeyPress {0} {1}", keyPressed, ((Keys)keyPressed).ToString());

            Action action = new Action();

            //Try and get corresponding Action from key.
            //Some actions are mapped to KeyDown others to KeyPressed, try and handle both
            if (ActionTranslator.GetAction(-1, new Key(0, keyPressed), ref action))
            {
                OnNewActionFromClient(action.wID.ToString());
            }
            else
            {
                //See if it's mapped to KeyPressed instead
                if (keyPressed >= (int)Keys.A && keyPressed <= (int)Keys.Z)
                {
                    keyPressed += 32; //convert to char code
                }
                if (ActionTranslator.GetAction(-1, new Key(keyPressed, 0), ref action))
                {
                    OnNewActionFromClient(action.wID.ToString());
                }
            }
        }
Exemple #3
0
 internal ChaosTestScenario(FabricClient fabricClient, string testScenarioName, ChaosTestScenarioParameters chaosScenarioParameters)
     : base(fabricClient, chaosScenarioParameters)
 {
     this.chaosScenarioParameters = chaosScenarioParameters;
     this.actionTranslator        = new ActionTranslator(this.ReportProgress);
     this.ScenarioInstanceName    = testScenarioName;
     this.random = new Random((int)DateTime.Now.Ticks);
     this.rootActionGenerator = new RootActionGenerator(chaosScenarioParameters.ActionGeneratorParameters, this.random);
 }
        public JsonResult GetUnitPage(int unitid, bool isshow, string jy)
        {
            if (Encrypt.MD5Hash(unitid.ToString(), "jzxd") == jy)
            {
                DtoLessonUnit p   = null;
                LessonUnitBll bll = new LessonUnitBll();
                if (!isshow)
                {
                    p = bll.SelectUnit(unitid, 0);
                }
                else
                {
                    p = bll.GetUnitFromRadis(unitid);
                }
                List <int> mediaIDs = new List <int>();
                List <int> textIDs  = new List <int>();
                var        page     = new Page()
                {
                    pageId   = p.Id,
                    pageNum  = p.Index,
                    pageName = p.Name,
                    coinsKey = Encrypt.EncryptQueryString($"{p.Coins}_{p.Id}_{p.LessonId}_{p.CourseId}"),//金币加密串(加密内容为"单元金币数_单元id_课时id_课程id")//Remark1
                    steps    = p.Steps.Select(s => new Step()
                    {
                        stepNum = s.StepNum,
                        actions = s.Actions.Select(a => ActionTranslator.DataToViewData(a, mediaIDs, textIDs)).ToList()
                    }).ToList()
                };
                //如果媒体id或文本id有值的话
                if (mediaIDs.Count > 0 || textIDs.Count > 0)
                {
                    ResourceBll rbll   = new ResourceBll();
                    var         medias = rbll.GetMediaObjectByIdList(mediaIDs.Distinct().ToList(), true); //获取所有的媒体对象字典
                    var         texts  = rbll.GetTextObjectByIdList(textIDs.Distinct().ToList());         //获取文本对象字典

                    page.steps.ForEach(s =>
                    {
                        s.actions.ForEach(a =>
                        {
                            ActionTranslator.SetViewDataMedia(a, medias, texts);
                        });
                    });
                }
                return(Json(new JsonResponse <Page>
                {
                    State = true,
                    ErrorCode = 0,
                    ErrorMsg = "",
                    Data = page
                }));
            }
            else
            {
                throw new Exception("GetUnitPage服务端校验失败");
            }
        }
        public void TestMethod1()
        {
            int page     = 1;
            int pagesize = 5;
            int courseid = 10016;
            int lessonid = 10047;

            LessonUnitBll bll   = new LessonUnitBll();
            var           pager = new Code.Common.PagingObject()
            {
                PageIndex  = page,     //开始页(包含)
                PageSize   = pagesize, //条数
                TotalCount = 0
            };
            var pages = bll.SelectUnitByNext(new Domain.Dto.Request.DtoLessonUnitSearch()
            {
                CourseID   = courseid,
                LessonID   = lessonid,
                StudentID  = 10000,
                Pagination = pager
            });
            List <int> mediaIDs = new List <int>();
            List <int> textIDs  = new List <int>();
            var        list     = pages.Select(p => new Page()
            {
                pageId   = p.Id,
                pageNum  = p.Index,
                pageName = p.Name,
                steps    = p.Steps.Select(s => new Step()
                {
                    stepNum = s.StepNum,
                    actions = s.Actions.Select(a => ActionTranslator.DataToViewData(a, mediaIDs, textIDs)).ToList()
                }).ToList()
            }).ToList();

            //如果媒体id或文本id有值的话
            if (mediaIDs.Count > 0 || textIDs.Count > 0)
            {
                ResourceBll rbll   = new ResourceBll();
                var         medias = rbll.GetMediaObjectByIdList(mediaIDs.Distinct().ToList()); //获取所有的媒体对象字典
                var         texts  = rbll.GetTextObjectByIdList(textIDs.Distinct().ToList());   //获取文本对象字典

                list.ForEach(p =>
                {
                    p.steps.ForEach(s =>
                    {
                        s.actions.ForEach(a =>
                        {
                            ActionTranslator.SetViewDataMedia(a, medias, texts);
                        });
                    });
                });
            }
            var str = JsonConvert.SerializeObject(list);
        }
        public void Test()
        {
            Regex re = new("(?<id>[^\\\\/]+?)(?:\\..+?)?\\.g4$",
                           (RegexOptions.IgnoreCase | RegexOptions.CultureInvariant));

            string[]             lang       = new string[] { "cpp", "csharp", "dart", "go", "javascript", "python3" };
            string[]             files      = Directory.GetFiles("Cases");
            IEnumerable <string> shouldFail = files.Where(n => n.Contains("fail"));
            IEnumerable <IGrouping <string, string> > group = files.Where(n => !n.Contains("fail")).GroupBy(n =>
            {
                Match m = re.Match(n);
                return(m.Groups["id"].Value);
            });

            foreach (string f in shouldFail)
            {
                string txt = File.ReadAllText(f);
                Assert.Catch(() => new ActionTranslator().TranslateFile(txt));
            }

            foreach (IGrouping <string, string> g in group)
            {
                string b = null;
                List <(string lang, string file)> c = new();
                foreach (string f in g)
                {
                    bool isResult = false;
                    foreach (string l in lang)
                    {
                        if (!f.ToLowerInvariant().Contains(l))
                        {
                            continue;
                        }
                        c.Add((l, f));
                        isResult = true;
                        break;
                    }

                    if (!isResult)
                    {
                        b = f;
                    }
                }

                Assert.NotNull(b);
                string orig = File.ReadAllText(b);

                foreach ((string l, string f) in c)
                {
                    string expected = File.ReadAllText(f);
                    string actual   = new ActionTranslator(l, null).TranslateFile(orig);
                    Assert.AreEqual(expected, actual, f);
                }
            }
        }
        public JsonResult GetLessonPage(DtoLessonUnitSearch search, bool isApprove = false)
        {
            LessonUnitBll bll = new LessonUnitBll();

            search.StudentID = GetCurrentUser().StudentId;//设置当前学生id
            if (isApprove)
            {
                search.Pagination.PageSize = 1;
            }                                                 //如果是审批的情况,只返回一条数据
            var        pages    = bll.SelectUnitByNext(search);
            List <int> mediaIDs = new List <int>();
            List <int> textIDs  = new List <int>();
            var        list     = pages.Select(p => new Page()
            {
                pageId   = p.Id,
                pageNum  = p.Index,
                pageName = p.Name,
                coinsKey = Encrypt.EncryptQueryString($"{p.Coins}_{p.Id}_{p.LessonId}_{p.CourseId}"),//金币加密串(加密内容为"单元金币数_单元id_课时id_课程id")//Remark1
                steps    = p.Steps.Select(s => new Step()
                {
                    stepNum = s.StepNum,
                    actions = s.Actions.Select(a => ActionTranslator.DataToViewData(a, mediaIDs, textIDs)).ToList()
                }).ToList()
            }).ToList();

            //如果媒体id或文本id有值的话
            if (mediaIDs.Count > 0 || textIDs.Count > 0)
            {
                ResourceBll rbll   = new ResourceBll();
                var         medias = rbll.GetMediaObjectByIdList(mediaIDs.Distinct().ToList(), true); //获取所有的媒体对象字典
                var         texts  = rbll.GetTextObjectByIdList(textIDs.Distinct().ToList());         //获取文本对象字典

                list.ForEach(p =>
                {
                    p.steps.ForEach(s =>
                    {
                        s.actions.ForEach(a =>
                        {
                            ActionTranslator.SetViewDataMedia(a, medias, texts);
                        });
                    });
                });
            }

            return(Json(new JsonResponse <List <Page> >
            {
                State = true,
                ErrorCode = 0,
                ErrorMsg = "",
                Data = list
            }));
        }
Exemple #8
0
        public InvokeRule(ParserFactory factory, GrammarAST ast, GrammarAST labelAST)
            : base(factory, ast)
        {
            if (ast.atnState != null)
            {
                RuleTransition ruleTrans = (RuleTransition)ast.atnState.Transition(0);
                stateNumber = ast.atnState.stateNumber;
            }

            this.name = ast.Text;
            Rule r = factory.GetGrammar().GetRule(name);

            ctxName = factory.GetTarget().GetRuleFunctionContextStructName(r);

            // TODO: move to factory
            RuleFunction rf = factory.GetCurrentRuleFunction();

            if (labelAST != null)
            {
                // for x=r, define <rule-context-type> x and list_x
                string label = labelAST.Text;
                if (labelAST.Parent.Type == ANTLRParser.PLUS_ASSIGN)
                {
                    factory.DefineImplicitLabel(ast, this);
                    string listLabel      = factory.GetTarget().GetListLabel(label);
                    RuleContextListDecl l = new RuleContextListDecl(factory, listLabel, ctxName);
                    rf.AddContextDecl(ast.GetAltLabel(), l);
                }
                else
                {
                    RuleContextDecl d = new RuleContextDecl(factory, label, ctxName);
                    labels.Add(d);
                    rf.AddContextDecl(ast.GetAltLabel(), d);
                }
            }

            ActionAST arg = (ActionAST)ast.GetFirstChildWithType(ANTLRParser.ARG_ACTION);

            if (arg != null)
            {
                argExprsChunks = ActionTranslator.TranslateAction(factory, rf, arg.Token, arg);
            }

            // If action refs rule as rulename not label, we need to define implicit label
            if (factory.GetCurrentOuterMostAlt().ruleRefsInActions.ContainsKey(ast.Text))
            {
                string          label = factory.GetTarget().GetImplicitRuleLabel(ast.Text);
                RuleContextDecl d     = new RuleContextDecl(factory, label, ctxName);
                labels.Add(d);
                rf.AddContextDecl(ast.GetAltLabel(), d);
            }
        }
Exemple #9
0
        public Action(OutputModelFactory factory, ActionAST ast)
            : base(factory, ast)
        {
            RuleFunction rf = factory.GetCurrentRuleFunction();

            if (ast != null)
            {
                chunks = ActionTranslator.TranslateAction(factory, rf, ast.Token, ast);
            }
            else
            {
                chunks = new List <ActionChunk>();
            }
            //System.out.println("actions="+chunks);
        }
        [ValidateInput(false)]//不做html验证
        public JsonResult ShowPage(string pagestr)
        {
            LessonUnitBll bll      = new LessonUnitBll();
            Page          pageInfo = new Page();
            JObject       obj      = JsonConvert.DeserializeObject(pagestr) as JObject;

            pageInfo.id      = Convert.ToInt32(obj["id"]);
            pageInfo.pageNum = Convert.ToInt32(obj["pageNum"]);
            pageInfo.name    = obj["name"].ToString();
            pageInfo.steps   = new List <Models.CurriculumSetViewModel.Step>();
            JArray steps = JsonConvert.DeserializeObject(obj["steps"].ToString()) as JArray;

            foreach (var s in steps)
            {
                Models.CurriculumSetViewModel.Step step = new Models.CurriculumSetViewModel.Step();
                step.stepNum = Convert.ToInt32(s["stepNum"]);
                step.actions = new List <ActionBase>();
                JArray actions = JsonConvert.DeserializeObject(s["actions"].ToString()) as JArray;
                foreach (var a in actions)
                {
                    step.actions.Add(ActionTranslator.JsonToViewData(a.ToString()));
                }
                pageInfo.steps.Add(step);
            }

            int coins     = 0;
            var stepsData = pageInfo.steps.Select(s => new Domain.JsonEntity.UnitStep.Step()
            {
                id      = s.id,
                StepNum = s.stepNum,
                Actions = s.actions.Select(a => ActionTranslator.ViewDataToData(a, ref coins)).ToList()
            }).ToList();

            //保存数据到Radis中
            bll.SaveUnitToRadis(new DtoLessonUnit
            {
                Id     = pageInfo.id,
                Index  = pageInfo.pageNum,
                Coins  = coins,
                Steps  = stepsData,
                Status = 0,
            });
            string key = Encrypt.EncryptQueryString($"{new Random().Next(0, 10000)}_{pageInfo.id}_{0}_{0}");

            return(Json(new JsonResponse <string> {
                State = true, ErrorCode = 0, ErrorMsg = "", Data = $"{ConfigurationManager.AppSettings["StudentClientDomain"]}LearningCenter/LessonApprove?ApproveKey={key}"
            }));
        }
Exemple #11
0
        public Action(OutputModelFactory factory, StructDecl ctx, string action)
            : base(factory, null)
        {
            ActionAST    ast = new ActionAST(new CommonToken(ANTLRParser.ACTION, action));
            RuleFunction rf  = factory.GetCurrentRuleFunction();

            if (rf != null)
            { // we can translate
                ast.resolver = rf.rule;
                chunks       = ActionTranslator.TranslateActionChunk(factory, rf, action, ast);
            }
            else
            {
                chunks = new List <ActionChunk>();
                chunks.Add(new ActionText(ctx, action));
            }
        }
        /// <summary>
        /// Map a key press to an action
        /// </summary>
        /// <param name="keyPressed"></param>
        /// <returns></returns>
        public static Action MapToAction(int keyPressed)
        {
            var action = new Action();

            if (ActionTranslator.GetAction(-1, new Key(0, keyPressed), ref action))
            {
                return(action);
            }
            //See if it's mapped to KeyPressed instead
            if (keyPressed >= (int)Keys.A && keyPressed <= (int)Keys.Z)
            {
                keyPressed += 32; //convert to char code
            }
            if (ActionTranslator.GetAction(-1, new Key(keyPressed, 0), ref action))
            {
                return(action);
            }
            return(null);
        }
        /// <summary>
        /// When the browser has a key press, try and map it to an action and fire the on action
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void _callback_OnBrowserKeyPress(int keyPressed)
        {
            var action = new Action();

            if (ActionTranslator.GetAction(-1, new Key(0, keyPressed), ref action))
            {
                GUIWindowManager_OnNewAction(action);
            }
            else
            {
                //See if it's mapped to KeyPressed instead
                if (keyPressed >= (int)Keys.A && keyPressed <= (int)Keys.Z)
                {
                    keyPressed += 32; //convert to char code
                }
                if (ActionTranslator.GetAction(-1, new Key(keyPressed, 0), ref action))
                {
                    GUIWindowManager_OnNewAction(action);
                }
            }
        }
Exemple #14
0
        /// <summary>
        /// Connect to the web service and attach the action handler
        /// </summary>
        public override void Initialise()
        {
            _logger.Debug("Initialising Remote handling");

            try
            {
                //Load keyboard mappings
                ActionTranslator.Load();
                //Load remote mappings
                InputDevices.Init();
                GUIGraphicsContext.OnNewAction += OnNewAction;
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                if (ex.InnerException != null)
                {
                    _logger.Error(ex.InnerException);
                }
            }
        }
        public JsonResult GetPage(int pageid, int processid)
        {
            LessonUnitBll bll  = new LessonUnitBll();
            var           unit = bll.SelectUnit(pageid, processid);
            var           page = new Page();

            page.courseId = unit.CourseId;
            page.lessonId = unit.LessonId;
            page.id       = unit.Id;
            page.name     = unit.Name;
            page.pageNum  = unit.Index;
            ////定义媒体资源id数组和文本资源id数组
            List <int> mediaids = new List <int>(), textids = new List <int>();

            page.steps = unit.Steps.Select(s => new Models.CurriculumSetViewModel.Step
            {
                id      = s.id,
                stepNum = s.StepNum,
                actions = s.Actions.Select(a => ActionTranslator.DataToViewData(a, mediaids, textids)).ToList()
            }).ToList();
            //如果媒体id或文本id有值的话
            if (mediaids.Count > 0 || textids.Count > 0)
            {
                ResourceBll rbll   = new ResourceBll();
                var         medias = rbll.GetMediaObjectByIdList(mediaids.Distinct().ToList()); //获取所有的媒体对象字典
                var         texts  = rbll.GetTextObjectByIdList(textids.Distinct().ToList());   //获取文本对象字典
                page.steps.ForEach((s) =>
                {
                    s.actions.ForEach((a) =>
                    {
                        ActionTranslator.SetViewDataMedia(a, medias, texts); //设置动作的媒体属性
                    });                                                      //遍历每一个动作
                });                                                          //遍历每一个步骤
            }
            page.approveType = unit.ApproveStatus;
            page.approve     = unit.Approve;
            return(Json(new JsonResponse <Page> {
                State = true, ErrorCode = 0, ErrorMsg = "", Data = page
            }));
        }
Exemple #16
0
        internal ChaosScenario(
            FabricClient fabricClient,
            ChaosParameters chaosParameters,
            IReliableDictionary <long, byte[]> eventsDictionary,
            IReliableDictionary <string, byte[]> lastEventKeyDict,
            IReliableStateManager stateManager,
            TimeSpan timeToRun,
            double chaosSnapshotTelemetrySamplingProbability,
            IStatefulServicePartition partition,
            bool testMode,
            CancellationToken cancellationToken)
        {
            this.actionTranslator    = new ActionTranslator();
            this.random              = new Random((int)DateTime.Now.Ticks);
            this.rootActionGenerator = new RootActionGenerator(chaosParameters.ActionGeneratorParameters, this.random);
            this.generatedActions    = new List <FabricTestAction>();
            this.FabricClient        = fabricClient;
            this.TestContext         = this.FabricClient.FaultManager.TestContext;
            this.ChaosParameters     = chaosParameters;
            this.EventsDictionary    = eventsDictionary;
            this.LastEventKeyDict    = lastEventKeyDict;
            this.StateManager        = stateManager;

            this.consecutiveFailures = 0;

            this.chaosSnapshotTelemetrySamplingProbability = chaosSnapshotTelemetrySamplingProbability;

            this.partition         = partition;
            this.cancellationToken = cancellationToken;

            if (testMode)
            {
                this.testMode = testMode;
                chaosParameters.OperationTimeout = FASConstants.TestOperationTimeout;
            }

            this.validationHelper = new ValidationHelper(chaosParameters, fabricClient);

            this.ApplyInternalConfigFromContextIfPresent(this.ChaosParameters.Context);
        }
        public override void OnAction(Action action)
        {
            if (action.wID == Action.ActionType.ACTION_KEY_PRESSED)
            {
                // translate the action as if our window was the WINDOW_FULLSCREEN_VIDEO
                if (ActionTranslator.GetAction((int)Window.WINDOW_FULLSCREEN_VIDEO, action.m_key, ref action))
                {
                    if (action.wID == Action.ActionType.ACTION_SHOW_OSD)                     // handle the OSD action differently - we need to show our OSD
                    {
                        base.OnAction(action);
                        if (GUIWindowManager.VisibleOsd == Window.WINDOW_OSD)
                        {
                            GUIWindowManager.VisibleOsd = (Window)GUIOnlineVideoOSD.WINDOW_ONLINEVIDEOS_OSD;
                        }
                        return;
                    }
                    else if (action.wID == Action.ActionType.ACTION_SHOW_GUI ||
                             action.wID == Action.ActionType.ACTION_NEXT_SUBTITLE)
                    {
                        return;                         // already handled by base class, but get's sent here again as keypress, so when we map it we must make sure not to handle it again
                    }
                    else if (action.wID == Action.ActionType.ACTION_VOLUME_UP ||
                             action.wID == Action.ActionType.ACTION_VOLUME_DOWN ||
                             action.wID == Action.ActionType.ACTION_VOLUME_MUTE)
                    {
                        // MediaPortal core sends this message to the Fullscreenwindow, we need to do it ourselves to make the Volume OSD show up
                        GUIWindowManager.SendThreadCallback((p1, p2, o) =>
                        {
                            Action showVolume = new Action(Action.ActionType.ACTION_SHOW_VOLUME, 0, 0);
                            GUIWindowManager.OnAction(showVolume);
                            return(0);
                        }, 0, 0, null);
                        return;
                    }
                }
            }

            base.OnAction(action);
        }
Exemple #18
0
        public SemPred(OutputModelFactory factory, [NotNull] ActionAST ast)
            : base(factory, ast)
        {
            Debug.Assert(ast.atnState != null &&
                         ast.atnState.NumberOfTransitions == 1 &&
                         ast.atnState.Transition(0) is AbstractPredicateTransition);

            GrammarAST failNode = ast.GetOptionAST("fail");

            predicate = ast.Text;
            if (predicate.StartsWith("{") && predicate.EndsWith("}?"))
            {
                predicate = predicate.Substring(1, predicate.Length - 3);
            }
            predicate = factory.GetTarget().GetTargetStringLiteralFromString(predicate);

            if (failNode == null)
            {
                return;
            }

            if (failNode is ActionAST)
            {
                ActionAST    failActionNode = (ActionAST)failNode;
                RuleFunction rf             = factory.GetCurrentRuleFunction();
                failChunks = ActionTranslator.TranslateAction(factory, rf,
                                                              failActionNode.Token,
                                                              failActionNode);
            }
            else
            {
                msg = factory.GetTarget().GetTargetStringLiteralFromANTLRStringLiteral(factory.GetGenerator(),
                                                                                       failNode.Text,
                                                                                       true);
            }
        }
        [ValidateInput(false)]//不做html验证
        public JsonResult SetPage(string pagestr)
        {
            LessonUnitBll bll      = new LessonUnitBll();
            Page          pageInfo = new Page();

            #region 解析数据
            JObject obj       = JsonConvert.DeserializeObject(pagestr) as JObject;
            string  base64Str = obj["thumbnail"].ToString().Split(',')[1];
            pageInfo.id      = Convert.ToInt32(obj["id"]);
            pageInfo.pageNum = Convert.ToInt32(obj["pageNum"]);
            pageInfo.name    = obj["name"].ToString();

            string thumbnailPath     = "UnitThumbnail";          //文件路径
            string thumbnailFileName = $"unit{pageInfo.id}.png"; //文件名称

            new Thread(() =>
            {
                byte[] arr              = Convert.FromBase64String(base64Str);
                MemoryStream ms         = new MemoryStream(arr);
                FileManageClient client = new FileManageClient(ConfigurationManager.AppSettings["uploadUrl"]);
                var response            = client.UploadCoverage(thumbnailFileName, ms, ConfigurationManager.AppSettings["OssSubject"], thumbnailPath, true);
            }).Start();                                                   //开启线程上传缩略图片

            pageInfo.thumbnail = $"/{thumbnailPath}/{thumbnailFileName}"; //拼接存储路径
            pageInfo.steps     = new List <Models.CurriculumSetViewModel.Step>();

            JArray steps = JsonConvert.DeserializeObject(obj["steps"].ToString()) as JArray;
            foreach (var s in steps)
            {
                Models.CurriculumSetViewModel.Step step = new Models.CurriculumSetViewModel.Step();
                step.stepNum = Convert.ToInt32(s["stepNum"]);
                step.actions = new List <ActionBase>();

                JArray actions = JsonConvert.DeserializeObject(s["actions"].ToString()) as JArray;
                foreach (var a in actions)
                {
                    step.actions.Add(ActionTranslator.JsonToViewData(a.ToString()));
                }
                pageInfo.steps.Add(step);
            }

            #endregion 解析数据
            int coins     = 0;
            var stepsData = pageInfo.steps.Select(s => new Domain.JsonEntity.UnitStep.Step()
            {
                id      = s.id,
                StepNum = s.stepNum,
                Actions = s.actions.Select(a => ActionTranslator.ViewDataToData(a, ref coins)).ToList()
            }).ToList();
            //修改数据
            bll.Update(new DtoLessonUnit
            {
                Id         = pageInfo.id,
                Name       = pageInfo.name,
                Screenshot = pageInfo.thumbnail,
                Status     = 0,
                Index      = pageInfo.pageNum,
                Steps      = stepsData,
                Coins      = coins
            });
            return(Json(new JsonResponse <string> {
                State = true, ErrorCode = 0, ErrorMsg = "", Data = ""
            }));
        }
Exemple #20
0
        private void Listener_XplMessageReceived(object sender, XplListener.XplEventArgs e)
        {
            if (e.XplMsg.Schema.msgClass.ToLower().Equals("hbeat") && e.XplMsg.Schema.msgType.ToLower().Equals("app"))
            {
                if (this.DoDebug)
                {
                    Log.Info("xPLConnector_Listener_XplMessageReceived: Received HEARTBEAT");
                }
                this._IsConnected = true;
            }
            else if (e.XplMsg.Schema.msgClass.ToLower().Equals("config"))
            {
                if (this.DoDebug)
                {
                    Log.Info("xPLConnector_Listener_XplMessageReceived: Received CONFIG message");
                }
            }
            else if ((e.XplMsg.Source.Vendor.ToLower().Equals(this.mVendorID.ToLower()) &&
                      e.XplMsg.Source.Device.ToLower().Equals(this.mDeviceID.ToLower())) &&
                     e.XplMsg.Source.Instance.ToLower().Equals(this.mInstanceID.ToLower()))
            {
                if (this.DoDebug)
                {
                    Log.Info("xPLConnector_Listener_XplMessageReceived: Received ECHO");
                }
            }
            else
            {
                if (this.DoDebug)
                {
                    Log.Info("xPLConnector_Listener_XplMessageReceived: {0} - {1} - {2}",
                             new object[] { e.XplMsg.Source.Vendor, e.XplMsg.Source.Device, e.XplMsg.Content });
                }
                string str   = e.XplMsg.Schema.msgClass.ToLower() + "." + e.XplMsg.Schema.msgType.ToLower();
                string str11 = str;
                if (str11 != null)
                {
                    if (!(str11 == "media.basic"))
                    {
                        if (!(str11 == "media.request"))
                        {
                            if (str11 == "remote.basic")
                            {
                                foreach (string str9 in e.XplMsg.GetParam(1, "keys").Split(new char[] { ',' }))
                                {
                                    if (this.DoDebug)
                                    {
                                        Log.Info("xPL_Connector.Listener_XplMessageReceived(): Received remote.basic \"{0}\"",
                                                 new object[] { str9 });
                                    }
                                    if (Enum.IsDefined(typeof(GUIWindow.Window), str9.ToUpper()))
                                    {
                                        if (this.DoDebug)
                                        {
                                            Log.Info("xPL_Connector.Listener_XplMessageReceived(): Received remote.basic window name",
                                                     new object[0]);
                                        }
                                        this.XPL_Send_Remote_Confirm_Message(e);
                                        int num8 = (int)Enum.Parse(typeof(GUIWindow.Window), str9.ToUpper());
                                        if (!GUIWindowManager.ActiveWindow.Equals(num8))
                                        {
                                            GUIWindowManager.SendThreadCallbackAndWait(
                                                new GUIWindowManager.Callback(this.ThreadMessageCallback), 1, num8, null);
                                            return;
                                        }
                                        break;
                                    }
                                    if (Enum.IsDefined(typeof(Keys), str9))
                                    {
                                        if (this.DoDebug)
                                        {
                                            Log.Info("xPL_Connector.Listener_XplMessageReceived(): Received remote.basic key name",
                                                     new object[0]);
                                        }
                                        this.XPL_Send_Remote_Confirm_Message(e);
                                        Key    key     = new Key(0, (int)Enum.Parse(typeof(Keys), str9));
                                        Action action3 = new Action();
                                        if (ActionTranslator.GetAction(GUIWindowManager.ActiveWindow, key, ref action3))
                                        {
                                            GUIWindowManager.OnAction(action3);
                                            return;
                                        }
                                    }
                                    foreach (string str10 in Enum.GetNames(typeof(RemoteButton)))
                                    {
                                        if (str10.ToLower().Equals(str9.ToLower()) || str9.ToLower().Equals("remote_" + str10.ToLower()))
                                        {
                                            if (this.DoDebug)
                                            {
                                                Log.Info(
                                                    "xPL_Connector.Listener_XplMessageReceived(): Received remote.basic remote key name \"{0}\"",
                                                    new object[] { str9 });
                                            }
                                            this.XPL_Send_Remote_Confirm_Message(e);
                                            if (!this.rHandler.MapAction((int)Enum.Parse(typeof(RemoteButton), str10)) && this.DoDebug)
                                            {
                                                Log.Info(
                                                    "xPL_Connector.Listener_XplMessageReceived(): COULD NOT FIRE REMOTE ACTION (isLoaded = {0})",
                                                    new object[] { this.rHandler.IsLoaded });
                                            }
                                            break;
                                        }
                                    }
                                    int result = 0;
                                    int.TryParse(str9, out result);
                                    if (result != 0)
                                    {
                                        if (this.DoDebug)
                                        {
                                            Log.Info("xPL_Connector.Listener_XplMessageReceived(): Received remote.basic raw keycode",
                                                     new object[0]);
                                        }
                                        this.XPL_Send_Remote_Confirm_Message(e);
                                        Key    key2    = new Key(0, result);
                                        Action action4 = new Action();
                                        if (ActionTranslator.GetAction(GUIWindowManager.ActiveWindow, key2, ref action4))
                                        {
                                            GUIWindowManager.OnAction(action4);
                                            return;
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            switch (e.XplMsg.GetParam(1, "request"))
                            {
                            case "devinfo":
                                this.XPL_SendDevInfo("xpl-stat");
                                return;

                            case "devstate":
                                if (e.XplMsg.GetParam(1, "mp").ToLower().Equals("player"))
                                {
                                    this.XPL_SendPlayerDevstate("xpl-stat");
                                }
                                return;

                            case "mpinfo":
                                if (e.XplMsg.GetParam(1, "mp").ToLower().Equals("player"))
                                {
                                    this.XPL_SendPlayerMediaPlayerInfo("xpl-stat");
                                    this.XPL_SendPlayerMediaPlayerInputInfo("xpl-stat");
                                }
                                return;

                            case "mptrnspt":
                                if (e.XplMsg.GetParam(1, "mp").ToLower().Equals("player"))
                                {
                                    this.XPL_SendPlayerTransportState("xpl-stat");
                                }
                                return;

                            case "mpmedia":
                                if (e.XplMsg.GetParam(1, "mp").ToLower().Equals("player"))
                                {
                                    this.XPL_SendMediaInfo("xpl-stat");
                                }
                                return;

                            case "mpconfig":
                                if (e.XplMsg.GetParam(1, "mp").ToLower().Equals("player"))
                                {
                                    this.XPL_SendPlayerMediaPlayerConfig("xpl-stat");
                                }
                                return;

                            case "mpqueue":
                                return;
                            }
                        }
                    }
                    else
                    {
                        int num;
                        switch (e.XplMsg.GetParam(1, "command").ToLower())
                        {
                        case "record":
                        case "position":
                        case "chapter":
                        case "power":
                        case "reboot":
                        case "input":
                        case "options":
                            return;

                        case "play":
                        {
                            string path = e.XplMsg.GetParam(1, "url").ToLower();
                            if (!(path.Equals(string.Empty) & g_Player.Paused))
                            {
                                if (path.Equals(g_Player.currentFileName) & g_Player.Paused)
                                {
                                    g_Player.Pause();
                                    if (this.DoDebug)
                                    {
                                        Log.Info(
                                            "xPLConnector_Listener_XplMessageReceived: Received media.basic play file command (unpause)",
                                            new object[0]);
                                        return;
                                    }
                                    return;
                                }
                                if (File.Exists(path) && !g_Player.currentFileName.Equals(path))
                                {
                                    GUIMessage message = new GUIMessage();
                                    message.Message = GUIMessage.MessageType.GUI_MSG_PLAY_FILE;
                                    message.Label   = path;
                                    GUIWindowManager.SendThreadMessage(message);
                                    if (!this.DoDebug)
                                    {
                                        return;
                                    }
                                    Log.Info("xPLConnector_Listener_XplMessageReceived: Received media.basic play file command",
                                             new object[0]);
                                }
                                return;
                            }
                            g_Player.Pause();
                            if (this.DoDebug)
                            {
                                Log.Info(
                                    "xPLConnector_Listener_XplMessageReceived: Received media.basic play file command (unpause)",
                                    new object[0]);
                            }
                            return;
                        }

                        case "stop":
                        {
                            GUIMessage message2 = new GUIMessage();
                            message2.Message = GUIMessage.MessageType.GUI_MSG_STOP_FILE;
                            GUIWindowManager.SendThreadMessage(message2);
                            if (this.DoDebug)
                            {
                                Log.Info("xPLConnector_Listener_XplMessageReceived: Received media.basic stop command",
                                         new object[0]);
                            }
                            return;
                        }

                        case "pause":
                            if (this.DoDebug)
                            {
                                Log.Info("xPLConnector_Listener_XplMessageReceived: Received media.basic pause command",
                                         new object[0]);
                            }
                            if (!g_Player.Paused)
                            {
                                g_Player.Pause();
                            }
                            return;

                        case "forward":
                        {
                            string str4 = e.XplMsg.GetParam(1, "speed").ToLower();
                            num = 0;
                            if (!str4.Equals(string.Empty))
                            {
                                num = int.Parse(str4.Replace("x", ""));
                                break;
                            }
                            num = g_Player.Speed * 2;
                            break;
                        }

                        case "rewind":
                        {
                            string str5 = e.XplMsg.GetParam(1, "speed").ToLower();
                            int    num2 = 0;
                            if (!str5.Equals(string.Empty))
                            {
                                num2 = int.Parse(str5.Replace("x", ""));
                            }
                            else
                            {
                                num2 = Math.Abs(g_Player.Speed) * 2;
                            }
                            if (num2 > 0x20)
                            {
                                num2 = 0x20;
                            }
                            if (this.DoDebug)
                            {
                                Log.Info("xPLConnector_Listener_XplMessageReceived: Received media.basic rewind ({0}x) command",
                                         new object[] { num2 });
                            }
                            g_Player.Speed = -num2;
                            return;
                        }

                        case "next":
                            Action action;
                            if (!g_Player.IsDVD)
                            {
                                action = new Action(Action.ActionType.ACTION_NEXT_ITEM, 0f, 0f);
                            }
                            else
                            {
                                action = new Action(Action.ActionType.ACTION_NEXT_CHAPTER, 0f, 0f);
                            }
                            GUIGraphicsContext.OnAction(action);
                            if (this.DoDebug)
                            {
                                Log.Info("xPLConnector_Listener_XplMessageReceived: Received media.basic next command",
                                         new object[0]);
                            }
                            return;

                        case "back":
                            Action action2;
                            if (!g_Player.IsDVD)
                            {
                                action2 = new Action(Action.ActionType.ACTION_PREV_ITEM, 0f, 0f);
                            }
                            else
                            {
                                action2 = new Action(Action.ActionType.ACTION_PREV_CHAPTER, 0f, 0f);
                            }
                            GUIGraphicsContext.OnAction(action2);
                            if (this.DoDebug)
                            {
                                Log.Info("xPLConnector_Listener_XplMessageReceived: Received media.basic back command",
                                         new object[0]);
                            }
                            return;

                        case "mute":
                            if (!(e.XplMsg.GetParam(1, "state").ToLower() == "on"))
                            {
                                if (this.DoDebug)
                                {
                                    Log.Info("xPLConnector_Listener_XplMessageReceived: Received media.basic mute off command",
                                             new object[0]);
                                }
                                VolumeHandler.Instance.IsMuted = false;
                                return;
                            }
                            if (this.DoDebug)
                            {
                                Log.Info("xPLConnector_Listener_XplMessageReceived: Received media.basic mute on command",
                                         new object[0]);
                            }
                            VolumeHandler.Instance.IsMuted = true;
                            return;

                        case "volume":
                        {
                            string str13;
                            string s = e.XplMsg.GetParam(1, "level").ToLower();
                            if (((str13 = s.Substring(0, 1)) == null) || (!(str13 == "+") && !(str13 == "-")))
                            {
                                int num7 = int.Parse(s);
                                VolumeHandler.Instance.Volume = (VolumeHandler.Instance.Maximum / 100) * num7;
                                if (this.DoDebug)
                                {
                                    Log.Info("xPLConnector_Listener_XplMessageReceived: Received media.basic volume command",
                                             new object[0]);
                                }
                                return;
                            }
                            int volume = VolumeHandler.Instance.Volume;
                            int num5   = int.Parse(s) * 0x28f;
                            int num6   = volume + num5;
                            if (num6 < 0)
                            {
                                num6 = 0;
                            }
                            if (num6 > 0xffdc)
                            {
                                num6 = 0xffdc;
                            }
                            VolumeHandler.Instance.Volume = num6;
                            if (this.DoDebug)
                            {
                                Log.Info(
                                    "xPLConnector_Listener_XplMessageReceived: Received media.basic volume {0} command = orig = {1}, new = {2}, delta = {3}",
                                    new object[] { s, volume, num6, num5 });
                            }
                            return;
                        }

                        default:
                            return;
                        }
                        if (num > 0x20)
                        {
                            num = 0x20;
                        }
                        if (this.DoDebug)
                        {
                            Log.Info("xPLConnector_Listener_XplMessageReceived: Received media.basic play forward ({0}x) command",
                                     new object[] { num });
                        }
                        g_Player.Speed = num;
                    }
                }
            }
        }
Exemple #21
0
        public override void OnAction(MediaPortal.GUI.Library.Action action)
        {
            if (action.wID == MediaPortal.GUI.Library.Action.ActionType.ACTION_VOLUME_UP ||
                action.wID == MediaPortal.GUI.Library.Action.ActionType.ACTION_VOLUME_DOWN ||
                action.wID == MediaPortal.GUI.Library.Action.ActionType.ACTION_VOLUME_MUTE)
            {
                // MediaPortal core sends this message to the Fullscreenwindow, we need to do it ourselves to make the Volume OSD show up
                base.OnAction(new MediaPortal.GUI.Library.Action(MediaPortal.GUI.Library.Action.ActionType.ACTION_SHOW_VOLUME, 0,
                                                                 0));
                return;
            }
            else if (action.wID == MediaPortal.GUI.Library.Action.ActionType.ACTION_CONTEXT_MENU)
            {
                OnShowContextMenu();
                return;
            }
            else
            {
                MediaPortal.GUI.Library.Action translatedAction = new MediaPortal.GUI.Library.Action();
                if (ActionTranslator.GetAction((int)GUIWindow.Window.WINDOW_FULLSCREEN_VIDEO, action.m_key,
                                               ref translatedAction))
                {
                    if (translatedAction.wID == MediaPortal.GUI.Library.Action.ActionType.ACTION_SHOW_OSD)
                    {
                        GUIPropertyManager.SetProperty("#Youtube.fm.FullScreen.ShowTitle", "false");
                        GUIPropertyManager.SetProperty("#Youtube.fm.FullScreen.ShowNextTitle", "false");
                        base.OnAction(translatedAction);
                        if (GUIWindowManager.VisibleOsd == GUIWindow.Window.WINDOW_OSD)
                        {
                            GUIWindowManager.VisibleOsd = (GUIWindow.Window) 29055;
                        }
                        return;
                    }
                    if (translatedAction.wID == MediaPortal.GUI.Library.Action.ActionType.ACTION_ASPECT_RATIO)
                    {
                        base.OnAction(translatedAction);
                        return;
                    }
                }
            }
            if (action.wID == MediaPortal.GUI.Library.Action.ActionType.ACTION_NEXT_ITEM || action.wID == MediaPortal.GUI.Library.Action.ActionType.ACTION_NEXT_CHAPTER)
            {
                if (Youtube2MP.player.CurrentSong > -1)
                {
                    Youtube2MP.player.PlayNext();
                    return;
                }
                if (Youtube2MP.temp_player.CurrentSong > -1)
                {
                    Youtube2MP.temp_player.PlayNext();
                    return;
                }
            }

            if (action.wID == MediaPortal.GUI.Library.Action.ActionType.ACTION_PREV_ITEM || action.wID == MediaPortal.GUI.Library.Action.ActionType.ACTION_PREV_CHAPTER)
            {
                if (Youtube2MP.player.CurrentSong > -1)
                {
                    Youtube2MP.player.PlayPrevious();
                    return;
                }
                if (Youtube2MP.temp_player.CurrentSong > -1)
                {
                    Youtube2MP.temp_player.PlayPrevious();
                    return;
                }
            }

            base.OnAction(action);
        }