Beispiel #1
0
        ActionHandlerResult ProcessVideo(ShareContent share, Regex reg, int valueIndex, string htmlContent)
        {
            if (htmlContent == null)
            {
                ActionHandlerResult result = new ActionHandlerResult();
                //result.HasError = true;
                result.ErrorMessage = "无法找到该网页";
                return(result);
            }
            else if (reg.IsMatch(htmlContent))
            {
                //Match title = Regex.Match(content, "<title>.*</title>");

                //if (title.Success)
                //    share.Title = title.Value;
                //else
                //    share.Title = share.URL;
                if (share.Title == null)
                {
                    share.Title = share.URL;
                }
                share.Content  = reg.Match(htmlContent).Groups[valueIndex].Value;
                share.Catagory = ShareType.Video;
                return(null);
            }
            else
            {
                share = null;
                return(null);
            }
        }
Beispiel #2
0
        public bool SendFrames(ActionHandlerResult frameData)
        {
            bool ret = false;

            ret = FrameBufferBlock.Send(frameData);
            return(ret);
        }
Beispiel #3
0
        private async Task <ActionHandlerResult> Handle(CropAction action)
        {
            var arguments = $"-i {action.InputPath} -vf \"crop = {action.Width}:{action.Height}:{action.X}:{action.Y}\" {action.OutputPath}";
            await _engine.Execute(arguments);

            return(ActionHandlerResult.Successful(action.OutputPath));
        }
Beispiel #4
0
        private CustomDataFrame SubstituteIncoming(CustomDataFrame dataFrame, List <ActionHandlerResult> ahResults, Dictionary <SubstituteIncomingFlags, CustomDataFrame> substitutedDataFrames)
        {
            ActionBase additionalAction;
            ActionBase completeAction;

            lock (_actionStateLock)
            {
                foreach (var item in Enumerable.Reverse(_substituteManagers))
                {
                    substitutedDataFrames.Add(item.Id, dataFrame);
                    dataFrame = item.SubstituteIncoming(dataFrame, out additionalAction, out completeAction);
                    if (additionalAction != null)
                    {
                        var ahRes = new ActionHandlerResult(null);
                        ahRes.NextActions.Add(additionalAction);
                        ahResults.Add(ahRes);
                    }
                    if (completeAction != null)
                    {
                        ProcessCompleted(completeAction);
                    }
                }
                return(dataFrame);
            }
        }
Beispiel #5
0
        private async Task <ActionHandlerResult> Handle(ResizeAction action)
        {
            var conversion = await Xabe.FFmpeg.FFmpeg.Conversions.FromSnippet
                             .ChangeSize(
                action.InputPath,
                action.OutputPath,
                action.Width,
                action.Height);

            var result = await conversion.Start();

            return(ActionHandlerResult.Successful(action.OutputPath));
        }
Beispiel #6
0
        private async Task <ActionHandlerResult> Handle(TrimAction action)
        {
            var conversion = await Xabe.FFmpeg.FFmpeg.Conversions.FromSnippet
                             .Split(
                action.InputPath,
                action.OutputPath,
                action.Start,
                action.Duration);

            var result = await conversion.Start();

            return(ActionHandlerResult.Successful(action.OutputPath));
        }
Beispiel #7
0
        public bool SendFrames(ActionHandlerResult frameData)
        {
            bool ret = false;

            if (IsReady)
            {
                ret = FrameBufferBlock.Send(frameData);
                if (!_hasTransmitFails && !ret)
                {
                    _hasTransmitFails = true;
                }
            }
            return(ret);
        }
Beispiel #8
0
        private async Task <ActionHandlerResult> Handle(GeneratePreviewAction action)
        {
            EnsureActionOutputIsImage(action);
            var previewPath = await GeneratePreview(action);

            if (previewPath == null)
            {
                return(ActionHandlerResult.Successful(action.OutputPath));
            }

            await UpdateRecordPreview(action, previewPath);

            return(ActionHandlerResult.Successful(action.OutputPath, createNewRecord: false));
        }
Beispiel #9
0
        public void ProcessNext(ActionHandlerResult ahResult)
        {
            if (ahResult != null && ahResult.NextActions != null)
            {
                var sendFrames    = ahResult.NextActions.Where(x => x is CommandMessage);
                var timeIntervals = ahResult.NextActions.Where(x => x is TimeInterval);
                var actions       = ahResult.NextActions.Where(x => x is ActionBase);
                if (sendFrames.Any())
                {
                    if (SendFramesCallback != null)
                    {
                        var isTransmitted = SendFramesCallback(ahResult);
                        if (isTransmitted)
                        {
                            ahResult.Parent.FixStates();
                        }
                        else
                        {
                            ahResult.Parent.Token.SetFailed();
                        }
                        if (ahResult.Parent.Token.IsStateFinished)
                        {
                            ActionCaseConsumer.Add(ahResult.Parent);
                        }
                    }
                }

                if (timeIntervals.Any())
                {
                    foreach (TimeInterval item in timeIntervals)
                    {
                        TimeoutManager.AddTimer(item);
                    }
                }

                if (actions.Any())
                {
                    foreach (ActionBase item in actions)
                    {
                        ActionCaseConsumer.Add(item);
                    }
                }
            }
        }
Beispiel #10
0
        public override void OnIncomingSubstituted(CustomDataFrame dataFrameOri, CustomDataFrame dataFrameSub, List <ActionHandlerResult> ahResults)
        {
            if (IsActive)
            {
                bool hasSendData = ahResults.FirstOrDefault(
                    x => x.NextActions != null && x.NextActions.FirstOrDefault(
                        y => y is SendDataOperation || y is SendDataExOperation) != null) != null;
                if (!hasSendData)
                {
                    byte[] cmdData;
                    byte   srcNodeId;
                    byte   destNodeId;
                    int    lenIndex;
                    if (TryParseCommand(dataFrameOri, out destNodeId, out srcNodeId, out lenIndex, out cmdData))
                    {
                        if (cmdData[0] == COMMAND_CLASS_SUPERVISION.ID && cmdData[1] == COMMAND_CLASS_SUPERVISION.SUPERVISION_GET.ID)
                        {
                            COMMAND_CLASS_SUPERVISION.SUPERVISION_GET cmd = cmdData;
                            var data = new COMMAND_CLASS_SUPERVISION.SUPERVISION_REPORT()
                            {
                                duration    = 0,
                                properties1 = new COMMAND_CLASS_SUPERVISION.SUPERVISION_REPORT.Tproperties1()
                                {
                                    sessionId = cmd.properties1.sessionId
                                },
                                status = 0xFF
                            };

                            var tempAction = new SendDataOperation(srcNodeId, data, TxOptions);
                            if ((((SubstituteIncomingFlags)dataFrameOri.SubstituteIncomingFlags) & SubstituteIncomingFlags.Security) > 0)
                            {
                                tempAction.SubstituteSettings.SetFlag(SubstituteFlags.UseSecurity);
                            }
                            var ahRes = new ActionHandlerResult(null);
                            ahRes.NextActions.Add(tempAction);
                            ahResults.Add(ahRes);
                        }
                    }
                }
            }
        }
Beispiel #11
0
        public async Task <ActionHandlerResult> Handle(IAction action)
        {
            if (action is null)
            {
                return(ActionHandlerResult.Failed());
            }

            if (!(action is TrimAction))
            {
                return(ActionHandlerResult.Failed());
            }

            //validate

            try
            {
                return(await Handle(action as TrimAction));
            }
            catch (Exception e)
            {
                return(ActionHandlerResult.Failed(e));
            }
        }
Beispiel #12
0
        public IActionHandlerResult Execute(IActionHandlerContext context, ITaskLog taskLog)
        {
            var deploymentId = context.Variables.Get(KnownVariables.Deployment.Id, "");
            var deployment   = mediator.Request(new GetDeploymentRequest(deploymentId.ToDeploymentId()), CancellationToken.None).GetAwaiter().GetResult().Deployment;

            var jiraServiceDeskChangeRequestId = context.Variables.Get("Octopus.Action.JiraIntegration.ServiceDesk.ServiceId");

            if (string.IsNullOrWhiteSpace(jiraServiceDeskChangeRequestId))
            {
                throw new ControlledActionFailedException("ServiceId is not set");
            }

            try
            {
                jiraDeployment.PublishToJira("in_progress", deployment, new JiraServiceDeskApiDeployment(jiraServiceDeskChangeRequestId), taskLog, CancellationToken.None).GetAwaiter().GetResult();
            }
            catch (JiraDeploymentException exception)
            {
                throw new ControlledActionFailedException(exception.Message);
            }

            return(ActionHandlerResult.FromSuccess());
        }
Beispiel #13
0
        public bool SendFrames(ActionHandlerResult frameData)
        {
            bool ret = false;

            if (frameData != null && frameData.NextActions != null)
            {
                var sendFrames = frameData.NextActions.Where(x => x is TextApiMessage);
                if (sendFrames.Any())
                {
                    foreach (TextApiMessage frame in sendFrames)
                    {
                        byte[] tmp = CreateBuffer(frame);
                        int    res = WriteData(tmp);
                        ret = res > 0;
                        frameData.Parent.AddTraceLogItem(DateTime.Now, tmp, true);
                    }
                    if (frameData.NextFramesCompletedCallback != null)
                    {
                        frameData.NextFramesCompletedCallback(ret);
                    }
                }
            }
            return(ret);
        }
Beispiel #14
0
 public void Add(ActionHandlerResult frame)
 {
     _queue.Add(frame);
 }
Beispiel #15
0
 public void Consume(ActionHandlerResult ahResult)
 {
     Send(ahResult);
 }
Beispiel #16
0
        public bool Send(ActionHandlerResult ahResult)
        {
            bool ret = false;

            if (ahResult != null && ahResult.NextActions != null)
            {
                var sendFrames = ahResult.NextActions.Where(x => x is CommandMessage);
                if (sendFrames.Any())
                {
                    ret = true;
                    foreach (CommandMessage frame in sendFrames)
                    {
                        byte[] tmp     = _createFrameBuffer(frame);
                        byte[] dataTmp = frame.Data;
                        if (frame.IsSequenceNumberRequired)
                        {
                            dataTmp = new byte[frame.Data.Length + 1];
                            Array.Copy(frame.Data, 0, dataTmp, 0, frame.Data.Length);
                            dataTmp[dataTmp.Length - 1] = frame.SequenceNumber;
                        }
                        _ackSignal.Reset();
                        _isTransmitted = false;
                        _writeData(tmp);
                        ahResult.Parent.AddTraceLogItem(DateTime.Now, dataTmp, true);
                        if (!frame.IsNoAck)
                        {
                            int countCAN = 0;
                            int countNAK = 0;
                            while (countCAN < 10 && countNAK < 2 && !_isTransmitted && _queue.IsOpen)
                            {
                                bool res = _ackSignal.WaitOne(ACK_TIME);
                                if (!_isTransmitted && _queue.IsOpen)
                                {
                                    _writeData(tmp);
                                    ahResult.Parent.AddTraceLogItem(DateTime.Now, dataTmp, true);
                                    if (res)
                                    {
                                        countCAN++;
                                        Thread.Sleep(countCAN * 200); //wait after CAN received (for example ctrl is busy with smart start)
                                        $"CAN RECEIVED {countCAN}"._DLOG();
                                    }
                                    else
                                    {
                                        countNAK++;
                                    }
                                }
                            }
                        }
                        else
                        {
                            _isTransmitted = true;
                        }
                        ret &= _isTransmitted;
                    }
                    if (ahResult.NextFramesCompletedCallback != null)
                    {
                        ahResult.NextFramesCompletedCallback(ret);
                    }
                }
            }
            return(ret);
        }
Beispiel #17
0
        //static Regex reg_news_qq_url = new Regex(@"http://news.qq.com/(.*?|\s*?)/[0-9]+/[0-9_]+.htm[l]{0,1}", RegexOptions.IgnoreCase);
        //static Regex reg_news_qq_title = new Regex(@"<div\s+id=""ArticleTit"">(.*?|\s*?)</div>", RegexOptions.IgnoreCase);

        ActionHandlerResult BeforeCreateShareHandler(BeforeCreateShare args)
        {
            ActionHandlerResult result;
            ShareContent        share = args.ShareContent;

            string htmlContent = GetContent(share.URL);

            if (htmlContent == null)
            {
                result = new ActionHandlerResult();
                //result.HasError = true;
                result.ErrorMessage = "无法找到该网页";
                return(result);
            }

            //视频
            if (reg_video_youtube.IsMatch(share.URL))
            {
                share.Catagory = ShareType.Video;
                share.Content  = reg_video_youtube.Match(share.URL).Groups[2].Value;
                share.Domain   = "youtube.com";
            }
            else if (reg_video_youku.IsMatch(share.URL))
            {
                share.Catagory = ShareType.Video;
                share.Domain   = "youku.com";
                share.Content  = reg_video_youku.Match(share.URL).Groups[1].Value;
                ProcessTitle(share, reg_video_youkutitle, htmlContent);
                ProcessImg(share, reg_video_youkuimgurl, htmlContent);
            }
            else if (reg_video_ku6_url1.IsMatch(share.URL))
            {
                share.Domain   = "ku6.com";
                share.Catagory = ShareType.Video;
                share.Content  = reg_video_ku6_url1.Match(share.URL).Groups[2].Value;
                ProcessTitle(share, reg_video_ku6_title, htmlContent);
                ProcessImg(share, reg_video_ku6_imgurl, htmlContent);
            }
            else if (reg_video_ku6_url2.IsMatch(share.URL))
            {
                share.Domain   = "ku6.com";
                share.Catagory = ShareType.Video;
                share.Content  = reg_video_ku6_url2.Match(share.URL).Groups[1].Value;
                ProcessTitle(share, reg_video_ku6_title, htmlContent);
                ProcessImg(share, reg_video_ku6_imgurl, htmlContent);
            }
            else if (reg_video_tudou.IsMatch(share.URL))
            {
                share.Domain   = "tudou.com";
                share.Catagory = ShareType.Video;
                share.Content  = reg_video_tudou.Match(share.URL).Groups[1].Value;
                ProcessTitle(share, reg_video_tudoutitle, htmlContent);
                ProcessImg(share, reg_video_tudouimgurl, htmlContent);
            }
            else if (reg_video_5show_url.IsMatch(share.URL))
            {
                share.Domain = "5show.com";
                return(ProcessVideo(share, reg_video_5show_swf, 2, htmlContent));
            }
            else if (reg_video_sina_url.IsMatch(share.URL))
            {
                share.Domain = "sina.com.cn";
                return(ProcessVideo(share, reg_video_sina_swf, 2, htmlContent));
            }
            else if (reg_video_sohu_url.IsMatch(share.URL))
            {
                string id   = reg_video_sohu_url.Match(share.URL).Groups[1].Value;
                string info = GetContent("http://v.blog.sohu.com/videinfo.jhtml?m=view&id=" + id + "&outType=3", Encoding.ASCII);
                if (info != null)
                {
                    Match match = reg_video_sohu_titleAndImg.Match(info);
                    if (match.Success)
                    {
                        share.ImgUrl = match.Groups["imgurl"].Value + "_1.jpg";
                        share.Title  = StringUtil.HexDecode(match.Groups["title"].Value);
                    }
                }
                share.Domain = "sohu.com";
                return(ProcessVideo(share, reg_video_sohu_swf, 1, htmlContent));
            }
            else if (reg_video_pomoho_url1.IsMatch(share.URL) || reg_video_pomoho_url2.IsMatch(share.URL))
            {
                share.Domain = "pomoho.com";
                ProcessTitle(share, reg_video_pomoho_title, htmlContent);
                return(ProcessVideo(share, reg_video_pomoho_swf, 1, htmlContent));
            }
            else if (reg_video_mofile.IsMatch(share.URL))
            {
                share.Domain   = "mofile.com";
                share.Catagory = ShareType.Video;
                Match match = reg_video_mofile_titleAndImgurl.Match(htmlContent);
                if (match.Success)
                {
                    share.Title  = match.Groups["title"].Value;
                    share.ImgUrl = "http://" + match.Groups["imgurl"].Value;
                }
                share.Content = reg_video_mofile.Match(share.URL).Groups[1].Value;
            }
            else if (reg_video_mofile_url2.IsMatch(share.URL))
            {
                Match match = reg_video_mofile_titleAndImgurl.Match(htmlContent);
                if (match.Success)
                {
                    share.Title  = match.Groups["title"].Value;
                    share.ImgUrl = "http://" + match.Groups["imgurl"].Value;
                }
                share.Domain   = "mofile.com";
                share.Catagory = ShareType.Video;
                share.Content  = reg_video_mofile_url2.Match(share.URL).Groups[1].Value;
            }
            else if (reg_video_baidu_url.IsMatch(share.URL))
            {
                share.Domain = "tieba.baidu.com";
                return(ProcessVideo(share, reg_video_baidu_swf, 1, htmlContent));
            }
            else if (reg_video_ouou_url.IsMatch(share.URL))
            {
                share.Domain = "ouou.com";
                return(ProcessVideo(share, reg_video_ouou_swf, 1, htmlContent));
            }

            return(null);
        }