Esempio n. 1
0
        public virtual void Execute(IEnumerable <CodeValuePair> presetArgs, Func <string, string> getValue = null)
        {
            string action = this.Title;
            string tool   = this.ToolTemplate;
            string args   = this.ToolArgsTemplate;

            try {
                StringBuilder         sout = new StringBuilder(1024), serr = new StringBuilder(512);
                Func <string, string> synthGetVal;
                if (getValue == null)
                {
                    synthGetVal = this.GetVal;
                }
                else
                {
                    synthGetVal = (s) => { return(getValue(s) ?? this.GetVal(s)); };
                }
                TextStencil tt = new TextStencil()
                {
                    FindParamValue = synthGetVal
                };
                if (presetArgs != null)
                {
                    foreach (var p in presetArgs)
                    {
                        tt.SetParameter(p.Code, p.Value);
                    }
                }

                tool = tt.Transform(this.ToolTemplate);
                args = tt.Transform(this.ToolArgsTemplate);

                action = string.Format("execute external cmd: \"{0}\" {1}", tool, args);
                var pcs = OSCommand.RunAndWait(tool, args, (s) => sout.AppendLine(s), (s) => serr.AppendLine(s), this.TimeoutSec * 1000);
                System.Threading.Thread.Sleep(20); // Sometimes sout is not populated to the end, need some cycles
                System.Diagnostics.Debug.WriteLine("XCmd: {0}\r\n\tExit code: {1}\r\n\tDuration: {4}\r\n\tStdOut:----\r\n{5}\r\n\t----\r\n\tStdErr----{6}\r\n\t----\r\n",
                                                   action, pcs.ExitCode, pcs.StartTime, pcs.ExitTime, (pcs.ExitTime - pcs.StartTime).TotalSeconds, sout, serr);
                if (pcs.ExitCode != 0)
                {
                    throw new BizException(string.Format("XCmd: {0}\r\n\tExit code: {1}\r\n\tDuration: {4}\r\n\tStdOut:----\r\n{5}\r\n\t----\r\n\tStdErr----{6}\r\n\t----\r\n",
                                                         action, pcs.ExitCode, pcs.StartTime, pcs.ExitTime, (pcs.ExitTime - pcs.StartTime).TotalSeconds, sout, serr));
                }
            }
            catch (BizException) {
                throw;
            }
            catch (Exception x) {
                x.Data["action"] = action;
                x.Data["xcmd"]   = this.Code;
                AppContext.Current.LogTechError(string.Format("Failed to {0}", action), x);
                throw new BizException(x.ToShortMsg(action));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the ff probe XML.
        /// </summary>
        /// <param name="sourcePath">The source path.</param>
        /// <returns></returns>
        /// <exception cref="Ops.NetCoe.LightFrame.BizException"></exception>
        public XElement GetFFProbeXml(string sourcePath)
        {
            StringBuilder sout = new StringBuilder(1024), serr = new StringBuilder(512);
            string        args   = string.Format("-i \"{0}\" -print_format xml -sexagesimal -show_error -show_format -show_streams", sourcePath);
            string        action = null;
            string        xtmp   = null;

            try {
                action = string.Format("execute and parse results: \"{0}\" {1}", this.FfProbePath, args);
                OSCommand.RunAndWait(this.FfProbePath, args, (s) => sout.AppendLine(s), (s) => serr.AppendLine(s));
                System.Threading.Thread.Sleep(20); // Sometimes sout is not populated to the end, need some cycles
                XElement xff = XElement.Parse(xtmp = sout.ToString());
                return(xff);
            }
            catch (Exception x) {
                AppContext.Current.LogTechError(string.Format("Failed to {0}", action), x);
                System.Diagnostics.Debug.WriteLine(xtmp);
                throw new BizException(x.ToShortMsg(action));
            }
        }