/// <summary> /// Change the name of a group. Old and new name must be both different from the default group name. /// </summary> /// <param name="oldName"> The old name of the group</param> /// <param name="newName"> The new name of the group</param> /// <returns> True if the group name was changed successfully, false otherwise.</returns> public bool ModifyGroupName(string oldName, string newName) { if (!_registered) { return(false); } if (String.IsNullOrEmpty(oldName) || String.IsNullOrEmpty(newName)) { return(false); } if (oldName == defGroup || newName == defGroup) { return(false); } if (oldName == newName) { return(true); } Storage.StorageManager sto = new Storage.StorageManager(); Storage.Group tempGroup = sto.getGroupByUser(_userId, oldName); if (tempGroup == null) { return(false); } tempGroup.nameGroup = newName; return(sto.commit()); }
/// <summary> /// Creates a new group with the name passed as parameter if it does not exist. /// </summary> /// <param name="name">The name of the new group.</param> /// <returns>True if the creation was successful, false otherwise.</returns> public bool CreateGroup(string name) { if (!_registered) { return(false); } if (String.IsNullOrEmpty(name)) { return(false); } if (name == defGroup) { return(false); } Storage.StorageManager sto = new Storage.StorageManager(); List <string> groupNames = new List <string>(); groupNames.Add(name); List <Storage.Group> results = sto.addGroups(groupNames, _userId); if (results == null) { return(false); } return(true); }
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); }
public static List <Service> List() { List <Service> servlist = new List <Service>(); Storage.StorageManager sto = new Storage.StorageManager(); List <Storage.Service> dbList = sto.getServices(); Service temp = null; if (dbList != null) { foreach (Storage.Service dbService in dbList) { if (dbService.nameService != "default") { if (dbService.nameService == "YouPorn") { temp = new Service(dbService.nameService, dbService.serviceID); } else { servlist.Add(new Service(dbService.nameService, dbService.serviceID)); } } } } if (temp != null) { servlist.Insert(0, temp); } return(servlist); }
/// <summary> /// Returns all of the contacts indexed by DB logic key (email, serviceId). /// </summary> /// <returns>User's contacts.</returns> public Dictionary <Storage.StorageManager.Pair <string, int>, Contact> GetContacts() { if (!_registered) { return(null); } Storage.StorageManager sto = new Storage.StorageManager(); List <Storage.Contact> contacts = sto.getContactsByUserID(_userId); Dictionary <Storage.StorageManager.Pair <string, int>, Contact> ret = new Dictionary <Storage.StorageManager.Pair <string, int>, Contact>(); if (contacts == null) { return(null); } foreach (Storage.Contact contact in contacts) { Storage.StorageManager.Pair <string, int> temPair = new Storage.StorageManager.Pair <string, int>(); Contact tempContact = new Contact(contact.nameContact, contact.externalUserID, new Service(contact.Service.nameService, contact.Service.serviceID)); temPair.First = contact.externalUserID; temPair.Second = contact.externalServiceID; //Controllo per evitare duplicati nel dictionary if (!ret.ContainsKey(temPair)) { ret.Add(temPair, tempContact); } } return(ret); }
/// <summary> /// Return all contact group's names. /// </summary> /// <returns>A List containing the user's groups names</returns> public List <string> GetGroups() { if (!_registered) { return(null); } Storage.StorageManager sto = new Storage.StorageManager(); return(sto.getGroupNames(_userId)); }
/// <summary> /// Added the contacts passed as parameter to the group that has the name as parameter passed. /// QUANDO SI INVOCA STO METODO IL GRUPPO DEVE ESSERE CREATO. /// </summary> /// <param name="name"> The group name to add contacts</param> /// <param name="contactList"> The list of contacts to be added.</param> /// <returns> True if the contacts have been added successfully, false otherwise.</returns> public bool AddContactsInGroup(string name, List <Contact> contactList, int servID) { if (!_registered) { return(false); } if (String.IsNullOrEmpty(name) || contactList == null) { return(false); } Storage.StorageManager sto = new Storage.StorageManager(); Storage.Group tempGroup = sto.getGroupByUser(_userId, name); if (tempGroup == null) { return(false); } Dictionary <string, string> contactsToAdd = new Dictionary <string, string>(); foreach (Security.Contact con in contactList) { if (con == null || contactsToAdd.ContainsKey(con.Email)) { continue; } contactsToAdd.Add(con.Email, con.Name); } // Insert contacts into the database List <Storage.Contact> contactsAdded = sto.addContacts(contactsToAdd, servID); List <Storage.Contact> contactsToRemove = new List <Storage.Contact>(); foreach (Storage.Contact c in sto.getContactsByGroup(_userId, defGroup)) { if (c == null) { continue; } if (contactsAdded.Contains(c)) { contactsToRemove.Add(c); } } Storage.Group otherGroup = sto.getGroupByUser(_userId, defGroup); sto.removeContactsFromGroup(contactsToRemove, otherGroup); // Link the contacts to the group List <Storage.GroupContact> result = sto.addContactsToGroup(contactsAdded, tempGroup); if (result == null) { return(false); } return(true); }
/// <summary> /// Return all services that the user subscribed. /// </summary> /// <returns>all services that the user subscribed</returns> public List <Service> GetSubscribedServices() { if (!_registered) { return(null); } Storage.StorageManager sto = new Storage.StorageManager(); Storage.User us = sto.getEntityByID <Storage.User>(_userId); //TODO: aspettare metodo getSubscribedService da storage List <Service> list = ExternalService.List(); return(list); }
/// <summary> /// Creates a new group with the name passed to the parameter if the group does not exist /// and adds the contacts passed to the parameter. /// </summary> /// <param name="name">The group name to create.</param> /// <param name="contactList"> The list of contacts to be added to the group.</param> /// <returns> True if the group was successfully created and contacts have been added, false otherwise.</returns> public bool CreateGroup(string name, List <Contact> contactList) { if (!_registered) { return(false); } if (String.IsNullOrEmpty(name) || contactList == null) { return(false); } if (name == defGroup) { return(false); } Storage.StorageManager sto = new Storage.StorageManager(); List <string> groupNames = new List <string>(); groupNames.Add(name); List <Storage.Group> groups = sto.addGroups(groupNames, _userId); if (groups == null || groups.Count == 0) { return(false); } List <Storage.Contact> contacts = ConvertToStorageContact(contactList); Storage.Group defStoGroup = null; foreach (Storage.Group g in sto.getGroupsByUserID(_userId)) { if (g.nameGroup.Equals(defGroup)) { defStoGroup = g; break; } } List <Storage.GroupContact> result2 = sto.addContactsToGroup(contacts, groups[0]); if (result2 == null) { return(false); } sto.removeContactsFromGroup(contacts, defStoGroup); return(true); }
/// <summary> /// Moved contacts, passed as parameter, from one group to another. /// </summary> /// <param name="groupIn"> The group name from which the contacts take.</param> /// <param name="groupOut"> The name of the group to move contacts.</param> /// <param name="contactList"> The list of contacts to be moved.</param> /// <returns> True if the contacts are moved successfully, false otherwise. In case of moving to the default group, contacts that are associated in more groups, will not move.</returns> public bool MoveContacts(string groupIn, string groupOut, List <Contact> contactList) { if (!_registered) { return(false); } if (String.IsNullOrEmpty(groupOut) || String.IsNullOrEmpty(groupIn) || contactList == null) { return(false); } if (groupIn == groupOut) { return(true); } Storage.StorageManager sto = new Storage.StorageManager(); Storage.Group tempGroupIn = sto.getGroupByUser(_userId, groupIn); Storage.Group tempGroupOut = sto.getGroupByUser(_userId, groupOut); if (tempGroupIn == null || tempGroupOut == null) { return(false); } List <Storage.Contact> stoContacts = ConvertToStorageContact(contactList); // se il groupOut e' other contacts, devo fare il controllo che gli elementi che vado a spostare // non stiano in altri gruppi if (groupOut.Equals(defGroup)) { List <Storage.Contact> orphan = sto.getContactsOrphanCandidates(_userId, groupIn); stoContacts = orphan.Intersect(stoContacts) as List <Storage.Contact>; } if (stoContacts == null) { //Nel caso che non sposto niente, cosa ritorno? return(true); } else { List <Storage.GroupContact> results = sto.moveContactsToGroup(stoContacts, tempGroupIn.groupID, tempGroupOut.groupID); if (results == null) { return(false); } } return(true); }
/// <summary> /// Return all editable workflow. /// </summary> /// <returns>all editable workflow</returns> public List <WorkflowReference> GetEditableWorkflows() { List <WorkflowReference> result = new List <WorkflowReference>(); if (!_registered) { return(result); } Storage.StorageManager sto = new Storage.StorageManager(); SortedList <int, Storage.StorageManager.Pair <string, string> > modlist = sto.getModelsByUserID(_userId); foreach (KeyValuePair <int, Storage.StorageManager.Pair <string, string> > models in modlist) { result.Add(new WorkflowReference(_userId, models.Key, models.Value.First, models.Value.Second)); } return(result); }
/// <summary> /// Return a list of /// </summary> /// <returns></returns> public List <FilledWorkflowReference> GetCompiledForms() { List <FilledWorkflowReference> ret = new List <FilledWorkflowReference>(); if (!_registered) { return(ret); } Storage.StorageManager db = new Storage.StorageManager(); Storage.User user = db.getEntityByID <Storage.User>(_userId); foreach (Storage.Publication pub in user.Publication) { ret.Add(new FilledWorkflowReference(pub.publicationID)); } return(ret); }
/// <summary> /// Removes the group with the name passed as parameter if it does exist. /// </summary> /// <param name="name">The name of the group.</param> /// <returns>True if the removal was successful, false otherwise.</returns> public bool RemoveGroup(string name, bool removeContacts) { if (!_registered) { return(false); } if (String.IsNullOrEmpty(name)) { return(false); } if (name == defGroup) { return(false); } Storage.StorageManager sto = new Storage.StorageManager(); Storage.Group temp = sto.getGroupByUser(_userId, name); if (temp == null) { return(false); } bool result; if (!removeContacts) { List <Storage.Contact> contacts = sto.getContactsByGroup(_userId, name); List <Storage.Contact> orphans = sto.getContactsOrphanCandidates(_userId, name); result = sto.removeEntity <Storage.Group>(temp.groupID); if (sto.addContactsToGroup(orphans, sto.getGroupByUser(_userId, defGroup)) != null) { return(result); } else { return(false); } } else { return(sto.removeEntity <Storage.Group>(temp.groupID)); } }
/// <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); }
/// <summary> /// Remove contacts passed as parameter by the group with the name passed as parameter. /// </summary> /// <param name="name"> The name of the group from which to remove contacts.</param> /// <param name="contactList"> The list of contacts to be removed.</param> /// <returns> True if the contacts have been successfully removed, false otherwise.</returns> public bool RemoveContactsFromGroup(string name, List <Contact> contactList) { if (!_registered) { return(false); } if (String.IsNullOrEmpty(name) || contactList == null) { return(false); } Storage.StorageManager sto = new Storage.StorageManager(); Storage.Group tempGroup = sto.getGroupByUser(_userId, name); if (tempGroup == null) { return(false); } List <Storage.Contact> contacts = ConvertToStorageContact(contactList); return(sto.removeContactsFromGroup(contacts, tempGroup)); }
/// <summary> /// Return all computable workflow. /// </summary> /// <returns>all computable workflow</returns> public List <ComputableWorkflowReference> GetComputableWorkflows() { List <ComputableWorkflowReference> result = new List <ComputableWorkflowReference>(); if (!_registered) { return(result); } Storage.StorageManager sto = new Storage.StorageManager(); List <Storage.StorageManager.PartialPublication> publist = sto.getPublicationsByUserID2(_userId); foreach (Storage.StorageManager.PartialPublication publication in publist) { result.Add(new ComputableWorkflowReference(_userId, publication.publicationID, publication.namePublication, publication.descr, false, publication.expirationDate)); } return(result); }
/// <summary> /// Add a new workflow. /// </summary> /// <param name="wf">the workflow</param> /// <returns>a new workflow reference</returns> public WorkflowReference AddNewWorkFlow(Workflow wf, string description) { if (!_registered) { return(null); } if (wf == null || description == null) { throw new ArgumentNullException(); } WorkflowReference result; Storage.StorageManager sto = new Storage.StorageManager(); Storage.Model mod = sto.addModel(_userId, defaultthemeid, wf.WorkflowName, wf, description); if (mod == null) { return(null); } result = new WorkflowReference(_userId, mod.modelID, wf.WorkflowName, description, mod.themeID); return(result); }
/// <summary> /// Get all public forms links with names and descriptions /// </summary> /// <returns>A Dictionary containing pairs of FormLink/<FormName,FormDescription&rt;</returns> public static Dictionary <string, Storage.StorageManager.Pair <string, string> > GetPublicFormsLinks() { int fakeId = 1; Storage.StorageManager sto = new Storage.StorageManager(); // We likes very long types List <Storage.StorageManager.Pair < Storage.StorageManager.PartialPublication, Storage.CompilationRequest > > completelypublicpubs = sto.getPublicationsCompilationRequestByContactID(fakeId); List <Storage.StorageManager.PartialPublication> publicpubs = sto.getPublicationsPublic(); Dictionary <string, Storage.StorageManager.Pair <string, string> > result = new Dictionary <string, Storage.StorageManager.Pair <string, string> >(); int i = 0; foreach (Storage.StorageManager.PartialPublication pub in publicpubs) { Storage.CompilationRequest creq = null; if (pub.publicationID == completelypublicpubs[i].First.publicationID) { // Completely public creq = completelypublicpubs[i].Second; i++; // If reached the last one, stay there if (i == completelypublicpubs.Count) { i--; } } Storage.StorageManager.Pair <string, string> pair = new Storage.StorageManager.Pair <string, string>(); pair.First = pub.namePublication; pair.Second = pub.descr; result.Add(ToLink(pub, creq), pair); Console.WriteLine(ToLink(pub, creq)); } return(result); }
/// <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); }
/// <summary> /// Convert a list of Security.Contact in a list of StorageManager.Contact /// </summary> /// <param name="contactsList"></param> /// <returns></returns> private List <Storage.Contact> ConvertToStorageContact(List <Security.Contact> contactsList) { if (!_registered) { return(null); } if (contactsList == null) { return(null); } Storage.StorageManager sto = new Storage.StorageManager(); List <Storage.StorageManager.Pair <string, int> > mycontacts = new List <Storage.StorageManager.Pair <string, int> >(); foreach (Contact secContact in contactsList) { Storage.StorageManager.Pair <string, int> pair; pair = new Storage.StorageManager.Pair <string, int>(); pair.First = secContact.Email; pair.Second = secContact.Service.ServiceId; mycontacts.Add(pair); } return(sto.getContactsByExtID(mycontacts)); }
/// <summary> /// Resurns a List containing the contacts which the group is composed of. /// </summary> /// <param name="groupName">Tha name of a contacts group</param> /// <returns>A List containing the contacts wich the group is composed of</returns> public List <Contact> GetContactsByGroup(string groupName) { if (!_registered) { return(null); } if (String.IsNullOrEmpty(groupName)) { return(null); } Storage.StorageManager sto = new Storage.StorageManager(); List <Storage.Contact> contacts = sto.getContactsByGroup(_userId, groupName); List <Contact> ret = new List <Contact>(); if (contacts == null) { return(null); } foreach (Storage.Contact contact in contacts) { ret.Add(new Contact(contact.contactID, contact.nameContact, contact.externalUserID, new Service(contact.Service.nameService, contact.Service.serviceID))); } return(ret); }
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); } }
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); } } }
public FilledWorkflowReference(int publicationId) { this.publicationId = publicationId; this.sto = new Storage.StorageManager(); }
/// <summary> /// Register the user on the database saving all external accounts that the user subscribed. On success, UserID property will be changed. /// </summary> /// <param name="Nickname">The nickname of the user</param> /// <param name="Email">The email of the user</param> /// <returns>True on succes or if already registered, false otherwise (in this case nothing is saved on the database)</returns> public RegisterMeResult RegisterMe(string Nickname, string Email, out string messageError) { messageError = ""; if (_registered) { return(RegisterMeResult.OK); } if (String.IsNullOrEmpty(Nickname)) { messageError = "Nickname is not valid."; return(RegisterMeResult.E_EMAIL); } if (String.IsNullOrEmpty(Email)) { messageError = "Email is not valid."; return(RegisterMeResult.E_EMAIL); } try { new System.Net.Mail.MailAddress(Email); } catch (Exception) { messageError = "Email is not valid."; return(RegisterMeResult.E_EMAIL); } Storage.StorageManager sto = new Storage.StorageManager(); Storage.User tempUser = sto.addUser(Nickname, Email); if (tempUser == null) { messageError = "An error has occured saving the new user on the database."; return(RegisterMeResult.E_GENERIC); } _userId = tempUser.userID; List <string> groupNames = new List <string>(); groupNames.Add(defGroup); List <Storage.Group> groupResult = sto.addGroups(groupNames, _userId); if (groupResult == null) { //rollback sto.removeEntity <Storage.User>(_userId); _userId = -1; { messageError = "An error has occured during the creation of default group."; return(RegisterMeResult.E_GENERIC); } } // Save all externalAccount foreach (int serviceID in _loggedServices.Keys) { Storage.ExternalAccount extAcc = sto.addExternalAccount(_userId, _loggedServices[serviceID].getUsername(), serviceID); if (extAcc == null) { //rollback sto.removeEntity <Storage.User>(_userId); sto.removeEntity <Storage.Group>(groupResult.First().groupID); _userId = -1; messageError = "An error has occured saving currently logged accounts."; return(RegisterMeResult.E_GENERIC); } } _username = Nickname; _email = Email; _registered = true; return(RegisterMeResult.OK); }
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); }