public ATFReturnResult DoATFTest(string args)
    {
        //Debugger.Break();

        string          err    = "";
        StringBuilder   sb     = new StringBuilder();
        ATFReturnResult result = new ATFReturnResult();

        // ----------- Example for Argument Parsing --------------- //
        Dictionary <string, string> dict = new Dictionary <string, string>();

        if (!ArgParser.parseArgString(args, ref dict))
        {
            err = "Invalid Argument String" + args;
            MessageBox.Show(err, "Exit Test Plan Run", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return(new ATFReturnResult(err));
        }


        int simHw;

        try
        {
            simHw = ArgParser.getIntItem(ArgParser.TagSimMode, dict);
        }
        catch (Exception ex)
        {
            err = ex.Message;
            MessageBox.Show(err, "Exit Test Plan Run", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return(new ATFReturnResult(err));
        }
        // ----------- END of Argument Parsing Example --------------- //


        #region Custom Test Coding Section
        //////////////////////////////////////////////////////////////////////////////////
        // ----------- ONLY provide your Custom Test Coding here --------------- //
        // Example for build TestPlan Result (Single Site)

        if (_firstTest == true)
        {
            string[] resultFileName = ATFCrossDomainWrapper.GetClothoCurrentResultFileFullPath().Split('_');

            if (_guiEnable == true)
            {
                if (resultFileName[0] != _initProTag)
                {
                    _programLoadSuccess = false;
                    MessageBox.Show("Product Tag accidentally changed to: " + resultFileName[0] + "\nPlease re-load program!");
                    err = "Product Tag accidentally changed to: " + resultFileName[0];
                    return(new ATFReturnResult(err));;
                }
            }
        }

        if (!_programLoadSuccess)
        {
            MessageBox.Show("Program was not loaded successfully.\nPlease resolve errors and reload program.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            err = "Program was not loaded successfully.\nPlease resolve errors and reload program";
            return(new ATFReturnResult(err));
        }

        GU.DoTest_beforeCustomCode();

        #region Retrieve lot ID# (for Datalog)
        //Retrieve lot ID#
        _tPVersion      = ATFCrossDomainWrapper.GetStringFromCache(PublishTags.PUBTAG_PACKAGE_TP_VER, "");
        _productTag     = ATFCrossDomainWrapper.GetStringFromCache(PublishTags.PUBTAG_PACKAGE_TAG, "").ToUpper();
        _lotId          = ATFCrossDomainWrapper.GetStringFromCache(PublishTags.PUBTAG_LOT_ID, "").ToUpper();
        _sublotId       = ATFCrossDomainWrapper.GetStringFromCache(PublishTags.PUBTAG_SUB_LOT_ID, "").ToUpper();
        _waferId        = ATFCrossDomainWrapper.GetStringFromCache(PublishTags.PUBTAG_WAFER_ID, "");
        _opId           = ATFCrossDomainWrapper.GetStringFromCache(PublishTags.PUBTAG_OP_ID, "");
        _handlerSn      = ATFCrossDomainWrapper.GetStringFromCache(PublishTags.PUBTAG_HANDLER_SN, "");
        _testerHostName = System.Net.Dns.GetHostName();
        _ipEntry        = System.Net.Dns.GetHostEntry(_testerHostName);
        _testerIp       = NetworkHelper.GetStaticIPAddress().Replace(".", ""); //Use Clotho method , original code has issue with IPv6 - 12/03/2015 Shaz

        if (_myDut.TmpUnitNo == 0)                                             //do this for the 1st unit only
        {
            _dt = DateTime.Now;

            if (_productTag != "")
            {
                _newPath = System.IO.Path.Combine(_activeDir, _productTag + "_" + _lotId + "_" + _sublotId + "_" + _testerIp + "\\");
            }
            else
            {
                string tempname = "DebugMode_" + _dt.ToString("yyyyMMdd" + "_" + "HHmmss");
                _newPath    = System.IO.Path.Combine(_activeDir, tempname + "\\");
                _productTag = "Debug";
                _lotId      = "1";
            }

            //Parse information to LibFbar
            _myDut.SnpFile.FileSourcePath     = _newPath;
            _myDut.SnpFile.FileOutputFileName = _productTag;
            _myDut.SnpFile.LotID = _lotId;
            // Added variable to solve issue with datalog when Inari operator using
            //Tally Generator to close lot instead of unload test plan
            //WaferId,OpId and HandlerSN are null when 2nd Lot started - make assumption that this 3 param are similar 1st Lot
            _tempWaferId         = _waferId;
            _tempOpId            = _opId;
            _tempHandlerSn       = _handlerSn;
            _previousLotSubLotId = _currentLotSubLotId;
        }

        DateTime      DT           = DateTime.Now;
        List <string> FileContains = new List <string>();
        FileContains.Add("DATE_START=" + DT.ToString("yyyyMMdd"));
        FileContains.Add("TIME_START=" + DT.ToString("HHmmss"));
        FileContains.Add("ENTITY=NA");
        FileContains.Add("SOURCE=FBAR");
        FileContains.Add("GROUP=DUPLEXER");
        FileContains.Add("PRODUCT_TAG=" + _productTag);
        FileContains.Add("LOT_NUMBER=" + _lotId + "_" + _sublotId);
        FileContains.Add("WAFER_ID=" + _waferId);
        FileContains.Add("OPERATOR_NAME=" + _opId);
        FileContains.Add("TESTER_NAME=FBAR");
        FileContains.Add("TESTER_HOST_NAME=" + _testerHostName);
        FileContains.Add("HANLDER_NAME=" + _handlerSn);
        FileContains.Add("TEST_PLAN_VERSION=" + _tPVersion);

        _myDut.FileFileContain = FileContains;
        #endregion

#if (!DEBUG)
        _myDut.TmpUnitNo = Convert.ToInt32(ATFCrossDomainWrapper.GetClothoCurrentSN());
#else
        _myDut.TmpUnitNo++;      // Need to enable this during debug mode
#endif

        for (GU.runLoop = 1; GU.runLoop <= GU.numRunLoops; GU.runLoop++)
        {
            ATFResultBuilder.Reset();
            _firstTest = false;
            _myDut.RunTest(ref result);

            GU.DoTest_afterCustomCode(ref result);
        }

        // ----------- END of Custom Test Coding --------------- //
        //////////////////////////////////////////////////////////////////////////////////
        #endregion Custom Test Coding Section

        //ATFReturnResult result = new ATFReturnResult();
        //ATFResultBuilder.AddResult(ref result, "PARAM", "X", 0.01);
        return(result);
    }
    public string DoATFInit(string args)
    {
        Debugger.Break();

        StringBuilder sb = new StringBuilder();

        sb.AppendFormat("Enter DoATFInit: {0}\nDo Minimum HW Init:\n{1}\n", args, ATFInitializer.DoMinimumHWInit());


        #region Custom Init Coding Section
        //////////////////////////////////////////////////////////////////////////////////
        // ----------- ONLY provide your Custom Init Coding here --------------- //

        _myDut = new MyDutFbar(ref sb)
        {
            TmpUnitNo = 0
        };
        _programLoadSuccess = _myDut.InitSuccess;

        _initProTag = ATFCrossDomainWrapper.GetStringFromCache(PublishTags.PUBTAG_PACKAGE_TAG, "");
        Clotho.EnableClothoTextBoxes(false);
        _firstTest = true;

        //Check boolean status of GUI ENTRY
        _guiEnable = false;

        FrmDataInput formInput;
        if (_guiEnable == true)
        {
            #region New InputUI
            formInput = new FrmDataInput();

            //string AssemblyID_ = " ";

            DialogResult rslt = formInput.ShowDialog();

            if (rslt == DialogResult.OK)
            {
                ATFCrossDomainWrapper.StoreStringToCache(PublishTags.PUBTAG_OP_ID, formInput.OperatorId + "\t");
                ATFCrossDomainWrapper.StoreStringToCache(PublishTags.PUBTAG_LOT_ID, formInput.LotId + "\t");
                ATFCrossDomainWrapper.StoreStringToCache(PublishTags.PUBTAG_SUB_LOT_ID, formInput.SublotId + "\t");
                ATFCrossDomainWrapper.StoreStringToCache(PublishTags.PUBTAG_DIB_ID, formInput.LoadBoardId + "\t");
                ATFCrossDomainWrapper.StoreStringToCache(PublishTags.PUBTAG_CONTACTOR_ID, formInput.ContactorId + "\t");
                ATFCrossDomainWrapper.StoreStringToCache(PublishTags.PUBTAG_HANDLER_SN, formInput.HandlerId);
                ATFCrossDomainWrapper.StoreStringToCache(PublishTags.PUBTAG_PCB_ID, "NA");
                ATFCrossDomainWrapper.StoreStringToCache(PublishTags.PUBTAG_WAFER_ID, "NA");
            }

            #region Lock ClothoUI
            if (!formInput.AdminLevel)
            {
                Thread t1 = new Thread(new ThreadStart(LockClothoInputUi));
                t1.Start();
            }
            #endregion

            #endregion
        }


        GU.DoInit_afterCustomCode(true, false, _myDut.ProductTag, @"C:\Avago.ATF.Common\Results");

        // ----------- END of Custom Init Coding --------------- //
        //////////////////////////////////////////////////////////////////////////////////
        #endregion Custom Init Coding Section

        return(sb.ToString());
    }