Beispiel #1
0
        private void ProcQueue(RegistryProcessStarter queueItem, Object oStarter)
        {
            LocalTheadObjects starter = null;

            StringBuilder tLog = new StringBuilder();

            try
            {
                if ((oStarter != null) && (oStarter is LocalTheadObjects))
                {
                    starter = (LocalTheadObjects)oStarter;
                }

                if (starter == null)
                {
                    throw new Exception("Thread object starts is null");
                }

                if (starter.db == null)
                {
                    throw new Exception("Thread object starts database is null");
                }

                if (queueItem == null)
                {
                    throw new Exception("Queue item is null");
                }

                if (starter.lockRules == null)
                {
                    throw new Exception("Lock rules is null");
                }

                if (starter.ignoreRules == null)
                {
                    throw new Exception("Ignore rules is null");
                }

                if (starter.roleRules == null)
                {
                    throw new Exception("Role rules is null");
                }

                if (licControl == null)
                {
                    throw new Exception("Licence control is null");
                }

                if (entKeys == null)
                {
                    throw new Exception("Enterprise keys is null");
                }

                if (entKeys[queueItem.enterpriseId] == null)
                {
                    throw new Exception("Enterprise key of enterprise " + queueItem.enterpriseId + " is null");
                }

                if (licControl[queueItem.enterpriseId] == null)
                {
                    throw new Exception("Licence control of enterprise " + queueItem.enterpriseId + " is null");
                }

                PluginConfig pluginConfig = null;

                if ((pluginConfig == null) || (pluginConfig.resource_plugin != queueItem.resourcePluginId))
                {
                    if (pluginConfig != null)
                    {
                        pluginConfig.Dispose();
                        pluginConfig = null;
                    }

                    using (DataTable dtContext = starter.db.Select("select p.scheme, rp.* from resource_plugin rp with(nolock) inner join plugin p with(nolock) on rp.plugin_id = p.id where rp.id = " + queueItem.resourcePluginId))
                    {
                        if ((dtContext != null) && (dtContext.Rows.Count > 0))
                        {
                            pluginConfig = new PluginConfig(starter.db.Connection, dtContext.Rows[0]["scheme"].ToString(), (Int64)dtContext.Rows[0]["plugin_id"], (Int64)dtContext.Rows[0]["id"]);
                        }
                    }
                }

                if (pluginConfig == null)
                {
                    throw new Exception("Resource x plugin not found");
                }

                if (starter.debugCallback != null)
                {
                    starter.debugCallback("Package ID: " + queueItem.packageId);
                }

                //Realiza todo o processamento deste registro

                using (RegistryProcess proc = new RegistryProcess(localConfig.SqlServer, localConfig.SqlDb, localConfig.SqlUsername, localConfig.SqlPassword, pluginConfig, queueItem))
                {
                    RegistryProcess.ProccessLog log = new RegistryProcess.ProccessLog(delegate(String text)
                    {
                        tLog.AppendLine(text);
                    });


                    proc.OnLog += log;
                    RegistryProcessStatus status = proc.Process((EnterpriseKeyConfig)entKeys[queueItem.enterpriseId].Clone(), starter.lockRules, starter.ignoreRules, starter.roleRules, licControl[queueItem.enterpriseId]);
                    proc.OnLog -= log;

                    starter.db.AddUserLog(LogKey.Import, null, "Engine", (status == RegistryProcessStatus.Error ? UserLogLevel.Error : UserLogLevel.Info), 0, 0, 0, queueItem.resourceId, queueItem.pluginId, proc.EntityId, proc.IdentityId, "Import processed", tLog.ToString());

                    if (status == RegistryProcessStatus.OK)
                    {
                        Console.Write(".");

                        if (proc.NewUser)
                        {
                            newUsers++;
                        }
                    }
                    else if (status == RegistryProcessStatus.Ignored)
                    {
                        ignored++;
                    }
                    else
                    {
                        Console.Write("!");
                        errors++;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Write("!");
                errors++;


                if (starter.debugCallback != null)
                {
                    starter.debugCallback("\tError processing package (" + queueItem.packageId + "): " + ex.Message);
                }

//#if !DEBUG
                try
                {
                    tLog.AppendLine("Package: " + queueItem.package);
                }
                catch { }

                tLog.AppendLine("StackTrace: " + ex.StackTrace);
//#endif


                starter.db.AddUserLog(LogKey.Import, null, "Engine", UserLogLevel.Error, 0, 0, 0, queueItem.resourceId, queueItem.pluginId, 0, 0, ex.Message, tLog.ToString());
                starter.db.ExecuteNonQuery("update collector_imports set status = 'E' where status = 'F' and resource_plugin_id = '" + queueItem.resourcePluginId + "' and  import_id = '" + queueItem.importId + "' and package_id = '" + queueItem.packageId + "'", CommandType.Text, null);
            }
            finally
            {
                tLog = null;

                atualReg++;

                percent = ((Double)(atualReg) / (Double)totalReg) * 100F;

                if (iPercent != (Int32)percent)
                {
                    iPercent = (Int32)percent;
                    TextLog.Log("Engine", "Importer", "\t" + iPercent + "% -> New users: " + newUsers + ", Ignored: " + ignored + ", Errors: " + errors + ", Updated: " + (atualReg - errors - ignored - newUsers));

                    Console.Write(" " + iPercent + "% ");

                    Taskbar.TaskbarProgress.SetProgressValue((Int32)atualReg, (Int32)totalReg, System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle);
                }
            }
        }