Beispiel #1
0
        protected override void ProcessRecord()
        {
            //TraceControlSettings.TraceLevel = System.Diagnostics.SourceLevels.All;
            //TraceControlSettings.AddTraceListener(new TextWriterTraceListener("XrmTooling.txt"));

            try
            {
                var service = ConnectToCrm();

                WriteDebug("Instantiating logic...");
                var logic = new ExportLogic(service);

                WriteDebug("Retrieving teams...");
                var teams = logic.RetrieveTeams();

                if (ExportAll.IsPresent)
                {
                    WriteDebug("Exporting ALL teams...");
                    logic.Export(FileName, teams);
                }
                else if (TeamNames != null && TeamNames.Length > 0)
                {
                    WriteDebug("Exporting teams: " + string.Join(", ", TeamNames));
                    logic.Export(FileName, teams.Where(t => TeamNames.Contains(t.Name)));
                }
                else if (TeamIds != null && TeamIds.Length > 0)
                {
                    WriteDebug("Exporting teams with Ids: " + string.Join(", ", TeamIds));
                    logic.Export(FileName, teams.Where(t => TeamIds.Contains(t.TeamId)));
                }
                else
                {
                    throw new ArgumentException("Encountered unexpected combination of arguments. Please review documentation and try again.");
                }
            }
            catch (Exception ex)
            {
                ThrowTerminatingError(new ErrorRecord(ex, ex.GetType().Name, ErrorCategory.NotSpecified, null));
            }
        }
Beispiel #2
0
        public void Draft(int i)
        {
            iteration++;
            try
            {
                //i will be -1 when no available players are left, i will be >= count if fair team is impossible
                if (i >= 0 && i < Players.Count)
                {
                    if (isPromisingTeam(i))
                    {
                        //Assign player to team
                        Players[i].isDrafted = true;
                        FinalTeam.Add(Players[i]);

                        //Draft next available
                        Draft(lowestAvail());

                        //Drafting is complete
                        if (FinalTeam.Count == Players.Count)
                        {
                            if (completeTeams >= sentinel || deviation > maxDeviation)
                            {
                                return;
                            }
                            String teamId = GetTotalTeamId(FinalTeam);
                            if (!TeamIds.Contains(teamId))
                            {
                                //TeamSet finalSet =  new TeamSet(FinalTeam, playersPerTeam, averageRank, teamId);
                                //String teamId = GetTotalTeamId(finalSet.TeamList);
                                //finalSet.teamId = teamId;

                                try
                                {
                                    TeamIds.Add(teamId);
                                    //@TA NOTE using a dictionary slows the process exponentially
                                    //team id is key, this will not allow duplicates
                                    CompletedSets.Add(new TeamSet(FinalTeam, playersPerTeam, averageRank, teamId));
                                    //CompletedSets.Add(teamId, finalSet);
                                    completeTeams++;
                                    // PrintTeams();
                                }
                                catch (Exception ex)
                                {
                                }
                            }

                            //PrintTeams();
                            //PrintTeamsOdds();
                        }

                        //Keep back tracking to get all possible combinations draft next
                        Players[i].isDrafted = false;
                        FinalTeam.Remove(FinalTeam[FinalTeam.Count - 1]);
                    }

                    //Player did not fit on team or we back tracked, draft next player
                    Draft(i + 1);
                }
            }
            catch (Exception ex)
            {
            }
        }