public void AcionaRele_Json() { LoginRequest acesso = new LoginRequest(); acesso.login = Login; acesso.password = Password; object result1 = WebJson.JsonCommand <LoginResult>(URL + "login.fcgi", acesso); if (result1 is LoginResult) { LoginResult dados = (LoginResult)result1; Console.WriteLine("Sessão: " + dados.session); if (dados.session != null) { ActionsRequest ar = new ActionsRequest(); ar.actions = new ActionItem[] { new ActionItem() { action = "door", parameters = "door=1" } }; // Não retorna saida WebJson.JsonCommand <string>(URL + "execute_actions.fcgi?session=" + dados.session, ar); } else { Assert.Inconclusive("Login invalido"); } } else { Assert.Fail((string)result1); } }
public void SetGeneralConfigValues(General cfgGeneral) { var cfg = new ConfigValues(cfgGeneral); CheckSession(); WebJson.JsonCommand <string>(URL + "set_configuration.fcgi?session=" + Session, cfg, null, TimeOut); }
public void Connect(string cIP_DNS_URL = null, string cLogin = null, string cPassword = null, bool?useSSL = null, int?nPort = null) { URL = cIP_DNS_URL ?? URL; Login = cLogin ?? Login; Password = cPassword ?? Password; SSL = useSSL ?? SSL; Port = nPort ?? Port; // Sem dados não fa nada! if (URL == null || Login == null || Password == null) { throw new cidException(ErroCodes.LoginRequestFields, "Invalid Request Start"); } // Limpa qualquer espaço desnecessário (evita erros de colagem) URL = URL.Trim().ToLower(); // Foi passado o IP/DNS em vez da URL, então converte para a URL direto if (!URL.StartsWith("http") && !URL.Contains("://")) { if (SSL) { URL = "https://" + URL + (Port == 443 ? "" : (":" + Port)); } else { URL = "http://" + URL + (Port == 80 ? "" : (":" + Port)); } } // Deve ser sempre terminado por '/' pois os comandos serão concatenados diretamente if (!URL.EndsWith("/")) { URL += "/"; } LoginRequest lreq = new LoginRequest(); lreq.login = Login; lreq.password = Password; var result = WebJson.JsonCommand <LoginResult>(URL + "login.fcgi", lreq, null, TimeOut); if (result is LoginResult) { LoginResult dados = (LoginResult)result; if (dados.session == null) { throw new cidException(ErroCodes.LoginRequestFields, "Invalid User/Password"); } dtConnection = dtLastCommand = DateTime.Now; Session = dados.session; } else { throw new cidException(ErroCodes.LoginInvalid, result.error ?? "Erro de conexão"); } }
/// <summary> /// Configura o Beep /// </summary> public void SetBeep(bool lEnable) { var cfg = new ConfigValues(true); cfg.general.beep_enabled = lEnable ? "1" : "0"; CheckSession(); WebJson.JsonCommand <string>(URL + "set_configuration.fcgi?session=" + Session, cfg, null, TimeOut); }
// TODO: unificar na configuração geral public void SetLeds(LedsColors leds) { ConfigValues cfg = new ConfigValues(leds); CheckSession(); WebJson.JsonCommand <string>(URL + "set_configuration.fcgi?session=" + Session, cfg, null, TimeOut); WebJson.JsonCommand <string>(URL + "led_rgb_refresh.fcgi?session=" + Session, null, null, TimeOut); }
public StatusResult ChangeDeviceLanguage(string language) { var cfg = new ConfigValues(true); cfg.general.language = language; CheckSession(); return(WebJson.JsonCommand <StatusResult>(URL + "set_configuration.fcgi?session=" + Session, cfg, null, TimeOut)); }
public GpioState GetGpio(int gpio) { GpioObject o = new GpioObject(); o.gpio = gpio; CheckSession(); return(WebJson.JsonCommand <GpioState>(URL + "gpio_state.fcgi?session=" + Session, o, null, TimeOut)); }
/// <summary> /// Configura o uso da campainha em um RELÊ específico /// </summary> public void SetBell(int nRele) { var cfg = new ConfigValues(true); cfg.general.beep_enabled = nRele == 0 ? "0":"1"; cfg.general.bell_relay = nRele.ToString(); CheckSession(); WebJson.JsonCommand <string>(URL + "set_configuration.fcgi?session=" + Session, cfg, null, TimeOut); }
/// <summary> /// Comando para setar uma nova senha master para o dispositivo /// </summary> /// <param name="password">Nova senha a ser definida no dispositivo</param> /// <returns></returns> public StatusResult SetMasterPassword(string password) { CheckSession(); var obj = new MasterPassword() { password = password }; return(WebJson.JsonCommand <StatusResult>(URL + "master_password.fcgi?session=" + Session, obj, null, TimeOut)); }
public void Disconnect() { try { string cLastSession = Session; Session = null; WebJson.JsonCommand <string>(URL + "logout.fcgi?session=" + cLastSession, null); } catch (Exception) { } }
public void SetCatra(ConfigCatra config) { /* synctask... * * if(dbDev.Modelo==ControliD.iDAccess.DeviceModels.iDBlock) * dev.SetCatra(dbDev.antiPassback) */ CheckSession(); var cfg = new ConfigValues(config); WebJson.JsonCommand <string>(URL + "set_configuration.fcgi?session=" + Session, cfg, null, TimeOut); }
/// <summary> /// Define a foto de um usuário, ou a remove se for informado 'null' /// </summary> public void SetUserImage(long nUserID, Image oFoto, bool lTry = false, bool lRecise = false) { CheckSession(); try { if (oFoto == null) { WebJson.JsonCommand <string>(URL + "user_destroy_image.fcgi?&session=" + Session, "{\"user_id\":" + nUserID + "}", null, TimeOut); } else { Image oSend; if (lRecise) { var width = DeviceImageWidth; var height = DeviceImageHeight; if (oFoto.Height > oFoto.Width) { height = oFoto.Height * width / oFoto.Width; } else { width = oFoto.Width * height / oFoto.Height; } Bitmap bmp = new Bitmap(width, height); Graphics graph = Graphics.FromImage(bmp); graph.DrawImage(oFoto, 0, 0, width, height); oSend = bmp; } else { oSend = oFoto; } WebJson.JsonCommand <string>(URL + "user_set_image.fcgi?user_id=" + nUserID + "&session=" + Session, oSend, null, TimeOut, System.Drawing.Imaging.ImageFormat.Jpeg); } } catch (Exception ex) { if (lTry) { LastError = ex; } else { throw ex; } } }
/// <summary> /// Comando para executar um Factory Reset (reset de fábrica) no equipamento /// </summary> /// <param name="keepNetworkInfo">Parâmetro que permite que o equipamento mantenha as configurações de rede após o reset.</param> /// <returns></returns> public StatusResult FactoryReset(bool keepNetworkInfo = false) { CheckSession(); if (keepNetworkInfo) { var obj = new FactoryReset() { keep_network_info = true }; return(WebJson.JsonCommand <StatusResult>(URL + "reset_to_factory_default.fcgi?session=" + Session, obj, null, TimeOut)); } else { return(WebJson.JsonCommand <StatusResult>(URL + "reset_to_factory_default.fcgi?session=" + Session, null, null, TimeOut)); } }
private void CheckSession() { WebJson.WriteLog(); if (Session == null) { Connect(); } else { var result = WebJson.JsonCommand <SessionResult>(URL + "session_is_valid.fcgi?session=" + Session); if (!result.session_is_valid) { Connect(); } } }
public void SetLogoImage(Image oFoto) { CheckSession(); try { if (oFoto == null) { WebJson.JsonCommand <string>(URL + "logo_destroy.fcgi?&session=" + Session, null, null, TimeOut); } else { WebJson.JsonCommand <string>(URL + "logo_change.fcgi?session=" + Session, oFoto, null, TimeOut, System.Drawing.Imaging.ImageFormat.Png); } } catch (Exception) { } }
public long DestroyRange <T>(long[] ids, int maxBlock = 250) where T : GenericItem { if (ids == null || ids.Length == 0) { return(0); } int changes = 0; string cName = typeof(T).Name.ToLower(); int start = 0; var idResult = new List <long>(); while (start < ids.Length) { string cList = ""; int count = ids.Length - start; if (count > maxBlock) { count = maxBlock; } for (int i = start; i < count; i++) { cList += ids[i] + ","; } if (cList.Length > 0) { cList = cList.Substring(0, cList.Length - 1); start += count; string cmd = "{\"object\":\"" + cName + "\",\"where\":{\"" + cName + "\":{\"id\":[" + cList + "]}}}"; var or = WebJson.JsonCommand <ObjectResult>(URL + "destroy_objects.fcgi?session=" + Session, cmd, null, TimeOut); changes += or.changes; } else { break; } } return(changes); }
public StatusResult UpdateFirmware(string url = "http://controlid.com.br/idaccess/acfw_update.php", string mode = "default") { CheckSession(); var updt = new UpdateFirmware() { server_url = url, update_mode = mode // factory_reset }; var sr = WebJson.JsonCommand <StatusResult>(URL + "update_from_custom_server.fcgi?session=" + Session, updt, null, TimeOut); if (sr.Status == null) // Se não retornou nada é porque deu certo e o equipamento reiniciou { return(new StatusResult(200, "OK")); } else // caso contrario houve algum erro { return(sr); } }
public void Connect_Json() { LoginRequest acesso = new LoginRequest(); acesso.login = Login; acesso.password = Password; object result = WebJson.JsonCommand <LoginResult>(URL + "login.fcgi", acesso); if (result is LoginResult) { LoginResult dados = (LoginResult)result; Console.WriteLine("Sessão: " + dados.session); Console.WriteLine("Erro:" + dados.error); if (dados.session == null) { Assert.Inconclusive("Login invalido"); } } else { Assert.Fail((string)result); } }
public Bitmap GetUserImage(long nUserID) { CheckSession(); return(WebJson.JsonCommand <Bitmap>(URL + "user_get_image.fcgi?user_id=" + nUserID + "&session=" + Session, null, null, TimeOut)); }
public StatusResult RebootRecovery() { CheckSession(); return(WebJson.JsonCommand <StatusResult>(URL + "reboot_recovery.fcgi?session=" + Session, null, null, TimeOut)); }
/// <summary> /// Retorna uma lista de id de pessoas com uma foto /// </summary> /// <returns></returns> public long[] UserListImages() { var result = WebJson.JsonCommand <UserListImagesResult>(URL + "user_list_images.fcgi?&session=" + Session); return(result.user_ids); }
public StatusResult FactoryReset() { CheckSession(); return(WebJson.JsonCommand <StatusResult>(URL + "reset_to_factory_default.fcgi?session=" + Session, null, null, TimeOut)); }
public TemplateResult TemplateMatch(byte[] btRequest) { CheckSession(); return(WebJson.JsonCommand <TemplateResult>(URL + "template_match.fcgi?session=" + Session + "&size0=" + btRequest.Length + "&temp_num=1", btRequest, null, TimeOut)); }
public StatusResult SetConfiguration(ConfigValues config) { CheckSession(); return(WebJson.JsonCommand <StatusResult>(URL + "set_configuration.fcgi?session=" + Session, config, null, TimeOut)); }
public ConfigValues GetConfiguration(ConfigKeys config) { CheckSession(); return(WebJson.JsonCommand <ConfigValues>(URL + "get_configuration.fcgi?session=" + Session, config, null, TimeOut)); }
public T Command <T>(string cmd, object req) { CheckSession(); return(WebJson.JsonCommand <T>(URL + cmd + ".fcgi?session=" + Session, req, null, TimeOut)); }
public TemplateResult TemplateCreate(long nUserID, int size1, int size2, int size3, byte[] btRequest, int nFingerType = 0) { CheckSession(); return(WebJson.JsonCommand <TemplateResult>(URL + "template_create.fcgi?session=" + Session + "&user_id=" + nUserID + "&size0=" + size1 + "&size1=" + size2 + "&size2=" + size3 + "&finger_type=" + nFingerType, btRequest, null, TimeOut)); }
/// <summary> /// Define a foto de uma lista de usuário /// </summary> public void SetUserImageList(UserImage[] userImages, bool lTry = false, bool resize = false) { CheckSession(); try { System.Collections.Generic.List <UserImage> listUserImagePayload = new System.Collections.Generic.List <UserImage>(); int byteLength = 0; foreach (UserImage userImage in userImages) { Image oFoto = userImage.photo; if (resize) { var width = DeviceImageWidth; var height = DeviceImageHeight; if (oFoto.Height > oFoto.Width) { height = oFoto.Height * width / oFoto.Width; } else { width = oFoto.Width * height / oFoto.Height; } Bitmap bmp = new Bitmap(width, height); using (Graphics graph = Graphics.FromImage(bmp)) graph.DrawImage(oFoto, 0, 0, width, height); userImage.photo.Dispose(); //Remove a foto velha userImage.photo = bmp; } else { userImage.photo = oFoto; } using (System.IO.MemoryStream m = new System.IO.MemoryStream()) { userImage.photo.Save(m, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] imageBytes = m.ToArray(); userImage.image = Convert.ToBase64String(imageBytes); byteLength += imageBytes.Length; listUserImagePayload.Add(userImage); } if (byteLength > 1000000) // Se payload com mais de 1MB, envia para o device { UserImagesRequest payload = new UserImagesRequest() { user_images = listUserImagePayload.ToArray(), }; byteLength = 0; WebJson.JsonCommand <string>(URL + "user_set_image_list.fcgi?&session=" + Session, payload, null, TimeOut, System.Drawing.Imaging.ImageFormat.Jpeg); listUserImagePayload.Clear(); } } if (listUserImagePayload.Count > 0) { UserImagesRequest payload = new UserImagesRequest() { user_images = listUserImagePayload.ToArray(), }; WebJson.JsonCommand <string>(URL + "user_set_image_list.fcgi?&session=" + Session, payload, null, TimeOut, System.Drawing.Imaging.ImageFormat.Jpeg); listUserImagePayload.Clear(); } } catch (Exception ex) { if (lTry) { LastError = ex; } else { throw ex; } } }
/// <summary> /// procurar alguem /// </summary> public TemplateResult TemplateMatch(int size1, int size2, int size3, byte[] btRequest) { CheckSession(); return(WebJson.JsonCommand <TemplateResult>(URL + "template_match.fcgi?session=" + Session + "&size0=" + size1 + "&size1=" + size2 + "&size2=" + size3, btRequest, null, TimeOut)); }
public string Send(string cmd, string data) { CheckSession(); return(WebJson.JsonCommand <string>(URL + cmd + ".fcgi?session=" + Session, data, null, TimeOut)); }