Ejemplo n.º 1
0
        // Generar sectorización recibida desde SACTA
        public GeneraSectorizacionDll.Sectorization GeneraSectorizacion(SactaInfo info, DateTime mementoActivacion)
        {
            GeneraSectorizacionDll.Sectorization generaSectorizacion = null;
            bool releaseSem = false;

            info["Resultado"] = 0;

            try
            {
                releaseSem = SemaforoSectorizacionSacta.WaitOne(60000, false);
                if (!releaseSem)
                {
                    throw new SectorizationException(SectorizationResult.TimeOutError, "SectorizationResult.TimeOutError");
                }

                lock (_Sync)
                {
                    GestorBDCD40.ConexionMySql.Open();
                    using (MySqlCommand myCommand = GestorBDCD40.ConexionMySql.CreateCommand())
                    {
                        generaSectorizacion = new GeneraSectorizacionDll.Sectorization(myCommand, (string)info["IdSistema"], (string)info["SectName"], (string)info["SectData"], 'C', 'P', Tipo_Sectorizacion.Sectorizacion_Completa, mementoActivacion, true);
                    }
                }
            }
            catch (SectorizationException x)
            {
                info["Resultado"]  = 1;
                info["ErrorCause"] = x.Message;
            }
            catch (System.Data.SqlClient.SqlException sqlException)
            {
                info["Resultado"] = 1;
                System.Diagnostics.Debug.Assert(false, sqlException.Number.ToString());
                info["ErrorCause"] = sqlException.Message;
            }
            catch (Exception ex)
            {
                info["Resultado"] = 1;
                System.Diagnostics.Debug.Assert(false, ex.Message);
                info["ErrorCause"] = ex.Message;
            }
            finally
            {
                SemaforoSectorizacionSacta.Release();
                GestorBDCD40.ConexionMySql.Close();
            }

            EventResultSectorizacion(info);

            return((int)info["Resultado"] == 0 ? generaSectorizacion : null);
        }
    public string SectorizeFromSacta(uint Version, string dataSect)
    {
        var       info            = new SactaInfo();
        var       FechaActivacion = DateTime.Now;
        var       util            = new Utilidades(MySqlConnectionToCd40);
        int       Result          = 0;
        string    Cause           = default(string);
        object    sectorizacion   = null;
        Exception exception       = default(Exception);

        util.EventResultSectorizacion += new CD40.BD.SectorizacionEventHandler <CD40.BD.SactaInfo>((resinfo) =>
        {
            Result = (int)resinfo["Resultado"];
            Cause  = resinfo.ContainsKey("ErrorCause") ? (string)resinfo["ErrorCause"] : null;
        });

        info["Version"]   = Version;
        info["IdSistema"] = "departamento";
        info["SectName"]  = "SACTA";
        info["SectData"]  = dataSect;
        try
        {
            sectorizacion = util.GeneraSectorizacion(info, FechaActivacion);
        }
        catch (Exception x)
        {
            Result    = 1;
            Cause     = String.Format("Exception {0}", x.Message);
            exception = x;
        }
        return(JsonConvert.SerializeObject(new
        {
            Executed = sectorizacion != null,
            FechaActivacion,
            Version,
            Result,
            Cause,
            DataIn = new
            {
                Version,
                dataSect
            },
            exception
        }));;
    }