public static Results CreateVKL(VKL vkl) { try { if (VKLExists(vkl.Name, vkl.Type)) { Common.LogError("Atempt to create a vkl that already exists.", "Vkm.CreateVKL", (int)Results.TamperingAttempt); return Results.AlreadyExists; } using (DataAccess da = new DataAccess ()) { vkl.Id = Convert.ToInt32(da.ExecuteSPForScalar("New_VKL", new SqlParameter[] { new SqlParameter("@langCode", vkl.LangCode), new SqlParameter("@name", vkl.Name), new SqlParameter("@userId", vkl.UserId), new SqlParameter("@type", (byte)vkl.Type), new SqlParameter("@visibility", (byte)vkl.Visibility) })); } vkl.Data.Save(VKLFilePath(vkl.Name, vkl.Type)); return Results.Ok; } catch (Exception ex) { Common.LogError("Error creating VKL: " + ex.Message, "VKM.CreateVKL", (int)Results.ResourceError); } return Results.SomeError; }
protected void done_Click(object sender, EventArgs e) { //foreach (var k in Request.Form.AllKeys) // if (!k.StartsWith("__")) // Response.Write(k + "=" + Request.Form[k]); //return; XElement XMappings; if (!CreateMappings(out XMappings)) { ErrorProvider.Text = "Errors have been encountered, please correct them and then try again."; return; } VKL vkl; if (Act == Activities.Creating) { vkl = new VKL {LangCode = vklLang.SelectedValue, Name = vklName.Text, Type = this.VKLType, UserId = Member.CurrentUser, Visibility = VKLVisibility.Personal}; vkl.Data = VKM.LoadTemplate(this.VKLType); var Props = vkl.Data.Element("props"); Props.Element("author").Value = User.Identity.Name; Props.Element("name").Value = vklName.Text; Props.Element("type").Value = VKLType.ToString(); Props.Element("inscript").Value = vklScript.SelectedItem.Text; var lang = Props.Element("language"); lang.SetAttributeValue("code", vklLang.SelectedValue); lang.Value = vklLang.SelectedItem.Text; } else { vkl = EditingVKL; // Quick security check. if (vkl == null || vkl.Id != EditingVKLId) { Common.LogError("Illegal editing atempt with svklId: " + EditingVKLId + " and vklid: " + (vkl == null ? "null" : vkl.Id.ToString()), "keyboard.done", (int)Results.TamperingAttempt); ErrorProvider.Text = "You seem to be not authorized to perform this acction. If you think you do, you may try a little while after."; return; } vkl.Data = VKM.LoadVKLData(vkl.Name, vkl.Type); vkl.Data.Element("mappings").Remove(); } vkl.Data.Add(XMappings); if (VKM.SaveVKL(vkl) == Results.Ok) { Response.Redirect("~/account.aspx"); } else ErrorProvider.Text = "Some error occured while performing this action, please try again."; }
/// <summary> /// Only saves the Data field (other details are read-only once a VKL created). Creates if VKL does not exist already. /// </summary> /// <param name="vkl"></param> public static Results SaveVKL(VKL vkl) { try { if (vkl.Id <= 0) // Is it New VKL? { return CreateVKL(vkl); } vkl.Data.Save(VKLFilePath(vkl.Name, vkl.Type)); return Results.Ok; } catch (Exception ex) { Common.LogError("Error saving VKL: " + ex.Message, "VKM.SaveVKL", (int)Results.ResourceError); } return Results.SomeError; }
public static VKL GetVKL(string vklName, VKLTypes type) { try { using (DataAccess da = new DataAccess()) { var dt = da.ExecuteQuerySPForDataTable("Sel_VKL", new SqlParameter[] { new SqlParameter("@name", vklName), new SqlParameter("@type", (int)type) }); if (dt.Rows.Count > 0) { var dr = dt.Rows[0]; var vkl = new VKL { Id = (int)dr["VKLId"], LangCode = (string)dr["LangCode"], Name = (string)dr["Name"], UserId = (int)dr["UserId"], Type = (VKLTypes)int.Parse(dr["Type"].ToString()), Visibility = (VKLVisibility)int.Parse(dr["Visibility"].ToString()) }; vkl.Data = XElement.Load(VKLFilePath(vkl.Name, vkl.Type)); return vkl; } else Common.LogError("The VKL " + vklName + " (" + type.ToString() + ") couldn't be found.", Common.GetMethodName(MethodBase.GetCurrentMethod()), (int)Results.NotFound); } } catch (SqlException sqlEx) { Common.LogError(sqlEx.Message, Common.GetMethodName(MethodBase.GetCurrentMethod()), sqlEx.Number); } catch (Exception otherEx) { Common.LogError(otherEx.Message, Common.GetMethodName(MethodBase.GetCurrentMethod())); } return null; }