示例#1
0
        /// <summary>
        /// FORSE QUESTO METODO NON SERVE
        /// SERVE ECCOMEEEE!!
        /// </summary>
        /// <returns>una lista vuota</returns>
        public List <ComputableWorkflowReference> GetToBeCompiledWorkflows()
        {
            List <ComputableWorkflowReference> ret = new List <ComputableWorkflowReference>();

            if (!_registered)
            {
                return(ret);
            }

            Storage.StorageManager db   = new Storage.StorageManager();
            Storage.User           user = db.getEntityByID <Storage.User>(_userId);
            List <Storage.StorageManager.Pair <string, int> > tempcontacts = new List <Storage.StorageManager.Pair <string, int> >();

            foreach (Storage.ExternalAccount extAcc in user.ExternalAccount)
            {
                Storage.StorageManager.Pair <string, int> pair = new Storage.StorageManager.Pair <string, int>();
                pair.First  = extAcc.username;
                pair.Second = extAcc.serviceID;
                tempcontacts.Add(pair);
            }
            List <Storage.Contact> mycontacts = db.getContactsByExtID(tempcontacts);

            foreach (Storage.Contact mycontact in mycontacts)
            {
                List <Storage.Publication> pubs = db.getListPublicationsByContactID(mycontact.contactID);
                foreach (Storage.Publication pub in pubs)
                {
                    Storage.CompilationRequest req = db.getCompilationRequestByPulicationAndContact(mycontact.contactID, pub.publicationID);
                    if (!req.compiled)
                    {
                        ret.Add(new ComputableWorkflowReference(_userId, pub.publicationID, pub.namePublication, pub.description,
                                                                pub.themeID, req.compilReqID, !pub.isPublic, true, pub.expirationDate));
                    }
                }
            }
            return(ret);
        }
示例#2
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);
            }
            }
        }