public static void BeginLog(UserToEdit user, TextWriter w) { w.Write("\r\nLog Entry : "); w.WriteLine($"{DateTime.Now.ToLongTimeString()} {DateTime.Now.ToLongDateString()}"); w.WriteLine($" :{user.Firstname} {user.Lastname} -- {user.UserID} [REFURL: {user.refURL}]"); w.WriteLine($" :"); }
public static string UpdateUserSkillMap(UserToEdit user, string skillMap, string userOuterXml, string rootURL, string username, string password) { XmlDocument xdoc = new XmlDocument(); xdoc.LoadXml(userOuterXml); XmlNode node = xdoc.SelectSingleNode("/resource/skillMap"); //Console.WriteLine("CURRENT SKILL MAP\n" + node.OuterXml + "\n\n"); XmlDocument xskilldoc = new XmlDocument(); xskilldoc.LoadXml(skillMap); XmlNode xNew = xskilldoc.SelectSingleNode("/skillMap"); //Console.WriteLine("NEW SKILL MAP\n" + xNew.InnerXml + "\n\n"); node.InnerXml = xNew.InnerXml; //Console.WriteLine("MODIFIED SKILL MAP\n" + node.OuterXml); //Console.WriteLine(xdoc.OuterXml); string requestXML = xdoc.OuterXml; string destinationURL = rootURL + "/resource/" + user.UserID; HttpWebResponse response = postXMLData(destinationURL, requestXML, username, password); if (response.StatusCode != HttpStatusCode.OK) { throw (new System.Exception(response.StatusCode + ": " + response.StatusDescription)); } return(response.StatusCode.ToString()); }
public static UserToEdit BuildUser(string fname, string lname, string uid, string refurl, string ext, string queue) { UserToEdit user = new UserToEdit(); user.Firstname = fname; user.Lastname = lname; user.UserID = uid; user.refURL = refurl; user.Extension = ext; user.newQueue = queue; return(user); }
static void Main(string[] args) { //Required for dotnet run --project <PATH> command to be used to execute the process via batch file string workingDirectory = Environment.CurrentDirectory; Console.WriteLine("\n\nWORKING DIRECTORY: " + workingDirectory); string projectDirectory = Directory.GetParent(workingDirectory).Parent.FullName; //Console.WriteLine(projectDirectory); string jsonPath = workingDirectory + "\\appsettings.json"; var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile(jsonPath, optional: true, reloadOnChange: true); IConfigurationRoot configuration = builder.Build(); //Pull Config items string username = configuration.GetSection("UCCXCredentials")["Username"]; string password = configuration.GetSection("UCCXCredentials")["Password"]; string env = SetEnv(); string rootURL = SetRootURL(env, configuration); string filePath = SetFilePath(env, configuration); string logPath = configuration.GetSection("Logging")["Path"] + env; string logName = "WFM_UpdateQueue_" + System.DateTime.Now.ToString("MMddyyyy_hh-mm-ss") + ".txt"; logName = logPath + "\\" + logName; using (StreamWriter w = File.AppendText(logName)) { Console.WriteLine("\n>Log File Created: " + logName + "\n"); Log("Beginning Run... [ENVIRONMENT: " + env + "] [URL: " + rootURL + "] [USERNAME: "******"] [EXCEL FILE: " + filePath + "]", w); //Create Config Object //SkillsToAdd Test Information, this will come from an Excel File on NAS Drive in the future List <SkillsToAdd> nsl = new List <SkillsToAdd>(); //Initialize Excel Reader Object with file path Reader xlReader = new Reader(filePath); //Build List of agents that need their queue changed/what queue to move them to List <AgentData> agentData = new List <AgentData>(); Console.WriteLine(">Reading Agent Data from Excel File...\n"); agentData = xlReader.ReadAgentData(1); //Build list of skills required for each queue List <SkillData> skillData = new List <SkillData>(); Console.WriteLine(">Reading Skill Data from Excel File...\n"); skillData = xlReader.ReadSkillData(2); //Retrieves all Skill Information from the ../adminapi/skill endpoint to prevent multiple redundant calls List <Skill> skillsList = new List <Skill>(); Console.WriteLine(">Retrieving All Skill via API Endpoint <URL>/adminapi/skill...\n"); skillsList = GetAllSkills(username, password, rootURL + "/skill"); //Cross References the SkillsToAdd List with the Skills List pulled from API, adds necessary information to update user skillMaps //DEBUG -- Print Skills to Add //foreach (SkillsToAdd skn in nsl) //{ // Console.WriteLine("{0} -- {1}\n{2}\n\n", skn.Name, skn.CompetencyLevel, skn.refURL); //} //---------------------------- var client = new WebClient { Credentials = new NetworkCredential(username, password) }; var response = client.DownloadString(rootURL + "/resource"); XmlDocument xml = new XmlDocument(); xml.LoadXml(response); Console.WriteLine(">Users Processed: " + usersProcessed.ToString() + "/" + agentData.Count.ToString()); foreach (XmlNode xn in xml.DocumentElement) { if (agentData.Any(agent => agent.agentName == xn["firstName"].InnerText + " " + xn["lastName"].InnerText)) { usersProcessed++; //Define User Variable to pass as parameter when updating user skillMap in UpdateUserSkillMap() UserToEdit user = BuildUser(xn["firstName"].InnerText, xn["lastName"].InnerText, xn["userID"].InnerText, xn["self"].InnerText, xn["extension"].InnerText, agentData.Where(agent => agent.agentName == xn["firstName"].InnerText + " " + xn["lastName"].InnerText).Select(agent => agent.Queue).First()); nsl = UpdateSkillsToAdd(skillsList, skillData, user.newQueue, w); //Console.WriteLine("\nSKILLS BEING ADDED: \n"); //foreach(SkillsToAdd skta in nsl) //{ // Console.WriteLine("SKILL: {0} -- {1}\n{2}\n\n", skta.Name, skta.CompetencyLevel, skta.refURL); //} //Returns XML String info of skillMap node string skillMap = ReturnSkillMap(xn); //Creates new skillMap XML String to insert into user skillMap skillMap = AppendMultipleSkills(skillMap, nsl); //Console.WriteLine("SKILL MAP FOR: " + user.newQueue + "\n\n" + skillMap); //Log which user is being edited BeginLog(user, w); Log("Attempting to update the XMLNode-->skillMap for " + user.Firstname + " " + user.Lastname, w); try { //Attempt to update User skillMap UpdateUserSkillMap(user, skillMap, xn.OuterXml, rootURL, username, password); Log(">" + user.Firstname + " " + user.Lastname + "'s skills have been successfully updated for the following Queue: " + user.newQueue, w); } catch (Exception e) { //Log reason for error if occurred Log(">An Error occurred updating the XMLNode-->skillMap. Please refer to the caught exception: " + e.Message.ToString(), w); } EndLog(w); Console.SetCursorPosition(Console.CursorLeft, Console.CursorTop - 1); Console.WriteLine(">Users Processed: " + usersProcessed.ToString() + "/" + agentData.Count.ToString()); } } } }