public void VisualizeProducts(DataIn data, string searchText = "no text") { var listData = new List <Product>(); foreach (var product in data.data) { if (product.SubCategoryId == subCategory.Id) { Image image = new Image(); var stream = new MemoryStream(product.Image); image.Source = ImageSource.FromStream(() => { return(stream); }); var currentProduct = new Product { Id = product.Id, SubCategory = product.SubCategory, SubCategoryId = product.SubCategoryId, Photo = image.Source, Image = product.Image, LangText = product.LangText, Name = product.Name }; listData.Add(currentProduct); } } if (searchText != "no text") { listData = listData.Where(x => x.Name.ToLower().Contains(searchText.ToLower())).ToList(); } listView.ItemsSource = listData; listView.IsRefreshing = false; }
public void VisualizeProducts(DataIn data, string searchText = "no text") { var listData = new List <SubCategory>(); foreach (var item in data.subCats) { Image image = new Image(); var stream = new MemoryStream(item.Image); image.Source = ImageSource.FromStream(() => { return(stream); }); var currentSubCategory = new SubCategory { Id = item.Id, Category = item.Category, CategoryId = item.CategoryId, Photo = image.Source, Name = item.Name }; listData.Add(currentSubCategory); } if (searchText != "no text") { listData = listData.Where(x => x.Name.ToLower().Contains(searchText.ToLower())).ToList(); } initialListView.ItemsSource = listData; initialListView.IsRefreshing = false; }
public MainPage(DataIn data, SubCategory subCat) { retrievedData = data; subCategory = subCat; InitializeComponent(); Title = subCat.Name; VisualizeProducts(data); }
private void ReaderThread() { using StreamReader read = new StreamReader(pipeIn); string?data; while ((data = read.ReadLine()) != null) { DataIn?.Invoke(this, new PipeReadEventArgs(data)); } }
public async void RefreshDataAsync(string searchText = "no text") { var client = new HttpClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenCode); //to implement with local stored timestamp if null => then 0 client.DefaultRequestHeaders.Add("Timestamp", await GetCurrentTimestamp()); //var uri = new Uri("http://stoianpp-001-site1.htempurl.com/api/values"); var uri = new Uri("http://stoianpp-001-site2.htempurl.com/api/values"); var response = await client.GetAsync(uri); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); DataIn data = JsonConvert.DeserializeObject <DataIn>(content); retrievedData = data; var newTimestamp = data.lastUpdated; if (data.longTimestamp.Split(new char[] { ' ' }).Length > 1) { newTimestamp += " " + data.longTimestamp.Split(new char[] { ' ' })[1]; } await fileSystem.WriteTextAsync("datain", content); await fileSystem.WriteTextAsync("timestamp", newTimestamp); Indicator.IsRunning = false; Indicator.IsVisible = false; VisualizeProducts(data); } else if (response.StatusCode == System.Net.HttpStatusCode.NotFound) { var content = await fileSystem.GetFile("datain"); DataIn data = JsonConvert.DeserializeObject <DataIn>(content); retrievedData = data; Indicator.IsRunning = false; Indicator.IsVisible = false; VisualizeProducts(data); } }
public string Calculate(DataIn dataIn) { int x = dataIn.A / dataIn.C; int y = dataIn.B / dataIn.C; int n = x * y; if (n > 0) { double s = dataIn.A * dataIn.B - n * Math.Pow(dataIn.C, 2); return("Прямоугольник " + dataIn.A + " х " + dataIn.B + " размещает " + n + " квадрат(-а,-ов) со стороной " + dataIn.C + "\nПлощадь ненезанятой части прямоугольника составляет: " + s + " кв.ед."); } else { return("На прямоугольнике " + dataIn.A + " х " + dataIn.B + " нельзя разместить ни одного квадрата со стороной " + dataIn.C); } }
public override void Go() { Start : Console.Clear(); Console.WriteLine("Task4"); Calculation calculation = new Calculation(); Console.WriteLine("Введите размеры сторон Исходного Прямоугольника " + "A, B " + "и размер стороны вписываемого Квадрата С\n" + "(целые положительные числа)"); DataIn dataIn = new DataIn(); Console.WriteLine("\n" + calculation.Calculate(dataIn)); Console.WriteLine("\nДля выхода - ESK - "); if (Console.ReadKey().Key != ConsoleKey.Escape) { goto Start; } }
public virtual void Shutdown(IEvolutionState state) { // prevent me from hitting this multiple times lock (_shutDownLock) { if (ShuttingDown) { return; } ShuttingDown = true; } // don't want to miss any of these so we'll wrap them individually try { // BRS: TODO : Not sure if shutdown status was intended here? DataOut.Write((byte)SlaveEvaluationType.Shutdown); } catch (Exception) { } // exception, not IOException, because JZLib throws some array exceptions try { DataOut.Flush(); } catch (Exception) { } try { DataOut.Close(); } catch (Exception) { } try { DataIn.Close(); } catch (Exception) { } try { EvalSocket.Close(); } catch (IOException) { } State.Output.SystemMessage(ToString() + " Slave is shutting down...."); SlaveMonitor.UnregisterSlave(this); // unregister me BEFORE I reschedule my jobs RescheduleJobs(State); lock (_jobs) { // notify my threads now that I've closed stuff in case they're still waiting SlaveMonitor.NotifyMonitor(_jobs); Reader.Interrupt(); // not important right now but... Writer.Interrupt(); // very important that we be INSIDE the jobs synchronization here so the writer doesn't try to wait on the monitor again. } State.Output.SystemMessage(ToString() + " Slave exits...."); }
private void ReadLoop() { Boolean Aborted = false; while (!Aborted) { try { System.Threading.Thread.Sleep(50); Receive(SystemSocket); if (receiveDone.WaitOne(SocketTimeoutMS)) { byte Data; Queue <byte> NewData = new Queue <byte>(); while (InBuffer.TryDequeue(out Data)) { NewData.Enqueue(Data); } if (NewData.Count > 0) { DataIn?.Invoke(this, NewData); } } } catch (ThreadAbortException) { Aborted = true; } catch { // Continue } } }
/// <summary> /// Platform-specific subclasses can call this to trigger the DataIn event /// </summary> /// <param name="DataBytes">Data received</param> protected void TriggerDataIn(Queue <byte> DataBytes) { DataIn?.Invoke(this, DataBytes); }
//FeederDemoCS.Run static void Main(string[] args) { // Create one joystick object and a position structure. joystick = new vJoy(); iReport = new vJoy.JoystickState(); //Server di = new DataIn(); // Device ID can only be in the range 1-16 if (args.Length > 0 && !String.IsNullOrEmpty(args[0])) { id = Convert.ToUInt32(args[0]); } if (id <= 0 || id > 16) { Console.WriteLine("Illegal device ID {0}\nExit!", id); return; } // Get the driver attributes (Vendor ID, Product ID, Version Number) if (!joystick.vJoyEnabled()) { Console.WriteLine("vJoy driver not enabled: Failed Getting vJoy attributes.\n"); return; } else { Console.WriteLine("Vendor: {0}\nProduct :{1}\nVersion Number:{2}\n", joystick.GetvJoyManufacturerString(), joystick.GetvJoyProductString(), joystick.GetvJoySerialNumberString()); } // Get the state of the requested device VjdStat status = joystick.GetVJDStatus(id); switch (status) { case VjdStat.VJD_STAT_OWN: Console.WriteLine("vJoy Device {0} is already owned by this feeder\n", id); break; case VjdStat.VJD_STAT_FREE: Console.WriteLine("vJoy Device {0} is free\n", id); break; case VjdStat.VJD_STAT_BUSY: Console.WriteLine("vJoy Device {0} is already owned by another feeder\nCannot continue\n", id); return; case VjdStat.VJD_STAT_MISS: Console.WriteLine("vJoy Device {0} is not installed or disabled\nCannot continue\n", id); return; default: Console.WriteLine("vJoy Device {0} general error\nCannot continue\n", id); return; } ; // Check which axes are supported bool AxisX = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_X); bool AxisY = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Y); bool AxisZ = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Z); bool AxisRX = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RX); bool AxisRZ = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RZ); // Get the number of buttons and POV Hat switchessupported by this vJoy device int nButtons = joystick.GetVJDButtonNumber(id); int ContPovNumber = joystick.GetVJDContPovNumber(id); int DiscPovNumber = joystick.GetVJDDiscPovNumber(id); // Print results Console.WriteLine("\nvJoy Device {0} capabilities:\n", id); Console.WriteLine("Numner of buttons\t\t{0}\n", nButtons); Console.WriteLine("Numner of Continuous POVs\t{0}\n", ContPovNumber); Console.WriteLine("Numner of Descrete POVs\t\t{0}\n", DiscPovNumber); Console.WriteLine("Axis X\t\t{0}\n", AxisX ? "Yes" : "No"); Console.WriteLine("Axis Y\t\t{0}\n", AxisX ? "Yes" : "No"); Console.WriteLine("Axis Z\t\t{0}\n", AxisX ? "Yes" : "No"); Console.WriteLine("Axis Rx\t\t{0}\n", AxisRX ? "Yes" : "No"); Console.WriteLine("Axis Rz\t\t{0}\n", AxisRZ ? "Yes" : "No"); // Test if DLL matches the driver UInt32 DllVer = 0, DrvVer = 0; bool match = joystick.DriverMatch(ref DllVer, ref DrvVer); if (match) { Console.WriteLine("Version of Driver Matches DLL Version ({0:X})\n", DllVer); } else { Console.WriteLine("Version of Driver ({0:X}) does NOT match DLL Version ({1:X})\n", DrvVer, DllVer); } // Acquire the target if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(id)))) { Console.WriteLine("Failed to acquire vJoy device number {0}.\n", id); return; } else { Console.WriteLine("Acquired: vJoy device number {0}.\n", id); } Console.WriteLine("\npress enter to stat feeding"); //Console.ReadKey(true); //joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref maxval); while (true) { System.Threading.Thread.Sleep(10000); } } // Main
public virtual bool ReadLoop() { IJob job; try { // block on an incoming job var val = (sbyte)DataIn.ReadByte(); Debug(ToString() + " Incoming Job"); // okay, we've got a job. Grab the earliest job, that's what's coming in lock (_jobs) { job = _jobs[0]; // NO SUCH ELEMENT EXCEPTION } Debug("Got job: " + job); ///// NEXT STEP: COPY THE INDIVIDUALS FORWARD INTO NEWINDS. ///// WE DO THIS SO WE CAN LOAD THE INDIVIDUALS BACK INTO NEWINDS ///// AND THEN COPY THEM BACK INTO THE ORIGINAL INDS, BECAUSE ECJ ///// DOESN'T HAVE A COPY(INDIVIDUAL,INTO_INDIVIDUAL) FUNCTION job.CopyIndividualsForward(); // now start reading. Remember that we've already got a byte. for (var i = 0; i < job.NewInds.Length; i++) { Debug(ToString() + " Individual# " + i); Debug(ToString() + " Reading Byte"); if (i > 0) { val = (sbyte)DataIn.ReadByte(); // otherwise we've got it already } Debug(ToString() + " Reading Individual"); if (val == (sbyte)SlaveReturnType.Individual) { job.NewInds[i].ReadIndividual(State, DataIn); } else if (val == (sbyte)SlaveReturnType.Fitness) { job.NewInds[i].Evaluated = DataIn.ReadBoolean(); job.NewInds[i].Fitness.ReadFitness(State, DataIn); } else if (val == (sbyte)SlaveReturnType.Nothing) { // do nothing } Debug(ToString() + " Read Individual"); } ///// NEXT STEP: COPY THE NEWLY-READ INDIVIDUALS BACK INTO THE ORIGINAL ///// INDIVIDUALS. THIS IS QUITE A HACK, IF YOU READ JOB.JAVA // Now we have all the individuals in so we're good. Copy them back into the original individuals job.CopyIndividualsBack(State); ///// LAST STEP: LET OTHERS KNOW WE'RE DONE AND AVAILABLE FOR ANOTHER JOB // we're all done! Yank the job from the queue so others think we're available lock (_jobs) { _jobs.RemoveAt(0); } // And let the slave monitor we just finished a job SlaveMonitor.NotifySlaveAvailability(this, job, State); } catch (IOException) { Shutdown(State); // will redistribute jobs return(false); } return(true); }
public void Balance_Simpay(long providerID, decimal balance) { Helpers.Connection.sConnectionStringDatabase = ConfigurationManager.ConnectionStrings["sConnectionString_SystemWarning"].ConnectionString; WarningLibrary.SystemWarning sw = new WarningLibrary.SystemWarning(); //list chua KQ check Rules List <LOGSEND> result = sw.Balance_Simpay(providerID, balance); //dataset chua Logsend DataSet dsLogSend = new DataSet(); //bien thong tin message Int64 intLOGSEND_AUTOID = 0; Int64 intRULE_AUTOID = 0; Int64 intACTION_AUTOID = 0; Int64 intUSERSEND_AUTOID = 0; Boolean blExist = false; //bien thoi gian DateTime dtNow; DateTime dtRULE_CREATEDATE; TimeSpan tsDiff; Int64 intDiff; //config dang Giay Int64 intInterval = Convert.ToInt64(ConfigurationManager.AppSettings["interval"]); //kiem tra trung message if (result.Count() > 0) { //kiem tra tung message foreach (LOGSEND log in result) { dsLogSend.Clear(); Helpers.Connection.sConnectionStringDatabase = ConfigurationManager.ConnectionStrings["sConnectionString_SystemWarning"].ConnectionString; dsLogSend = DataOut.SW_LOGSEND_Select_All(); //neu dsLogSend co message - set tung message trong Logsend if (dsLogSend.Tables[0].Rows.Count > 0) { blExist = false; //kiem tra ton tai message for (int i = 0; i < dsLogSend.Tables[0].Rows.Count; i++) { //lay thong tin message intLOGSEND_AUTOID = Convert.ToInt64(dsLogSend.Tables[0].Rows[i][LOGSEND.COLUMN_LOGSEND_AUTOID].ToString().Trim()); intRULE_AUTOID = Convert.ToInt64(dsLogSend.Tables[0].Rows[i][LOGSEND.COLUMN_RULE_AUTOID].ToString().Trim()); intACTION_AUTOID = Convert.ToInt64(dsLogSend.Tables[0].Rows[i][LOGSEND.COLUMN_ACTION_AUTOID].ToString().Trim()); intUSERSEND_AUTOID = Convert.ToInt64(dsLogSend.Tables[0].Rows[i][LOGSEND.COLUMN_USERSEND_AUTOID].ToString().Trim()); //truong hop ton tai message (cung [RULE_AUTOID], [ACTION_AUTOID], [USERSEND_AUTOID]) if (log.RULE_AUTOID == intRULE_AUTOID && log.ACTION_AUTOID == intACTION_AUTOID && log.USERSEND_AUTOID == intUSERSEND_AUTOID) { blExist = true; break; } else { blExist = false; } } //truong hop ton tai message if (blExist) { dtNow = DateTime.Now; dtRULE_CREATEDATE = Convert.ToDateTime(DataOut.SW_LOGSEND_SelectByID(intLOGSEND_AUTOID).Tables[0].Rows[0][LOGSEND.COLUMN_RULE_CREATEDATE].ToString().Trim()); tsDiff = dtNow - dtRULE_CREATEDATE; intDiff = (tsDiff.Days * 24 * 60 * 60) + (tsDiff.Hours * 60 * 60) + (tsDiff.Minutes * 60) + tsDiff.Seconds; //truong hop <= config if (intDiff <= intInterval) { //cap nhat thoi gian message //DataIn.SW_LOGSEND_UpdateByID(intLOGSEND_AUTOID); } else { //cap nhat thoi gian message DataIn.SW_LOGSEND_UpdateByID(intLOGSEND_AUTOID); //thuc hien gui Balance_Simpay_Insert_Send(log, balance); } } //truong hop khong ton tai message else { //insert Logsend DataIn.SW_LOGSEND_Insert(log); //thuc hien gui Balance_Simpay_Insert_Send(log, balance); } } //neu dsLogSend khong co message - insert va gui luon else { //insert Logsend DataIn.SW_LOGSEND_Insert(log); //thuc hien gui Balance_Simpay_Insert_Send(log, balance); } } } }
private void Balance_Simpay_Insert_Send(LOGSEND log, decimal balance) { //thoi gian he thong string strNow = string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now); string strNowTitle = string.Format("{0:yyyy-MM-dd}", DateTime.Now); //lay title Email la ruleName Helpers.Connection.sConnectionStringDatabase = ConfigurationManager.ConnectionStrings["sConnectionString_SystemWarning"].ConnectionString; string titleEmail = DataOut.SW_RULES_SelectByID(log.RULE_AUTOID).Tables[0].Rows[0][RULE.COLUMN_RULE_NAME].ToString().Trim(); titleEmail += " " + strNowTitle; //lay noi dung gui la gia tri cua cac conditions string strContentSend = null; DataSet dsContent = new DataSet(); dsContent = DataOut.SW_RULEDETAIL_BALANCESSIMPAY_All(log.RULE_AUTOID); for (int i = 0; i < dsContent.Tables[0].Rows.Count; i++) { //chi lay cac conditions da Active if (Convert.ToBoolean(dsContent.Tables[0].Rows[i][RULEDETAIL.COLUMN_RULEDETAIL_ISACTIVE].ToString().Trim()) == true) { //truong hop condition "so du tai khoan" if (Convert.ToInt64(dsContent.Tables[0].Rows[i][RULEDETAIL.COLUMN_CONDITION_AUTOID].ToString().Trim()) == 3) { strContentSend += (dsContent.Tables[0].Rows[i]["CONDITION_NAME"].ToString().Trim()) + ": " + balance.ToString("#,##0 VNĐ") + " " + (dsContent.Tables[0].Rows[i]["KEY_NOTE2"].ToString().Trim()) + " " + Convert.ToDecimal(dsContent.Tables[0].Rows[i]["KEYVALUE"].ToString().Trim()).ToString("#,##0 VNĐ") + "; "; } //truong hop condition "nha cung cap" else if (Convert.ToInt64(dsContent.Tables[0].Rows[i][RULEDETAIL.COLUMN_CONDITION_AUTOID].ToString().Trim()) == 2) { strContentSend += (dsContent.Tables[0].Rows[i]["CONDITION_NAME"].ToString().Trim()) + ": " + (dsContent.Tables[0].Rows[i]["KEYVALUE"].ToString().Trim()) + "; "; } //truong hop condition "thoi diem" else if (Convert.ToInt64(dsContent.Tables[0].Rows[i][RULEDETAIL.COLUMN_CONDITION_AUTOID].ToString().Trim()) == 4) { //truong hop la ngay co dinh if (Convert.ToInt64(dsContent.Tables[0].Rows[i][RULEDETAIL.COLUMN_RULEDETAIL_TYPE].ToString().Trim()) == 3) { strContentSend += (dsContent.Tables[0].Rows[i]["CONDITION_NAME"].ToString().Trim()) + ": " + (dsContent.Tables[0].Rows[i]["KEYVALUE"].ToString().Trim()) + "; "; } //truong hop chon thu else { strContentSend += (dsContent.Tables[0].Rows[i]["CONDITION_NAME"].ToString().Trim()) + ": " + (dsContent.Tables[0].Rows[i]["CONDITIONDETAIL_VALUE"].ToString().Trim()) + "; "; } } } } //send message Helpers.Connection.sConnectionStringDatabase = ConfigurationManager.ConnectionStrings["sConnectionString_Crm"].ConnectionString; //SMS if (log.ACTION_AUTOID == 1) { //insert vao DB SMS Librarys.CRM.TRANSACTION trans = new Librarys.CRM.TRANSACTION(); trans.RECEIVEACCOUNT = log.USERSEND_HANDPHONE; trans.FROMACCOUNT = ""; trans.LASTUPDATE = DateTime.Now; trans.CODE = 1; trans.STATUS = 1; trans.VALUE = Protect.RemoveVNString(strContentSend).Trim(); trans.TRANSTYPECODE = 4; trans.RECEIVEID = DateTime.Now.Ticks.ToString(); trans.COMSIMID = 0; DataIn.CRM_TRANSACTION_InsertUpdate(trans); } //EMAIL else if (log.ACTION_AUTOID == 2) { //insert vao DB EMAIL Librarys.CRM.TRANSACTION trans = new Librarys.CRM.TRANSACTION(); trans.RECEIVEACCOUNT = log.USERSEND_EMAIL; trans.FROMACCOUNT = "*****@*****.**"; trans.LASTUPDATE = DateTime.Now; trans.CODE = 1; trans.STATUS = 1; trans.VALUE = string.Format("{0}##{1}", titleEmail, strNow + "; " + strContentSend); trans.TRANSTYPECODE = 10; trans.RECEIVEID = "<" + Guid.NewGuid().ToString() + "@simpay.com.vn>"; trans.COMSIMID = 0; DataIn.CRM_TRANSACTION_InsertUpdate(trans); } }