コード例 #1
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);
        }
コード例 #2
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;
            }
        }