public Project Get(int projectId) { using (var db = new SQLite.SQLiteConnection(Settings.DatabasePath)) { return db.Find<Project>(projectId); } }
public ProcessingResult Process(RequestContext context) { IRequest request = context.Request; IResponse response = context.Response; var header = request.Headers["FWCID"].HeaderValue; var IsFWCHandy = header != null; bool IsAuthed = false; if (IsFWCHandy) { IsAuthed = (dbConn.Find <users>(x => x.mobile_id == header)).mobile_id == header; } string output = ""; string R = System.IO.Path.GetFileName(request.Uri.LocalPath); if (R == "register") { var xUsr = new users { mobile_id = header, Nachname = request.Parameters["lname"], Vorname = request.Parameters["fname"], rights = "" }; System.Net.WebClient WC = new System.Net.WebClient(); WC.DownloadString("https://www.feuerwehrcloud.de/deiva/regalert.php?fname=" + request.Parameters["fname"] + "&lname=" + request.Parameters["lname"] + "&id=" + header + "&fwid=" + System.Environment.MachineName); dbConn.Insert(xUsr); } else if (R == "alarms" && IsAuthed) { System.Collections.Generic.Dictionary <string, string> Data = new System.Collections.Generic.Dictionary <string, string>(); foreach (var item in System.IO.Directory.GetFiles("public/alarms/", "*.txt")) { //var F = new System.Collections.Generic.Dictionary<string, string>(); Data.Add(item, System.IO.File.ReadAllText(item.Replace(".txt", ".xml"))); } output = JsonConvert.SerializeObject(Data, Formatting.Indented); } else if (R == "mydata" && IsAuthed) { } else { return(ProcessingResult.Continue); } // Set default content type response.ContentType = new ContentTypeHeader("text/html"); //ProcessHeaders(response, CgiFeuerwehrCloud.Helper.ParseCgiHeaders(ref output)); response.ContentLength.Value = output.Length; ResponseWriter generator = new ResponseWriter(); generator.SendHeaders(context.HttpContext, response); generator.Send(context.HttpContext, output, System.Text.Encoding.UTF8); return(ProcessingResult.Abort); }
public int UpdateFiliere(Filiere filiere) { Filiere f = (Filiere)database.Find <Filiere>(filiere.Id_fil); int id = filiere.Id_fil; f = filiere; f.Id_fil = id; return(database.Update(f)); }
public T Read <T>(int index) where T : new() { T data = default(T); using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(db_path)) { conn.CreateTable <T>(); data = conn.Find <T>(index); } return(data); }
public Account GetAccount(int index) { Account account = null; using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(PATH_ACCOUNTS)) { conn.CreateTable <Account>(); account = conn.Find <Account>(index); } return(account); }
private void DisplayConfirmation(string confString) { var writer = new ZXing.Mobile.BarcodeWriter(); writer.Format = BarcodeFormat.QR_CODE; writer.Options = new QrCodeEncodingOptions(); writer.Options.Width = 512; writer.Options.Height = 512; var code = writer.Write(confString); SetContentView(Resource.Layout.QrLayout); var confObject = Newtonsoft.Json.JsonConvert.DeserializeObject <Confirmation>(confString); var imageView = FindViewById <ImageView>(Resource.Id.qrImageView); imageView.SetImageBitmap(code); var btn = FindViewById <Button>(Resource.Id.qrButton); btn.Text = "Zpìt do menu"; var allTasks = new List <ChallengeTask>(); foreach (var c in AppState.State.Instance.Challenges) { allTasks.AddRange(c.BasicTasks); allTasks.AddRange(c.ExtraTasks); } var targetName = (confObject.Request.Type == ConfirmationType.Challenge ? AppState.State.Instance.Challenges .ToList()[confObject.Request.TargetId].Names[0].Name : allTasks.FirstOrDefault(t => t.Id == confObject.Request.TargetId)?.Name); Model.User targetUser; using (var db = new SQLite.SQLiteConnection(AppState.State.Instance.DbPath)) { targetUser = db.Find <Model.User>(confObject.Request.UserId); } var text = FindViewById <TextView>(Resource.Id.qrScanRequestText); text.Text = "Potvrzení " + (confObject.Request.Type == ConfirmationType.Challenge ? "zkoušky " : "úkolu ") + targetName + " pro uživatele " + targetUser.Name; btn.Click += (o, e) => { SetResult(Android.App.Result.Ok); Finish(); }; }
//public UserOperation() { } public User FindUserByEmailAndPassword(String email, String password) { User s = (User)database.Find <User>(email); if (s != null && s.Password.Equals(password)) { return(s); } else { return(null); } }
public int CheckCredentials(string username, string password) { try { var item = database.Find <Verification>(i => i.Username == username); if (item == null) { return(-1); } if (password != item.Password) { return(-1); } return(item.PersonId); } catch (Exception e) { Debug.WriteLine($"Error checking credentials!! {e.Message}"); return(0); } }
private bool Verify(string data, string expectedSignature, int signerId) { RsaKeyParameters signerKey; using (var db = new SQLite.SQLiteConnection(AppState.State.Instance.DbPath)) { var signerKeyEncoded = db.Find <Model.User>(signerId).PublicKeyEncoded; signerKey = (RsaKeyParameters)PublicKeyFactory.CreateKey(signerKeyEncoded); } ISigner signer = SignerUtilities.GetSigner("SHA256withRSA"); signer.Init(false, signerKey); var expectedSig = Convert.FromBase64String(expectedSignature); var msgBytes = Encoding.UTF8.GetBytes(data); signer.BlockUpdate(msgBytes, 0, msgBytes.Length); return(signer.VerifySignature(expectedSig)); }
public Etudiant ReadEtudiant(int cne) { //database.CreateTable<Etudiant>(); return((Etudiant)database.Find <Etudiant>(cne)); }
public Image ReadImage(int id) { //database.CreateTable<Image>(); return((Image)database.Find <Image>(id)); }
// Processing private void ProcessRequest(object sender, ConfirmationRequest request) { try { using (var db = new SQLite.SQLiteConnection(AppState.State.Instance.DbPath)) { if (request.UserId == AppState.State.Instance.UserDetails.UserId) { throw new ConfirmationException("Nemùžete potvrzovat vlastní požadavky"); } var r = db.Table <Model.User>(); var l = db.Get <Model.User>(request.UserId); var targetUser = db.Find <Model.User>(request.UserId); if (targetUser == null) { throw new ConfirmationException("Vaše zaøízení tohoto uživatele nerozpoznalo. Jeho požadavek nelze potvrdit."); } string dialogText; if (request.Type == ConfirmationType.Challenge) { var challenge = AppState.State.Instance.Challenges.FirstOrDefault((c) => c.Id == request.TargetId); if (challenge == null) { throw new ConfirmationException("Neznámá zkouška"); } dialogText = $"Uživatel { targetUser.Name} žádá o potvrzení zkoušky { challenge.Names[0].Name}. Potvrdit?"; } else { ChallengeTask task = null; foreach (var challenge in AppState.State.Instance.Challenges) { if ((task = challenge.BasicTasks.FirstOrDefault((t) => t.Id == request.TargetId)) != null) { break; } if ((task = challenge.ExtraTasks.FirstOrDefault((t) => t.Id == request.TargetId)) != null) { break; } } if (task == null) { throw new ConfirmationException("Neznámý úkol"); } dialogText = $"Uživatel { targetUser.Name} žádá o potvrzení úkolu { task.Name}. Potvrdit?"; } new AlertDialog.Builder(this) .SetTitle("Požadavek od uživatele") .SetMessage(dialogText) .SetPositiveButton("Ano", (o, e) => GenerateConfirmation(request)) .SetNegativeButton("Ne", CancelAction) .Create() .Show(); } } catch (Exception e) { new AlertDialog.Builder(this) .SetMessage("Pøi ovìøování došlo k chybì: " + e.Message) .SetNeutralButton("Ok", (o, ev) => { SetResult(Android.App.Result.Canceled); Finish(); }) .Create() .Show(); } }