Esempio n. 1
0
        public static int Run(NewOptions options, string[] args)
        {
            MeetingFile.Meeting meeting = new MeetingFile.Meeting();
            meeting.ID       = options.MeetingID;
            meeting.Password = options.Password;

            string name = options.Name;

            while (name.Length == 0)
            {
                Console.Write("Name for this meeting: ");
                name = Console.ReadLine();
            }

            while (meeting.ID.Length == 0)
            {
                Console.Write("Meeting ID: ");
                meeting.ID = Console.ReadLine();
            }

            if (meeting.Password.Length == 0)
            {
                Console.Write("Password: ");
                meeting.Password = Console.ReadLine();
            }

            return(Convert.ToInt32(MeetingFile.AddMeeting(name, meeting)));
        }
Esempio n. 2
0
        public static int Run(UpdateOptions options, string[] args)
        {
            // parse through args
            if (options.Name.Length == 0)
            {
                List <string> trimmedArgs = new List <string>(args);
                trimmedArgs.RemoveAll(s => s.StartsWith("-") || s == "update");

                options.Name = trimmedArgs.Count > 0 ? trimmedArgs[0] : options.Name;
            }

            // if user didn't supply name of object to change
            while (options.Name.Length == 0)
            {
                Console.Write("Name of meeting to update: ");
                options.Name = Console.ReadLine();
            }

            Dictionary <string, MeetingFile.Meeting> dict = MeetingFile.toObject(
                File.ReadAllText(Program.MEETING_FILE_PATH)
                );

            MeetingFile.Meeting meeting;

            // try to update
            if (dict.TryGetValue(options.Name, out meeting))
            {
                // store in new values user supplied
                meeting.ID       = options.MeetingID.Length > 0 ? options.MeetingID : meeting.ID;
                meeting.Password = options.Password.Length > 0 ? options.Password : meeting.Password;

                // if no change, prompt user
                if (meeting.ID != options.MeetingID)
                {
                    meeting.ID = IOCommands.ReadInputWithDefault("Meeting ID: ", meeting.ID);
                }

                // if no change, prompt user
                if (meeting.Password != options.Password || meeting.Password.Length == 0)
                {
                    meeting.Password = IOCommands.ReadInputWithDefault("Meeting password: "******"Could not find meeting with name " + options.Name);
                Console.ForegroundColor = defaultColor;

                return(1);
            }
        }