/// <summary> /// Use system user token to perform work /// </summary> /// <param name="token">Token returned from SuperId and validated</param> /// <returns>Contact entity created as the system user</returns> private static ContactEntity DoWorkAsSystemUser(SuperIdToken token) { // Enter database context for the customer (enter the right multi-tenant context) using (var context = SoDatabaseContext.EnterDatabaseContext(token.ContextIdentifier)) { // set appropriate url for the customer tenant // ConfigFile.WebServices.RemoteBaseURL = token.NetserverUrl; // Log in as the system user using (var session = SoSession.Authenticate(new SoCredentials(token.Ticket))) { // Do work as the system user var principal = SoContext.CurrentPrincipal; System.Diagnostics.Trace.WriteLine(principal.Associate); using (var agent = new ContactAgent()) { var timestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; var entity = agent.CreateDefaultContactEntity(); entity.Name = "SuperId-" + timestamp; return(agent.SaveContactEntity(entity)); } } } }
/// <summary> /// Is the currently authenticated NetServer user authorized to use web and from the correct tenant /// </summary> /// <returns></returns> private static bool IsAutorizedWithNetServer() { var principal = SoContext.CurrentPrincipal; if (Context == null) { return(false); } if (!IsAuthenticatedWithNetServer(principal)) { return(false); } if (principal.UserType != UserType.InternalAssociate) { return(false); } if (!principal.HasLicense(SoLicenseNames.Web)) { return(false); } if (!String.Equals(SoDatabaseContext.GetCurrent().ContextIdentifier, Context.ContextIdentifier, StringComparison.InvariantCultureIgnoreCase)) { return(false); } //All checks were successful. return(true); }
public IEnumerable <AppointmentInfo> GetAppointmentEntitiesFromId(int appointmentId, string ticket, string contextIdentifier, string netserverUrl, Dictionary <string, WishlistElement> infoWishList) { using (SoDatabaseContext.EnterDatabaseContext(contextIdentifier)) { ConfigFile.WebServices.RemoteBaseURL = netserverUrl; using (SoSession.Authenticate(new SoCredentials(ticket))) using (var appAgent = new AppointmentAgent()) //using (new AssociateAgent()) using (var personAgent = new PersonAgent()) { var appEnts = new List <AppointmentInfo>(); AppointmentInfo appInfo; AppointmentEntity appEntity; do { appEntity = appAgent.GetAppointmentEntity(appointmentId); if (appEntity?.Associate == null) { continue; } var associatePerson = personAgent.GetPersonEntity(appEntity.Associate.PersonId); var appointmentPerson = personAgent.GetPersonEntity(appEntity.Person.PersonId); appInfo = new AppointmentInfo { AppointmentId = appEntity.AppointmentId, EmailReceiver = appointmentPerson.Emails.FirstOrDefault()?.Value, MessageDescription = appEntity.Description, Receptionist = associatePerson.FullName, RecepTitle = associatePerson.Title, SmsPhoneNumber = appointmentPerson.MobilePhones.FirstOrDefault()?.Value, CustWantsCallBack = ResolveVariableInfo(appEntity, infoWishList.FirstOrDefault(k => k.Key == "CustWantsCallBack").Value), SendSms = ResolveVariableInfo(appointmentPerson, infoWishList.FirstOrDefault(k => k.Key == "SendSms").Value), CustCallsBack = ResolveVariableInfo(appEntity, infoWishList.FirstOrDefault(k => k.Key == "CustCallsBack").Value), CustomerHighPriority = ResolveVariableInfo(appEntity, infoWishList.FirstOrDefault(k => k.Key == "CustomerHighPriority").Value), Customer = ResolveVariableInfo(appEntity, infoWishList.FirstOrDefault(k => k.Key == "Customer").Value), CustomerContact = ResolveVariableInfo(appEntity, infoWishList.FirstOrDefault(k => k.Key == "CustomerContact").Value), CustomerContactPhone = ResolveVariableInfo(appEntity, infoWishList.FirstOrDefault(k => k.Key == "CustomerContactPhone").Value), }; appEnts.Add(appInfo); appointmentId++; Debug.WriteLine($"AppEntity desc {appInfo.MessageDescription} with ID {appointmentId}"); } while (appEntity != null); return(appEnts); } } }
public void CreateAndSaveWebPanel(string name, string webPanelName, string url, Navigation navigation) { try { var panel = CreateWebPanel(webPanelName, url + "&ctx=" + SoDatabaseContext.GetCurrent().ContextIdentifier, navigation); } catch (WebPanelNameNotUniqueException ex) { // If the panel already exists, I guess that is OK } }
/// <summary> /// Is the currently authenticated NetServer user authorized to use web and from the correct tenant /// </summary> /// <returns></returns> private static bool IsAutorizedWithNetServer() { var principal = SoContext.CurrentPrincipal; var context = Context; return(context != null && IsAuthenticatedWithNetServer(principal) && principal.UserType == UserType.InternalAssociate && principal.HasLicense(SoLicenseNames.Web) && String.Equals(SoDatabaseContext.GetCurrent().ContextIdentifier, context.ContextIdentifier, StringComparison.InvariantCultureIgnoreCase)); }
protected override TResponse Execute <TRequest, TResponse>(TRequest request, Action <IQuoteConnector, TResponse> action) { using (SoDatabaseContext.EnterDatabaseContext(request.ContextIdentifier)) { var systemUserToken = SystemUserManager.GetSystemUserToken(request.ContextIdentifier); SuperOffice.Configuration.ConfigFile.WebServices.RemoteBaseURL = systemUserToken.NetserverUrl; using (SoSession session = SoSession.Authenticate(new SoCredentials() { Ticket = systemUserToken.Ticket })) { return(base.Execute <TRequest, TResponse>(request, action)); } } }
private static void SyncCustomers() { var customerDataSource = new SuperOffice.DevNet.Online.SystemUser.PartnerDBLibrary.Models.CustomerDataSource(); foreach (var customer in customerDataSource.Customers) { Log("Getting System User Token."); var token = GetSystemUserToken(customer.SystemUserToken, customer.ContextIdentifier); if (token != null) { // Enter database context for the customer (enter the right multi-tenant context) using (var context = SoDatabaseContext.EnterDatabaseContext(token.ContextIdentifier)) { // set appriiriate url for the customer tenant ConfigFile.WebServices.RemoteBaseURL = token.NetserverUrl; try { // Log in as the system user using (var session = SoSession.Authenticate(new SoCredentials(token.Ticket))) { //var listHelper = new SuperOffice.DevNet.Online.Provisioning.ListHelper(); //listHelper.CreateSaleSourceListItem("NewSaleSource", "NewSaleSourceToolTip"); //// Do work as the system user Log("Logged on to context {0} as {1}", token.ContextIdentifier, SoContext.CurrentPrincipal == null ? "Unknown" : SoContext.CurrentPrincipal.Associate); } } catch (Exception ex) { while (ex.InnerException != null) { ex = ex.InnerException; } Log("Exception during authentication for customer {0}: {1}", token.ContextIdentifier, ex.Message); } } } else { Log("Unable to get token for customer {0}.", customer.ContextIdentifier); } } }