Esempio n. 1
0
        public static ComputableWorkflowReference GetWorkflow(string wid, string crid, string username, string service, string token)
        {
            Storage.StorageManager sto = new Storage.StorageManager();
            int pubid  = -1;
            int creqid = -1;

            try
            {
                pubid  = int.Parse(wid);
                creqid = int.Parse(crid);
            }
            catch (Exception)
            { // Storage-style exception catching :P
                return(null);
            }
            Storage.Publication pub = sto.getEntityByID <Storage.Publication>(pubid);
            if (pub == null)
            {
                return(null);
            }
            FormType ftype = GetWorkflowType(pub);

            switch (ftype)
            {
            case FormType.PUBLIC_WITH_REPLICATION:
            {
                Storage.CompilationRequest creq = sto.getEntityByID <Storage.CompilationRequest>(creqid);
                if (creq == null)
                {
                    return(null);
                }
                // Public, check strings
                if (creq.publicationID == pub.publicationID &&
                    String.IsNullOrEmpty(username) &&
                    String.IsNullOrEmpty(service) &&
                    String.IsNullOrEmpty(token))
                {
                    // All ok, create and returns the wf
                    return(new ComputableWorkflowReference(pub.userID, pub.publicationID, pub.namePublication, pub.description, pub.themeID, creqid, false, true, pub.expirationDate));
                }
                else
                {
                    // Public publication, but not null parameters, forged link
                    return(null);
                }
            }

            case FormType.PUBLIC_WITHOUT_REPLICATION:
            {
                // Check with contact authentication
                int serviceID = -1;
                try
                {
                    serviceID = int.Parse(service);
                }
                catch (Exception)
                {
                    serviceID = -1;
                }
                if (serviceID == -1)
                {
                    // Errore
                    return(null);
                }
                Storage.Contact contact = sto.getContactByUserService(username, serviceID);
                if (contact == null)
                {
                    // All right, we create it now
                    contact = sto.addContact(username, serviceID, "Filler_Only_Contact");
                    if (contact == null)
                    {
                        // No way
                        return(null);
                    }
                }
                // Get the right CompilationRequest
                Storage.CompilationRequest creq = sto.getCompilationRequestByPulicationAndContact(contact.contactID, pub.publicationID);
                if (creq == null)
                {
                    // The user has surely not compiled it before
                    creq = sto.addContactToPublication(pub.publicationID, contact.contactID, "DUMMY_TOKEN");
                    if (creq == null)
                    {
                        // No way
                        return(null);
                    }
                }
                if (creq.compiled)
                {
                    // Already Compiled
                    return(null);
                }
                else
                {
                    return(new ComputableWorkflowReference(pub.userID, pub.publicationID, pub.namePublication, pub.description, pub.themeID, creq.compilReqID, true, true, pub.expirationDate));
                }
            }

            case FormType.PUBLIC_BY_SERVICE:
            {
                // Check with contact authentication
                int serviceID = -1;
                try
                {
                    serviceID = int.Parse(service);
                }
                catch (Exception)
                {
                    serviceID = -1;
                }
                if (serviceID == -1)
                {
                    // Errore
                    return(null);
                }
                if (pub.Service.serviceID != serviceID)
                {
                    // This serviceID is not allowed to fill the publication
                    return(null);
                }
                Storage.Contact contact = sto.getContactByUserService(username, serviceID);
                if (contact == null)
                {
                    // All right, we create it now
                    contact = sto.addContact(username, serviceID, "Filler_Only_Contact");
                    if (contact == null)
                    {
                        // No way
                        return(null);
                    }
                }
                // Get the right CompilationRequest
                Storage.CompilationRequest creq = sto.getCompilationRequestByPulicationAndContact(contact.contactID, pub.publicationID);
                if (creq == null)
                {
                    // The user has surely not compiled it before
                    creq = sto.addContactToPublication(pub.publicationID, contact.contactID, "DUMMY_TOKEN");
                    if (creq == null)
                    {
                        // No way
                        return(null);
                    }
                }
                if (creq.compiled)
                {
                    // Already Compiled
                    return(null);
                }
                else
                {
                    return(new ComputableWorkflowReference(pub.userID, pub.publicationID, pub.namePublication, pub.description, pub.themeID, creq.compilReqID, true, true, pub.expirationDate));
                }
            }

            case FormType.PRIVATE_NOT_ANONYM:
            case FormType.PRIVATE_ANONYM:
            {
                // Private, check strings
                if (creqid != -1)
                {
                    // Check with token
                    Storage.CompilationRequest creq = sto.getEntityByID <Storage.CompilationRequest>(creqid);
                    if (creq == null)
                    {
                        return(null);
                    }
                    if (creq.publicationID == pub.publicationID &&
                        creq.token.Equals(token) &&
                        ((creq.Contact.nameContact).ToUpper()).Equals(username) &&
                        creq.Contact.Service.nameService.Equals(service) &&
                        !creq.compiled)
                    {
                        // Right compilation request, all done!
                        return(new ComputableWorkflowReference(pub.userID, pub.publicationID, pub.namePublication, pub.description, pub.themeID, creqid, true, true, pub.expirationDate));
                    }
                    else
                    {
                        // Wrong authentication parameters
                        return(null);
                    }
                }
                else
                {
                    // Check with contact authentication
                    int serviceID = -1;
                    try
                    {
                        serviceID = int.Parse(service);
                    }
                    catch (Exception)
                    {
                        serviceID = -1;
                    }
                    if (serviceID == -1)
                    {
                        // Errore
                        return(null);
                    }
                    Storage.Contact contact = sto.getContactByUserService(username, serviceID);
                    if (contact == null)
                    {
                        // In this case, if the contact doesn't exists, is an error
                        return(null);
                    }
                    // Get the right CompilationRequest
                    Storage.CompilationRequest creq = sto.getCompilationRequestByPulicationAndContact(contact.contactID, pub.publicationID);
                    if (creq == null)
                    {
                        // L'utente non ha il permesso per riempire la form
                        return(null);
                    }
                    if (creq.compiled)
                    {
                        // L'utente ha già inserito la form
                        return(null);
                    }
                    else
                    {
                        return(new ComputableWorkflowReference(pub.userID, pub.publicationID, pub.namePublication, pub.description, pub.themeID, creq.compilReqID, true, true, pub.expirationDate));
                    }
                }
            }

            default:
            {
                return(null);
            }
            }
        }
Esempio n. 2
0
        public bool SendFilledDocument(int compilationRequestId, string username, string service, string token, string dataStr)
        {
            XmlDocument data = new XmlDocument();

            data.LoadXml(dataStr);

            Storage.StorageManager     manager            = new Storage.StorageManager();
            Storage.CompilationRequest compilationRequest = manager.getEntityByID <Storage.CompilationRequest>(compilationRequestId);
            if (compilationRequest == null)
            {
                return(false);
            }
            Storage.Publication publication = compilationRequest.Publication;

            IComputableWorkflow cw;

            if (publication.isPublic)
            {
                //pubblico
                cw = (IComputableWorkflow)manager.getWorkflowByPublication(publication);
            }
            else
            {
                //privato
                if (token == null || !compilationRequest.token.Equals(token))
                {
                    return(false);
                }
                Storage.Contact contact = compilationRequest.Contact;
                if (username == null || service == null ||
                    !(contact.externalUserID.Equals(username) && (contact.Service.nameService.Equals(service))))
                {
                    return(false);
                }
                if (compilationRequest.compiled)
                {
                    return(false);
                }
                cw = (IComputableWorkflow)manager.getWorkflowByPublication(publication);
            }
            cw.setWFname(publication.namePublication);

            System.Xml.Schema.XmlSchemaSet schema = cw.GetCollectedDocumentSchemas();
            data.Schemas = schema;
            try
            {
                data.Validate(null);
            }
            catch (XmlSchemaValidationException)
            {
                return(false);
            }
            Storage.Result           res          = null;
            System.Xml.Linq.XElement dataXElement = Storage.StorageManager.xmlDocumentToXElement(data);
            res = (Storage.Result)manager.addResult(compilationRequest.compilReqID, dataXElement);
            if (res == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }