private AA.AsinJsonFile findSeriesFileDirectOrSku(Book.Part part, bool fileOnly, string filePrefix, GetProductsDelegate getProducts) { // try to find sims by series file, either locally, relative or absolute // precondition content meta file is available // either by ASIN (single-part book) or by SKU (multipart book) // get asin var afi = part.AaxFileItem; string asin = afi.ContentMetadataFile?.ASIN; if (asin is null) { Log(3, this, () => $"ASIN not found."); return(null); } Log(3, this, () => $"ASIN={asin}{(filePrefix.IsNullOrWhiteSpace() ? string.Empty : $", prefix={filePrefix}")}");
static async Task Main(string[] args) { Console.WriteLine("------------------Mutable------------------------"); //Values are mutable int x = 10; x = 20; x = 30; x = 50; Console.WriteLine(x); Console.WriteLine("------------------Dynamically implemented properties------------------------"); Students student = new Students("James", 18, "21/ug-223/BSCS", 3000); //age mutable student.age = 28; //name is readyOnly(immutable); cannot rewrite //student.name="Job"; //regNo is mutable student.regNo = "21/ug-335/BSSE-S"; student.tution = 7000; Console.WriteLine(student.name); Console.WriteLine(student.age); Console.WriteLine(student.regNo); Console.WriteLine(student.tution); Console.WriteLine("------------------Implicity typing------------------------"); var scores = new[] { 1, 2.5, 3, 4, 5 }; foreach (double element in scores) { Console.WriteLine(element); } Console.WriteLine("------------------Object and collactions initializers------------------------"); Products phone = new Products { pPrice = 3000, pName = "Smart Phone", pQuantity = 20, pBrand = "Oppo" }; phone = new Products(); Console.WriteLine(phone.pName + "" + phone.pPrice); // List<Products> products = new List<Products>{ // new Products { pPrice = 3000, pName = "Smart Phone", pQuantity = 20, pBrand = "Oppo" }, // new Products { pPrice = 6000, pName = "Smart Tv", pQuantity = 10, pBrand = "Samsung" } , // new Products { pPrice = 4000, pName = "Fridge", pQuantity = 5, pBrand = "LG" }, // new Products { pPrice = 5000, pName = "Oven", pQuantity = 2, pBrand = "LG" }, // }; GetProductsDelegate productsDelegate = new GetProductsDelegate(getProducts); List <Products> products = productsDelegate.Invoke(); Console.WriteLine("------------------Lambda expression ------------------------"); //Lambda expression //Lambda calculus //Anything coming after the arrow funtion, should be condition. List <Products> hightPrices = products.FindAll(value => value.pPrice < 4000); foreach (Products product in hightPrices) { Console.WriteLine(product.pName + " " + product.pPrice); } Console.WriteLine("------------------LINQ Expression queries------------------------"); // IEnumerable <Products> lowPrices = from product in products where product.pPrice < 5000 orderby product.pName ascending select product; foreach (Products product in lowPrices) { Console.WriteLine(product.pName + " " + product.pPrice); } Console.WriteLine("------------------ANONYMOUS DATATYPE------------------------"); // Example in Js /* * Example in Js * var user={ * fristname:'', * lastname:'', * nationality:'', * } */ // Example in C# var user = new { firstname = "Victor", lastname = "Manakana", nationality = "SA" }; Console.WriteLine(user.firstname); Console.WriteLine(user.lastname); Console.WriteLine(user.nationality); //Dynamic Console.WriteLine("--------------------------dynamic typing ----------------------------"); Calculator <double> calculator = new Calculator <double>(); dynamic sum = calculator.sum(10.9, 12.9); Console.WriteLine("Sum is" + sum); //Optional parameters Console.WriteLine("--------------------------Optional parameters ----------------------------"); Lecturers lecturers = new Lecturers(200.0); Console.WriteLine("Sum is: " + lecturers.name + " " + lecturers.wages); Lecturers lecturers2 = new Lecturers(name: "James", wages: 200.0); //Asynchronous Console.WriteLine("--------------------------Asynchronous----------------------------"); // synchronization , asynchronization // T1 & T2, waits for t1 to finish // OS dictionary Program program = new Program(); await program.checkin(); await fetchUserData(); await fetchResultsData(); //Asynchronous Pending tasks Console.WriteLine("--------------------------Moving next within Pending tasks----------------------------"); IAsyncEnumerator <int> asyncEnumerator = pendingTasks(1, 4).GetAsyncEnumerator(); while (await asyncEnumerator.MoveNextAsync()) { Console.WriteLine($"Current task value is :{asyncEnumerator.Current}"); } //Tasks, threads, Jobs Console.WriteLine("--------------------------Custom task types revisited----------------------------"); // Thread thread= new Thread(new ThreadStart(thread1)); // thread.Start(); // await doPurchaseJob1(); //Run multiple tasks at the same time //Tasks, threads, Jobs Console.WriteLine("--------------------------Run multiple tasks at the same time----------------------------"); List <Task> tasks = new List <Task>(); tasks.Add(Task.Run(async() => { await Task.Delay(1000); Console.WriteLine("Task1"); })); tasks.Add(Task.Run(async() => { await Task.Delay(2000); Console.WriteLine("Task2"); })); tasks.Add(Task.Run(async() => { //await Task.Delay(3000); await fetchUserData(); Console.WriteLine("Task3"); })); tasks.Add(Task.Run(async() => { await Task.Delay(2000); Console.WriteLine("Task4"); })); // Task.WaitAll(tasks.ToArray()); //Convariance and contravariance Console.WriteLine("-------------------------------------Convariance and contravariance------------------------------"); //------------contravariance // Cow cow= new Mammars(); Mammars mammars = new Cow(); // Mammars mammars1= new Animal(); Animal animal = new Mammars(); //------------convariance IEnumerable <Animal> animals = new List <Mammars>(); //out , in //SmartPhone<PhoneTypes> smartPhones= new List<IApple>(); Console.WriteLine("-------------------------------------Convariance and contravariance------------------------------"); string studentDetails = String.Format(" Hey Mr {0} and {1}", "James", "John"); long workerId = 11100000; string workerDetails = String.Format(" Hey My ID is {0}", workerId); // Decimal //double x= 30.00000000000000000000000000000000E25; Decimal wages = 5000000000000000.50m; //5,000,000,000,000,000 string engineerWages = String.Format("James wages is {0:N0}", wages); Console.WriteLine(studentDetails); Console.WriteLine(wages); String[] students = { "Victor", "Faith", "Khoza" }; Decimal[] marks = new Decimal[] { 80000000, 8000000, 90000000 }; String[] positions = new String[] { "Senior softwareEng ", "Senior softwareEng", "Senior softwareEng" }; var stringBuilder = new System.Text.StringBuilder(); stringBuilder.Append(String.Format("{0,5} {1,8} {2,7} \n\n", "Engineers", "Salary", "Position")); for (int i = 0; i < students.Length; i++) { stringBuilder.Append(String.Format("{0,5} {1,8:N0} {2,7} \n\n", students[i], marks[i], positions[i])); } Console.WriteLine(stringBuilder); }
private bool findSeriesFile(Book.Part part, bool fileOnly, string filePrefix, GetProductsDelegate getProducts) { try { var simsBySeriesFile = findSeriesFileDirectOrSku(part, fileOnly, filePrefix, getProducts); if (simsBySeriesFile is null || simsBySeriesFile.Filename is null) { part.AaxFileItem.SimsBySeriesFile = new AA.AsinJsonFile(null, null); return(false); } part.AaxFileItem.SimsBySeriesFile = simsBySeriesFile; string metafile = simsBySeriesFile.Filename; Log(3, this, () => $"\"{metafile.SubstitUser ()}\""); return(true); } catch (Exception exc) { Log(1, this, () => exc.ToShortString()); return(false); } }