示例#1
0
        private static FormType GetWorkflowType(Storage.Publication pub)
        {
            bool isPublic           = pub.isPublic;
            bool isAnonymous        = pub.anonymResult;
            bool isResultReplicated = pub.isResultReplicated;

            if (isPublic)
            {
                if (isResultReplicated)
                {
                    return(FormType.PUBLIC_WITH_REPLICATION);
                }
                else
                if (pub.Service.serviceID != 1)
                {
                    return(FormType.PUBLIC_BY_SERVICE);
                }
                else
                {
                    return(FormType.PUBLIC_WITHOUT_REPLICATION);
                }
            }
            else
            {
                if (isAnonymous)
                {
                    return(FormType.PRIVATE_ANONYM);
                }
                else
                {
                    return(FormType.PRIVATE_NOT_ANONYM);
                }
            }
        }
示例#2
0
        public List <XmlDocument> getResults()
        {
            List <XmlDocument> results = new List <XmlDocument>();

            Storage.StorageManager db  = new Storage.StorageManager();
            Storage.Publication    pub = db.getEntityByID <Storage.Publication>(publicationId);
            if (pub == null)
            {
                return(null);
            }

            if (pub.anonymResult || pub.isPublic)
            {
                foreach (Storage.Result res in pub.Result)
                {
                    results.Add(Storage.StorageManager.XElementToXmlDocument(res.xmlResult));
                }
            }
            else
            {
                //private non anonime
                foreach (Storage.CompilationRequest req in pub.CompilationRequest)
                {
                    if (req.contactID != -1)
                    {
                        foreach (Storage.Result res in req.Result)
                        {
                            results.Add(Storage.StorageManager.XElementToXmlDocument(res.xmlResult));
                        }
                    }
                }
            }
            return(results);
        }
示例#3
0
 /// <summary>
 /// Reurns the workflow for this filling
 /// </summary>
 /// <returns>the workflow for this filling</returns>
 public Core.WF.IComputableWorkflow GetWorkflow()
 {
     Storage.Publication         pub = sto.getEntityByID <Storage.Publication>(publicationId);
     Core.WF.IComputableWorkflow cwf = (Core.WF.IComputableWorkflow)sto.byteArray2Object(pub.xml.ToArray());
     cwf.setWFname(pub.namePublication);
     cwf.SetDescription(pub.description);
     return(cwf);
 }
示例#4
0
        internal static string ToLink(Storage.Publication publication, Storage.CompilationRequest compilationRequest)
        {
            // Used only for public publications; for the private ones it's better to check
            Storage.StorageManager.PartialPublication ppublication = new Storage.StorageManager.PartialPublication();
            ppublication.publicationID     = publication.publicationID;
            ppublication.externalServiceID = (int)publication.externalServiceID;
            ppublication.isPublic          = publication.isPublic;

            return(ToLink(ppublication, compilationRequest));
        }
示例#5
0
 public string getPublicationDescription()
 {
     if (_publicationDescription == null)
     {
         Storage.Publication pub = sto.getEntityByID <Storage.Publication>(publicationId);
         if (pub == null)
         {
             return(null);
         }
         _publicationDescription = pub.description;
     }
     return(_publicationDescription);
 }
示例#6
0
 public string getFilledWorkflowName()
 {
     if (_workflowName == null)
     {
         Storage.Publication pub = sto.getEntityByID <Storage.Publication>(publicationId);
         if (pub == null)
         {
             return(null);
         }
         _workflowName = pub.namePublication;
     }
     return(_workflowName);
 }
示例#7
0
        /// <summary>
        /// Get the workflow's result
        /// </summary>
        /// <returns>A list of pair composte of: contact that fill and xmlDocument that contain the result. If the form is anonim, the value of the contact is always null</returns>
        public List <Storage.StorageManager.Pair <Contact, XmlDocument> > getFilledDocument()
        {
            List <Storage.StorageManager.Pair <Contact, XmlDocument> > results = new List <Storage.StorageManager.Pair <Contact, XmlDocument> >();

            Storage.StorageManager db  = new Storage.StorageManager();
            Storage.Publication    pub = db.getEntityByID <Storage.Publication>(publicationId);
            if (pub == null)
            {
                return(null);
            }

            if (pub.anonymResult || pub.isPublic)
            {
                foreach (Storage.Result res in pub.Result)
                {
                    Storage.StorageManager.Pair <Contact, XmlDocument> el = new Storage.StorageManager.Pair <Contact, XmlDocument>();
                    el.First  = null;
                    el.Second = Storage.StorageManager.XElementToXmlDocument(res.xmlResult);
                    results.Add(el);
                }
            }
            else
            {
                //private non anonime
                foreach (Storage.CompilationRequest req in pub.CompilationRequest)
                {
                    if (req.contactID != -1)
                    {
                        foreach (Storage.Result res in req.Result)
                        {
                            Storage.StorageManager.Pair <Contact, XmlDocument> el = new Storage.StorageManager.Pair <Contact, XmlDocument>();
                            el.First  = new Contact(req.Contact.nameContact, req.Contact.externalUserID, new Service(req.Contact.Service.nameService, req.Contact.Service.serviceID));
                            el.Second = Storage.StorageManager.XElementToXmlDocument(res.xmlResult);
                            results.Add(el);
                        }
                    }
                }
            }
            return(results);
        }
示例#8
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);
            }
            }
        }
示例#9
0
        public WorkflowInformations GetWorkflow(int compilationRequestId, string username, string service, string token)
        {
            Storage.StorageManager     manager            = new Storage.StorageManager();
            Storage.CompilationRequest compilationRequest = manager.getEntityByID <Storage.CompilationRequest>(compilationRequestId);

            WorkflowInformations infs = new WorkflowInformations();

            infs.status = ResultStatus.OK;

            if (compilationRequest == null)
            {
                infs.status = ResultStatus.WRONG_COMPILATION_REQUEST_ID;
                return(infs);
            }

            Storage.Publication publication         = compilationRequest.Publication;
            Security.ComputableWorkflowReference cw = Security.Token.GetWorkflow("" + publication.publicationID, "" + compilationRequestId, username, service, token);
            if (cw == null)
            {
                infs.status = ResultStatus.WRONG_COMPILATION_REQUEST_ID;
                return(infs);
            }

            infs.description            = cw.GetWorkflow().GetEntireWorkflowDescription();
            infs.publicationDescription = cw.GetWorkflowDescription();
            infs.status = ResultStatus.OK;

            /*
             * if (publication.isPublic)
             * {
             * //pubblico
             * IComputableWorkflow cw = (IComputableWorkflow)manager.getWorkflowByPublication(publication);
             * cw.setWFname(publication.namePublication);
             * infs.description = cw.GetEntireWorkflowDescription();
             * infs.publicationDescription = publication.description;
             * }
             * else
             * {
             * //privato
             * if (token==null || !compilationRequest.token.Equals(token))
             * {
             * infs.status = ResultStatus.WRONG_TOKEN;
             * return infs;
             * }
             * Storage.Contact contact = compilationRequest.Contact;
             * if (username==null || service == null ||
             * !(contact.externalUserID.Equals(username) && (contact.Service.nameService.Equals(service))))
             * {
             * infs.status = ResultStatus.WRONG_USERNAME_OR_SERVICE;
             * return infs;
             * }
             * if (compilationRequest.compiled)
             * {
             * infs.status = ResultStatus.ALREADY_COMPILED;
             * }
             * IComputableWorkflow cw = (IComputableWorkflow)manager.getWorkflowByPublication(publication);
             * cw.setWFname(publication.namePublication);
             * infs.description = cw.GetEntireWorkflowDescription();
             * infs.publicationDescription = publication.description;
             * }
             */
            return(infs);
        }
示例#10
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);
            }
        }