예제 #1
0
 public T GetData <T>(String data, CookieContainer cookie, XML.DebugMessage debugCallback)
 {
     try
     {
         return(XML.XmlWebRequest <T>(serverUri, getPostData(data), "application/x-www-form-urlencoded", null, "POST", cookie, debugCallback));
     }
     catch (DeserializeException ex)
     {
         throw ex.Exception;
     }
 }
예제 #2
0
        public List <Dictionary <String, String> > GetUsers(XML.DebugMessage debugCallback = null)
        {
            try
            {
                List <Dictionary <String, String> > tmp = new List <Dictionary <string, string> >();

                Uri callUri = new Uri(this.baseUri.Scheme + "://" + this.baseUri.Host + ":" + this.baseUri.Port + "/g5-senior-services/rubi_Synccom_senior_g5_rh_fp_colaboradoresAdmitidos?wsdl");

                for (Int32 abrTipCol = 1; abrTipCol <= 3; abrTipCol++)
                {
                    StringBuilder post = new StringBuilder();

                    post.AppendLine("<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"http://services.senior.com.br\">");
                    post.AppendLine("  <soapenv:Body>");
                    post.AppendLine("    <ser:ColaboradoresAdmitidos>");
                    post.AppendLine("      <user>" + this.username + "</user>");
                    post.AppendLine("      <password>" + this.password + "</password>");
                    post.AppendLine("      <encryption>0</encryption>");
                    post.AppendLine("      <parameters>");
                    post.AppendLine("        <numEmp>" + this.numEmp + "</numEmp>");
                    post.AppendLine("        <abrTipCol>" + abrTipCol + "</abrTipCol>");
                    post.AppendLine("        <iniPer>" + DateTime.Now.AddDays(-365).ToString("dd/MM/yyyy") + "</iniPer>");
                    //post.AppendLine("        <iniPer>18/10/2017</iniPer>");
                    //post.AppendLine("        <fimPer>" + DateTime.Now.ToString("dd/MM/yyyy") + "</fimPer>");
                    post.AppendLine("      </parameters>");
                    post.AppendLine("    </ser:ColaboradoresAdmitidos>");
                    post.AppendLine("  </soapenv:Body>");
                    post.AppendLine("</soapenv:Envelope>");

                    ColaboradoresAdmitidosSOAP result = XML.XmlWebRequest <ColaboradoresAdmitidosSOAP>(callUri, post.ToString(), "text/xml", null, "POST", this.cookie, debugCallback);

                    if (result == null || result.Body == null || result.Body.ColaboradoresResponse == null || result.Body.ColaboradoresResponse.Result == null)
                    {
                        throw new SafeTrend.Xml.ResultEmptyException("ResultSet is empty");
                    }

                    if (!String.IsNullOrEmpty(result.Body.ColaboradoresResponse.Result.ErroExecucao))
                    {
                        throw new Exception(result.Body.ColaboradoresResponse.Result.ErroExecucao);
                    }

                    tmp.AddRange(result.Body.ColaboradoresResponse.Result.getDict());
                }

                return(tmp);
            }
            catch (DeserializeException ex)
            {
                throw ex.Exception;
            }
        }
예제 #3
0
        public List <Dictionary <String, String> > GetComplememtaryByCPF(String cpf, XML.DebugMessage debugCallback = null)
        {
            try
            {
                List <Dictionary <String, String> > tmp = new List <Dictionary <string, string> >();

                Uri callUri = new Uri(this.baseUri.Scheme + "://" + this.baseUri.Host + ":" + this.baseUri.Port + "/g5-senior-services/rubi_Synccom_senior_g5_rh_fp_consultarColaboradorPorCPF?wsdl");


                StringBuilder post = new StringBuilder();

                post.AppendLine("<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"http://services.senior.com.br\">");
                post.AppendLine("  <soapenv:Header/>");
                post.AppendLine("  <soapenv:Body>");
                post.AppendLine("    <ser:Complementares>");
                post.AppendLine("      <user>" + this.username + "</user>");
                post.AppendLine("      <password>" + this.password + "</password>");
                post.AppendLine("      <encryption>0</encryption>");
                post.AppendLine("      <parameters>");
                post.AppendLine("        <numcpf>" + cpf + "</numcpf>");
                post.AppendLine("      </parameters>");
                post.AppendLine("    </ser:Complementares>");
                post.AppendLine("  </soapenv:Body>");
                post.AppendLine("</soapenv:Envelope>");

                ComplementaresSOAP result = XML.XmlWebRequest <ComplementaresSOAP>(callUri, post.ToString(), "text/xml", null, "POST", this.cookie, debugCallback);

                if (result == null || result.Body == null || result.Body.ComplementaresResponse == null || result.Body.ComplementaresResponse.Result == null)
                {
                    throw new SafeTrend.Xml.ResultEmptyException("ResultSet is empty");
                }

                if (!String.IsNullOrEmpty(result.Body.ComplementaresResponse.Result.ErroExecucao))
                {
                    throw new Exception(result.Body.ComplementaresResponse.Result.ErroExecucao);
                }

                tmp.AddRange(result.Body.ComplementaresResponse.Result.getDict());

                return(tmp);
            }
            catch (DeserializeException ex)
            {
                throw ex.Exception;
            }
        }
예제 #4
0
파일: akna.cs 프로젝트: radtek/safeid
        public override void ProcessDeploy(String cacheId, PluginConnectorBaseDeployPackage package, Dictionary <String, Object> config, List <PluginConnectorBaseDeployPackageMapping> fieldMapping)
        {
            String lastStep = "CheckInputConfig";

            if (!CheckInputConfig(config, true, Log))
            {
                return;
            }

            StringBuilder processLog = new StringBuilder();
            StringBuilder debugLog   = new StringBuilder();
            PluginLogType logType    = PluginLogType.Information;
            AknaAPI       akna       = new AknaAPI(config["username"].ToString(), config["password"].ToString());


            XML.DebugMessage dbgC = new XML.DebugMessage(delegate(String data, String debug)
            {
                debugLog.AppendLine("######");
                debugLog.AppendLine("## JSON Debug message: " + data);
                debugLog.AppendLine(debug);

#if DEBUG
                Log2(this, PluginLogType.Debug, package.entityId, package.identityId, "JSON Debug message: " + data, debug);
#endif
            });


            try
            {
                lastStep = "Check info";

                String container = package.container;

                if (String.IsNullOrEmpty(container))
                {
                    container = "IAMUsers";
                }

                //Este plugin estava gerando milhares de listas indevidamente devido ao container
                //Desta forma foi fixado o container como sempre Sendo SafeIDUsers
                container = "IAMUsers";

                String email = "";



                String mail_domain = "";//config["mail_domain"].ToString();

                if ((config.ContainsKey("mail_domain")) && (!String.IsNullOrEmpty(config["mail_domain"].ToString())))
                {
                    mail_domain = config["mail_domain"].ToString();
                }

                //Busca o e-mail nas propriedades específicas desto usuário
                foreach (PluginConnectorBasePackageData dt in package.entiyData)
                {
                    if (dt.dataValue.ToLower().IndexOf("@" + mail_domain) > 1)
                    {
                        email = dt.dataValue;
                    }
                }

                //Busca o e-mail nas propriedades específicas deste plugin
                if ((email == null) || (email == ""))
                {
                    foreach (PluginConnectorBasePackageData dt in package.pluginData)
                    {
                        if (dt.dataValue.ToLower().IndexOf("@" + mail_domain) > 1)
                        {
                            email = dt.dataValue;
                        }
                    }
                }

                //Se não encontrou o e-mail testa nas propriedades maracas como ID
                if ((email == null) || (email == ""))
                {
                    foreach (PluginConnectorBasePackageData dt in package.ids)
                    {
                        if (dt.dataValue.ToLower().IndexOf("@" + mail_domain) > 1)
                        {
                            email = dt.dataValue;
                        }
                    }
                }

                //Se não encontrou o e-mail testa nas propriedades gerais
                if ((email == null) || (email == ""))
                {
                    foreach (PluginConnectorBasePackageData dt in package.properties)
                    {
                        if (dt.dataValue.ToLower().IndexOf("@" + mail_domain) > 1)
                        {
                            email = dt.dataValue;
                        }
                    }
                }

                //Se não encontrou nenhum e-mail do dominio principal adiciona qualquer outro e-mail
                if ((email == null) || (email == ""))
                {
                    foreach (PluginConnectorBasePackageData dt in package.properties)
                    {
                        if (dt.dataValue.ToLower().IndexOf("@") > 1)
                        {
                            email = dt.dataValue;
                        }
                    }
                }


                if (email == "")
                {
                    String jData = "";

                    try
                    {
                        jData = JSON.Serialize <PluginConnectorBaseDeployPackage>(package);
                        if (package.password != "")
                        {
                            jData = jData.Replace(package.password, "Replaced for user security");
                        }
                    }
                    catch { }

                    logType = PluginLogType.Error;
                    processLog.AppendLine("IAM Email not found in properties list. " + jData);
                    Log2(this, PluginLogType.Error, package.entityId, package.identityId, "IAM Email not found in properties list.", jData);
                    return;
                }



                if ((package.fullName == null) || (package.fullName.fullName.Trim() == ""))
                {
                    String jData = "";

                    try
                    {
                        jData = JSON.Serialize <PluginConnectorBaseDeployPackage>(package);
                        if (package.password != "")
                        {
                            jData = jData.Replace(package.password, "Replaced for user security");
                        }
                    }
                    catch { }

                    logType = PluginLogType.Error;
                    processLog.AppendLine("IAM Full Name not found in properties list. " + jData);
                    Log2(this, PluginLogType.Error, package.entityId, package.identityId, "IAM Full Name not found in properties list", jData);
                    return;
                }

                lastStep = "Auth";

                Uri serverUri = new Uri("https://api.akna.com.br/emkt/int/integracao.php");

                CookieContainer cookie = new CookieContainer();

                lastStep = "Get groups";

                String tst = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<MAIN><FUNC TRANS=\"\" KEY=\"0ea001e9ca76917fcfaffacf5bad\"><RETURN ID=\"01\">Usuário e/ou senha inválidos</RETURN></FUNC></MAIN>";

                AknaListResponse tst2 = SafeTrend.Xml.XML.Deserialize <AknaListResponse>(tst);

                AknaListResponse listas = akna.GetData <AknaListResponse>("<main><emkt trans=\"11.02\"></emkt></main>", cookie, dbgC);

                //AknaListResponse listas = JSON.JsonWebRequest<AknaListResponse>(serverUri, getPostData(config["username"].ToString(), config["password"].ToString(), "<main><emkt trans=\"11.02\"></emkt></main>"), "application/x-www-form-urlencoded", null, "POST", cookie, dbgC);

                if ((listas == null) || (listas.EMKT == null) || (listas.EMKT.Listas == null) || (listas.EMKT.Listas.Count == 0))
                {
                    logType = PluginLogType.Error;

                    if ((listas != null) && (listas.FUNC != null) && (listas.FUNC._return != null) && (!String.IsNullOrEmpty(listas.FUNC._return[0].value)))
                    {
                        throw new Exception("Error retriving groups: " + listas.FUNC._return[0].value);
                    }
                    else
                    {
                        throw new Exception("Error retriving groups");
                    }
                }

                List <String> dbg = new List <string>();
                if ((listas.EMKT.Listas != null) && (listas.EMKT.Listas.Count > 0))
                {
                    foreach (AknaListResponse.aknaLista.aknaListaItem l in listas.EMKT.Listas)
                    {
                        dbg.Add("Lista: " + l.name.ToString());
                    }
                }



                lastStep = "Check groups/roles";
                List <String> grpIds       = new List <String>();
                List <String> grpIdsRemove = new List <String>();

                //Busca os grupos que este usuário fará parte
                if ((package.pluginAction != null) && (package.pluginAction.Count > 0))
                {
                    foreach (PluginConnectorBaseDeployPackageAction act in package.pluginAction)
                    {
                        try
                        {
                            processLog.AppendLine("Role: " + act.roleName + " (" + act.actionType.ToString() + ") " + act.ToString());

                            switch (act.actionKey.ToLower())
                            {
                            case "group":
                                if (act.actionType == PluginActionType.Add)
                                {
                                    String grpAddId = null;
                                    if ((listas.EMKT.Listas != null) && (listas.EMKT.Listas.Count > 0))
                                    {
                                        foreach (AknaListResponse.aknaLista.aknaListaItem l in listas.EMKT.Listas)
                                        {
                                            if ((!String.IsNullOrEmpty(l.name)) && (l.name.ToLower() == act.actionValue.ToLower()))
                                            {
                                                grpAddId = l.name;
                                                grpIds.Add(grpAddId);
                                            }
                                        }
                                    }

                                    if (grpAddId == null)
                                    {
                                        processLog.AppendLine("List '" + act.actionValue + "' not exists yet, creating...");
                                    }

                                    try
                                    {
                                        StringBuilder putXML = new StringBuilder();
                                        putXML.Append("<main><emkt trans=\"11.05\">");
                                        putXML.Append("<nome>" + act.actionValue + "</nome>");
                                        putXML.Append("<substituir>N</substituir>");
                                        putXML.Append("<destinatario codigo=\"" + package.login + "\">");
                                        putXML.Append("<nome>" + package.fullName.fullName + "</nome>");
                                        putXML.Append("<email>" + email + "</email>");

                                        putXML.Append("</destinatario></emkt></main>");

                                        AknaCommandResponse cmd = akna.GetData <AknaCommandResponse>(putXML.ToString(), cookie, dbgC);

                                        if ((cmd == null) || (cmd.EMKT == null) || (cmd.EMKT._return == null) || (cmd.EMKT._return.Count == 0) || (cmd.EMKT._return[0].id != "00"))
                                        {
                                            if ((cmd != null) && (cmd.EMKT != null) && (cmd.EMKT._return != null) && (!String.IsNullOrEmpty(cmd.EMKT._return[0].value)))
                                            {
                                                throw new Exception("Adding group " + act.actionValue + " by role " + act.roleName + ": " + cmd.EMKT._return[0].value);
                                            }
                                            else
                                            {
                                                throw new Exception("Adding group " + act.actionValue + " by role " + act.roleName);
                                            }
                                        }

                                        processLog.AppendLine("User added in group " + act.actionValue + " by role " + act.roleName);
                                    }
                                    catch (Exception ex)
                                    {
                                        StringBuilder putXML = new StringBuilder();
                                        putXML.Append("<main><emkt trans=\"11.05\">");
                                        putXML.Append("<nome>" + act.actionValue + "</nome>");
                                        putXML.Append("<substituir>N</substituir>");
                                        putXML.Append("<destinatario codigo=\"" + package.login + "\">");
                                        putXML.Append("<nome>" + package.fullName.fullName + "</nome>");
                                        putXML.Append("<email>" + email + "</email>");
                                        putXML.Append("</destinatario></emkt></main>");

                                        AknaCommandResponse cmd = akna.GetData <AknaCommandResponse>(putXML.ToString(), cookie, dbgC);

                                        if ((cmd == null) || (cmd.EMKT == null) || (cmd.EMKT._return == null) || (cmd.EMKT._return.Count == 0) || (cmd.EMKT._return[0].id != "00"))
                                        {
                                            if ((cmd != null) && (cmd.EMKT != null) && (cmd.EMKT._return != null) && (!String.IsNullOrEmpty(cmd.EMKT._return[0].value)))
                                            {
                                                throw new Exception("Adding group " + act.actionValue + " by role " + act.roleName + ": " + cmd.EMKT._return[0].value);
                                            }
                                            else
                                            {
                                                throw new Exception("Adding group " + act.actionValue + " by role " + act.roleName);
                                            }
                                        }

                                        processLog.AppendLine("User added in group " + act.actionValue + " by role " + act.roleName);
                                    }
                                }
                                else if (act.actionType == PluginActionType.Remove)
                                {
                                    /*if ((groups != null) && (groups.Length > 0))
                                     *  foreach (emGroup g in groups)
                                     *      if ((!String.IsNullOrEmpty(g.name)) && (g.name.ToLower() == act.actionValue.ToLower()))
                                     *      {
                                     *          grpIdsRemove.Add(g.id);
                                     *          processLog.AppendLine("User removed from group " + act.actionValue + " by role " + act.roleName);
                                     *      }*/
                                }
                                break;

                            default:
                                processLog.AppendLine("Action not recognized: " + act.actionKey);
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            processLog.AppendLine("Error on execute action (" + act.actionKey + "): " + ex.Message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logType = PluginLogType.Error;
                processLog.AppendLine("Error on process deploy (" + lastStep + "): " + ex.Message);

                Log2(this, PluginLogType.Error, package.entityId, package.identityId, "Error on process deploy: " + ex.Message, "Last step: " + lastStep);
            }
            finally
            {
                if (logType != PluginLogType.Information)
                {
                    processLog.AppendLine(debugLog.ToString());
                }

                Log2(this, logType, package.entityId, package.identityId, "Deploy executed", processLog.ToString());
                processLog.Clear();
                processLog = null;

                debugLog.Clear();
                debugLog = null;
            }
        }
예제 #5
0
        public override PluginConnectorBaseFetchResult FetchFields(Dictionary <String, Object> config)
        {
            PluginConnectorBaseFetchResult ret = new PluginConnectorBaseFetchResult();

            LogEvent iLog = new LogEvent(delegate(Object sender, PluginLogType type, string text)
            {
                if (Log != null)
                {
                    Log(sender, type, text);
                }
            });


            if (!CheckInputConfig(config, true, iLog, true, true))
            {
                ret.success = false;
                return(ret);
            }

            List <PluginConfigFields> cfg = new List <PluginConfigFields>();

            PluginConfigFields[] tmpF = this.GetConfigFields();
            foreach (PluginConfigFields cf in tmpF)
            {
                try
                {
                    iLog(this, PluginLogType.Information, "Field " + cf.Name + " (" + cf.Key + "): " + (config.ContainsKey(cf.Key) ? config[cf.Key].ToString() : "empty"));
                }
                catch (Exception ex)
                {
                    iLog(this, PluginLogType.Information, "Field " + cf.Name + " (" + cf.Key + "): error on get data -> " + ex.Message);
                }
            }

            SeniorAPI api = new SeniorAPI(config["username"].ToString(), config["password"].ToString(), config["numemp"].ToString(), new Uri(config["server_uri"].ToString()));

            XML.DebugMessage dbgC = new XML.DebugMessage(delegate(String data, String debug)
            {
#if DEBUG
                iLog(this, PluginLogType.Information, "## JSON Debug message: " + data + debug);
#endif
            });

            try
            {
                List <Dictionary <String, String> > users = api.GetUsers(dbgC);
                Int32 cnt = 0;
                foreach (Dictionary <String, String> u in users)
                {
                    foreach (String key in u.Keys)
                    {
                        if (!ret.fields.ContainsKey(key))
                        {
                            ret.fields.Add(key, new List <string>());
                        }

                        ret.fields[key].Add(u[key]);
                    }

                    cnt++;
                    if (cnt >= 10)
                    {
                        break;
                    }
                }



                ret.success = true;
            }
            catch (Exception ex)
            {
                iLog(this, PluginLogType.Error, ex.Message);
                ret.success = false;
            }

            return(ret);
        }
예제 #6
0
        public override void ProcessImportAfterDeploy(String cacheId, PluginConnectorBaseDeployPackage package, Dictionary <String, Object> config, List <PluginConnectorBaseDeployPackageMapping> fieldMapping)
        {
            String lastStep = "CheckInputConfig";

            if (!CheckInputConfig(config, true, Log))
            {
                return;
            }

            StringBuilder processLog = new StringBuilder();
            StringBuilder debugLog   = new StringBuilder();
            PluginLogType logType    = PluginLogType.Information;
            SeniorAPI     api        = new SeniorAPI(config["username"].ToString(), config["password"].ToString(), config["numemp"].ToString(), new Uri(config["server_uri"].ToString()));


            XML.DebugMessage dbgC = new XML.DebugMessage(delegate(String data, String debug)
            {
                debugLog.AppendLine("######");
                debugLog.AppendLine("## JSON Debug message: " + data);
                debugLog.AppendLine(debug);
            });

            try
            {
                String importID = "ImpAfDep-" + Guid.NewGuid().ToString();

                lastStep = "Checa CPF no pacote";

                String cpf = "";

                //Busca o e-mail nas propriedades específicas desto usuário
                foreach (PluginConnectorBasePackageData dt in package.entiyData)
                {
                    if (dt.dataName.ToLower() == "numcpf" && !String.IsNullOrEmpty(dt.dataValue.ToLower()))
                    {
                        cpf = dt.dataValue;
                    }
                }

                //Busca o e-mail nas propriedades específicas deste plugin
                if ((cpf == null) || (cpf == ""))
                {
                    foreach (PluginConnectorBasePackageData dt in package.pluginData)
                    {
                        if (dt.dataName.ToLower() == "numcpf" && !String.IsNullOrEmpty(dt.dataValue.ToLower()))
                        {
                            cpf = dt.dataValue;
                        }
                    }
                }

                //Se não encontrou o e-mail testa nas propriedades maracas como ID
                if ((cpf == null) || (cpf == ""))
                {
                    foreach (PluginConnectorBasePackageData dt in package.ids)
                    {
                        if (dt.dataName.ToLower() == "numcpf" && !String.IsNullOrEmpty(dt.dataValue.ToLower()))
                        {
                            cpf = dt.dataValue;
                        }
                    }
                }

                //Se não encontrou o e-mail testa nas propriedades gerais
                if ((cpf == null) || (cpf == ""))
                {
                    foreach (PluginConnectorBasePackageData dt in package.properties)
                    {
                        if (dt.dataName.ToLower() == "numcpf" && !String.IsNullOrEmpty(dt.dataValue.ToLower()))
                        {
                            cpf = dt.dataValue;
                        }
                    }
                }

#if DEBUG
                try
                {
                    String jData = JSON.Serialize <PluginConnectorBaseDeployPackage>(package);
                    if (package.password != "")
                    {
                        jData = jData.Replace(package.password, "Replaced for user security");
                    }

                    Log2(this, PluginLogType.Debug, package.entityId, package.identityId, "Package data", jData);
                }
                catch { }
#endif

                if (cpf == "")
                {
                    String jData = "";

                    try
                    {
                        jData = JSON.Serialize <PluginConnectorBaseDeployPackage>(package);
                        if (package.password != "")
                        {
                            jData = jData.Replace(package.password, "Replaced for user security");
                        }
                    }
                    catch { }

                    logType = PluginLogType.Error;
                    processLog.AppendLine("CPF (numCpf) not found in properties list. " + jData);
                    Log2(this, PluginLogType.Error, package.entityId, package.identityId, "CPF (numCpf) not found in properties list", jData);
                    return;
                }

                lastStep = "Resgata informações do colaborador";

                List <Dictionary <String, String> > users = api.GetUserData(cpf, dbgC);

                if (users == null)
                {
                    throw new Exception("User data is empty");
                }

                foreach (Dictionary <String, String> u in users)
                {
                    String cNumCad = "";//Data de admissao

                    if (u.ContainsKey("numCad"))
                    {
                        cNumCad = u["numCad"];
                    }
                    else if (u.ContainsKey("numcad"))
                    {
                        cNumCad = u["numcad"];
                    }


                    PluginConnectorBaseImportPackageUser packageImp = new PluginConnectorBaseImportPackageUser(importID);
                    try
                    {
                        foreach (String key in u.Keys)
                        {
                            if (key.ToLower() == "numcpf")
                            {
                                packageImp.AddProperty(key, u[key].Replace("-", "").Replace(".", "").Replace(" ", ""), "string");
                            }
                            else
                            {
                                packageImp.AddProperty(key, u[key], "string");
                            }
                        }


                        Dictionary <String, Dictionary <String, String> > cData = GetComplementatyData(api, u, dbgC);
                        if (cData.ContainsKey(cNumCad))
                        {
                            foreach (String key in cData[cNumCad].Keys)
                            {
                                if (key.ToLower() == "numcpf")
                                {
                                    packageImp.AddProperty(key, cData[cNumCad][key].Replace("-", "").Replace(".", "").Replace(" ", ""), "string");
                                }
                                else
                                {
                                    packageImp.AddProperty(key, cData[cNumCad][key], "string");
                                }
                            }
                        }
                    }
                    catch (Exception ex2)
                    {
                        processLog.AppendLine("Error: " + ex2.Message);
                    }
                    finally
                    {
                        processLog.AppendLine("Import (after deploy) package generated:");
                        processLog.AppendLine("\tImport ID: " + importID);
                        processLog.AppendLine("\tPackage ID: " + packageImp.pkgId);
                        processLog.AppendLine("");
                        processLog.AppendLine("Package data:");
                        processLog.AppendLine(JSON.Serialize(packageImp));

                        ImportPackageUser(packageImp);
                    }
                }
            }
            catch (Exception ex)
            {
                logType = PluginLogType.Error;
                processLog.AppendLine("Error processing import (" + lastStep + "): " + ex.Message);

                if (ex is SafeTrend.Xml.ResultEmptyException)
                {
                    Log2(this, PluginLogType.Error, package.entityId, package.identityId, "Network erro or API lock error importing user data", ex.Message + Environment.NewLine + debugLog.ToString());
                }

                try
                {
                    Log2(this, PluginLogType.Error, package.entityId, package.identityId, "Error processing import after deploy: " + ex.Message, debugLog.ToString());
                }
                catch
                {
                    Log2(this, PluginLogType.Error, 0, 0, "Error processing import after deploy: " + ex.Message, debugLog.ToString());
                }
            }
            finally
            {
#if DEBUG
                processLog.AppendLine(debugLog.ToString());

                Log2(this, PluginLogType.Debug, 0, 0, "Import debug log", debugLog.ToString());

                Log2(this, PluginLogType.Debug, package.entityId, package.identityId, "Import debug log", debugLog.ToString());
#else
                if (logType != PluginLogType.Information)
                {
                    processLog.AppendLine(debugLog.ToString());
                }
#endif

                Log2(this, logType, package.entityId, package.identityId, "Import executed", processLog.ToString());

                processLog.Clear();
                processLog = null;

                debugLog.Clear();
                debugLog = null;
            }
        }
예제 #7
0
        private Dictionary <String, Dictionary <String, String> > GetComplementatyDataOld(SeniorAPI api, Dictionary <String, String> user, XML.DebugMessage debugCallback = null)
        {
            Dictionary <String, Dictionary <String, String> > uData = new Dictionary <string, Dictionary <string, string> >();
            List <String> dates = new List <String>();

            //Preeche as datas que detem contratacoes
            String datAdm = "";//Data de admissao

            if (user.ContainsKey("datAdm"))
            {
                datAdm = user["datAdm"];
            }
            else if (user.ContainsKey("datadm"))
            {
                datAdm = user["datadm"];
            }

            if (!String.IsNullOrEmpty(datAdm))
            {
                if (!dates.Contains(datAdm))
                {
                    dates.Add(datAdm);
                }
            }


            if (dates.Count == 0)
            {
                return(uData);
            }

            //Resgata todos os colaboradores por cada um das datas
            foreach (String d in dates)
            {
                try
                {
                    List <Dictionary <String, String> > usersData = api.GetComplememtaryByDate(d, debugCallback);

                    if (usersData == null)
                    {
                        continue;
                    }

                    foreach (Dictionary <String, String> u in usersData)
                    {
                        String cNumCad = "";//Data de admissao

                        if (u.ContainsKey("numCad"))
                        {
                            cNumCad = u["numCad"];
                        }
                        else if (u.ContainsKey("numcad"))
                        {
                            cNumCad = u["numcad"];
                        }

                        if (!String.IsNullOrEmpty(cNumCad))
                        {
                            if (!uData.ContainsKey(cNumCad))
                            {
                                uData.Add(cNumCad, new Dictionary <string, string>(u));
                            }
                        }
                    }
                }
                catch (Exception ex) {
                    if (debugCallback != null)
                    {
                        debugCallback("Error getting complementary user data", ex.Message);
                    }

                    if (ex is SafeTrend.Xml.ResultEmptyException)
                    {
                        throw ex;
                    }
                }
            }

            return(uData);
        }
예제 #8
0
        private Dictionary <String, Dictionary <String, String> > GetComplementatyData(SeniorAPI api, Dictionary <String, String> user, XML.DebugMessage debugCallback = null)
        {
            Dictionary <String, Dictionary <String, String> > uData = new Dictionary <string, Dictionary <string, string> >();

            //Preeche as datas que detem contratacoes
            String numCpf = "";//Data de admissao

            if (user.ContainsKey("numCpf"))
            {
                numCpf = user["numCpf"];
            }
            else if (user.ContainsKey("numcpf"))
            {
                numCpf = user["numcpf"];
            }

            numCpf = numCpf.Replace("-", "").Replace(".", "").Replace(" ", "");

            if (!String.IsNullOrEmpty(numCpf))
            {
                try
                {
                    List <Dictionary <String, String> > usersData = api.GetComplememtaryByCPF(numCpf, debugCallback);

                    if (usersData == null)
                    {
                        return(uData);
                    }

                    foreach (Dictionary <String, String> u in usersData)
                    {
                        String cNumCad = "";//Data de admissao

                        if (u.ContainsKey("numCad"))
                        {
                            cNumCad = u["numCad"];
                        }
                        else if (u.ContainsKey("numcad"))
                        {
                            cNumCad = u["numcad"];
                        }

                        if (!String.IsNullOrEmpty(cNumCad))
                        {
                            if (!uData.ContainsKey(cNumCad))
                            {
                                uData.Add(cNumCad, new Dictionary <string, string>(u));
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (debugCallback != null)
                    {
                        debugCallback("Error getting complementary user data", ex.Message);
                    }


                    if (ex is SafeTrend.Xml.ResultEmptyException)
                    {
                        throw ex;
                    }
                }
            }

            return(uData);
        }
예제 #9
0
        public override void ProcessImport(String cacheId, String importId, Dictionary <String, Object> config, List <PluginConnectorBaseDeployPackageMapping> fieldMapping)
        {
            String lastStep = "CheckInputConfig";

            if (!CheckInputConfig(config, true, Log))
            {
                return;
            }

            StringBuilder processLog = new StringBuilder();
            StringBuilder debugLog   = new StringBuilder();
            PluginLogType logType    = PluginLogType.Information;
            SeniorAPI     api        = new SeniorAPI(config["username"].ToString(), config["password"].ToString(), config["numemp"].ToString(), new Uri(config["server_uri"].ToString()));


            XML.DebugMessage dbgC = new XML.DebugMessage(delegate(String data, String debug)
            {
                debugLog.AppendLine("######");
                debugLog.AppendLine("## [" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "] JSON Debug message: " + data);
                debugLog.AppendLine(debug);
            });

            try
            {
                lastStep = "Resgata os colaboradores contratados nos últimos 365 dias";

                List <Dictionary <String, String> > users = api.GetUsers(dbgC);

                if (users == null)
                {
                    throw new Exception("User data is empty");
                }


                foreach (Dictionary <String, String> u in users)
                {
                    StringBuilder userDebugLog = new StringBuilder();

                    //userDebugLog.AppendLine(debugLog.ToString());

                    try
                    {
                        userDebugLog.AppendLine("######");
                        userDebugLog.AppendLine("### User Data");
                        userDebugLog.AppendLine(JSON.Serialize <Dictionary <String, String> >(u));
                    }
                    catch { }

                    userDebugLog.AppendLine("");

                    String cNumCad = "";//Data de admissao

                    if (u.ContainsKey("numCad"))
                    {
                        cNumCad = u["numCad"];
                    }
                    else if (u.ContainsKey("numcad"))
                    {
                        cNumCad = u["numcad"];
                    }

                    PluginConnectorBaseImportPackageUser package = new PluginConnectorBaseImportPackageUser(importId);
                    userDebugLog.AppendLine("######");
                    userDebugLog.AppendLine("### Package id: " + package.pkgId);
                    foreach (String key in u.Keys)
                    {
                        if (key.ToLower() == "numcpf")
                        {
                            package.AddProperty(key, u[key].Replace("-", "").Replace(".", "").Replace(" ", ""), "string");
                        }
                        else
                        {
                            package.AddProperty(key, u[key], "string");
                        }
                    }

                    userDebugLog.AppendLine("");

                    XML.DebugMessage userDbgC = new XML.DebugMessage(delegate(String data, String debug)
                    {
                        userDebugLog.AppendLine("######");
                        userDebugLog.AppendLine("## [" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "] JSON Debug message: " + data);
                        userDebugLog.AppendLine(debug);
                    });


                    Dictionary <String, Dictionary <String, String> > cData = GetComplementatyData(api, u, userDbgC);
                    if (cData.ContainsKey(cNumCad))
                    {
                        foreach (String key in cData[cNumCad].Keys)
                        {
                            if (key.ToLower() == "numcpf")
                            {
                                package.AddProperty(key, cData[cNumCad][key].Replace("-", "").Replace(".", "").Replace(" ", ""), "string");
                            }
                            else
                            {
                                package.AddProperty(key, cData[cNumCad][key], "string");
                            }
                        }
                    }

#if DEBUG
                    Log2(this, PluginLogType.Debug, 0, 0, "Import debug log for pachage " + package.pkgId, userDebugLog.ToString());
#endif

                    ImportPackageUser(package);
                }
            }
            catch (Exception ex)
            {
                logType = PluginLogType.Error;
                processLog.AppendLine("Error on process import (" + lastStep + "): " + ex.Message);


                if (ex is SafeTrend.Xml.ResultEmptyException)
                {
                    Log2(this, PluginLogType.Error, 0, 0, "Network erro or API lock error importing user data", ex.Message + Environment.NewLine + "Last step: " + lastStep);
                }
                else
                {
                    Log2(this, PluginLogType.Error, 0, 0, "Error on process import: " + ex.Message, "Last step: " + lastStep);
                }
            }
            finally
            {
#if DEBUG
                Log2(this, PluginLogType.Debug, 0, 0, "Import debug log", debugLog.ToString());
#endif

                if (logType != PluginLogType.Information)
                {
                    processLog.AppendLine(debugLog.ToString());
                }

                Log2(this, logType, 0, 0, "Import executed", processLog.ToString());
                processLog.Clear();
                processLog = null;

                debugLog.Clear();
                debugLog = null;
            }
        }