예제 #1
0
        //internal void Creation_Team()
        //{
        //    string DirectionCsvFile = @"C:\_dev\itop\cmdb_itop\cmd_test_sharp_lib\data\directions.csv.txt";

        //    if(File.Exists(DirectionCsvFile))
        //    {
        //        TextReader reader = File.OpenText(DirectionCsvFile);
        //        List<TeamDirection> TeamDirection = CsvSerializer.DeserializeFromReader<List<TeamDirection>>(reader);
        //        Creation_Team_Direction(TeamDirection,true);
        //    }
        //    else
        //    {
        //        List<string> DirectionCsaShortName = new List<string>();
        //        DirectionCsaShortName.Add("DAFSI");
        //        DirectionCsaShortName.Add("AC");
        //        DirectionCsaShortName.Add("DICI");
        //        DirectionCsaShortName.Add("DAEI");
        //        DirectionCsaShortName.Add("DP");
        //        DirectionCsaShortName.Add("DG");
        //        DirectionCsaShortName.Add("DJ");
        //        DirectionCsaShortName.Add("DMR");
        //        DirectionCsaShortName.Add("DMT");
        //        DirectionCsaShortName.Add("PRESIDENCE");

        //        List<string> DirectionCsaEmail = new List<string>();
        //        DirectionCsaEmail.Add("*****@*****.**");
        //        DirectionCsaEmail.Add("*****@*****.**");
        //        DirectionCsaEmail.Add("*****@*****.**");
        //        DirectionCsaEmail.Add("*****@*****.**");
        //        DirectionCsaEmail.Add("*****@*****.**");
        //        DirectionCsaEmail.Add("*****@*****.**");
        //        DirectionCsaEmail.Add("*****@*****.**");
        //        DirectionCsaEmail.Add("*****@*****.**");
        //        DirectionCsaEmail.Add("*****@*****.**");
        //        DirectionCsaEmail.Add("");

        //        List<TeamDirection> TeamDirection = new List<TeamDirection>();
        //        List<string> DirectionCSA = ADUser.GetDirection();
        //        int i = 0;
        //        foreach (string dir in DirectionCSA)
        //        {
        //            TeamDirection newTeam = new TeamDirection();
        //            newTeam.NameFromAD = dir;
        //            newTeam.ShortName = DirectionCsaShortName[i];
        //            newTeam.Mail = DirectionCsaEmail[i];
        //            i++;
        //            TeamDirection.Add(newTeam);
        //        }
        //        TextWriter writer = File.CreateText(DirectionCsvFile);
        //        CsvSerializer.SerializeToWriter<List<TeamDirection>>(TeamDirection, writer);
        //        writer.Close();

        //        this.Creation_Team(); // appel de creation team cette fois le fichier existe

        //    }
        //    Console.WriteLine("");

        //}
        //internal void Creation_Team_Direction(List<TeamDirection> TeamDirection, bool isDirection)
        //{
        //    foreach(TeamDirection td in TeamDirection)
        //    {
        //        Team _team = new Team();
        //        Response QueryResult = new Response();
        //        if(td.Mail == null)
        //        {
        //            td.Mail = "";
        //        }
        //        if (isDirection)
        //        {
        //            _team.Create(td.ShortName, td.Mail, "", "Direction", out QueryResult);
        //            List<string> Departements = ADUser.GetDepartements(td.NameFromAD);
        //            Creation_Team_Departement(Departements, td.ShortName);
        //        }
        //        else
        //        {
        //            _team.Create(td.ShortName, td.Mail, "", "Departement", out QueryResult);
        //        }

        //    }
        //}
        //internal void Creation_Team_Departement(List<string> Departement,string direction)
        //{
        //    List<string> DirectionCsaShortName = new List<string>();
        //    List<string> DirectionCsaEmail = new List<string>();
        //    List<TeamDirection> TeamDepartement = new List<TeamDirection>();
        //    switch (direction)
        //    {
        //        case "DAFSI":
        //            {

        //                DirectionCsaShortName.Add("Dabf");
        //                DirectionCsaShortName.Add("Dmg");
        //                DirectionCsaShortName.Add("Drh");
        //                DirectionCsaShortName.Add("Dsi");

        //                DirectionCsaEmail.Add("*****@*****.**");
        //                DirectionCsaEmail.Add("*****@*****.**");
        //                DirectionCsaEmail.Add("*****@*****.**");
        //                DirectionCsaEmail.Add("*****@*****.**");
        //                break;
        //            }
        //    }

        //    int i = 0;
        //    foreach (string Dep in Departement)
        //    {
        //        TeamDirection newTeam = new TeamDirection();
        //        newTeam.NameFromAD = Dep;
        //        newTeam.ShortName = DirectionCsaShortName[i];
        //        newTeam.Mail = DirectionCsaEmail[i];
        //        i++;
        //        TeamDepartement.Add(newTeam);
        //    }
        //    Creation_Team_Direction(TeamDepartement,false);
        //}

        internal void CreateUserInItop(List <ADUser> usersInDir, string direction, string departement, bool prestataire)
        {
            foreach (ADUser usr in usersInDir)
            {
                Person   newPerson   = new Person();
                Response QueryResult = new Response();

                string[] SplitNom = usr.CN.Split(' ');
                if (SplitNom.Length == 2)
                {
                    string nom    = usr.CN.Split(' ')[0];
                    string prenom = usr.CN.Split(' ')[1];

                    if (usr.title == null)
                    {
                        Console.WriteLine("todo titre non saisie dans l'AD: {0}", usr.CN);
                        usr.title = "err2";
                    }

                    if (usr.departement == null)
                    {
                        Console.WriteLine("todo departement non saisie dans l'AD: {0}", usr.CN);
                        usr.title = "err1";
                    }

                    // Creation du contact
                    int person_id = newPerson.Create(nom, prenom, usr.mail, usr.departement, out QueryResult);

                    // creation du lien Equipe / Person : lnkPersonToTeam

                    lnkPersonToTeam lptt         = new lnkPersonToTeam();
                    Response        QueryResult2 = new Response();

                    ContactType objContactType  = new ContactType();
                    int         role_id_interne = objContactType.GetID("Interne");
                    int         role_id_externe = objContactType.GetID("Externe");

                    if (direction != null)
                    {
                        //Get IDs ( équipe et role )
                        Team objTeam = new Team();
                        int  team_id = objTeam.GetID(direction);

                        lptt.Create(person_id, team_id, role_id_interne, out QueryResult2);
                    }

                    if (departement != null)
                    {
                        //Get IDs ( équipe et role )
                        Team objTeam = new Team();
                        int  team_id = objTeam.GetID(departement);

                        if (prestataire)
                        {
                            lptt.Create(person_id, team_id, role_id_externe, out QueryResult2);
                        }
                        else
                        {
                            lptt.Create(person_id, team_id, role_id_interne, out QueryResult2);
                        }
                    }



                    Console.WriteLine("Création d'un contact : {0}", usr.CN);
                }
            }
        }