Exemplo n.º 1
0
        /// <summary>
        /// Funzione per l'acquisizione del file da associare ad un allegato
        /// </summary>
        /// <param name="path">Il path relativo del file da caricare</param>
        /// <param name="administrationCode">Il codice dell'amministrazione</param>
        /// <param name="userInfo">Le informazioni sull'utente che ha lanciato la procedura</param>
        /// <param name="ftpAddress">L'indirizzo a cui è possibile recuperare le informazioni sul file</param>
        /// <param name="attachment">L'allegato a cui associare il file</param>
        protected void AcquireFile(string path, string administrationCode, InfoUtente userInfo, string ftpAddress, Allegato attachment, String ftpUsername, String ftpPassword, DocumentRowData rowData)
        {
            #region Dichiarazione Variabili

            // Il contenuto del file
            byte[] fileContent;

            // L'oggetto fileRequest
            FileRequest fileRequest;

            // L'oggetto fileDocumento
            FileDocumento fileDocumento;

            #endregion

            #region Lettura file documento

            try
            {
                // Apertura, lettura e chiusura del file
                //fileContent = ImportUtils.DownloadFileFromFTP(
                //     ftpAddress,
                //     String.Format("{0}/{1}/{2}",
                //         administrationCode,
                //         userInfo.userId,
                //         path),
                //     ftpUsername,
                //     ftpPassword);

                // nuova versione, i file vengono presi in locale e caricati dagli utenti in locale nella procedura di import

                fileContent = ImportUtils.DounloadFileFromUserTempFolder(rowData, userInfo, true);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }

            #endregion

            #region Creazione dell'oggetto fileDocumento

            // Creazione dell'oggetto fileDocumento
            fileDocumento = new FileDocumento();

            // Impostazione del nome del file
            fileDocumento.name = Path.GetFileName(path);

            // Impostazione del full name
            fileDocumento.fullName = path;

            // Impostazione del path
            fileDocumento.path = Path.GetPathRoot(path);

            // Impostazione della grandezza del file
            fileDocumento.length = fileContent.Length;

            // Impostazione del content del documento
            fileDocumento.content = fileContent;

            #endregion

            #region Creazione dell'oggetto fileRequest

            fileRequest = (FileRequest)attachment;

            #endregion

            #region Acquisizione del file

            try
            {
                FileManager.putFile(fileRequest, fileDocumento, userInfo);
            }
            catch (Exception e)
            {
                // Aggiunta del problema alla lista dei problemi
                throw new Exception("Errore durante l'upload del file.");
            }

            #endregion
        }