void OnAddBinaryValueActivate(object o, EventArgs args) { FileChooserDialog fcd = new FileChooserDialog( Mono.Unix.Catalog.GetString("Select file to add as binary attribute"), Gtk.Stock.Open, null, FileChooserAction.Open); fcd.AddButton(Gtk.Stock.Cancel, ResponseType.Cancel); fcd.AddButton(Gtk.Stock.Open, ResponseType.Ok); fcd.SelectMultiple = false; ResponseType response = (ResponseType)fcd.Run(); if (response == ResponseType.Ok) { byte[] fileBytes = ReadFileBytes(fcd.Filename); if (fileBytes.Length == 0) { return; } string attributeName = GetAttributeName(); string attributeValue = Base64.encode(SupportClass.ToSByteArray(fileBytes)); LdapEntry le = conn.Data.GetEntry(currentDN); LdapAttribute la = le.getAttribute(attributeName); bool existing = false; if (la != null) { existing = true; } LdapAttribute newla = new LdapAttribute(attributeName); newla.addBase64Value(attributeValue); LdapModification lm; if (existing) { lm = new LdapModification(LdapModification.REPLACE, newla); } else { lm = new LdapModification(LdapModification.ADD, newla); } List <LdapModification> modList = new List <LdapModification> (); modList.Add(lm); Util.ModifyEntry(conn, currentDN, modList.ToArray()); this.Show(conn, conn.Data.GetEntry(currentDN), displayAll); } fcd.Destroy(); }
void RunViewerPlugin(AttributeViewPlugin avp, string attributeName) { LdapEntry le = conn.Data.GetEntry(currentDN); LdapAttribute la = le.getAttribute(attributeName); bool existing = false; if (la != null) { existing = true; } LdapAttribute newla = new LdapAttribute(attributeName); switch (avp.DataType) { case ViewerDataType.Binary: if (existing) { avp.OnActivate(attributeName, SupportClass.ToByteArray(la.ByteValue)); } else { avp.OnActivate(attributeName, new byte[0]); } break; case ViewerDataType.String: if (existing) { avp.OnActivate(attributeName, la.StringValue); } else { avp.OnActivate(attributeName, ""); } break; } if (avp.ByteValue != null) { newla.addBase64Value(System.Convert.ToBase64String(avp.ByteValue, 0, avp.ByteValue.Length)); } else if (avp.StringValue != null) { newla.addValue(avp.StringValue); } else { return; } LdapModification lm; if (existing) { lm = new LdapModification(LdapModification.REPLACE, newla); } else { lm = new LdapModification(LdapModification.ADD, newla); } List <LdapModification> modList = new List <LdapModification> (); modList.Add(lm); Util.ModifyEntry(conn, currentDN, modList.ToArray()); this.Show(conn, conn.Data.GetEntry(currentDN), displayAll); }