Exemple #1
0
        internal static TokenInfo ValidaToken(RequestBase request)
        {
            TokenInfo result = null;

            using (var db = new BiblosDS2010APIEntities())
            {
                var token = db.LoginTokens.Where(x => x.IdLoginToken == request.Token).SingleOrDefault();
                if (token != null)
                {
                    if (DateTime.Compare(DateTime.Now, token.DateExpire) > 0)
                    {
                        db.DeleteObject(token);
                    }
                    else
                    {
                        result = new TokenInfo();
                        result.DataScadenza = DateTime.Now.AddMinutes(20);
                        result.Token        = token.IdLoginToken;
                        result.IdCliente    = token.IdCustomer;
                        token.DateExpire    = result.DataScadenza;
                    }
                    db.SaveChanges();
                }
            }
            return(result);
        }
Exemple #2
0
 internal static void UpdateDocumentIdByIdDocument(Guid idDocument, Guid newIdDocument)
 {
     using (var db = new BiblosDS2010APIEntities())
     {
         var documentKey = db.DocumentKeys.Where(x => x.IdDocument == idDocument).SingleOrDefault();
         documentKey.IdDocument = newIdDocument;
         db.SaveChanges();
     }
 }
Exemple #3
0
 internal static void DeleteDocumentKey(Guid idDocument)
 {
     using (var db = new BiblosDS2010APIEntities())
     {
         var documentKey = db.DocumentKeys.Where(x => x.IdDocument == idDocument).SingleOrDefault();
         db.DeleteObject(documentKey);
         db.SaveChanges();
     }
 }
Exemple #4
0
        internal static bool ExistDocumentChiave(string idCliente, string chiave)
        {
            bool exist = false;

            using (var db = new BiblosDS2010APIEntities())
            {
                exist = db.DocumentKeys.Any(x => x.IdCustomer == idCliente && x.Code == chiave);
            }

            //Ritorna il documento legato al customer/document class
            return(exist);
        }
Exemple #5
0
        internal static bool ExistDocumentById(RequestBase request, Guid idDocumento)
        {
            bool exist = false;

            using (var db = new BiblosDS2010APIEntities())
            {
                exist = db.DocumentKeys.Any(x => x.IdCustomer == request.IdCliente && x.IdDocument == idDocumento);
            }

            //Ritorna il documento legato al customer/document class
            return(exist);
        }
Exemple #6
0
        internal static Guid?GetArchive(RequestBase request)
        {
            CustomerKey customerKey;

            using (var db = new BiblosDS2010APIEntities())
            {
                customerKey = db.CustomerKeys.Where(x => x.DocumentClass == request.TipoDocumento && x.IdCustomer == request.IdCliente).SingleOrDefault();
            }

            //Ritorna l'archivio legato al customer/document class
            return(customerKey == null ? (Guid?)null : customerKey.IdArchive);
        }
        /// <summary>
        /// Metodo di autenticazione a biblos tramite Username e Password
        /// </summary>
        /// <param name="request"><see cref="LoginRequest">LoginRequest</see></param>
        /// <returns><see cref="LoginResponse">LoginResponse</see></returns>
        public static LoginResponse Login(LoginRequest request)
        {
            LoginResponse response = new LoginResponse();

            try
            {
                logger.Debug("Login request");
                if (string.IsNullOrEmpty(request.IdCliente))
                {
                    response.CodiceEsito = CodiceErrore.IdClienteErrato;
                }
                else if (string.IsNullOrEmpty(request.UserName) || string.IsNullOrEmpty(request.Password))
                {
                    response.CodiceEsito = CodiceErrore.LoginNonValido;
                }
                else
                {
                    using (var db = new BiblosDS2010APIEntities())
                    {
                        string passwordEncrypted = PasswordService.GenerateHash(request.Password);
                        var    userLogin         = db.CustomerLogins.Where(x => x.IdCustomer == request.IdCliente && x.UserName == request.UserName && x.Password == passwordEncrypted).FirstOrDefault();
                        if (userLogin != null)
                        {
                            response.TokenInfo = new TokenInfo {
                                Token = Guid.NewGuid(), DataScadenza = DateTime.Now.AddMinutes(20)
                            };
                            db.LoginTokens.AddObject(new LoginToken {
                                IdLoginToken = response.TokenInfo.Token, IdCustomerLogin = userLogin.IdCustomerLogin, IdCustomer = userLogin.IdCustomer, DateCreated = DateTime.Now, DateExpire = response.TokenInfo.DataScadenza
                            });
                            db.SaveChanges();
                            response.Eseguito = true;
                        }
                        else
                        {
                            response.CodiceEsito = CodiceErrore.LoginNonValido;
                        }
                    }
                }
                logger.DebugFormat("Login response:{0}", response.ToString());
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                response.CodiceEsito     = CodiceErrore.ErroreGenerico;
                response.MessaggioErrore = ex.ToString();
            }
            return(response);
        }
Exemple #8
0
 internal static void SetDocumentKey(RequestBase request, Guid idDocumento, string chiave)
 {
     using (var db = new BiblosDS2010APIEntities())
     {
         DocumentKey documentKey = db.DocumentKeys.Where(x => x.DocumentClass == request.TipoDocumento && x.IdCustomer == request.IdCliente && x.Code == chiave).SingleOrDefault();
         if (documentKey == null)
         {
             db.AddToDocumentKeys(new DocumentKey {
                 DocumentClass = request.TipoDocumento, IdCustomer = request.IdCliente, Code = chiave, IdDocument = idDocumento, CreatedDate = DateTime.Now
             });
             db.SaveChanges();
         }
         else
         {
             throw new Exception("Document alrady exists: " + idDocumento + ", chiave: " + chiave);
         }
     }
 }
Exemple #9
0
        internal static Dictionary <int, string> GetErrori()
        {
            var retval   = new Dictionary <int, string>();
            var errorMsg = string.Empty;

            using (var db = new BiblosDS2010APIEntities())
            {
                var query = db.ErrorMessageDecodes;
                int errorCode;

                foreach (var item in query)
                {
                    try
                    {
                        if (!int.TryParse(item.ErrorCode, out errorCode))
                        {
                            throw new ApplicationException();
                        }

                        if (retval.ContainsKey(errorCode))
                        {
                            errorMsg = string.Format("GetErrori : Il codice d'errore \"{0}\" risulta duplicato in banca dati.", item.ErrorCode);
                            break;
                        }

                        retval.Add(errorCode, item.ErrorMessage);
                    }
                    catch
                    {
                        errorMsg = string.Format("Impossibile convertire il codice d'errore \"{0}\".", item.ErrorCode);
                        break;
                    }
                }

                if (!string.IsNullOrWhiteSpace(errorMsg))
                {
                    throw new ApplicationException(errorMsg);
                }
            }

            return(retval);
        }
Exemple #10
0
        internal static Guid?GetDocumentByChiave(string tipoDocumento, string idCliente, string chiave, out CodiceErrore errore)
        {
            DocumentKey documentKey;

            errore = CodiceErrore.NessunErrore;
            using (var db = new BiblosDS2010APIEntities())
            {
                documentKey = db.DocumentKeys.Where(x => x.IdCustomer == idCliente && x.DocumentClass == tipoDocumento && x.Code == chiave).SingleOrDefault();
            }
            if (documentKey == null)
            {
                return(null);
            }
            if (documentKey.IdCustomer != idCliente)
            {
                errore = CodiceErrore.DocumentoNonDelCliente;
            }
            //Ritorna il documento legato al customer/document class
            return(documentKey == null ? null : documentKey.IdDocument);
        }
 /// <summary>
 /// Logout
 /// </summary>
 /// <param name="token">Id del token di autenticazione</param>
 public static void Logout(Guid token)
 {
     try
     {
         logger.DebugFormat("Login Logout:{0}", token);
         using (var db = new BiblosDS2010APIEntities())
         {
             var userLogin = db.LoginTokens.Where(x => x.IdLoginToken == token).FirstOrDefault();
             if (userLogin != null)
             {
                 db.DeleteObject(userLogin);
                 db.SaveChanges();
             }
         }
     }
     catch (Exception ex)
     {
         logger.Error(ex);
         //LogOut sempre valida non da mai eccezione
         //throw;
     }
 }
        /// <summary>
        /// Metodo che torna gli archivi associati ad un cliente con i relativi metadati
        /// </summary>
        /// <param name="request"><see cref="GetArchiviRequest">GetProfiliRequest</see></param>
        /// <example>
        /// GetProfiliRequest request = new GetProfiliRequest {  Token = token.TokenInfo.Token, IdCliente = token.TokenInfo.IdCliente };
        /// GetProfiliResponse actual = DocumentoFacade.GetProfili(request);
        /// </example>
        /// <remarks>
        /// Il Token è recuperato della chiamata al metodo Login
        /// </remarks>
        /// <returns>
        /// Risposta <see cref="GetArchiviResponse">GetProfiliResponse</see> con i profili configurati per il cliente
        /// </returns>
        public static GetArchiviResponse GetProfili(GetArchiviRequest request)
        {
            GetArchiviResponse response = new GetArchiviResponse();

            try
            {
                logger.DebugFormat("GetProfili request:{0}", request.ToString());
                response.TokenInfo = Helpers.ValidaToken(request);
                if (response.TokenInfo == null)
                {
                    response.CodiceEsito = CodiceErrore.TokenNonValidoOScaduto;
                }
                else
                {
                    using (var db = new BiblosDS2010APIEntities())
                    {
                        var archiviAbillitati = db.CustomerKeys.Where(x => x.IdCustomer == response.TokenInfo.IdCliente);
                        using (var client = new DocumentsClient())
                        {
                            foreach (var item in archiviAbillitati)
                            {
                                try
                                {
                                    var             metadata     = client.GetMetadataStructure(item.IdArchive);
                                    DocumentArchive archive      = null;
                                    string          nomeArchivio = string.Empty;
                                    if (metadata.Count() > 0)
                                    {
                                        archive      = metadata.First().Archive;
                                        nomeArchivio = archive == null ? "ND" : archive.Name;
                                    }
                                    response.Archivi.Add(new Archivio {
                                        Descrizione = item.Description, TipoDocumento = item.DocumentClass, Nome = nomeArchivio, Metadati = metadata.Select(x => new MetadatoItem {
                                            Name = x.Name, Tipo = x.AttributeType, Posizione = x.ConservationPosition.GetValueOrDefault(), Obbligatorio = x.IsRequired
                                        }).ToList()
                                    });
                                    response.Eseguito = true;
                                    logger.DebugFormat("GetProfili response:{0}", response.ToString());
                                }
                                catch (FaultException <BiblosDsException> faultEx)
                                {
                                    logger.Error(faultEx);
                                    response.Eseguito = false;
                                    ParseBiblosDSFaultException(response, faultEx);
                                }
                                catch (Exception ex)
                                {
                                    logger.Error(ex);
                                    response.CodiceEsito     = CodiceErrore.ErroreChiamataAlServizioRemoto;
                                    response.MessaggioErrore = ex.ToString();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                response.CodiceEsito     = CodiceErrore.ErroreGenerico;
                response.MessaggioErrore = ex.ToString();
            }
            response.CheckResponse();
            return(response);
        }