コード例 #1
0
        public Crm(Comun comun)
        {
            Comun = comun;

            //Conexion a CRM
            CrmServiceClient conn = new CrmServiceClient(Comun.ConnStringCrm);

            IOS = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;

            UOMID             = GetDefaultUOMID();
            SheduleUOMID      = GetSheduleDefaultUOMID();
            TipoProductoNorma = GetTipoProductoDefaultNorma();
        }
コード例 #2
0
        List <KeyValuePair <string, string> > EmparentarComites;   //Comite , Comite padre.
        #endregion PROPIEDADES


        #region METODOS
        public Dictionary <string, Guid> Iniciar(Oracle ora, Comun com, Crm crm)
        {
            try
            {
                OracleGlobal = ora;
                ComunGlobal  = com;
                CrmGlobal    = crm;


                //1. Leer Comités de Oracle y CRM
                //Inicializa PFECore
                CrmGlobal.InicializarPFE(OracleGlobal);
                LeerComitesFromCRM();
                LeerComitesFromOracle();


                //2. Cargar Comités sin comité padre (son comités padres)   |
                //3. Cargar Resto de comités                                |  Cargar todos y emparentar despues
                if (ComitesOracle.Any())
                {
                    ComunGlobal.LogText("----   Iniciando sincronización COMITES   ------");
                    ComunGlobal.LogText("****   Registros a cotejar: " + ComitesOracle.Count);
                    #region PROCESA COMITES
                    bool          ok;
                    ComiteTecnico auxContCRM = new ComiteTecnico();
                    Entity        comiteUpdate;

                    foreach (var cmt in ComitesOracle)
                    {
                        ok = ComitesCRM.TryGetValue(cmt.Value.Aen_Codigo_Comite, out auxContCRM);

                        try
                        {
                            if (ok) // Existe, actualizamos
                            {
                                comiteUpdate = new Entity(NombresCamposComiteTecnico.EntityName);

                                bool res = cmt.Value.ComitesIguales(auxContCRM, ref comiteUpdate);

                                if (res)
                                {
                                    //Emparentar en update (por si el padre del comité se crea en este bloque también)
                                    //if (!cmt.Value.Aen_Codigo_PadreSTR.Equals(string.Empty) && cmt.Value.Aen_Codigo_Padre.Equals(Guid.Empty))
                                    //    EmparentarComites.Add(new KeyValuePair<string, string>(cmt.Value.Aen_Codigo_Comite, cmt.Value.Aen_Codigo_PadreSTR));

                                    CrmGlobal.AnadirElementoEmr(new UpdateRequest {
                                        Target = comiteUpdate
                                    });
                                }
                                else
                                {
                                    CrmGlobal.Iguales++;
                                }
                            }
                            else //No existe, creamos
                            {
                                Entity newCom = cmt.Value.GetEntity();

                                //Emparentar post-creación
                                if (!cmt.Value.Aen_Codigo_PadreSTR.Equals(string.Empty) && cmt.Value.Aen_Codigo_Padre.Equals(Guid.Empty))
                                {
                                    EmparentarComites.Add(new KeyValuePair <string, string>(cmt.Value.Aen_Codigo_Comite, cmt.Value.Aen_Codigo_PadreSTR));
                                }

                                CrmGlobal.AnadirElementoEmr(new CreateRequest {
                                    Target = newCom
                                });
                            }
                        }
                        catch (Exception e)
                        {
                            ComunGlobal.LogText("ERROR con el comité " + cmt.Value.Aen_Codigo_Comite + " ::: " + e.ToString());
                        }
                    }
                    CrmGlobal.ProcesarUltimosEmr();
                    #endregion PROCESA COMITES
                    CrmGlobal.MostrarEstadisticas("COMITES");
                    ComunGlobal.LogText("----   FIN sincronización COMITES   ------");
                }
                else
                {
                    ComunGlobal.LogText("No hay Comités Técnicos en origen, terminamos");
                }


                //4. Indexar Comités <códigoComite, Guid>
                CargaDiccionarioGuidsComites();

                //5. Emparentar Comités
                EmparentacionDeComites();

                LimpiezaDiccionarios();

                return(MaestroComitesCRM);
            }
            catch (Exception e)
            {
                ComunGlobal.LogText("ERROR en Lanzador de COMITES ::: " + e.ToString());
                if (OracleGlobal != null && OracleGlobal.OraConnParaLog.State == ConnectionState.Open)
                {
                    OracleGlobal.OraConnParaLog.Dispose();
                }

                return(null);
            }
        }
コード例 #3
0
ファイル: LanzadorICS.cs プロジェクト: jrtease/Migracion
        List <KeyValuePair <string, string> > EmparentarICS;   //Comite , Comite padre.
        #endregion PROPIEDADES


        #region METODOS
        public Dictionary <string, Guid> Iniciar(Oracle ora, Comun com, Crm crm)
        {
            try
            {
                OracleGlobal = ora;
                ComunGlobal  = com;
                CrmGlobal    = crm;


                //1. Leer ICS de Oracle y CRM
                //Inicializa PFECore
                CrmGlobal.InicializarPFE(OracleGlobal);
                LeerICSFromCRM();
                LeerICSFromOracle();


                //2. Cargar iCS sin ics padre (son ICS padres)   |
                //3. Cargar Resto de ICSs                        |  Cargar todos y emparentar despues
                if (ICSOracle.Any())
                {
                    ComunGlobal.LogText("----   Iniciando sincronización ICS   ------");
                    ComunGlobal.LogText("****   Registros a cotejar: " + ICSOracle.Count);
                    #region PROCESA ICS
                    bool   ok;
                    ICS    auxICSCRM = new ICS();
                    Entity icsUpdate;

                    foreach (var ics in ICSOracle)
                    {
                        ok = ICSCRM.TryGetValue(ics.Value.Aen_Codigo_Ics, out auxICSCRM);

                        try
                        {
                            if (ok) // Existe, actualizamos
                            {
                                icsUpdate = new Entity(NombresCamposICS.EntityName);

                                bool res = ics.Value.ICSIguales(auxICSCRM, ref icsUpdate);

                                if (res)
                                {
                                    //Emparentar en update (por si el padre del ICS se crea en este bloque también)
                                    //if (!ics.Value.Aen_Codigo_Ics_PadreSTR.Equals(string.Empty) && ics.Value.Aen_Codigo_Ics_Padre.Equals(Guid.Empty))
                                    //    EmparentarICS.Add(new KeyValuePair<string, string>(ics.Value.Aen_Codigo_Ics, ics.Value.Aen_Codigo_Ics_PadreSTR));

                                    CrmGlobal.AnadirElementoEmr(new UpdateRequest {
                                        Target = icsUpdate
                                    });
                                }
                                else
                                {
                                    CrmGlobal.Iguales++;
                                }
                            }
                            else //No existe, creamos
                            {
                                Entity newI = ics.Value.GetEntity();

                                //Emparentar post-creación
                                if (!ics.Value.Aen_Codigo_Ics_PadreSTR.Equals(string.Empty) && ics.Value.Aen_Codigo_Ics_Padre.Equals(Guid.Empty))
                                {
                                    EmparentarICS.Add(new KeyValuePair <string, string>(ics.Value.Aen_Codigo_Ics, ics.Value.Aen_Codigo_Ics_PadreSTR));
                                }

                                CrmGlobal.AnadirElementoEmr(new CreateRequest {
                                    Target = newI
                                });
                            }
                        }
                        catch (Exception e)
                        {
                            ComunGlobal.LogText("ERROR con el ICS " + ics.Value.Aen_Codigo_Ics + " ::: " + e.ToString());
                        }
                    }
                    CrmGlobal.ProcesarUltimosEmr();
                    #endregion PROCESA ICS
                    CrmGlobal.MostrarEstadisticas("ICS");
                    ComunGlobal.LogText("----   FIN sincronización ICS   ------");
                }
                else
                {
                    ComunGlobal.LogText("No hay ICS en origen, terminamos");
                }



                //4. Indexar Comités <códigoComite, Guid>
                CargaDiccionarioGuidsICS();

                //5. Emparentar Comités
                EmparentacionDeICS();

                LimpiezaDiccionarios();

                return(MaestroICSCRM);
            }
            catch (Exception e)
            {
                ComunGlobal.LogText("ERROR en Lanzador de ICS ::: " + e.ToString());
                if (OracleGlobal != null && OracleGlobal.OraConnParaLog.State == ConnectionState.Open)
                {
                    OracleGlobal.OraConnParaLog.Dispose();
                }

                return(null);
            }
        }
コード例 #4
0
        public void Iniciar(Oracle ora, Comun com, Crm crm)
        {
            try
            {
                OracleGlobal = ora;
                ComunGlobal  = com;
                CrmGlobal    = crm;

                ComunGlobal.LogText("*************************************************************************");

                /*1. Carga Comités Padres (Tabla 'Comites Tecnicos')
                 * 2. Carga resto Comités (Tabla 'Comites Tecnicos')*/
                MaestroComitesCRM = new LanzadorComitesTecnicos().Iniciar(OracleGlobal, ComunGlobal, CrmGlobal);
                ComunGlobal.LogText("*************************************************************************");


                /*3. Carga Normas ICS sin padres (Tabla 'ICS')
                 * 4. Carga resto de Normas ICS (Tabla 'ICS') */
                MaestroICSCRM = new LanzadorICS().Iniciar(OracleGlobal, ComunGlobal, CrmGlobal);
                ComunGlobal.LogText("*************************************************************************");


                LeeFromCRMMaestros();
                LeeFromOracleRaices();

                //5. Cargar Normas (Raíz: De las tablas de 'Normas' obtener los distintos valores de Aen_Raiz_Norma y cargarlos en la entidad aen_norma)
                //  5.1 Diccionario <código, Guid> de Normas Raices
                #region PROCESAR NORMAS RAIZ
                bool   ok;
                Guid   normRGuid;
                Entity auxRaiz;
                if (RaicesNormas.Any())
                {
                    ComunGlobal.LogText("----   Iniciando CARGA NORMAS RAIZ  ------");
                    ComunGlobal.LogText("****   Registros a cotejar: " + RaicesNormas.Count);
                    foreach (var rz in RaicesNormas)
                    {
                        ok = RaicesNormasCRM.TryGetValue(rz, out normRGuid);
                        //No existe, creamos
                        if (!ok)
                        {
                            auxRaiz = new Entity(NombreCamposNormas.EntityNameRaiz);
                            auxRaiz[NombreCamposNormas.Aen_CodigoRaizNorma] = rz;
                            CrmGlobal.AnadirElementoEmr(new CreateRequest {
                                Target = auxRaiz
                            });
                        }
                        else
                        {
                            CrmGlobal.Iguales++;
                        }
                    }
                    CrmGlobal.ProcesarUltimosEmr();

                    if (RaicesNormas.Count > 0)
                    {
                        CargaMaestroRaicesCRM();
                    }

                    CrmGlobal.MostrarEstadisticas("NORMAS RAIZ");
                    ComunGlobal.LogText("----   FINALIZADA CARGA NORMAS RAIZ  ------");
                }
                else
                {
                    ComunGlobal.LogText("No hay NORMAS RAIZ en origen, terminamos");
                }
                #endregion PROCESAR NORMAS RAIZ
                ComunGlobal.LogText("*************************************************************************");


                //6. Cargar Normas-Version (Tabla 'Normas' enlazando ya el campo Aen_Raiz_Norma)
                LeeFromCRMVersiones();
                LeeFromOracleVersiones();
                if (NormasOracle.Any())
                {
                    #region PROCESA NORMAS VERSION
                    ComunGlobal.LogText("----   Iniciando CARGA NORMAS VERSION  ------");
                    ComunGlobal.LogText("****   Registros a cotejar: " + NormasOracle.Count);
                    Normas auxNormCRM = new Normas();
                    Entity norUpdate;

                    foreach (var nor in NormasOracle)
                    {
                        ok = NormasCRM.TryGetValue(nor.Value.Aen_Articulo, out auxNormCRM);

                        try
                        {
                            if (ok) // Existe, actualizamos
                            {
                                norUpdate = new Entity(NombresCamposICS.EntityName);

                                bool res = nor.Value.VersionesIguales(auxNormCRM, ref norUpdate);

                                if (res)
                                {
                                    CrmGlobal.AnadirElementoEmr(new UpdateRequest {
                                        Target = norUpdate
                                    });
                                }
                                else
                                {
                                    CrmGlobal.Iguales++;
                                }
                            }
                            else //No existe, creamos
                            {
                                Entity newI = nor.Value.GetEntity();
                                CrmGlobal.AnadirElementoEmr(new CreateRequest {
                                    Target = newI
                                });
                            }
                        }
                        catch (Exception e)
                        {
                            ComunGlobal.LogText("ERROR con la Norma Versión " + nor.Value.Aen_Articulo + " ::: " + e.ToString());
                        }
                    }
                    CrmGlobal.ProcesarUltimosEmr();
                    CrmGlobal.MostrarEstadisticas("NORMAS VERSION");
                    ComunGlobal.LogText("----   Finalizada CARGA NORMAS VERSION  ------");
                    #endregion PROCESA NORMAS VERSION
                }
                else
                {
                    ComunGlobal.LogText("No hay NORMAS VERSION en origen, terminamos");
                }
                ComunGlobal.LogText("*************************************************************************");


                //7. Cargar Productos (Tabla 'Normas-Producto')
                CargaMaestroVersionesCRM();
                LeeFromCRMProductoseICS();
                LeeFromOracleProductoseICS();
                if (NormasProductosOracle.Any())
                {
                    #region PROCESA PRODUCTOS
                    ComunGlobal.LogText("----   Iniciando CARGA PRODUCTOS  ------");
                    ComunGlobal.LogText("****   Registros a cotejar: " + NormasProductosOracle.Count);
                    NormasProductos auxNpCRM = new NormasProductos();
                    Entity          npUpdate;

                    foreach (var norP in NormasProductosOracle)
                    {
                        ok = NormasProductosCRM.TryGetValue(norP.Value.Aen_Codigo_Producto, out auxNpCRM);

                        try
                        {
                            if (ok) // Existe, actualizamos
                            {
                                npUpdate = new Entity(NombreCamposNormasProductos.EntityName);

                                bool res = norP.Value.NormasProductosIguales(auxNpCRM, ref npUpdate, CrmGlobal.TipoProductoNorma, CrmGlobal.UOMID, CrmGlobal.SheduleUOMID);

                                if (res)
                                {
                                    CrmGlobal.AnadirElementoEmr(new UpdateRequest {
                                        Target = npUpdate
                                    });
                                }
                                else
                                {
                                    CrmGlobal.Iguales++;
                                }
                            }
                            else //No existe, creamos
                            {
                                Entity newE = norP.Value.GetEntity(CrmGlobal.TipoProductoNorma, CrmGlobal.UOMID, CrmGlobal.SheduleUOMID);
                                CrmGlobal.AnadirElementoEmr(new CreateRequest {
                                    Target = newE
                                });
                            }
                        }
                        catch (Exception e)
                        {
                            ComunGlobal.LogText("ERROR con el producto " + norP.Value.Aen_Codigo_Producto + " ::: " + e.ToString());
                        }
                    }
                    CrmGlobal.ProcesarUltimosEmr();
                    CrmGlobal.MostrarEstadisticas("PRODUCTOS Carga");
                    ComunGlobal.LogText("----   Finalizada CARGA PRODUCTOS  ------");
                    #endregion PROCESA PRODUCTOS
                }
                else
                {
                    ComunGlobal.LogText("No hay PRODUCTOS en origen, terminamos");
                }
                ComunGlobal.LogText("*************************************************************************");


                //8. Asociar Normas ICS (Tabla 'ICS' + intermedia 'Normas-ICS') a Normas Versión
                if (NormasICSOracle.Any())
                {
                    #region PROCESA RELACIONES NORMAS VERSION - ICS
                    ComunGlobal.LogText("----   Iniciando ENLACE ICS-VERSION  ------");
                    ComunGlobal.LogText("****   Registros a cotejar: " + NormasICSOracle.Count);
                    KeyValuePair <Guid, Guid> aux;
                    foreach (var nicsOra in NormasICSOracle)
                    {
                        if (nicsOra.Key != Guid.Empty && nicsOra.Value != Guid.Empty)
                        {
                            bool enlazado = NormasICSCRM.TryGetValue(nicsOra.Key.ToString() + "&" + nicsOra.Value.ToString(),
                                                                     out aux);
                            if (!enlazado)
                            {
                                CrmGlobal.AnadirElementoEmr(CrmGlobal.getAssociateRequest(NombresCamposICS.EntityName, nicsOra.Value, NombresCamposNormasICS.RelationshipName, NombreCamposNormas.EntityNameVersion, nicsOra.Key));
                            }
                            else
                            {
                                CrmGlobal.Iguales++;
                            }
                        }
                    }
                    CrmGlobal.ProcesarUltimosEmr();
                    CrmGlobal.MostrarEstadisticas("ENLACES ICS-VERSION");
                    ComunGlobal.LogText("----   Finalizado ENLACE ICS-VERSION  ------");
                    #endregion PROCESA RELACIONES NORMAS VERSION - ICS
                }
                else
                {
                    ComunGlobal.LogText("No hay ICS a enlazar en NORMAS VERSION, terminamos");
                }
                ComunGlobal.LogText("*************************************************************************");

                LimpiezaDiccionarios();

                ComunGlobal.LogText("----   FIN CARGA   ------");
            }
            catch (Exception e)
            {
                ComunGlobal.LogText("ERROR en Lanzador de NORMAS ::: " + e.ToString());
                if (OracleGlobal != null && OracleGlobal.OraConnParaLog.State == ConnectionState.Open)
                {
                    OracleGlobal.OraConnParaLog.Dispose();
                }
            }
        }