static async Task test1() { string _type = "Socks"; cAccesoDatos gDatos; gDatos = (cAccesoDatos)CObjectFactory.CreateObject("Conn", _type); gDatos.Server = "DB01"; gDatos.DataBase = "Sistemas"; gDatos.User = "******"; gDatos.Password = "******"; await gDatos.ConnectAsync(); SPFrame _sp; _sp = (SPFrame)CObjectFactory.CreateObject("SP", _type, gDatos, "pLogonUser"); _sp.AddParameterValue("User", "restelles"); _sp.AddParameterValue("Password", "G8npi3rc"); _sp.AddParameterValue("Origin", "LOGON5"); await _sp.ExecuteAsync(); RSFrame _rs; _rs = (RSFrame)CObjectFactory.CreateObject("RS", _type, "Select top 10 * from ItemsCab", gDatos); await _rs.OpenAsync(); _rs.Rows.ForEach(r => Console.WriteLine(r["UserCode"])); }
public void Classification_Fitness_Test1() { var cl1 = new List <CObject>(); var cl2 = new List <CObject>(); cl1.Add(CObjectFactory.GetFromProperties(new { x = 1, y = 1 }, "x", "y")); cl1.Add(CObjectFactory.GetFromProperties(new { x = 1, y = 2 }, "x", "y")); cl1.Add(CObjectFactory.GetFromProperties(new { x = 2, y = 1 }, "x", "y")); cl1.Add(CObjectFactory.GetFromProperties(new { x = 2, y = 2 }, "x", "y")); cl1.Add(CObjectFactory.GetFromProperties(new { x = 3, y = 3 }, "x", "y")); cl2.Add(CObjectFactory.GetFromProperties(new { x = -1, y = -1 }, "x", "y")); cl2.Add(CObjectFactory.GetFromProperties(new { x = -1, y = -2 }, "x", "y")); cl2.Add(CObjectFactory.GetFromProperties(new { x = -2, y = -1 }, "x", "y")); cl2.Add(CObjectFactory.GetFromProperties(new { x = -2, y = -2 }, "x", "y")); cl2.Add(CObjectFactory.GetFromProperties(new { x = -3, y = -3 }, "x", "y")); var line1Attrs = new decimal[] { 1, 1, 0 }; var line2Attrs = new decimal[] { 1, 1, 1 }; var line3Attrs = new decimal[] { 1, -1, 0 }; var line4Attrs = new decimal[] { 0, 1, -10 }; var val1 = FitnessValueHelper.GetValue(cl1, cl2, line1Attrs); var val2 = FitnessValueHelper.GetValue(cl1, cl2, line2Attrs); var val3 = FitnessValueHelper.GetValue(cl1, cl2, line3Attrs); var val4 = FitnessValueHelper.GetValue(cl1, cl2, line4Attrs); Assert.IsTrue(val1 > val2); Assert.IsTrue(val2 > val3); Assert.IsTrue(val3 > val4); }
public void ClassificationIris_Test2() { var cult = new CultureInfo("en-US"); var lines = System.IO.File.ReadAllLines("iris.data"); var irisList = lines.Select(i => { var irisItem = i.Split(','); return(new IrisItem() { SepalLength = Convert.ToDecimal(irisItem[0], cult), SepalWidth = Convert.ToDecimal(irisItem[1], cult), PetalLength = Convert.ToDecimal(irisItem[2], cult), PetalWidth = Convert.ToDecimal(irisItem[3], cult), ClassName = irisItem[4] }); }).ToList(); var classes = irisList.Select(i => i.ClassName).Distinct().Select(i => new CClass() { Name = i }).ToList(); var space = new CSpace(); space.Classes.AddRange(classes); foreach (var irisItem in irisList) { var objCl = classes.First(i => i.Name == irisItem.ClassName); var obj = CObjectFactory.GetFromProperties(objCl, irisItem, "SepalLength", "SepalWidth", "PetalLength", "PetalWidth"); space.Objects.Add(obj); } List <CObject> unknownObjects = new List <CObject>(); foreach (var cl in space.Classes) { var objToRemove = space.Objects.Where(i => i.Class == cl).Take(10).ToList(); unknownObjects.AddRange(objToRemove); foreach (var obj in objToRemove) { space.Objects.Remove(obj); } } var resolver = new CResolver(space); int allCnt = unknownObjects.Count; int resolvedCnt = 0; foreach (var obj in unknownObjects) { var result = resolver.Resolve(obj); if (result == obj.Class) { resolvedCnt++; } } Assert.IsTrue(resolvedCnt * 1.0 / allCnt > 0.1); }
public void Classification_ObjectFactory_Test1() { var obj = CObjectFactory.GetFromProperties(new { A = 1, B = 2.0m, C = -1.5 }, "A", "B", "C"); Assert.IsNotNull(obj); Assert.AreEqual(3, obj.AttributeValues.Count); Assert.AreEqual((decimal) - 1.5, obj.AttributeValues["C"]); }
public void Classification_ObjectFactory_Test2() { var obj = CObjectFactory.GetFromProperties(new { A = 1, B = 2.0m, C = -1.5 }, "A", "B", "C"); var attrs = obj.Attributes; Assert.IsNotNull(attrs); Assert.AreEqual(3, attrs.Length); Assert.AreEqual((decimal) - 1.5, attrs[2]); }
public void Classification_Resolver_2_4() { var space = new CSpace(); var senior = new CClass() { Name = "Старший разработчик" }; var middle = new CClass() { Name = "Средний разработчик" }; var junior = new CClass() { Name = "Младший разработчик" }; space.Classes.Add(senior); space.Classes.Add(middle); space.Classes.Add(junior); space.Objects.Add(CObjectFactory.GetFromProperties(senior, new { codePoints = 6, databasePoints = 5, experience = 21, education = 4 }, "codePoints", "databasePoints", "experience", "education")); space.Objects.Add(CObjectFactory.GetFromProperties(middle, new { codePoints = 5, databasePoints = 3, experience = 20, education = 4 }, "codePoints", "databasePoints", "experience", "education")); space.Objects.Add(CObjectFactory.GetFromProperties(junior, new { codePoints = 2, databasePoints = 1, experience = 9, education = 3 }, "codePoints", "databasePoints", "experience", "education")); List <CObject> unknownObjects = new List <CObject>(); unknownObjects.Add(CObjectFactory.GetFromProperties(senior, new { codePoints = 7, databasePoints = 5, experience = 120, education = 5 }, "codePoints", "databasePoints", "experience", "education")); unknownObjects.Add(CObjectFactory.GetFromProperties(senior, new { codePoints = 6, databasePoints = 4, experience = 25, education = 4 }, "codePoints", "databasePoints", "experience", "education")); unknownObjects.Add(CObjectFactory.GetFromProperties(middle, new { codePoints = 4, databasePoints = 4, experience = 25, education = 4 }, "codePoints", "databasePoints", "experience", "education")); unknownObjects.Add(CObjectFactory.GetFromProperties(middle, new { codePoints = 3, databasePoints = 3, experience = 19, education = 3 }, "codePoints", "databasePoints", "experience", "education")); unknownObjects.Add(CObjectFactory.GetFromProperties(middle, new { codePoints = 5, databasePoints = 3, experience = 19, education = 3 }, "codePoints", "databasePoints", "experience", "education")); unknownObjects.Add(CObjectFactory.GetFromProperties(junior, new { codePoints = 4, databasePoints = 2, experience = 7, education = 4 }, "codePoints", "databasePoints", "experience", "education")); unknownObjects.Add(CObjectFactory.GetFromProperties(junior, new { codePoints = 2, databasePoints = 3, experience = 9, education = 3 }, "codePoints", "databasePoints", "experience", "education")); CResolver resolver = new CResolver(space); int verifiedCount = 0; foreach (var obj in unknownObjects) { var calcClass = resolver.Resolve(obj); if (calcClass != null && calcClass.Equals(obj.Class)) { verifiedCount++; } } Assert.IsTrue(verifiedCount * 1.0 / unknownObjects.Count > 0.5); }
public void Classification_Resolver_2_3() { var space = new CSpace(); var cl1 = new CClass() { Name = "Plus" }; var cl2 = new CClass() { Name = "Minus" }; var cl3 = new CClass() { Name = "AbsMinus" }; space.Classes.Add(cl1); space.Classes.Add(cl2); space.Classes.Add(cl3); // 1 четверть space.Objects.Add(CObjectFactory.GetFromProperties(cl1, new { x = 1, y = 1 }, "x", "y")); space.Objects.Add(CObjectFactory.GetFromProperties(cl1, new { x = 1, y = 2 }, "x", "y")); space.Objects.Add(CObjectFactory.GetFromProperties(cl1, new { x = 2, y = 1 }, "x", "y")); space.Objects.Add(CObjectFactory.GetFromProperties(cl1, new { x = 2, y = 2 }, "x", "y")); space.Objects.Add(CObjectFactory.GetFromProperties(cl1, new { x = 3, y = 3 }, "x", "y")); // 2 четверть space.Objects.Add(CObjectFactory.GetFromProperties(cl2, new { x = -1, y = 1 }, "x", "y")); space.Objects.Add(CObjectFactory.GetFromProperties(cl2, new { x = -1, y = 2 }, "x", "y")); space.Objects.Add(CObjectFactory.GetFromProperties(cl2, new { x = -2, y = 1 }, "x", "y")); space.Objects.Add(CObjectFactory.GetFromProperties(cl2, new { x = -2, y = 2 }, "x", "y")); space.Objects.Add(CObjectFactory.GetFromProperties(cl2, new { x = -3, y = 3 }, "x", "y")); // 3 четверть space.Objects.Add(CObjectFactory.GetFromProperties(cl3, new { x = -1, y = -1 }, "x", "y")); space.Objects.Add(CObjectFactory.GetFromProperties(cl3, new { x = -1, y = -2 }, "x", "y")); space.Objects.Add(CObjectFactory.GetFromProperties(cl3, new { x = -2, y = -1 }, "x", "y")); space.Objects.Add(CObjectFactory.GetFromProperties(cl3, new { x = -2, y = -2 }, "x", "y")); space.Objects.Add(CObjectFactory.GetFromProperties(cl3, new { x = -3, y = -3 }, "x", "y")); var resolver = new CResolver(space); var objCl1 = resolver.Resolve(CObjectFactory.GetFromProperties(new { x = 4, y = 4 }, "x", "y")); var objCl2 = resolver.Resolve(CObjectFactory.GetFromProperties(new { x = -4, y = -4 }, "x", "y")); var objCl3 = resolver.Resolve(CObjectFactory.GetFromProperties(new { x = -4, y = 4 }, "x", "y")); Assert.IsNotNull(objCl1); Assert.IsNotNull(objCl2); Assert.IsNotNull(objCl3); Assert.AreEqual("Plus", objCl1.Name); Assert.AreEqual("AbsMinus", objCl2.Name); Assert.AreEqual("Minus", objCl3.Name); }
//Main method protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); //get the layout from Resources SetContentView(Resource.Layout.LogonScreen); //Form Elements cUser = FindViewById <TextInputEditText>(Resource.Id.User); cUser.SetSingleLine(); cUser.EditorAction += CUser_EditorAction;; //cUser.Text = "REJ"; cPassword = FindViewById <TextInputEditText>(Resource.Id.Password); cPassword.EditorAction += CPassword_EditorAction; //cPassword.Text = "5380"; cMsgText = FindViewById <TextView>(Resource.Id.msgText); cPackageInfoText = FindViewById <TextView>(Resource.Id.msgPkgInfo); progressBarHolder = FindViewById <FrameLayout>(Resource.Id.progressBarHolder); //Button event typeofCaller = Intent.GetStringExtra("ConnectionType") ?? "Net"; version = Intent.GetStringExtra("Version"); packageName = Intent.GetStringExtra("PackageName"); // cPackageInfoText.Text = string.Format("{0} Version {1}", packageName, version); LogonDetails.ConnectionServer = "net.espackeuro.com";//typeofCaller == "Net" ? "net.espackeuro.com" : "logon.espackeuro.com"; switch (typeofCaller) { case "Net": gDatos = (cAccesoDatosNet)CObjectFactory.CreateObject("Conn", typeofCaller, serial: cDeviceInfo.Serial); break; case "Socks": gDatos = (cAccesoDatosXML)CObjectFactory.CreateObject("Conn", typeofCaller, serial: cDeviceInfo.Serial); break; } ; cPackageInfoText.Text = string.Format("{0} Version {1}", packageName, version); #if DEBUG cUser.Text = "dvalles"; cPassword.Text = "1893"; #endif // [dvalles] 20220520: Recover the user/password values from the previous session if (!String.IsNullOrEmpty(Intent.GetStringExtra("User"))) { cUser.Text = Intent.GetStringExtra("User"); cPassword.Text = Intent.GetStringExtra("Password"); DoThings(); } }
//Main method protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); //get the layout from Resources SetContentView(Resource.Layout.LogonScreen); //Form Elements cLoginButton = FindViewById <Button>(Resource.Id.btnLogin); cUser = FindViewById <TextInputEditText>(Resource.Id.User); //cUser.Text = "REJ"; cPassword = FindViewById <TextInputEditText>(Resource.Id.Password); //cPassword.Text = "5380"; cMsgText = FindViewById <TextView>(Resource.Id.msgText); cPackageInfoText = FindViewById <TextView>(Resource.Id.msgPkgInfo); //Button event cLoginButton.Click += CLoginButton_Click; typeofCaller = Intent.GetStringExtra("ConnectionType") ?? "Net"; version = Intent.GetStringExtra("Version"); packageName = Intent.GetStringExtra("PackageName"); // cPackageInfoText.Text = string.Format("{0} Version {1}", packageName, version); LogonDetails.ConnectionServer = "net.espackeuro.com";//typeofCaller == "Net" ? "net.espackeuro.com" : "logon.espackeuro.com"; switch (typeofCaller) { case "Net": gDatos = (cAccesoDatosNet)CObjectFactory.CreateObject("Conn", typeofCaller, serial: cDeviceInfo.Serial); break; case "Socks": gDatos = (cAccesoDatosXML)CObjectFactory.CreateObject("Conn", typeofCaller, serial: cDeviceInfo.Serial); break; } ; cPackageInfoText.Text = string.Format("{0} Version {1}", packageName, version); #if DEBUG cUser.Text = "restelles"; cPassword.Text = "1312"; #endif }
private async Task DoThings() { if (cUser.Text == "" || cPassword.Text == "") { cMsgText.Text = "Please input correct User and Password"; } else { this.RunOnUiThread(() => { cUser.Enabled = false; cPassword.Enabled = false; }); gDatos.DataBase = "SISTEMAS"; gDatos.Server = LogonDetails.ConnectionServer; gDatos.User = "******"; gDatos.Password = "******"; bool error = false; try { await gDatos.ConnectAsync(); //RunOnUiThread(async () => { }); } catch (Exception ex) { var builder = new Android.Support.V7.App.AlertDialog.Builder(this); builder.SetTitle("ERROR"); builder.SetIcon(Android.Resource.Drawable.IcDialogAlert); builder.SetMessage("Error: " + ex.Message); builder.SetNeutralButton("OK", delegate { Intent intent = new Intent(); intent.PutExtra("Result", "ERROR"); SetResult(Result.Ok, intent); Finish(); }); RunOnUiThread(() => { builder.Create().Show(); }); error = true; } if (!error) { RSFrame _RS; _RS = (RSFrame)CObjectFactory.CreateObject("RS", typeofCaller, "select date=getdate()", gDatos); await _RS.OpenAsync(); gDatos.Close(); SPFrame LogonSP; LogonSP = (SPFrame)CObjectFactory.CreateObject("SP", typeofCaller, gDatos, "pLogonUser"); LogonSP.AddParameterValue("User", cUser.Text); LogonSP.AddParameterValue("Password", cPassword.Text); LogonSP.AddParameterValue("Origin", packageName.ToUpper()); LogonSP.AddParameterValue("FullName", ""); string _version = "123456"; string _packageName = "123456789"; LogonSP.AddParameterValue("Version", _version); LogonSP.AddParameterValue("PackageName", _packageName); try { await LogonSP.ExecuteAsync(); if (LogonSP.LastMsg.Substring(0, 2) != "OK") { throw new Exception(LogonSP.LastMsg); } else { Toast.MakeText(this, "Logon OK!", ToastLength.Short).Show(); LogonDetails.User = LogonSP.ReturnValues()["@User"].ToString(); LogonDetails.Password = LogonSP.ReturnValues()["@Password"].ToString(); LogonDetails.FullName = LogonSP.ReturnValues()["@FullName"].ToString(); _version = LogonSP.ReturnValues()["@Version"].ToString(); var _versionArray = _version.Split('.'); _version = string.Format("{0}.{1}", _versionArray[0], _versionArray[1]); var versionArray = version.Split('.'); version = string.Format("{0}.{1}", versionArray[0], versionArray[1]); _packageName = LogonSP.ReturnValues()["@PackageName"].ToString(); #if DEBUG //if (true) if (Convert.ToSingle(_version) > Convert.ToSingle(version)) #else if (Convert.ToSingle(_version) > Convert.ToSingle(version)) #endif { bool dialogResult = await AlertDialogHelper.ShowAsync(this, "New version found", "Do you want to update your current program?", "Yes", "No"); if (dialogResult) { try { Window.SetFlags(Android.Views.WindowManagerFlags.NotTouchable, Android.Views.WindowManagerFlags.NotTouchable); progressBarHolder.Visibility = ViewStates.Visible; await UpdatePackageURL(_packageName); //pd.Dismiss(); progressBarHolder.Visibility = ViewStates.Gone; Window.ClearFlags(WindowManagerFlags.NotTouchable); } catch (Exception ex) { Window.ClearFlags(WindowManagerFlags.NotTouchable); cMsgText.Text = string.Format("Error updating app, {0}: {1}", ex.Message, ex.InnerException.Message); Window.ClearFlags(WindowManagerFlags.NotTouchable); } } } Intent intent = new Intent(); intent.PutExtra("Result", "OK"); SetResult(Result.Ok, intent); Finish(); } } catch (Exception ex) { cMsgText.Text = string.Format("{0}: {1}", ex.Message, ex.InnerException.Message); cUser.Text = ""; cPassword.Text = ""; #if DEBUG cUser.Text = "restelles"; cPassword.Text = "1312"; #endif cUser.RequestFocus(); } } this.RunOnUiThread(() => { cUser.Enabled = true; cPassword.Enabled = true; }); } }
public void ClassificationIris_Test() { var cult = new CultureInfo("en-US"); var lines = System.IO.File.ReadAllLines("iris.data"); var irisList = lines.Select(i => { var irisItem = i.Split(','); return(new IrisItem() { SepalLength = Convert.ToDecimal(irisItem[0], cult), SepalWidth = Convert.ToDecimal(irisItem[1], cult), PetalLength = Convert.ToDecimal(irisItem[2], cult), PetalWidth = Convert.ToDecimal(irisItem[3], cult), ClassName = irisItem[4] }); }).ToList(); var classes = irisList.Select(i => i.ClassName).Distinct().Select(i => new CClass() { Name = i }).ToList(); var space = new CSpace(); space.Classes.AddRange(classes); foreach (var irisItem in irisList) { var objCl = classes.First(i => i.Name == irisItem.ClassName); var obj = CObjectFactory.GetFromProperties(objCl, irisItem, "SepalLength", "SepalWidth", "PetalLength", "PetalWidth"); space.Objects.Add(obj); } int validCnt = 0; var resolver = new CResolver(space); var newIris1 = new IrisItem() { SepalLength = 5, SepalWidth = 3.5m, PetalLength = 1.5m, PetalWidth = 0.2m }; var result1 = resolver.Resolve(CObjectFactory.GetFromProperties(newIris1, "SepalLength", "SepalWidth", "PetalLength", "PetalWidth")); //Assert.AreEqual(result1.Name, "Iris-setosa"); if (result1 != null && result1.Name == "Iris-setosa") { validCnt++; } var newIris2 = new IrisItem() { SepalLength = 6, SepalWidth = 2.7m, PetalLength = 4m, PetalWidth = 1.3m }; var result2 = resolver.Resolve(CObjectFactory.GetFromProperties(newIris2, "SepalLength", "SepalWidth", "PetalLength", "PetalWidth")); //Assert.AreEqual(result2.Name, "Iris-versicolor"); if (result2 != null && result2.Name == "Iris-versicolor") { validCnt++; } var newIris3 = new IrisItem() { SepalLength = 6.5m, SepalWidth = 3, PetalLength = 5.5m, PetalWidth = 2 }; var result3 = resolver.Resolve(CObjectFactory.GetFromProperties(newIris3, "SepalLength", "SepalWidth", "PetalLength", "PetalWidth")); //Assert.AreEqual(result3.Name, "Iris-virginica"); if (result3 != null && result3.Name == "Iris-virginica") { validCnt++; } Assert.IsTrue(validCnt > 0); }
private void getClassBtn_Click(object sender, EventArgs e) { try { var nameValue = string.IsNullOrEmpty(name.Text) ? "Неведомый разработчик" : name.Text; int codePointsValue = 0; if (!int.TryParse(codePoints.Text, out codePointsValue)) { throw new Exception($"{codePointsLabel.Text} указано некорректно."); } int databasePointsValue = 0; if (!int.TryParse(databasePoints.Text, out databasePointsValue)) { throw new Exception($"{databasePointsLabel.Text} указано некорректно."); } int experienceValue = 0; if (!int.TryParse(experience.Text, out experienceValue)) { throw new Exception($"{experienceLabel.Text} указан некорректно."); } int educationValue = 0; if (!int.TryParse(education.Text, out educationValue)) { throw new Exception($"{educationLabel.Text} указано некорректно."); } var space = new CSpace(); var senior = new CClass() { Name = "Старший разработчик" }; var middle = new CClass() { Name = "Средний разработчик" }; var junior = new CClass() { Name = "Младший разработчик" }; space.Classes.Add(senior); space.Classes.Add(middle); space.Classes.Add(junior); space.Objects.Add(CObjectFactory.GetFromProperties(senior, new { codePoints = 7, databasePoints = 5, experience = 120, education = 5 }, "codePoints", "databasePoints", "experience", "education")); space.Objects.Add(CObjectFactory.GetFromProperties(senior, new { codePoints = 6, databasePoints = 5, experience = 21, education = 4 }, "codePoints", "databasePoints", "experience", "education")); space.Objects.Add(CObjectFactory.GetFromProperties(senior, new { codePoints = 6, databasePoints = 4, experience = 25, education = 4 }, "codePoints", "databasePoints", "experience", "education")); space.Objects.Add(CObjectFactory.GetFromProperties(middle, new { codePoints = 5, databasePoints = 3, experience = 20, education = 4 }, "codePoints", "databasePoints", "experience", "education")); space.Objects.Add(CObjectFactory.GetFromProperties(middle, new { codePoints = 4, databasePoints = 4, experience = 25, education = 4 }, "codePoints", "databasePoints", "experience", "education")); space.Objects.Add(CObjectFactory.GetFromProperties(middle, new { codePoints = 3, databasePoints = 3, experience = 19, education = 3 }, "codePoints", "databasePoints", "experience", "education")); space.Objects.Add(CObjectFactory.GetFromProperties(middle, new { codePoints = 5, databasePoints = 3, experience = 19, education = 3 }, "codePoints", "databasePoints", "experience", "education")); space.Objects.Add(CObjectFactory.GetFromProperties(junior, new { codePoints = 4, databasePoints = 2, experience = 7, education = 4 }, "codePoints", "databasePoints", "experience", "education")); space.Objects.Add(CObjectFactory.GetFromProperties(junior, new { codePoints = 2, databasePoints = 1, experience = 9, education = 3 }, "codePoints", "databasePoints", "experience", "education")); space.Objects.Add(CObjectFactory.GetFromProperties(junior, new { codePoints = 2, databasePoints = 3, experience = 9, education = 3 }, "codePoints", "databasePoints", "experience", "education")); CResolver resolver = new CResolver(space); var result = resolver.Resolve(CObjectFactory.GetFromProperties(new { codePoints = codePointsValue, databasePoints = databasePointsValue, experience = experienceValue, education = educationValue }, "codePoints", "databasePoints", "experience", "education")); if (result == null) { throw new Exception($"{nameValue} относится к неизвестному типу разработчиков."); } throw new Exception($"{nameValue} - {result.Name}"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }