/// <summary> ///sorting the state for population, Density and Area /// </summary> public static string SortCSVFileOnNumbersAndWriteInJsonAndReturnData(string filePath, string jsonFilepath, string sortBy) { LoadCSVData(filePath, jsonFilepath); ConvertInJArrayFormat(jsonFilepath, sortBy); //CSVOperations.SortJsonBasedOnKeyAndValueIsNumber(jsonFilepath, sortBy); return(CSVOperations.RetriveLastDataOnKey(jsonFilepath, sortBy)); }
// Reads card info in from cvs file private void LoadCardData() { string[] cardDataStrings = CSVOperations.Load("CardIndex"); string[] line = new string[9]; for (int i = 1; i < cardDataStrings.Length - 1; i++) { CardData tempData = new CardData(); line = cardDataStrings[i].Split(','); tempData._name = line[0]; tempData._type = (CardData.CardType) int.Parse(line[1]); tempData._deploymentCost = tempData.SetDeploymentCosts(line[2]); tempData._class = (CardData.CardClass) int.Parse(line[3]); tempData._subClass = line[4]; //tempData._cardText.text = line[5]; tempData._rarity = char.Parse(line[6]); tempData._statAttack = int.Parse(line[7]); tempData._statHP = int.Parse(line[8]); tempData._cardLocation = CardData.CurrentLocation.LOOSE; tempData._cardController = null; _allCards[line[0]] = tempData; } }
/// <summary> /// Defines the entry point of the application. /// </summary> /// <param name="args">The arguments.</param> static void Main(string[] args) { IAsyncLogger logger = O365GroupsFactory.GetLogger(new string[] { Constants.AppSettings.LoggerInstanceKey }) as IAsyncLogger; var siteMapFileName = ConfigurationManager.AppSettings[Constants.AppSettings.SiteMapKey]; var siteMapSheetName = ConfigurationManager.AppSettings[Constants.AppSettings.SiteMapSheetKey]; var userMappingFileName = ConfigurationManager.AppSettings[Constants.AppSettings.UserMappingKey]; var userMappingSheetName = ConfigurationManager.AppSettings[Constants.AppSettings.UserMappingSheetKey]; var retryCount = int.Parse(ConfigurationManager.AppSettings[Constants.AppSettings.RetryCountKey]); var delay = int.Parse(ConfigurationManager.AppSettings[Constants.AppSettings.DelayKey]); var userAgent = ConfigurationManager.AppSettings[Constants.AppSettings.UserAgentKey]; logger.Log("Reading Files..."); var csvOperation = new CSVOperations(); var siteMapDetails = csvOperation.ReadFile(Constants.SiteMapSheet, siteMapFileName, siteMapSheetName).Cast <SiteMapReport>().ToList(); SecurityPrincipal.UserMappingList = csvOperation.ReadFile(Constants.UserMappingSheet, userMappingFileName, userMappingSheetName).Cast <UserMappingReport>().ToList(); if (siteMapDetails != null) { SecureString sourcePassword = GetSecureString(Constants.PasswordMessageSource); SecureString targetPassword = GetSecureString(Constants.PasswordMessageTarget); Object lockObj = new Object(); //Stopwatch watch = new Stopwatch(); //watch.Start(); List <ModernWeb> websList = new List <ModernWeb>(); logger.Log("Processing read sites from CSV"); foreach (var siteMap in siteMapDetails) { logger.Log("Reading " + siteMap.SourceSiteUrl); var modernWeb = new ModernWeb { SourceSiteUrl = siteMap.SourceSiteUrl, TargetSiteUrl = siteMap.TargetSiteUrl, SourceUserName = siteMap.SourceUser, TargetUserName = siteMap.TargetUser, SourcePassword = sourcePassword, TargetPassword = targetPassword }; WebsOperation websOperation = new WebsOperation(logger, retryCount, delay, userAgent); websOperation.ModernWeb = modernWeb; websOperation.MigrateWebs(); } //watch.Stop(); logger.Log("Processing complete"); Console.WriteLine("Processing Complete"); //Console.WriteLine("Elapsed Time " + watch.Elapsed.ToString()); } Console.ReadLine(); }
//public WebSite(int retryCount, int delay, string userAgent) //{ // RetryCount = retryCount; // Delay = delay; // UserAgent = userAgent; //} /// <summary> /// Exports the users for the current website. /// </summary> public (string, string) ExportUsers() { ConsoleOperations.WriteToConsole("Exporting users for website: " + SourceSiteUrl, ConsoleColor.White); var domainToSearch = ConfigurationManager.AppSettings[Constants.AppSettings.DomainToSearchKey]; var exportReportFileName = ConfigurationManager.AppSettings[Constants.AppSettings.UserExportSiteMapReportKey]; var batchSize = ConfigurationManager.AppSettings[Constants.AppSettings.BatchSizeKey]; var csvOperation = new CSVOperations(); string completedSite = string.Empty; string erroredSite = string.Empty; try { var userInformationList = Web.SiteUserInfoList; var camlQuery = CamlQuery.CreateAllItemsQuery(int.Parse(batchSize), new string[] { "FieldValuesAsText" }); ClientContext.ExecutingWebRequest += delegate(object sender, WebRequestEventArgs e) { e.WebRequestExecutor.WebRequest.UserAgent = UserAgent; }; List <ListItem> items = new List <ListItem>(); do { ListItemCollection listItemCollection = userInformationList.GetItems(camlQuery); ClientContext.Load(listItemCollection); //ClientContext.ExecuteQuery(); ClientContext.ExecuteQueryWithIncrementalRetry(RetryCount, Delay); items.AddRange(listItemCollection); camlQuery.ListItemCollectionPosition = listItemCollection.ListItemCollectionPosition; } while (camlQuery.ListItemCollectionPosition != null); ConsoleOperations.WriteToConsole($"Extracted all users for {SourceSiteUrl}", ConsoleColor.Green); IEnumerable <User> domainUsers = GetDesiredDomainUsers(items, domainToSearch); ConsoleOperations.WriteToConsole($"Writing Users List for {SourceSiteUrl}. Total users found are: " + domainUsers.Count(), ConsoleColor.Yellow); bool isSuccess = csvOperation.WriteCsv(domainUsers, exportReportFileName); if (isSuccess) { completedSite = SourceSiteUrl; } else { erroredSite = SourceSiteUrl; } } catch (Exception ex) { ConsoleOperations.WriteToConsole($"Error in Exporting users {ex.Message}", ConsoleColor.Red); erroredSite = SourceSiteUrl; } return(completedSite, erroredSite); }
public void LoadFromDataSetFile(string fileName, int maxParallelThreads) { CSVOperations csv = new CSVOperations(); FileData fd = csv.Read(fileName, maxParallelThreads); //Shallow Copy of Data _trainingData = fd.values;// new double[fd.attributeHeaders.Length][]; _attributeHeaders = fd.attributeHeaders; _indexTargetAttribute = fd.attributeHeaders.Length - 1; }
public void CSV_file_read_invalid_2_raises_exception() { IFileOperations csvOps = new CSVOperations(); string path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; path = path + "\\CSVReadInvalid2Test.csv"; FileData fd; fd = csvOps.Read(path, -1); }
static void Main(string[] args) { var EmployeeList = CSVOperations.GetEmployeesFromCSV(); LoginAndValidation.AdminLogin(EmployeeList); string inputName = ""; while (true) { Console.WriteLine("Write 1 to print all Employees. \n" + "Write 2 to create a new Employee. \n" + "Write 3 to edit a Employee. \n" + "Write 4 to save Employees to CSV-file.\n" + "Write 5 to remove a Employee."); string x = ""; x = Console.ReadLine(); if (x == "1") { Console.Clear(); CSVOperations.PrintEmployees(EmployeeList); continue; } if (x == "2") { Console.Clear(); CSVOperations.AddEmployee(EmployeeList); continue; } if (x == "3") { Console.Clear(); CSVOperations.EditEmployee(inputName, EmployeeList); continue; } if (x == "4") { Console.Clear(); CSVOperations.SaveToCSV(EmployeeList); continue; } if (x == "5") { CSVOperations.RemoveEmployee(EmployeeList); continue; } } }
public static string ConvertInJArrayFormat(string jsonFilepath, string sortBy) { try { //convert json data into JArray Format JArray arr = CSVOperations.SortJsonBasedOnKey(jsonFilepath, sortBy); var jsonArray = JsonConvert.SerializeObject(arr, Formatting.Indented); File.WriteAllText(jsonFilepath, jsonArray); return(null); } catch { throw new CensusAnalyzerException(CensusAnalyzerException.ExceptionType.Invalid_Census_Data, "Invalid Census Data"); } }
static void Main(string[] args) { var EmployeeList = CSVOperations.GetEmployeesFromCSV(); string inputName = LoginAndValidation.UserLogin(EmployeeList); while (true) { Console.WriteLine("Write 1 to print all Employees. \n" + "Write 2 to view your info. \n" + "Write 3 to edit your info. \n" + "Write 4 to save Employees to CSV-file.\n"); string x = ""; x = Console.ReadLine(); if (x == "1") { Console.Clear(); CSVOperations.PrintEmployees(EmployeeList); continue; } if (x == "2") { Console.Clear(); CSVOperations.PrintCurrentUser(inputName, EmployeeList); continue; } if (x == "3") { inputName = CSVOperations.EditCurrentUser(inputName, EmployeeList); continue; } if (x == "4") { CSVOperations.SaveToCSV(EmployeeList); continue; } x = ""; } }
public void CSV_file_read() { IFileOperations csvOps = new CSVOperations(); string path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; path = path + "\\CSVReadTest.csv"; FileData fd; try { fd = csvOps.Read(path, -1); } catch { Assert.Fail(); return; } Assert.AreEqual(fd.attributeHeaders.Length, 3); Assert.AreEqual(fd.values[0].Length, 31); }
public void CSV_file_write() { IFileOperations csvOps = new CSVOperations(); string path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; path = path + "\\CSVWriteTest.csv"; //Delete file if (File.Exists(path)) { File.Delete(path); } try { csvOps.Write(_trainingData, _attributeHeaders, path); } catch { Assert.Fail(); return; } Assert.IsTrue(File.Exists(path)); }
/// <summary> /// Defines the entry point of the application. /// </summary> /// <param name="args">The arguments.</param> static void Main(string[] args) { Console.WriteLine("Please enter the user name."); string userName = Console.ReadLine(); //ConfigurationManager.AppSettings["UserName"]; Console.WriteLine("Please enter the password."); string txtPassword = Console.ReadLine(); //ConfigurationManager.AppSettings["Password"]; string webUrl = ConfigurationManager.AppSettings["WebUrl"]; string groupExportPath = ConfigurationManager.AppSettings["GroupExportPath"]; string groupExportSheetName = ConfigurationManager.AppSettings["GroupExportSheetName"]; var csvOperation = new CSVOperations(); var groupDetails = csvOperation.ReadFile("GroupExport", groupExportPath, groupExportSheetName).Cast <GroupExportReport>().ToList(); if (groupDetails != null) { foreach (var group in groupDetails) { if (!string.IsNullOrEmpty(group.Id)) { Console.WriteLine("Processing " + group.DisplayName); var Id = group.Id.Substring(group.DisplayName.Length + 1); ClaimsWebClient wc = new ClaimsWebClient(new Uri(webUrl), userName, txtPassword); var fileRelativeUrl = Constants.GROUP_STATUS_URL + $"?id={Id}&target=site"; //https://tenantname.sharepoint.com/_layouts/groupstatus.aspx?id=567da1b0-8a75-4405-9553-12e8c30c1234&target=site byte[] response = wc.DownloadData(webUrl + fileRelativeUrl); Console.WriteLine("Processed " + group.DisplayName); } } } Console.WriteLine("Operation Completed Successfully!"); Console.Read(); }
/// <summary> ///sorting the state for population /// </summary> public static int SortCSVFileWriteInJsonAndReturnNumberOfStatesSorted(string filePath, string jsonFilepath, string sortBy) { LoadCSVData(filePath, jsonFilepath); return(CSVOperations.SortJsonBasedOnKeyAndReturnNumberOfStatesSorted(jsonFilepath, sortBy)); }
/// <summary> ///Method for sort last value from json file /// </summary> public static string SortCSVFileWriteInJsonAndReturnLastData(string filePath, string jsonFilepath, string sortBy) { LoadCSVData(filePath, jsonFilepath); ConvertInJArrayFormat(jsonFilepath, sortBy); return(CSVOperations.RetriveLastDataOnKey(jsonFilepath, sortBy)); }
static void Main(string[] args) { IAsyncLogger logger = O365GroupsFactory.GetLogger(new string[] { Constants.AppSettings.LoggerInstanceKey }) as IAsyncLogger; var siteMapFileName = ConfigurationManager.AppSettings[Constants.AppSettings.UserExportSiteMapKey]; var siteMapSheetName = ConfigurationManager.AppSettings[Constants.AppSettings.SiteMapSheetKey]; var retryCount = int.Parse(ConfigurationManager.AppSettings[Constants.AppSettings.RetryCountKey]); var delay = int.Parse(ConfigurationManager.AppSettings[Constants.AppSettings.DelayKey]); var userAgent = ConfigurationManager.AppSettings[Constants.AppSettings.UserAgentKey]; List <string> completedSitesList = new List <string>(); List <string> erroredSitesList = new List <string>(); ConsoleOperations.WriteToConsole("Reading Files...", ConsoleColor.White); var csvOperation = new CSVOperations(); var siteMapDetails = csvOperation.ReadFile(Constants.AppSettings.UserExportSiteMapKey, siteMapFileName, siteMapSheetName).Cast <UserExportSiteMapReport>().ToList(); if (siteMapDetails != null) { SecureString sourcePassword = GetSecureString(Constants.PasswordMessageSource); //Stopwatch watch = new Stopwatch(); //watch.Start(); List <WebSite> websList = new List <WebSite>(); ConsoleOperations.WriteToConsole("Processing read sites from CSV", ConsoleColor.White); foreach (var siteMap in siteMapDetails) { logger.Log("Reading " + siteMap.SourceSiteUrl); var website = new WebSite { SourceSiteUrl = siteMap.SourceSiteUrl.Trim(), SourceUserName = siteMap.SourceUser.Trim(), SourcePassword = sourcePassword, Delay = delay, RetryCount = retryCount, UserAgent = userAgent }; websList.Add(website); } try { WebsUtility websOperation = new WebsUtility(retryCount, delay, userAgent); websOperation.WebSiteList = websList; (completedSitesList, erroredSitesList) = websOperation.ExportUsersList(); } catch (Exception ex) { ConsoleOperations.WriteToConsole("Error ocurred: " + ex.Message, ConsoleColor.Red); } //watch.Stop(); logger.Log("Processing complete"); ConsoleOperations.WriteToConsole($"Processing Complete; Total successful site count: {completedSitesList.Count}. The completed list is as follows:", ConsoleColor.Green); completedSitesList.ForEach(site => { ConsoleOperations.WriteToConsole(site, ConsoleColor.DarkCyan); }); ConsoleOperations.WriteToConsole("Total Errored sites: " + erroredSitesList.Count, ConsoleColor.Red); if (erroredSitesList.Count > 0) { ConsoleOperations.WriteToConsole("List: ", ConsoleColor.Red); erroredSitesList.ForEach(site => { ConsoleOperations.WriteToConsole(site, ConsoleColor.Red); }); } Console.ReadLine(); //Console.WriteLine("Elapsed Time " + watch.Elapsed.ToString()); } }