//----------------------------------------------------------------------
        private void CFormVisualisationRapport_Load(object sender, System.EventArgs e)
        {
            if (m_document != null)
            {
                ReportDocument doc = new ReportDocument();
                m_proxyGED = new CProxyGED(m_document.ContexteDonnee.IdSession, m_document.ReferenceDoc);
                if (!m_proxyGED.IsFichierRappatrie())
                {
                    CResultAErreur result = m_proxyGED.CopieFichierEnLocal();
                    if (!result)
                    {
                        return;
                    }
                }
                doc.Load(m_proxyGED.NomFichierLocal);
                doc.Refresh();
                doc.SetDataSource(m_dataset);
                m_viewer.ReportSource = doc;
                return;
            }

            if (!m_bRapportLoadInViewer)
            {
                m_lblReport.Text = "";
                if (m_rapport == null)
                {
                    return;
                }
                m_lblReport.Text = m_rapport.Libelle;
                try
                {
                    m_proxyGED = new CProxyGED(m_rapport.ContexteDonnee.IdSession, m_rapport.DocumentGED.ReferenceDoc);
                }
                catch
                {
                    CFormAlerte.Afficher(I.T("The Report model is not defined|1008"), EFormAlerteType.Erreur);
                    return;
                }
                CResultAErreur result = m_proxyGED.CopieFichierEnLocal();
                if (!result)
                {
                    return;
                }


                m_viewer.DisplayGroupTree = false;

                ChargerPanelFiltre();
                if (!m_panelFiltre.Visible)
                {
                    Filtrer();
                }

                m_bRapportLoadInViewer = true;
            }
        }
Esempio n. 2
0
        private void UpdateVisuel()
        {
            m_picDocument.Visible = !m_wndDocuments.HideHeader;
            this.SuspendDrawing();
            bool bPreviewVisible = false;

            if (m_listeDocuments.Count == 1 && m_wndDocuments.DisplayDocuments)
            {
                CDocumentGED doc = m_listeDocuments[0];
                if (m_proxyVisu != null)
                {
                    m_proxyVisu.Dispose();
                    m_proxyVisu = null;
                }
                m_proxyVisu = new CProxyGED(doc.ContexteDonnee.IdSession, doc.ReferenceDoc);
                if (!m_proxyVisu.CopieFichierEnLocal())
                {
                    m_proxyVisu.Dispose();
                    m_proxyVisu = null;
                }
                else
                {
                    if (m_visualiseurGed.ShowDocument(m_proxyVisu.NomFichierLocal))
                    {
                        m_lblDocument.Visible    = false;
                        m_visualiseurGed.Dock    = DockStyle.Fill;
                        m_visualiseurGed.Visible = true;
                        bPreviewVisible          = true;
                    }
                }
            }
            if (!bPreviewVisible)
            {
                m_visualiseurGed.Visible = false;
                m_lblDocument.Visible    = true;
                bool bShowLabel = m_listeDocuments.Count == 1 && m_listeDocuments[0].Libelle.Length > 0;
                if (bShowLabel)
                {
                    m_lblDocument.Text = m_listeDocuments[0].Libelle;
                }
                else
                {
                    if (m_listeDocuments.Count == 0)
                    {
                        m_lblDocument.Text = I.T("No document|20758");
                    }
                    else
                    {
                        m_lblDocument.Text = I.T("@1 document(s)|20759", m_listeDocuments.Count.ToString());
                    }
                }
            }
            this.ResumeDrawing();
        }
Esempio n. 3
0
        private CResultAErreur CopyToFtp(
            int nIdSession,
            CDocumentGED document,
            string strNomFichierDest,
            string strUser,
            string strPassword)
        {
            CResultAErreur result = CResultAErreur.True;

            if (!strNomFichierDest.ToUpper().StartsWith("FTP://"))
            {
                result.EmpileErreur(I.T("Bad file name '@1' for ftp transfert|20252", strNomFichierDest));
                return(result);
            }
            try
            {
                using (CProxyGED proxy = new CProxyGED(nIdSession, document.ReferenceDoc))
                {
                    result = proxy.CopieFichierEnLocal();
                    if (!result)
                    {
                        return(result);
                    }

                    FtpWebRequest req = (FtpWebRequest)WebRequest.Create(strNomFichierDest);
                    req.Method = WebRequestMethods.Ftp.UploadFile;
                    if (strUser.Length > 0 || strPassword.Length > 0)
                    {
                        req.Credentials = new NetworkCredential(strUser, strPassword);
                    }
                    FileStream reader        = new FileStream(proxy.NomFichierLocal, FileMode.Open, FileAccess.Read);
                    byte[]     buff          = new byte[1024];
                    Stream     requestStream = req.GetRequestStream();
                    int        nSize         = 0;
                    int        nSizeTotal    = 0;
                    while ((nSize = reader.Read(buff, 0, 1024)) > 0)
                    {
                        nSizeTotal += nSizeTotal;
                        requestStream.Write(buff, 0, nSize);
                    }
                    req.ContentLength = nSizeTotal;
                    requestStream.Close();
                    reader.Close();
                    FtpWebResponse reponse = (FtpWebResponse)req.GetResponse();
                    reponse.Close();
                }
            }
            catch (Exception e)
            {
                result.EmpileErreur(new CErreurException(e));
            }
            return(result);
        }
        private void m_btnModifierModele_Click(object sender, System.EventArgs e)
        {
            CResultAErreur result = CResultAErreur.True;

            MAJ_Champs();

            if ((Rapport.DocumentGED == null || Rapport.DocumentGED.ReferenceDoc == null) && m_proxyReport == null)
            {
                m_proxyReport.CreateNewFichier();
            }
            else
            {
                if (!m_proxyReport.IsFichierRappatrie())
                {
                    result = m_proxyReport.CopieFichierEnLocal();
                    if (!result)
                    {
                        result.EmpileErreur(I.T("Error while reading document from EDM|30230"));
                        CFormAlerte.Afficher(result.Erreur);
                        if (CFormAlerte.Afficher(I.T("The original model could not have been read again, create a new model ?|30231"),
                                                 EFormAlerteType.Question) == DialogResult.No)
                        {
                            return;
                        }
                        m_proxyReport.CreateNewFichier();
                    }
                }
            }

            if (!CreateJeuDeTest())
            {
                return;
            }

            DataSet m_datasetTest = m_panelMultiStructure.GetJeuEssai(null);

            m_fichierDonnees.CreateNewFichier();
            result = new CExporteurDatasetAccess().Export(m_datasetTest, new CDestinationExportFile(m_fichierDonnees.NomFichier));
            if (!result)
            {
                CFormAlerte.Afficher(result.Erreur);
                return;
            }
            if (result)
            {
                CEditeurEtatCrystal.EditeEtat(m_fichierDonnees.NomFichier, m_proxyReport.NomFichierLocal);
            }
        }
Esempio n. 5
0
        //-------------------------------------------------------------------------------------
        public static void AfficheAlarmes(CMemoryDb database, CParametrageAffichageListeAlarmes paramConsultation, CFormNavigateur nav)
        {
            CFormConsultationAlarmesEnCours form = new CFormConsultationAlarmesEnCours();

            form.Text         = paramConsultation.Libelle;
            form.m_dataBase   = database;
            form.m_navigateur = nav;
            form.TopMost      = false;
            CParametreAffichageListeAlarmes parametre = paramConsultation.ParametreAffichageAlarmes;

            if (parametre == null)
            {
                parametre = CParametreAffichageListeAlarmes.ParametreParDefaut;
            }

            form.m_parametreAffichage = parametre;

            CDocumentGED docSonnerie = paramConsultation.DocumentFichierSon;

            if (docSonnerie != null && docSonnerie.ReferenceDoc != null)
            {
                CProxyGED proxySonnerie = new CProxyGED(paramConsultation.ContexteDonnee.IdSession, docSonnerie.ReferenceDoc);
                if (proxySonnerie.CopieFichierEnLocal())
                {
                    form.m_proxySonnerie = proxySonnerie;
                }
                else
                {
                    proxySonnerie.Dispose();
                    proxySonnerie = null;
                }
            }

            form.m_dicImages.Clear();
            CListeObjetsDonnees listTypesAlarmes = new CListeObjetsDonnees(paramConsultation.ContexteDonnee, typeof(CTypeAlarme));

            foreach (CTypeAlarme typeAlarme in listTypesAlarmes)
            {
                if (typeAlarme.Image != null)
                {
                    form.m_dicImages.Add(typeAlarme.Id.ToString(), typeAlarme.Image);
                }
            }

            form.Show();
        }
Esempio n. 6
0
        /// ///////////////////////////////////////////
        public override sc2i.common.CResultAErreur RunService(object parametre)
        {
            CResultAErreur result = CResultAErreur.True;

            CActionCopieDocumentGed.CParametreCopierLocalDansGed parametreCopie = parametre as CActionCopieDocumentGed.CParametreCopierLocalDansGed;
            if (parametreCopie == null)
            {
                result.EmpileErreur(I.T("Bad parameter value for service SetLocalFile|20125"));
                return(result);
            }
            using (CContexteDonnee contexte = new CContexteDonnee(CTimosApp.SessionClient.IdSession, true, false))
            {
                CDocumentGED document = new CDocumentGED(contexte);
                if (!document.ReadIfExists(parametreCopie.IdDocumentGed))
                {
                    result.EmpileErreur(I.T("Document @1 doesn't exists|20126"));
                    return(result);
                }
                try
                {
                    using (CProxyGED proxy = new CProxyGED(CTimosApp.SessionClient.IdSession, document.ReferenceDoc))
                    {
                        result = proxy.CopieFichierEnLocal();
                        if (!result)
                        {
                            return(result);
                        }
                        File.Copy(proxy.NomFichierLocal, parametreCopie.NomFichier, true);
                    }
                }
                catch (Exception e)
                {
                    result.EmpileErreur(new CErreurException(e));
                }
            }
            return(result);
        }
Esempio n. 7
0
        public CFormListeAlarmeEnCours(CConsultationAlarmesEnCoursInDb consultation, CFormNavigateur navigateur)
        {
            c_nBaseControleRetombee = 15000 / c_nTimeClignote;

            List <string> strNomColonnes;
            string        st;
            TimeSpan      duree;
            DateTime      start, stop;

            m_consultationEnCours = consultation;

            m_navigateur = navigateur;

            start = DateTime.Now;

            InitializeComponent();

            this.Text             = consultation.Libelle;
            m_timerVoyant.Enabled = true;

            stop  = DateTime.Now;
            duree = stop - start; //test duree = 8 sec !!!!!!!

            m_recepteurNotifications = new CRecepteurNotification(CSc2iWin32DataClient.ContexteCourant.IdSession, typeof(CDonneeNotificationAlarmes));
            m_recepteurNotifications.OnReceiveNotification += new NotificationEventHandler(OnReceiveNotificationAlarmEnCours);

            /*   m_recepteurNotificationsStop = new CRecepteurNotification(CSc2iWin32DataClient.ContexteCourant.IdSession, typeof(CDonneeNotificationAlarmesStop));
             * m_recepteurNotificationsStop.OnReceiveNotification += new NotificationEventHandler(OnReceiveNotificationStop);
             *
             * m_recepteurNotificationsMask = new CRecepteurNotification(CSc2iWin32DataClient.ContexteCourant.IdSession, typeof(CDonneeNotificationAlarmesMask));
             * m_recepteurNotificationsMask.OnReceiveNotification += new NotificationEventHandler(OnReceiveNotificationMask);
             *
             * m_recepteurNotificationsAcknowledge = new CRecepteurNotification(CSc2iWin32DataClient.ContexteCourant.IdSession, typeof(CDonneeNotificationAlarmesAcknowledge));
             * m_recepteurNotificationsAcknowledge.OnReceiveNotification += new NotificationEventHandler(OnReceiveNotificationAcknowledge);*/


            List <CInfoAlarmeAffichee> lstEnCours = new List <CInfoAlarmeAffichee>();
            List <CInfoAlarmeAffichee> lstRetombe = new List <CInfoAlarmeAffichee>();

            m_lstViewEnCours.OnGetDonneesObjet += new GetDonneesLigneEventHandler(GetDonneesObjetEnCours);
            m_lstViewRetombe.OnGetDonneesObjet += new GetDonneesLigneEventHandler(GetDonneesObjetRetombe);

            m_lstViewEnCours.DoubleClick += new EventHandler(OnLstViewEnCoursDoubleClick);
            m_lstViewRetombe.DoubleClick += new EventHandler(OnLstViewRetombeDoubleClick);

            lstEnCours = GetAlarmsInfoFromDB();

            strNomColonnes = m_consultationEnCours.Parametres.GetColumnNames();

            m_lstViewEnCours.Init(strNomColonnes.ToArray(), lstEnCours.ToArray());

            st = I.T("End date|60023");
            strNomColonnes.Add(st);
            st = I.T("Duration|60022");
            strNomColonnes.Add(st);
            m_lstViewRetombe.Init((string[])strNomColonnes.ToArray(), lstRetombe.ToArray());

            m_strMaskAdminButtonText = I.T("Alarms masked by Administrator|60016") + " : ";
            m_strMaskBrigButtonText  = I.T("Alarms masked by Operating agent|60017") + " : ";
            m_strFrequentButtonText  = I.T("Current frequent alarms|60018") + " : ";

            InitButtonsInfo();

            MAJFrequentButtonText();
            MAJAdminButtonText();
            MAJBrigButtonText();

            m_btnMaskedOnCreation.Text = I.T("Alarms masked on creation|60047") + " : " + m_NbMasqCreat.ToString();

            label1.Text = I.T("Current alarms|60014");
            label2.Text = I.T("Cleared alarms|60015");

            CDocumentGED docSonnerie = consultation.DocumentGEDSoundFile;

            if (docSonnerie != null && docSonnerie.ReferenceDoc != null)
            {
                m_proxySonnerie = new CProxyGED(consultation.ContexteDonnee.IdSession, docSonnerie.ReferenceDoc);
                if (!m_proxySonnerie.CopieFichierEnLocal())
                {
                    m_proxySonnerie.Dispose();
                    m_proxySonnerie = null;
                }
            }

            //SetVoyantAlarme();
            Type tpVar = GetType();

            Type tpGeneric = typeof(List <>);

            tpGeneric = tpGeneric.MakeGenericType(tpVar);

            object liste = Activator.CreateInstance(tpGeneric);
        }
Esempio n. 8
0
        /// ////////////////////////////////////////////////////////////////
        public CResultAErreur SendMail(CMailSC2I mail)
        {
            CResultAErreur result  = CResultAErreur.True;
            MailMessage    message = new MailMessage();

            message.From       = new MailAddress(mail.Expediteur);
            message.Subject    = mail.Sujet;
            message.Body       = mail.Message;
            message.IsBodyHtml = mail.IsFormatHTML;
            // Destinataires To
            if (mail.Destinataires != null)
            {
                foreach (string strDest in mail.Destinataires)
                {
                    message.To.Add(new MailAddress(strDest));
                }
            }

            // Destinataires CC
            if (mail.DestinatairesCC != null)
            {
                foreach (string strDest in mail.DestinatairesCC)
                {
                    message.CC.Add(new MailAddress(strDest));
                }
            }

            // Destinataires BCC
            if (mail.DestinatairesBCC != null)
            {
                foreach (string strDest in mail.DestinatairesBCC)
                {
                    message.Bcc.Add(new MailAddress(strDest));
                }
            }


            ArrayList lstProxy = new ArrayList();

            using (CContexteDonnee contexte = new CContexteDonnee(IdSession, true, false))
            {
                foreach (int nIdDoc in mail.DocumentsGED)
                {
                    CDocumentGED doc = new CDocumentGED(contexte);
                    if (doc.ReadIfExists(nIdDoc) && doc.ReferenceDoc != null)
                    {
                        CProxyGED proxy = new CProxyGED(IdSession, doc.ReferenceDoc);
                        // Ajouter un paramètre optionnel CopieFichierEnLocal(doc.Libelle)
                        if (proxy.CopieFichierEnLocal(mail.UseDocLabelAsFileName ? doc.Libelle : ""))
                        {
                            lstProxy.Add(proxy);
                            Attachment att = new Attachment(proxy.NomFichierLocal);
                            message.Attachments.Add(att);
                        }
                    }
                }
            }

            try
            {
                string strServeur = "";
                string strUser    = "";
                string strPass    = "";
                int    nPort      = 0;

                if (mail.SMTPServer != String.Empty)
                {
                    strServeur = mail.SMTPServer;
                    nPort      = mail.SMTPPort;
                    strUser    = mail.SMTPUser;
                    strPass    = mail.SMTPPassword;
                }
                else
                {
                    strServeur = CTimosServeurRegistre.SMTPServer;
                    nPort      = CTimosServeurRegistre.SMTPPort;
                    strUser    = CTimosServeurRegistre.SMTPUser;
                    strPass    = CTimosServeurRegistre.SMTPPassword;
                }

                using (SmtpClient clientSmtp = new SmtpClient())
                {
                    clientSmtp.Host = strServeur;
                    if (nPort > 0)
                    {
                        clientSmtp.Port = nPort;
                    }
                    if (strUser != "" || strPass != "")
                    {
                        clientSmtp.Credentials = new NetworkCredential(strUser, strPass);
                    }
                    else
                    {
                        clientSmtp.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
                    }
                    clientSmtp.Send(message);
                }
            }
            catch (Exception e)
            {
                result.EmpileErreur(e.ToString());
                result.EmpileErreur(I.T("Error while sending mail|30000"));
            }
            finally
            {
                message.Dispose();
            }
            foreach (CProxyGED proxy in lstProxy)
            {
                proxy.Dispose();
            }
            return(result);
        }
Esempio n. 9
0
        /// ////////////////////////////////////////////////////////
        protected override CResultAErreur MyExecute(CContexteExecutionAction contexte)
        {
            CResultAErreur result = CResultAErreur.True;
            CProxyGED      proxy  = null;

            try
            {
                CContexteEvaluationExpression ctxEval = new CContexteEvaluationExpression(Process);
                if (FormuleFichierSource == null)
                {
                    result.EmpileErreur(I.T("Incorrect source file formula|506"));
                    return(result);
                }
                result = FormuleFichierSource.Eval(ctxEval);
                if (!result)
                {
                    return(result);
                }


                string strFichier = "";

                if (result.Data is CDocumentGED)
                {
                    CDocumentGED doc = result.Data as CDocumentGED;
                    proxy  = new CProxyGED(contexte.IdSession, doc.ReferenceDoc);
                    result = proxy.CopieFichierEnLocal();
                    if (!result)
                    {
                        return(result);
                    }
                    strFichier = proxy.NomFichierLocal;
                }
                else
                {
                    strFichier = result.Data.ToString();
                }
                if (!File.Exists(strFichier))
                {
                    result.EmpileErreur(I.T("Source file @1 doesn't exist |508", result.Data.ToString()));
                    return(result);
                }

                if (FormuleTableAImporter == null)
                {
                    result.EmpileErreur(I.T("Incorrect destination table formula|505"));
                    return(result);
                }
                result = FormuleTableAImporter.Eval(ctxEval);
                if (!result)
                {
                    result.EmpileErreur(I.T("Error while evaluating destination table formula|510"));
                    return(result);
                }
                if (!(result.Data is CTableParametrable))
                {
                    result.EmpileErreur(I.T("Destination table formula doesn't return a table|511"));
                    return(result);
                }
                CTableParametrable tableParametrable = (CTableParametrable)result.Data;

                if (tableParametrable.TypeTable.ParametrageCSV == null)
                {
                    result.EmpileErreur(I.T("Table type @1 doesn't contains import setup|20002", tableParametrable.TypeTable.Libelle));
                    return(result);
                }

                // Sélectionne le type de fichier Excel ou CSV (texte)
                IParametreLectureFichier parametre;
                int    nPositionduPoint = strFichier.LastIndexOf('.');
                string strExtension     = strFichier.Substring(nPositionduPoint + 1, strFichier.Length - nPositionduPoint - 1);
                if (strExtension.ToUpper() == "XLS" || strExtension.ToUpper() == "XLSX")
                {
                    parametre = tableParametrable.TypeTable.ParametrageXLS;
                }
                else
                {
                    parametre = tableParametrable.TypeTable.ParametrageCSV;
                }

                result = parametre.LectureFichier(strFichier);

                if (!result || !(result.Data is DataTable))
                {
                    result.EmpileErreur(I.T("Error while reading text file|509"));
                    return(result);
                }
                DataTable tableSource = (DataTable)result.Data;

                Dictionary <DataColumn, CColonneTableParametrable> mappage = new Dictionary <DataColumn, CColonneTableParametrable>();
                int nNbChamps = Math.Min(parametre.Mappage.StringsA.Count, parametre.Mappage.StringsB.Count);
                for (int nChamp = 0; nChamp < nNbChamps; nChamp++)
                {
                    DataColumn col = tableSource.Columns[parametre.Mappage.StringsA[nChamp]];
                    if (col != null)
                    {
                        CColonneTableParametrable colRetenue = null;
                        foreach (CColonneTableParametrable colonne in tableParametrable.TypeTable.Colonnes)
                        {
                            if (colonne.Libelle == parametre.Mappage.StringsB[nChamp])
                            {
                                colRetenue = colonne;
                                break;
                            }
                        }
                        if (colRetenue != null)
                        {
                            mappage[col] = colRetenue;
                        }
                    }
                }


                // Réalise l'import
                result = tableParametrable.ImportTable(tableSource, mappage, m_modeImport);
                if (!result)
                {
                    return(result);
                }
            }
            catch (Exception e)
            {
                result.EmpileErreur(new CErreurException(e));
            }
            finally
            {
                if (proxy != null)
                {
                    proxy.Dispose();
                }
            }

            return(result);
        }
Esempio n. 10
0
        /// ////////////////////////////////////////////////////////
        protected override CResultAErreur MyExecute(CContexteExecutionAction contexte)
        {
            CResultAErreur result = CResultAErreur.True;

            CContexteEvaluationExpression contexteEval = new CContexteEvaluationExpression(Process);

            if (FormuleDocument == null)
            {
                result.EmpileErreur(I.T("Incorrect document formula|363"));
                return(result);
            }
            result = FormuleDocument.Eval(contexteEval);
            if (!result)
            {
                result.EmpileErreur(I.T("Error during Document evaluation|367"));
                return(result);
            }
            if (!(result.Data is CDocumentGED))
            {
                result.EmpileErreur(I.T("The document formula must return an EDM document|364"));
                return(result);
            }
            CDocumentGED document = (CDocumentGED)result.Data;

            if (FormuleNomFichier == null)
            {
                result.EmpileErreur(I.T("Incorrect file name formula|365"));
                return(result);
            }
            result = FormuleNomFichier.Eval(contexteEval);
            if (!result)
            {
                result.EmpileErreur(I.T("Error during the destination file name of document evaluation|368"));
                return(result);
            }
            if (!(result.Data is string))
            {
                result.EmpileErreur(I.T("File name formula doesn't return a file name string|369"));
                return(result);
            }

            string strNomFichier = result.Data.ToString();

            if (strNomFichier.ToUpper().StartsWith("FTP://"))
            {
                string strUser     = "";
                string strPassword = "";
                if (FormuleUser != null)
                {
                    result = FormuleUser.Eval(contexteEval);
                }
                if (!result)
                {
                    result.EmpileErreur(I.T("Error in User formula|20250"));
                    return(result);
                }
                else
                {
                    strUser = result.Data != null?result.Data.ToString() : "";
                }
                if (FormulePassword != null)
                {
                    result = FormulePassword.Eval(contexteEval);
                }
                if (!result)
                {
                    result.EmpileErreur(I.T("Error in password formula|20250"));
                    return(result);
                }
                else
                {
                    strPassword = result.Data != null?result.Data.ToString() : "";
                }
                return(CopyToFtp(contexte.IdSession, document, strNomFichier, strUser, strPassword));
            }
            else if (CopierDepuisLePosteClient)
            {
                CSessionClient sessionClient = CSessionClient.GetSessionForIdSession(contexte.IdSession);
                if (sessionClient != null)
                {
                    //TESTDBKEYOK
                    if (sessionClient.GetInfoUtilisateur().KeyUtilisateur == contexte.Branche.KeyUtilisateur)
                    {
                        using (C2iSponsor sponsor = new C2iSponsor())
                        {
                            CServiceSurClient service = sessionClient.GetServiceSurClient(c_idServiceClientSetFichier);
                            if (service != null)
                            {
                                sponsor.Register(service);
                                CParametreCopierLocalDansGed parametre = new CParametreCopierLocalDansGed(
                                    document.Id,
                                    strNomFichier);
                                result = service.RunService(parametre);
                                return(result);
                            }
                        }
                    }
                }
            }

            if (File.Exists(strNomFichier))
            {
                #region renommage du fichier existant
                if (FormuleNomFichierRenommage != null)
                {
                    result = FormuleNomFichierRenommage.Eval(contexteEval);
                    if (!result)
                    {
                        result.EmpileErreur(I.T("Error in the renaming file name|370"));
                        return(result);
                    }
                    if (!(result.Data is string))
                    {
                        result.EmpileErreur(I.T("The renaming formula doesn't return text|371"));
                        return(result);
                    }
                    int    nIndex    = 0;
                    string strRename = result.Data.ToString();
                    string strExt    = "";
                    nIndex = strNomFichier.LastIndexOf('.');
                    string strNom = strRename;
                    if (nIndex >= 0)
                    {
                        strNom    = strRename.Substring(0, nIndex);
                        strExt    = strRename.Substring(nIndex);
                        strRename = strNom;
                    }
                    nIndex = 0;
                    while (File.Exists(strNom + strExt))
                    {
                        nIndex++;
                        strNom = strRename + "_" + nIndex;
                    }
                    try
                    {
                        if (strExt != "")
                        {
                            strNom = strNom + strExt;
                        }
                        File.Copy(strNomFichier, strNom, true);
                    }
                    catch (Exception e)
                    {
                        result.EmpileErreur(new CErreurException(e));
                        result.EmpileErreur(I.T("New name : '@1'|372", strNom));
                        result.EmpileErreur(I.T("Error during file renaming|373"));

                        return(result);
                    }
                }
                #endregion
            }
            try
            {
                using (CProxyGED proxy = new CProxyGED(contexte.IdSession, document.ReferenceDoc))
                {
                    result = proxy.CopieFichierEnLocal();
                    if (!result)
                    {
                        return(result);
                    }
                    //Si le fichier existe, il est renommé
                    File.Copy(proxy.NomFichierLocal, strNomFichier, true);
                }
            }
            catch (Exception e)
            {
                result.EmpileErreur(new CErreurException(e));
                return(result);
            }


            return(result);
        }
Esempio n. 11
0
        ///////////////////////////////////////////////////////////////
        public CResultAErreur Compile(int nIdMibModule)
        {
            CResultAErreur result = CResultAErreur.True;

            using (CContexteDonnee contexte = new CContexteDonnee(IdSession, true, false))
            {
                CSpvMibmodule mibModule = new CSpvMibmodule(contexte);
                if (!mibModule.ReadIfExists(nIdMibModule))
                {
                    result.EmpileErreur(I.T("Mib module @1 doesn't exists|20000", nIdMibModule.ToString()));
                    return(result);
                }
                CDocumentGED doc = mibModule.DocumentGEDModuleMib;
                if (doc == null)
                {
                    result.EmpileErreur(I.T("Mib module @1 should be associated to a mib file|20001", mibModule.NomModuleOfficiel));
                    return(result);
                }
                using (CProxyGED proxy = new CProxyGED(m_nIdSession, doc.ReferenceDoc))
                {
                    result = proxy.CopieFichierEnLocal();
                    if (!result)
                    {
                        return(result);
                    }

                    CMibModuleWrapper  mibModuleWrapper = new CMibModuleWrapper();
                    IDatabaseConnexion connexion        = CSc2iDataServer.GetInstance().GetDatabaseConnexion(m_nIdSession, GetType());
                    string             strConnexion     = connexion.ConnexionString;
                    string             strDatabase      = "";
                    string             strUser          = "";
                    string             strPassword      = "";
                    string[]           strRubriques     = strConnexion.Split(';');
                    foreach (string strRubrique in strRubriques)
                    {
                        string[] strData = strRubrique.Split('=');
                        if (strData.Length == 2)
                        {
                            string strCle = strData[0].ToUpper().Trim();
                            if (strCle == "DATA SOURCE")
                            {
                                strDatabase = strData[1].Trim();
                            }
                            if (strCle == "USER ID")
                            {
                                strUser = strData[1].Trim();
                            }
                            if (strCle == "PASSWORD")
                            {
                                strPassword = strData[1].Trim();
                            }
                        }
                    }
                    if (strDatabase == "" || strUser == "" || strPassword == "")
                    {
                        result.EmpileErreur(I.T("Can not parse connexion string|20002"));
                        return(result);
                    }

                    string strConnexionOracle = strUser + "/" + strPassword + "@" + strDatabase;
                    mibModuleWrapper.Init(strConnexionOracle, proxy.NomFichierLocal,
                                          mibModule.NomModuleUtilisateur, Convert.ToInt32(mibModule.Id));

                    int nResult = mibModuleWrapper.Compile();
                    if (nResult < 0)
                    {
                        result.EmpileErreur(I.T("Failed to compile mib module @1|20003", mibModule.NomModuleOfficiel));
                        string strMess;
                        while ((strMess = mibModuleWrapper.GetNextErrMess()) != "")
                        {
                            result.EmpileErreur(strMess);
                        }

                        if (mibModuleWrapper.AreCompileErrors())
                        {
                            result.EmpileErreur(mibModuleWrapper.GetCompileErrors());
                        }

                        if (mibModuleWrapper.AreCompileLogs())
                        {
                            result.EmpileErreur(mibModuleWrapper.GetCompileLogs());
                        }

                        return(result);
                    }
                    else
                    {
                        List <IDonneeNotification> notifs = new List <IDonneeNotification>();
                        notifs.Add(new CDonneeNotificationAjoutEnregistrement(m_nIdSession, CSpvMibmodule.c_nomTable));
                        notifs.Add(new CDonneeNotificationAjoutEnregistrement(m_nIdSession, CSpvMibobj.c_nomTable));
                        CEnvoyeurNotification.EnvoieNotifications(notifs.ToArray());
                    }
                }
            }
            return(result);
        }
Esempio n. 12
0
        /// ////////////////////////////////////////////////////////
        protected override CResultAErreur MyExecute(CContexteExecutionAction contexte)
        {
            CResultAErreur result = CResultAErreur.True;

            if (ExpressionListeDocuments == null)
            {
                result.EmpileErreur(I.T("Document list formula is null|20051"));
                return(result);
            }
            CContexteEvaluationExpression contexteEval = new CContexteEvaluationExpression(contexte.Branche.Process);

            result = ExpressionListeDocuments.Eval(contexteEval);
            if (!result)
            {
                return(result);
            }

            IEnumerable enDocs        = result.Data as IEnumerable;
            string      strCle        = "";
            string      strDescriptif = "";
            string      strLibelle    = "";

            result = ExpressionCle.Eval(contexteEval);
            if (result)
            {
                strCle = result.Data.ToString();
            }
            else
            {
                result.EmpileErreur(I.T("Document key could not be computed|30050"));
                return(result);
            }
            if (enDocs == null)
            {
                result.EmpileErreur(I.T("Document list formul returns an incorrect value|20052"));
                return(result);
            }
            List <CDocumentGED> lstDocs = new List <CDocumentGED>();

            try
            {
                foreach (CDocumentGED doc in enDocs)
                {
                    if (doc.Cle != strCle)
                    {
                        lstDocs.Add(doc);
                    }
                }
            }
            catch (Exception e)
            {
                result.EmpileErreur(new CErreurException(e));
                result.EmpileErreur(I.T("Error in document list|20053"));
            }

            MemoryStream    stream    = new MemoryStream();
            ZipOutputStream zipStream = new ZipOutputStream(stream);

            zipStream.SetLevel(9);
            HashSet <string> lstNomsDocuments = new HashSet <string>();

            foreach (CDocumentGED doc in lstDocs)
            {
                CContexteEvaluationExpression ctxDoc = new CContexteEvaluationExpression(doc);
                string strNomFichier = "";
                if (ExpressionNomsFichiers != null)
                {
                    result = ExpressionNomsFichiers.Eval(ctxDoc);
                    if (result && result.Data != null)
                    {
                        strNomFichier = result.Data.ToString();
                    }
                }
                if (strNomFichier == "")
                {
                    strNomFichier = I.T("File|20054");
                }
                foreach (char c in "\"/\\*?<>|:")
                {
                    if (strNomFichier.Contains(c.ToString()))
                    {
                        strNomFichier = strNomFichier.Replace(c, '_');
                    }
                }

                if (lstNomsDocuments.Contains(strNomFichier.ToUpper()))
                {
                    int    nIndex = 1;
                    string strTmp = strNomFichier + "_" + nIndex;
                    while (lstNomsDocuments.Contains(strTmp.ToUpper()))
                    {
                        nIndex++;
                        strTmp = strNomFichier + "_" + nIndex;
                    }
                    strNomFichier = strTmp.ToUpper();
                }
                lstNomsDocuments.Add(strNomFichier.ToUpper());
                strNomFichier += "." + doc.ReferenceDoc.GetExtension();

                using (CProxyGED proxy = new CProxyGED(contexte.IdSession, doc.ReferenceDoc))
                {
                    result = proxy.CopieFichierEnLocal();
                    if (result)
                    {
                        ZipEntry entry = new ZipEntry(ZipEntry.CleanName(strNomFichier));
                        try
                        {
                            FileStream fstream = new FileStream(proxy.NomFichierLocal, FileMode.Open, FileAccess.Read);
                            entry.DateTime = DateTime.Now;
                            entry.Size     = fstream.Length;

                            int    nBufLength = 1024 * 1024;
                            byte[] buffer     = new byte[nBufLength];
                            int    nRead      = 0;

                            zipStream.PutNextEntry(entry);
                            while ((nRead = fstream.Read(buffer, 0, nBufLength)) != 0)
                            {
                                zipStream.Write(buffer, 0, nRead);
                            }
                            fstream.Close();
                            zipStream.CloseEntry();
                        }
                        catch (Exception e)
                        {
                            result.EmpileErreur(new CErreurException(e));
                            return(result);
                        }
                    }
                }
            }
            zipStream.Finish();

            stream.Seek(0, SeekOrigin.Begin);

            CSourceDocumentStream sourceDoc = new CSourceDocumentStream(stream, "zip");

            //On a notre stream zippé, création du document



            result = ExpressionLibelle.Eval(contexteEval);
            if (result)
            {
                strLibelle = result.Data.ToString();
            }
            else
            {
                result.EmpileErreur(I.T("Document label could not be computed|30051"));
                return(result);
            }

            result = ExpressionDescriptif.Eval(contexteEval);
            if (result)
            {
                strDescriptif = result.Data.ToString();
            }
            else
            {
                result.EmpileErreur(I.T("Document description could not be computed|30052"));
                return(result);
            }

            CDocumentGED docZip = new CDocumentGED(contexte.ContexteDonnee);

            //Si la clé n'est pas nulle, cherche un document avec cette clé
            if (strCle.Trim() != "")
            {
                CFiltreData filtre = new CFiltreData(CDocumentGED.c_champCle + "=@1", strCle);
                if (!docZip.ReadIfExists(filtre))
                {
                    docZip.CreateNew();
                }
                else
                {
                    docZip.BeginEdit();
                }
            }
            else
            {
                docZip.CreateNew();
            }
            docZip.Libelle    = strLibelle;
            docZip.Descriptif = strDescriptif;
            docZip.Cle        = strCle;

            List <CDbKey> lstToCreate = new List <CDbKey>(ListeDbKeysCategoriesStockage);
            List <CRelationDocumentGED_Categorie> lstToDelete = new List <CRelationDocumentGED_Categorie>();
            //Affecte les catégories
            CListeObjetsDonnees listeCategoriesExistantes = CRelationDocumentGED_Categorie.GetRelationsCategoriesForDocument(docZip);

            foreach (CRelationDocumentGED_Categorie rel in listeCategoriesExistantes)
            {
                if (!lstToCreate.Contains(rel.Categorie.DbKey))
                {
                    lstToDelete.Add(rel);
                }
                lstToCreate.Remove(rel.Categorie.DbKey);
            }
            foreach (CRelationDocumentGED_Categorie rel in lstToDelete)
            {
                rel.Delete();
            }
            foreach (CDbKey dbKey in lstToCreate)
            {
                CCategorieGED cat = new CCategorieGED(docZip.ContexteDonnee);
                if (cat.ReadIfExists(dbKey))
                {
                    CRelationDocumentGED_Categorie rel = new CRelationDocumentGED_Categorie(docZip.ContexteDonnee);
                    rel.CreateNewInCurrentContexte();
                    rel.Categorie = cat;
                    rel.Document  = docZip;
                }
            }
            result = CDocumentGED.SaveDocument(contexte.IdSession, sourceDoc, sourceDoc.TypeReference, docZip.ReferenceDoc, true);
            if (sourceDoc != null)
            {
                sourceDoc.Dispose();
            }
            zipStream.Close();
            zipStream.Dispose();

            stream.Dispose();
            if (!result)
            {
                return(result);
            }
            CReferenceDocument refDoc = result.Data as CReferenceDocument;

            docZip.ReferenceDoc = refDoc;
            result = docZip.CommitEdit();
            if (!result)
            {
                return(result);
            }
            if (VariableResultat != null)
            {
                Process.SetValeurChamp(VariableResultat, docZip);
            }
            return(result);
        }