Example #1
0
		static void UnitTestNoDispatch()
		{
			CmdLineConfig cfg = new CmdLineConfig(new CmdLineSwitch[] 
				{
					new CmdLineSwitch("t", true, true, "required toggle switch t", null, null),
					new CmdLineSwitch("a", true, false, "optional toggle switch a", null, null),
					new CmdLineSwitch("b", false, false, "optional switch b", null, null),
					new CmdLineSwitch("abc", false, false, "optional multichar switch abc", null, null)
				} );

			CmdLine cl = new CmdLine(cfg);
			string sError;

			Debug.Assert(cl.FParse(new string[] { "-t" }, null, null, out sError));
			cl = new CmdLine(cfg);

			Debug.Assert(cl.FParse(new string[] { "-t", "-a" }, null, null, out sError));
			Debug.Assert(cl.FIsSwitchSet("t"));
			Debug.Assert(cl.FIsSwitchSet("a"));
			Debug.Assert(!cl.FIsSwitchSet("b"));
			Debug.Assert(!cl.FIsSwitchSet("abc"));

			cl = new CmdLine(cfg);

			Debug.Assert(cl.FParse(new string[] { "-t", "-a", "-b", "bar" }, null, null, out sError));
			Debug.Assert(cl.FIsSwitchSet("t"));
			Debug.Assert(cl.FIsSwitchSet("a"));
			Debug.Assert(cl.FIsSwitchSet("b"));
			Debug.Assert(!cl.FIsSwitchSet("abc"));

			Debug.Assert(String.Compare("bar", cl.ParamFromSwitch("b")) == 0);

			cl = new CmdLine(cfg);

			Debug.Assert(cl.FParse(new string[] { "-t", "-a", "-abc", "bar" }, null, null, out sError));
			Debug.Assert(cl.FIsSwitchSet("t"));
			Debug.Assert(cl.FIsSwitchSet("a"));
			Debug.Assert(!cl.FIsSwitchSet("b"));
			Debug.Assert(cl.FIsSwitchSet("abc"));

			Debug.Assert(String.Compare("bar", cl.ParamFromSwitch("abc")) == 0);

			cl = new CmdLine(cfg);
			Debug.Assert(!cl.FParse(new String[] { }, null, null, out sError));

			cl = new CmdLine(cfg);

			Debug.Assert(!cl.FParse(new string[] { "-t", "-a", "-abc" }, null, null, out sError));
		}
Example #2
0
        static void Main(string[] args)
        {
            UnitTest();
            string sError;

            CmdLineConfig clcfg = new CmdLineConfig(new CmdLineSwitch[]
                {
                    new CmdLineSwitch("r", false, false, "record to a file", "filename", null),
                    new CmdLineSwitch("f", true, false, "fast mode", null, null),
                    new CmdLineSwitch("p", false, false, "playback from a file", "filename", null),
                    new CmdLineSwitch("n", false, false, "name this server (for later playback)", "servername", null),
                    new CmdLineSwitch("h", false, false, "name this server share (for later playback)", "sharename", null),
                    new CmdLineSwitch("v", true, false, "verbose - show each file", null, null),
                    new CmdLineSwitch("z", true, false, "zeros - show directories that are 0 size", null, null),
                    new CmdLineSwitch("d", false, false, "depth - max depth to show", "depth", null),
                    new CmdLineSwitch("0", true, false, "depth 0 - alias for -d 0", null, null),
                    new CmdLineSwitch("1", true, false, "depth 0 - alias for -d 1", null, null),
                    new CmdLineSwitch("2", true, false, "depth 0 - alias for -d 2", null, null),
                    new CmdLineSwitch("3", true, false, "depth 0 - alias for -d 3", null, null),
                    new CmdLineSwitch("x", true, false, "exclusions - use the global exclusion list", null, null),
                    new CmdLineSwitch("X", false, false, "eXclusions - load more exclusions from the named file", "filename", null),
                    new CmdLineSwitch("i", false, false, "inclusions - this is the selection list to match against", "filename", null)
                } );
            BEList belExclusions = new BEList();
            BEList belSelection = new BEList();
            BEDir bedProgram = new BEDir(Assembly.GetExecutingAssembly().Location, "");
            BEPref bep = new BEPref(belSelection, belExclusions, bedProgram.Dir);

            bep.MaxDepth=2;

            CmdLine cl = new CmdLine(clcfg);

            if (!cl.FParse(args, bep, null, out sError))
                {
                Console.WriteLine(sError);
                cl.Usage(OutputLine);
                return;
                }

            if (belSelection.Empty)
                belSelection = null;

            BEDir bedRoot = new BEDir(Environment.CurrentDirectory + @"\", ".");	// make sure we append a "/" because otherwise we won't know its a directory

            long cBytesExcl;

            //            bedRoot.GetDirSize(".", bedRoot.DirInfo, belExclusions, null, 0, bep, out cBytesExcl);
            // are we recording, playing back, or what?
            IReportUsage iru;
            if (bep.Fast)
                {
                iru = new ConsoleReportUsage(bep);
                BEDir.GetDirSizeFromDirectoryInfo(".", bedRoot.DirInfo, belExclusions, belSelection, 0, bep, iru, out cBytesExcl);
                }
            else
                {
                if (bep.Playback)
                    {
                    bedRoot = BedFromXml(XmlReader.Create(new StreamReader(bep.RecordFile)), bep);
                    // load the file here...
                    }

                if (bep.Record)
                    {
                    iru = new RecordReportUsage(bep, bep.ServerName, bep.ServerShare);
                    }
                else
                    {
                    iru = new ConsoleReportUsage(bep);
                    }

                iru.WritePrologue();
                bedRoot.ProcessDir(belExclusions, belSelection, 0, bep, iru);
                iru.WriteEpilogue();
                iru.Flush();
                }
        }
Example #3
0
        /* A W  M A I N  F O R M */
        /*----------------------------------------------------------------------------
            %%Function: AwMainForm
            %%Qualified: ArbWeb.AwMainForm.AwMainForm
            %%Contact: rlittle

        ----------------------------------------------------------------------------*/
        public AwMainForm(string[] rgsCmdLine)
        {
            //
            // Required for Windows Form Designer support
            //
            m_plCursor = new List<Cursor>();

            InitializeComponent();

            m_srpt = new StatusBox.StatusRpt(m_recStatus);
            m_awc = new ArbWebControl(m_srpt);
            m_fDontUpdateProfile = true;
            RegistryKey rk = Registry.CurrentUser.OpenSubKey("Software\\Thetasoft\\ArbWeb");

            if (rk == null)
                rk = Registry.CurrentUser.CreateSubKey("Software\\Thetasoft\\ArbWeb");

            string []rgs = rk.GetSubKeyNames();

            foreach(string s in rgs)
                {
                m_cbxProfile.Items.Add(s);
                }
            m_rgreheProfile = new[]
                {
                    new Settings.SettingsElt("Login", Settings.Type.Str, m_ebUserID, ""),
                    new Settings.SettingsElt("Password", Settings.Type.Str, m_ebPassword, ""),
                    new Settings.SettingsElt("GameFile", Settings.Type.Str, m_ebGameFile, ""),
                    new Settings.SettingsElt("Roster", Settings.Type.Str, m_ebRoster, ""),
                    new Settings.SettingsElt("GameFileCopy", Settings.Type.Str, m_ebGameCopy, ""),
                    new Settings.SettingsElt("RosterCopy", Settings.Type.Str, m_ebRosterWorking, ""),
                    new Settings.SettingsElt("GameOutput", Settings.Type.Str, m_ebGameOutput, ""),
                    new Settings.SettingsElt("OutputFile", Settings.Type.Str, m_ebOutputFile, ""),
                    new Settings.SettingsElt("IncludeCanceled", Settings.Type.Bool, m_cbIncludeCanceled, 0),
                    new Settings.SettingsElt("ShowBrowser", Settings.Type.Bool, m_cbShowBrowser, 0),
                    new Settings.SettingsElt("LastSlotStartDate", Settings.Type.Dttm, m_dtpStart, ""),
                    new Settings.SettingsElt("LastSlotEndDate", Settings.Type.Dttm, m_dtpEnd, ""),
                    new Settings.SettingsElt("LastOpenSlotDetail", Settings.Type.Bool, m_cbOpenSlotDetail, 0),
                    new Settings.SettingsElt("LastGroupTimeSlots", Settings.Type.Bool, m_cbFuzzyTimes, 0),
                    new Settings.SettingsElt("LastTestEmail", Settings.Type.Bool, m_cbTestEmail, 0),
                    new Settings.SettingsElt("AddOfficialsOnly", Settings.Type.Bool, m_cbAddOfficialsOnly, 0),
                    new Settings.SettingsElt("AfiliationIndex", Settings.Type.Int, m_ebAffiliationIndex, 0),
                    new Settings.SettingsElt("LastSplitSports", Settings.Type.Bool, m_cbSplitSports, 0),
                    new Settings.SettingsElt("LastPivotDate", Settings.Type.Bool, m_cbDatePivot, 0),
                    new Settings.SettingsElt("LastLogToFile", Settings.Type.Bool, m_cbLogToFile, 0),
                    new Settings.SettingsElt("FilterMailMergeByRank", Settings.Type.Bool, m_cbFilterRank, 0),
                    new Settings.SettingsElt("DownloadOnlyFutureGames", Settings.Type.Bool, m_cbFutureOnly, 0),
                    new Settings.SettingsElt("LaunchMailMergeDoc", Settings.Type.Bool, m_cbLaunch, 0),
                    new Settings.SettingsElt("SetArbiterAnnouncement", Settings.Type.Bool, m_cbSetArbiterAnnounce, 0),
                };

            m_rgrehe = new []
                {
                    new Settings.SettingsElt("LastProfile", Settings.Type.Str, m_cbxProfile, "")
                };

            SetupLogToFile();

            m_reh = new Settings(m_rgrehe, "Software\\Thetasoft\\ArbWeb", "root");
            m_reh.Load();

            m_rehProfile = new Settings(m_rgreheProfile, String.Format("Software\\Thetasoft\\ArbWeb\\{0}", m_cbxProfile.Text), m_cbxProfile.Text);

            // load MRU from registry
            m_rehProfile.Load();
            m_fDontUpdateProfile = false;
            EnableControls();

            if (m_cbShowBrowser.Checked)
                m_awc.Show();

            CmdLineConfig clcfg = new CmdLineConfig(new CmdLineSwitch[]
                {
                new CmdLineSwitch("H", true /*fToggle*/, false /*fReq*/, "Update arbiter HELP NEEDED (includes downloading games, calculating slots). Requires -DS and -DE.", "help announce", null),
                new CmdLineSwitch("DS", false /*fToggle*/, false /*fReq*/, "Start date for slot calculation (required if -H specified)", "date start", null),
                new CmdLineSwitch("DE", false /*fToggle*/, false /*fReq*/, "End date for slot calculation (required if -H specified)", "date end", null),
                new CmdLineSwitch("F", false /*fToggle*/, false /*fReq*/, "Check this item in the Game/Slot filter", "Sport filter", null),
                new CmdLineSwitch("f", true /*fToggle*/, false /*fReq*/, "Force the games download to only download future games", "Future Games Only", null),
                });

            CmdLine cl = new CmdLine(clcfg);
            string sError = null;

            if (rgsCmdLine != null && rgsCmdLine.Length > 0)
                m_srpt.AddMessage(String.Format("Commandline args: {0} {1}", rgsCmdLine.Length, rgsCmdLine[0]));

            if (!cl.FParse(rgsCmdLine, this, null, out sError) || (m_fAutomateUpdateHelp && (m_sAutomateDateEnd == null || m_sAutomateDateStart == null)))
                {
                m_sbUsage = new StringBuilder();

                cl.Usage(AppendUsageString);
                MessageBox.Show(String.Format("Command Line error: {0}\n{1}", sError, m_sbUsage.ToString()), "ArbWeb");
                m_fAutomating = true;
                Close();
                }

            if (rgsCmdLine != null && rgsCmdLine.Length > 0)
                {
                m_fAutomating = true;

                if (m_fAutomateUpdateHelp)
                    {
                    DateTime dttmStart = DateTime.Parse(m_sAutomateDateStart);
                    DateTime dttmEnd = DateTime.Parse(m_sAutomateDateEnd);

                    m_cbLaunch.Checked = false;
                    m_cbSetArbiterAnnounce.Checked = true;
                    m_dtpStart.Value = dttmStart;
                    m_dtpEnd.Value = dttmEnd;
                    if (m_fForceFutureGames)
                        m_cbFutureOnly.Checked = true;

                    QueueUIOp(new DelayedUIOpDel(DoDownloadGames), new object[]{null, null});
                    QueueUIOp(new DelayedUIOpDel(CalcOpenSlots), new object[]{null, null});
                    QueueUIOp(new DelayedUIOpDel(DoCheckSportListboxes), new object[]{null, null});
                    QueueUIOp(new DelayedUIOpDel(GenMailMergeMail), new object[]{null, null});
                    QueueUIOp(new DelayedUIOpDel(DoExitApp), new object[]{null, null});

                    DoPendingQueueUIOp();
                    }
            }
        }
Example #4
0
		/* C M D  L I N E */
		/*----------------------------------------------------------------------------
			%%Function: CmdLine
			%%Contact: rlittle

		----------------------------------------------------------------------------*/
		public CmdLine(CmdLineConfig cfg)
		{
			m_cfg = cfg;

			foreach (CmdLineSwitch cls in cfg.Switches)
				{
				if (cls.Switch.Length == 1)
					{
					if (m_mpchSwitch == null)
						m_mpchSwitch = new Dictionary<char, CmdLineSwitch>();

					m_mpchSwitch.Add(cls.Switch[0], cls);
					}
				else
					{
					if (m_mpsSwitch == null)
						m_mpsSwitch = new Dictionary<string, CmdLineSwitch>();

					m_mpsSwitch.Add(cls.Switch, cls);
					}
       			cls.Reset();
				}
		}
Example #5
0
		static void UnitTestDispatch()
		{
			CmdLineConfig cfg = new CmdLineConfig(new CmdLineSwitch[] 
				{
					new CmdLineSwitch("t", true, true, "required toggle switch t", null, null),
					new CmdLineSwitch("a", true, false, "optional toggle switch a", null, null),
					new CmdLineSwitch("b", false, false, "optional switch b", null, null),
					new CmdLineSwitch("abc", false, false, "optional multichar switch abc", null, null)
				} );

			CmdLine cl = new CmdLine(cfg);
			UnitTestCmdLineDispatch cld = new UnitTestCmdLineDispatch();
			string sError;

			Debug.Assert(cl.FParse(new string[] { "-t" }, null, null, out sError));
			cl = new CmdLine(cfg);
			cld = new UnitTestCmdLineDispatch();

			Debug.Assert(cl.FParse(new string[] { "-t", "-a" }, cld, null, out sError));
			Debug.Assert(cld.m_fTSet);
			Debug.Assert(cld.m_fASet);
			Debug.Assert(!cld.m_fBSet);
			Debug.Assert(!cld.m_fABCSet);

			cl = new CmdLine(cfg);
			cld = new UnitTestCmdLineDispatch();

			Debug.Assert(cl.FParse(new string[] { "-t", "-a", "-b", "bar" }, cld, null, out sError));
			Debug.Assert(cld.m_fTSet);
			Debug.Assert(cld.m_fASet);
			Debug.Assert(cld.m_fBSet);
			Debug.Assert(!cld.m_fABCSet);

			Debug.Assert(String.Compare("bar", cld.m_sBParam) == 0);

			cl = new CmdLine(cfg);
			cld = new UnitTestCmdLineDispatch();

			Debug.Assert(cl.FParse(new string[] { "-t", "-a", "-abc", "bar" }, cld, null, out sError));
			Debug.Assert(cld.m_fTSet);
			Debug.Assert(cld.m_fASet);
			Debug.Assert(!cld.m_fBSet);
			Debug.Assert(cld.m_fABCSet);

			Debug.Assert(String.Compare("bar", cld.m_sABCParam) == 0);

			cl = new CmdLine(cfg);
			cld = new UnitTestCmdLineDispatch();

			Debug.Assert(!cl.FParse(new String[] { }, cld, null, out sError));

			cl = new CmdLine(cfg);
			cld = new UnitTestCmdLineDispatch();

			Debug.Assert(!cl.FParse(new string[] { "-t", "-a", "-abc" }, null, null, out sError));
		}