Beispiel #1
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));
        }