Beispiel #1
0
        private bool fillReference()
        {
            StorageManager sto = new StorageManager();

            Storage.Publication pub = sto.getEntityByID <Publication>(publicationId);
            if (pub == null)
            {
                return(false);
            }
            this.themeId = pub.themeID;

            this.isPrivate = !pub.isPublic;
            if (themeId == defaultthemeid)
            {
                isDefTheme = true;
            }
            else
            {
                isDefTheme = false;
            }
            if (filling)
            {
                // Find the compilationRequest
                Storage.CompilationRequest creq = sto.getCompilationRequestByPulicationAndContact(userId, publicationId);
                if (creq == null)
                {
                    return(false);
                }
                else
                {
                    compilationReqId = creq.compilReqID;
                }
            }
            this.complete = true;
            return(true);
        }
Beispiel #2
0
        private static string _bodyHTMLFormat      = StorageManager.getEnvValue("loaMailBodyHTMLFormat");      //DANYTODO


        //private static string _bodyPlainTextFormat = "Ciao,\n"
        //    + "sei stato/a invitato/a a compilare il questionario \"{0}\" raggiungibile attraverso questo link:\n"
        //    + "{1}\">{1}\n\n"
        //    + "Per compilarlo tramite l'applicazione dedicata ai dispositivi mobili,\n"
        //    + "utilizza i seguenti parametri:\n{2}\n\n"
        //    + "Questa mail è generata automaticamente, non rispondere direttamente.";

        //private static string _bodyHTMLFormat = "<html><head></head><body>"
        //    + "Ciao,<br/>"
        //    + "sei stato/a invitato/a a compilare il questionario \"{0}\" raggiungibile attraverso questo link:<br/>"
        //    + "<a href=\"{1}\">{1}</a><br/><br/>"
        //    + "Per compilarlo tramite l'applicazione dedicata ai dispositivi mobili,<br/>"
        //    + "utilizza i seguenti parametri:<br/>{3}<br/><br/>"
        //    + "Questa mail &egrave; generata automaticamente, non rispondere direttamente."
        //    + "</body></html>";


        /// <summary>
        /// Build an email conteining the link to the private form.
        /// </summary>
        /// <param name="receiverMail">the recipient mail address</param>
        /// <param name="questionnaireName">the name of the questionnaire</param>
        /// <param name="compilationRequest">the compilation request</param>
        public LoaMail(MailAddress receiverMail, string questionnaireName, Storage.CompilationRequest compilationRequest)
        {
            if (webServerAddress == null)
            {
                webServerAddress = StorageManager.getEnvValue("webServerAddress");
            }

            From = senderAdd;
            To.Add(receiverMail);

            Subject = StorageManager.getEnvValue("mailSubject");
            //Subject = "Floading - Un nuovo questionario da compilare!";

            Object[] parameters = new Object[4];
            parameters[0] = questionnaireName;
            StorageManager manager  = new StorageManager();
            bool           isPublic = compilationRequest.Publication.isPublic;

            parameters[1] = "http://"
                            + webServerAddress + fillerpage
                            + "?WorkflowID=" + compilationRequest.publicationID
                            + "&CompilationRequestID=" + compilationRequest.compilReqID;
            parameters[2] = "CompilationRequestID: " + compilationRequest.compilReqID;
            parameters[3] = "CompilationRequestID: " + compilationRequest.compilReqID;
            if (!isPublic)
            {
                Storage.Contact con = compilationRequest.Contact;
                parameters[1] += "&Username="******"&Service=" + con.Service.nameService
                                 + "&Token=" + compilationRequest.token;
                parameters[2] += "\nUsername: "******"\nService: " + con.Service.nameService
                                 + "\nToken: " + compilationRequest.token;
                parameters[3] += "<br/>Username: "******"<br/>Service: " + con.Service.nameService
                                 + "<br/>Token: " + compilationRequest.token;
            }

            /*try
             * {
             *  IsBodyHtml = true;
             *  Body =String.Format(_bodyHTMLFormat, parameters);
             *
             * }
             * catch (Exception) { return; }*/

            // Add the alternate body to the message.
            //AlternateView alternateHTML = AlternateView.CreateAlternateViewFromString(String.Format(_bodyHTMLFormat, parameters), null,System.Net.Mime.MediaTypeNames.Text.Html);
            //Metto caratteri speciali giusti. Il db li codifica diversamenti, qui li rimetto a posto.
            string message = String.Format(_bodyPlainTextFormat, parameters);
            int    index;
            string sub;

            index = message.IndexOf("\\n");
            if (index != -1 && index < message.Length - 2)
            {
                sub     = message.Substring(index, 2);
                message = message.Replace(sub, "\n");
            }
            index = message.IndexOf("\\r");
            if (index != -1 && index < message.Length - 2)
            {
                sub     = message.Substring(index, 2);
                message = message.Replace(sub, "\n");
            }
            index = message.IndexOf("\\t");
            if (index != -1 && index < message.Length - 2)
            {
                sub     = message.Substring(index, 2);
                message = message.Replace(sub, "\t");
            }
            AlternateView alternatePLAIN = AlternateView.CreateAlternateViewFromString(message, new System.Net.Mime.ContentType("text/plain"));

            alternatePLAIN.TransferEncoding = System.Net.Mime.TransferEncoding.SevenBit;
            //if (alternatePLAIN==null || alternateHTML==null) return;
            //if (alternatePLAIN == null) return;
            //AlternateViews.Add(alternateHTML);
            AlternateViews.Add(alternatePLAIN);
        }
Beispiel #3
0
        /// <summary>
        /// Authorizes a list of contacts to fill this ComputableWorkflow.
        /// This Method can be used only in the _NOT_ filling case
        /// This Method can be used only for private Workflows
        /// </summary>
        /// <param name="contactList">The list of <see cref="Security.Contact"/>s to be allowed</param>
        /// <returns><value>true</value> on success, <value>false</value>otherwise (including operation not permitted)</returns>
        public bool PermitContacts(List <Security.Contact> contactList)
        {
            if (!complete)
            {
                fillReference();
            }

            if (!isPrivate || filling)
            {
                return(false);
            }

            if (contactList == null)
            {
                return(false);
            }

            LoaMailSender mailSender = new LoaMailSender();

            List <Security.Contact> rejected = new List <Contact>();

            foreach (Security.Contact contact in contactList)
            {
                string token = RandomStringGenerator.GetRandomString(10);
                Storage.CompilationRequest creq = sto.addContactToPublication(this.publicationId, contact.ContactID, token);
                if (creq == null)
                {
                    creq = sto.getCompilationRequestByPulicationAndContact(contact.ContactID, publicationId);
                    if (creq == null)
                    {
                        return(false);
                    }
                }

                Storage.Service s = sto.getEntityByID <Storage.Service>(contact.Service.ServiceId);
                if (s == null)
                {
                    return(false);
                }

                // Check if the service uses emails and if the email seems correct

                if (s.externalUserIDMail)
                {
                    try
                    {
                        System.Net.Mail.MailAddress address = new System.Net.Mail.MailAddress(contact.Email);
                        LoaMail mail = new LoaMail(address, GetWorkflowName(), creq);
                        if (!mailSender.SendMail(mail))
                        {
                            rejected.Add(contact);
                        }
                    }
                    catch (Exception)
                    {
                        rejected.Add(contact);
                    }
                }
                else
                {
                    rejected.Add(contact);
                }
            }


            if (rejected.Count > 0)
            {
                Storage.User user = sto.getEntityByID <Storage.User>(userId);
                //Genero email per creatore
                try
                {
                    System.Net.Mail.MailAddress userMail = new System.Net.Mail.MailAddress(user.mail);
                    MailToFormCreator           mail     = new MailToFormCreator(userMail, GetWorkflowName(), publicationId, rejected);
                    LoaMailSender sender = new LoaMailSender();
                    return(sender.SendMail(mail));
                }
                catch
                {
                    //non dovrebbe mai arrivare qui, la mail dello user e' controllata in fase di registrazione
                    return(false);
                }
            }
            return(true);
        }
Beispiel #4
0
        /// <summary>
        /// Build an email conteining the link to the private form.
        /// </summary>
        /// <param name="receiverMail">the recipient mail address</param>
        /// <param name="publication">the publication</param>
        /// <param name="compilationRequest">the compilation request</param>
        public MailForPublicForm(MailAddress receiverMail, Storage.Publication publication, Storage.CompilationRequest compilationRequest)
        {
            From = senderAdd;
            To.Add(receiverMail);

            //Subject = "Floading - Form pubblica creata!";
            Subject = _Subject;

            Object[] parameters = new Object[4];
            parameters[0] = publication.namePublication;
            parameters[1] = Token.ToLink(publication, compilationRequest);
            if (compilationRequest == null)
            {
                parameters[2] = "CompilationRequestID: " + "-1";
                parameters[3] = "CompilationRequestID: " + "-1";
            }
            else
            {
                parameters[2] = "CompilationRequestID: " + compilationRequest.compilReqID;
                parameters[3] = "CompilationRequestID: " + compilationRequest.compilReqID;
            }
            //Metto caratteri speciali giusti. Il db li codifica diversamenti, qui li rimetto a posto.
            string message = String.Format(_bodyPlainTextFormat, parameters);
            int    index;
            string sub;

            index = message.IndexOf("\\n");
            if (index != -1 && index < message.Length - 2)
            {
                sub     = message.Substring(index, 2);
                message = message.Replace(sub, "\n");
            }
            index = message.IndexOf("\\r");
            if (index != -1 && index < message.Length - 2)
            {
                sub     = message.Substring(index, 2);
                message = message.Replace(sub, "\n");
            }
            index = message.IndexOf("\\t");
            if (index != -1 && index < message.Length - 2)
            {
                sub     = message.Substring(index, 2);
                message = message.Replace(sub, "\t");
            }
            AlternateView alternatePLAIN = AlternateView.CreateAlternateViewFromString(message, new System.Net.Mime.ContentType("text/plain"));

            alternatePLAIN.TransferEncoding = System.Net.Mime.TransferEncoding.SevenBit;
            //if (alternatePLAIN==null || alternateHTML==null) return;
            if (alternatePLAIN == null)
            {
                return;
            }
            //AlternateViews.Add(alternateHTML);
            AlternateViews.Add(alternatePLAIN);
        }