コード例 #1
0
        private int countAttachments(Protocol protocol)
        {
            if (protocol.IdAttachments.GetValueOrDefault(0) > 0)
            {
                try
                {
                    var chain  = new UIDChain(protocol.Location.ProtBiblosDSDB, protocol.IdAttachments.Value);
                    var result = BiblosDocumentInfo.GetDocuments(chain);

                    if (!result.IsNullOrEmpty())
                    {
                        return(result.Count);
                    }
                }
                catch (Exception ex)
                {
                    string message = "countAttachments: " + ex.Message;
                    throw new Exception(message, ex);
                }
            }
            return(0);
        }
コード例 #2
0
        /// <summary>
        /// Archivia gli allegati del protocollo.
        /// </summary>
        /// <param name="sessionId">Identificativo della sessione di lavoro.</param>
        /// <param name="protocol">Protocollo di riferimento.</param>
        /// <returns></returns>
        private IList <int> archiveAttachments(string sessionId, Protocol protocol)
        {
            if (!protocol.IdAttachments.HasPositiveValue())
            {
                return(null);
            }

            // Recupero gli allegati da Biblos.
            UIDLocation location = new UIDLocation(protocol.Location.ProtBiblosDSDB);
            IList <BiblosDocumentInfo> attachments = null;

            try
            {
                UIDChain attachmentsUid = new UIDChain(location, protocol.IdAttachments.Value);
                attachments = BiblosDocumentInfo.GetDocuments(attachmentsUid);
            }
            catch (Exception ex)
            {
                string message = "archiveAttachments: errore in recupero documenti da Biblos. {0} - {1}";
                message = string.Format(message, ex.Source, ex.Message);
                throw new Exception(message, ex);
            }

            if (attachments.IsNullOrEmpty())
            {
                return(null);
            }

            // Recupero il dizionario degli attributi.
            IDictionary <string, string> attributes = null;

            try
            {
                attributes = getAttachmentAttributes(protocol);
            }
            catch (Exception ex)
            {
                string message = "archiveAttachments: errore in recupero dizionario degli attributi. {0} - {1}";
                message = string.Format(message, ex.Source, ex.Message);
                throw new Exception(message, ex);
            }

            // Archivio gli allegati.
            IList <int> archived = new List <int>();
            int         counter  = 1;

            try
            {
                foreach (var item in attachments)
                {
                    attributes["Numero Allegato"] = counter.ToString();
                    var pid    = getProductId(item.Name);
                    var fields = attributes.Keys.ToArray();
                    var values = attributes.Values.ToArray();
                    int result = -1;

                    var message = string.Format("TopMedia Archive - sessionid: {0}, attachmenttype: {1}, fields: {2}, values: {3}, name: {4}, stream: {5}, pid: {6}",
                                                sessionId,
                                                DocSuiteContext.Current.ProtocolEnv.TopMediaParameters.AttachmentType,
                                                fields.Length, values.Length,
                                                item.Name, item.Stream.Length,
                                                pid);
                    FileLogger.Info("FileLog", message);
#if DEBUG
                    result = counter;
#else
                    result = Services.TopMedia.Service.Archive(sessionId, DocSuiteContext.Current.ProtocolEnv.TopMediaParameters.AttachmentType, fields, values, item.Name, item.Stream, pid);
#endif
                    FileLogger.Info("FileLog", "result: " + result.ToString());
                    archived.Add(result);
                    counter++;
                }
            }
            catch (Exception ex)
            {
                string message = "archiveAttachments: errore in archiviazione documento. {0} - {1}";
                message = string.Format(message, ex.Source, ex.Message);
                throw new Exception(message, ex);
            }
            return(archived);
        }