コード例 #1
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);
        }
コード例 #2
0
        /// <summary>
        /// Make the workflow pointed by this WorkflowReference computable
        /// </summary>
        /// <param name="ftype">The <see cref="Security.FormType"/>of the computable workflow</param>
        /// <param name="serviceId"> The serviceId allowed to fill this workflow</param>
        /// <param name="publicationDescription"> The workflowdescription of the publication, empty string for empty description</param>
        /// <param name="expireDate"> The expire date gg/mm/aaaa</param>
        /// <param name="communicationUri"> The uri used by communication package</param>
        /// <returns>A <see cref="Security.ComputableWorkflowReference"/> pointing the newly created <see cref="Core.WF.IComputableWorkflow"/>; <value>null</value> if an error happens</returns>
        public ComputableWorkflowReference MakeComputable(FormType ftype, int serviceId, string publicationDescription, string expireDate, string communicationUri)
        {
            if (publicationDescription == null)
            {
                return(null);
            }
            if (!complete)
            {
                fillReference();
            }

            bool publicp          = ((ftype == FormType.PUBLIC_BY_SERVICE) || (ftype == FormType.PUBLIC_WITH_REPLICATION) || (ftype == FormType.PUBLIC_WITHOUT_REPLICATION));
            bool anonym           = ((ftype == FormType.PRIVATE_ANONYM) || (ftype == FormType.PUBLIC_BY_SERVICE) || (ftype == FormType.PUBLIC_WITH_REPLICATION) || (ftype == FormType.PUBLIC_WITHOUT_REPLICATION));
            bool resultReplicated = (ftype == FormType.PUBLIC_WITH_REPLICATION);

            if (ftype == FormType.PUBLIC_BY_SERVICE && (serviceId == 1))
            {
                // Not allowed, we need a valid serviceId
                return(null);
            }


            if (wf_cache == null)
            {
                if (!_RetrieveWf())
                {
                    return(null);
                }
            }

            IFormatProvider provider = CultureInfo.InvariantCulture;
            DateTime        date;

            if (!DateTime.TryParse(expireDate, provider, DateTimeStyles.AdjustToUniversal, out date))
            {
                provider = CultureInfo.GetCultureInfo("it-IT");
                if (!DateTime.TryParse(expireDate, provider, DateTimeStyles.AdjustToUniversal, out date))
                {
                    date = DateTime.Now.AddMonths(1);
                }
            }

            Publication pub = sto.publish(modelId, DateTime.Now, date, "", wf_cache.Save(), anonym, publicp, resultReplicated, serviceId, communicationUri, "Inutile", publicationDescription);

            if (pub == null)
            {
                return(null);
            }

            // Make it public
            int creqid = -1;

            if (publicp)
            {
                CompilationRequest creq = null;
                if (resultReplicated)
                {
                    creq = sto.addPublicPublication(pub.publicationID);
                    if (creq == null)
                    {
                        return(null);
                    }
                    creqid = creq.compilReqID;
                }

                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);
                    MailForPublicForm           mail     = new MailForPublicForm(userMail, pub, creq);
                    LoaMailSender sender = new LoaMailSender();
                    sender.SendMail(mail);
                }
                catch
                {
                    //non dovrebbe mai arrivare qui visto che la mail dell'utente e' controllata in fase di registrazione
                    return(null);
                }
            }
            if (!String.IsNullOrEmpty(communicationUri))
            {
                CommunicationService.Instance.Setup(pub);
            }

            return(new ComputableWorkflowReference(userId, pub.publicationID, pub.namePublication, pub.description, themeId, creqid, !publicp, false, date));
        }