示例#1
0
 public static void Reset()
 {
     _configuration = null;
     _mapper        = null;
     isMobile       = null;
     isNative       = null;
 }
示例#2
0
        public static void Configure(SmartResultConfiguration configuration)
        {
            mapperConfiguration = new MapperConfiguration(cfg =>
            {
                configuration.Profiles.ForEach(p =>
                {
                    cfg.AddProfile(p);
                });
            });
            mapper = mapperConfiguration.CreateMapper();

            isMobile = configuration.IsMobileBrowser();
            isNative = configuration.IsNativeDevice();
        }
示例#3
0
        private void ExecuteInvoke(object contextObject)
        {
            CodeActivityContext context = contextObject as CodeActivityContext;

            string commandLine     = FileName.Get(context) + " " + Arguments.Get(context);
            bool   useShellExecute = UseShellExecute.Get <bool>(context);
            bool   showWindow      = ShowWindow.Get <bool>(context);
            string stdOut          = string.Empty;
            string errOut          = string.Empty;
            bool   isNative        = IsNative.Get(context);

            WriteLineConsole((useShellExecute ? "Open : " : "") + commandLine);

            Process processRunner = new Process();

            if (isNative)
            {
                processRunner.StartInfo.FileName = Environment.GetEnvironmentVariable("COMSPEC");
            }
            else
            {
                processRunner.StartInfo.FileName  = FileName.Get(context);
                processRunner.StartInfo.Arguments = Arguments.Get(context);
            }


            processRunner.StartInfo.WorkingDirectory = WorkingDirectory.Get <string>(context);
            processRunner.StartInfo.UseShellExecute  = useShellExecute;
            processRunner.StartInfo.CreateNoWindow   = showWindow;
            processRunner.StartInfo.Verb             = Verb.Get <string>(context);

            if (!useShellExecute && !showWindow)
            {
                processRunner.StartInfo.RedirectStandardOutput = true;
                processRunner.StartInfo.RedirectStandardError  = true;
                processRunner.StartInfo.RedirectStandardInput  = true;
            }

            try
            {
                processRunner.Start();
            }
            catch (Exception ex)
            {
                ExitCode.Set(context, 1);
                if (ThrowOnExitCode.Get <bool>(context))
                {
                    throw new InvalidOperationException(ex.Message);
                }
                else
                {
                    WriteLineConsole(ex.Message);
                    Output.Set(context, ex.Message);
                }
                return;
            }

            if (!useShellExecute && !showWindow)
            {
                if (IsNative.Get(context))
                {
                    processRunner.StandardInput.WriteLine("echo off");
                    processRunner.StandardInput.WriteLine(commandLine);
                    processRunner.StandardInput.WriteLine("exit");
                }

                string outPutLine;
                string outPut        = string.Empty;
                bool   blockedOutput = IsNative.Get(context);

                while ((outPutLine = processRunner.StandardOutput.ReadLine()) != null)
                {
                    if ((blockedOutput) || (outPutLine == "exit"))
                    {
                        if (outPutLine == commandLine)
                        {
                            blockedOutput = false;
                        }
                        continue;
                    }
                    stdOut += outPutLine + "\n";
                    WriteLineConsole(outPutLine);
                }

                while ((outPutLine = processRunner.StandardError.ReadLine()) != null)
                {
                    if ((blockedOutput) || (outPutLine == "exit"))
                    {
                        if (outPutLine == commandLine)
                        {
                            blockedOutput = false;
                        }
                        continue;
                    }
                    errOut += outPutLine + "\n";
                    WriteLineConsole(outPutLine);
                }
                processRunner.WaitForExit();

                ExitCode.Set(context, processRunner.ExitCode);

                bool success = (processRunner.ExitCode == 0);

                if (success)
                {
                    Output.Set(context, stdOut);
                }
                else
                {
                    if (!ThrowOnExitCode.Get <bool>(context))
                    {
                        Output.Set(context, errOut);
                    }
                }

                if (processRunner != null && !processRunner.HasExited)
                {
                    processRunner.Kill();
                    processRunner = null;
                }

                if (!success && ThrowOnExitCode.Get <bool>(context))
                {
                    throw new InvalidOperationException(errOut);
                }
            }
        }
示例#4
0
 public SmartResultConfiguration(List <Profile> profiles, IsMobile isMobile = null, IsNative isNative = null)
 {
     this.profiles = profiles;
     this.isMobile = isMobile != null ? isMobile : IsMobileBrowser;
     this.isNative = isNative != null ? isNative : IsMobileBrowser;
 }
示例#5
0
 public SmartResultConfiguration(List <ISmartResultProfile> profiles, IsMobile isMobile = null, IsNative isNative = null)
 {
     this.Profiles = profiles;
     this.isMobile = isMobile ?? IsMobileBrowser;
     this.isNative = isNative;
 }