public async Task <List <ShortCompanyInfo> > SuggestCompanies(string name) { GetRequiredParameters(out string serviceUrl, out string apiKey); #if NETFRAMEWORK _restClient.BaseUrl = serviceUrl; #else _restClient.BaseUrl = new Uri(serviceUrl); #endif _restClient.AddDefaultHeader("ApiKey", apiKey); IRestRequest request = _restClient.CreateRequest(SuggestCompaniesMethodName); request.AddParameter(CompanyNameParameter, name); request.AddParameter(ApiKeyParameter, apiKey); IRestResponse response; try { response = await _restClient.ExecutePostTaskAsync(request).ConfigureAwait(false); } catch (Exception ex) { throw new HttpException((int)HttpStatusCode.InternalServerError, ex.Message); } #if !NETFRAMEWORK if (!response.IsSuccessful) { string message = response.Content.IsNotNullOrEmpty() ? response.Content : response.StatusDescription; throw new HttpException((int)HttpStatusCode.InternalServerError, message); } #endif var responseInfo = ServiceStackTextHelper.Deserialize <CloudRestResponse>(response.Content); if (responseInfo?.CompaniesInfo == null) { throw new HttpException((int)HttpStatusCode.InternalServerError, response.Content); } return(responseInfo.CompaniesInfo); }
/// <summary> /// Starts the train session. /// </summary> /// <param name="ignoreMetricThreshold">if set to <c>true</c> ignore metric threshold on applying model /// instance.</param> /// <returns> /// New train session identifier. /// </returns> public Guid StartTrainSession(bool ignoreMetricThreshold = false) { try { Select trainingSelectQuery = BuildTrainingSelectQuery(); var modelValidator = ClassFactory.Get <IMLModelValidator>(); modelValidator.CheckColumns(trainingSelectQuery); modelValidator.CheckSqlQuery(trainingSelectQuery); string outputColumnName = GetMetadataOutputName() ?? DefaultOutputColumnAlias; ModelSchemaMetadata modelSchemaMetadata = _metadataGenerator.GenerateMetadata(trainingSelectQuery, _modelConfig.MetaData, outputColumnName); MergeFitParams(modelSchemaMetadata, _modelConfig); Guid sessionId = _proxy.StartTrainSession(ServiceStackTextHelper.Serialize(modelSchemaMetadata), _modelConfig.Id); SaveTrainSessionId(sessionId); InsertTrainSession(_modelConfig.Id, sessionId, TrainSessionState.DataTransferring, ignoreMetricThreshold); return(sessionId); } catch (Exception ex) { _modelConfig.TrainSessionId = Guid.NewGuid(); UpdateModelOnError(_modelConfig.Id, ex.Message); InsertTrainSession(_modelConfig.Id, _modelConfig.TrainSessionId, TrainSessionState.Error, ignoreMetricThreshold, ex.Message); throw; } }
private bool EnrichAccountData(Guid accountId, SearchInfoRequest requestBody) { var request = _restClient.CreateJsonRequest(SearchMethodName, requestBody); IRestResponse response; try { response = _restClient.Post(request); } catch (Exception ex) { throw new HttpException((int)HttpStatusCode.InternalServerError, ex.Message); } HandleRestClientError(response); SearchInfoResponse responseInfo = ServiceStackTextHelper.Deserialize <SearchInfoResponse>(response.Content); if (responseInfo.Status == "error") { throw new HttpException((int)HttpStatusCode.InternalServerError, responseInfo.Message); } if (responseInfo.CommunicationInfo == null) { var message = $"CommunicationInfo is null. StatusCode = '{response.StatusCode}' " + $"ResponseStatus = '{response.ResponseStatus}' ErrorMessage = '{response.ErrorMessage}' " + $"Content: {response.Content}"; throw new HttpException((int)HttpStatusCode.InternalServerError, message); } bool result = UpdateEnrichedData(accountId, responseInfo.CommunicationInfo); return(result); }
public string GetVisaEntities(Guid sysAdminUnitId, RequestOptions requestOptions) { var helper = GetVisaHelper(sysAdminUnitId); SelectQueryResponse result = helper.GetEntities(requestOptions); return(ServiceStackTextHelper.Serialize(result)); }
public string GetVisaEntity(Guid sysAdminUnitId, Guid visaId) { var helper = GetVisaHelper(sysAdminUnitId); SelectQueryResponse result = helper.GetEntity(visaId); return(ServiceStackTextHelper.Serialize(result)); }
public virtual void SetDefaultSysMsgUserSettings() { var entitySchemaManager = UserConnection.GetSchemaManager("EntitySchemaManager") as EntitySchemaManager; EntitySchema wSysAccountSchema = entitySchemaManager.GetInstanceByName("WSysAccount"); Entity wSysAccountEntity = wSysAccountSchema.CreateEntity(UserConnection); EntitySchema sysMsgUserSettingsSchema = entitySchemaManager.GetInstanceByName("SysMsgUserSettings"); Entity sysMsgUserSettingsEntity = sysMsgUserSettingsSchema.CreateEntity(UserConnection); sysMsgUserSettingsEntity.SetDefColumnValues(); sysMsgUserSettingsEntity.SetColumnValue("UserId", Entity.PrimaryColumnValue); sysMsgUserSettingsEntity.SetColumnValue("SysMsgLibId", WebitelSymMsgLibId); Dictionary <string, object> connectionParamsDictionary = new Dictionary <string, object>() { { "isWrapUpDisabled", false }, { "debugMode", false }, { "disableCallCentre", false }, { "isAutoLogin", true }, { "useWebitelCti", false }, { "useWebPhone", true }, { "useVideo", false } }; string connectionParams = ServiceStackTextHelper.Serialize(connectionParamsDictionary); sysMsgUserSettingsEntity.SetColumnValue("ConnectionParams", connectionParams); sysMsgUserSettingsEntity.Save(); }
public string GetExecutionData(EmailTemplateUserTask userTask) { string informationOnStep = LocalizableString.IsNullOrEmpty(userTask.InformationOnStep) ? userTask.GetParameterValue("InformationOnStep")?.ToString() ?? string.Empty : userTask.InformationOnStep.Value; string allowedActivityResults = ProcessUserTaskUtilities.GetAllowedActivityResults(UserConnection, userTask.ActivityId); Guid parentProcessId = ProcessUserTaskUtilities.GetParentProcessId(userTask.Owner); return (ServiceStackTextHelper.Serialize( new { procElUId = userTask.UId, name = userTask.Name, processId = parentProcessId, isProcessExecutedBySignal = userTask.Owner.IsProcessExecutedBySignal, processName = userTask.Owner.Name, entitySchemaName = "Activity", recommendation = GetActivityTitle(userTask), informationOnStep, pageTypeId = ActivityConsts.EmailTypeUId, activityRecordId = userTask.ActivityId, executionContext = userTask.ExecutionContext, nextProcElUId = "nextProcElUIdValue", allowedResults = allowedActivityResults })); }
public string FindUsers(string searchCriteria, string socialNetworks) { if (string.IsNullOrEmpty(searchCriteria)) { return(""); } SocialNetwork network = SocialNetwork.All; if (!string.IsNullOrEmpty(socialNetworks)) { network = (SocialNetwork)Enum.Parse(typeof(SocialNetwork), socialNetworks, true); } var commutator = new SocialCommutator(UserConnection, network); var exceptionNetworks = SocialNetwork.None; var accessTokenExceptionNetworks = SocialNetwork.None; commutator.ExceptionOccurred += delegate(ISocialNetwork n, Exception e) { if (e is AccessTokenExpired) { accessTokenExceptionNetworks = (SocialNetwork)accessTokenExceptionNetworks | (e as AccessTokenExpired).SocialNetwork; } else if (e is SocialNetworkException) { exceptionNetworks = (SocialNetwork)exceptionNetworks | (e as SocialNetworkException).SocialNetwork; } else { throw e; } }; List <ISocialNetworkUser> bag = new List <ISocialNetworkUser>(commutator.FindUsers(searchCriteria)); string users = ServiceStackTextHelper.Serialize(bag); return(string.Format("{{\"users\":{0}, \"accessTokenExNetworks\":\"{1}\", \"exeptionNetworks\":\"{2}\"}}", users, accessTokenExceptionNetworks.ToString(), exceptionNetworks.ToString())); }
public string AddFoldersQueueItems(List <object> folderIds, string entitySchemaName, Guid queueId) { List <String> emptyParameters = new List <String>(); if (folderIds.IsNullOrEmpty()) { emptyParameters.Add("folderIds"); } if (entitySchemaName.IsNullOrEmpty()) { emptyParameters.Add("entitySchemaName"); } if (queueId.IsEmpty()) { emptyParameters.Add("queueId"); } if (!emptyParameters.IsNullOrEmpty()) { string message = string.Format(new LocalizableString("Terrasoft.Common", "Exception.ArgumentNullOrEmpty"), StringUtilities.Concat(emptyParameters)); var emptyParametersResult = new { addedEntitiesCount = 0, errorMessages = message }; return(ServiceStackTextHelper.Serialize(emptyParametersResult)); } UserConnection userConnection = (UserConnection)HttpContext.Current.Session["UserConnection"]; EntitySchemaManager entitySchemaManager = userConnection.EntitySchemaManager; var esq = new EntitySchemaQuery(entitySchemaManager, entitySchemaName + "Folder"); esq.PrimaryQueryColumn.IsVisible = true; esq.AddColumn("SearchData"); esq.AddColumn("FolderType"); esq.Filters.Add(esq.CreateFilterWithParameters(FilterComparisonType.Equal, "Id", folderIds)); Terrasoft.Core.Entities.EntityCollection entities = esq.GetEntityCollection(userConnection); var addedEntitiesCount = 0; StringBuilder errorMessages = new StringBuilder(); foreach (Entity entity in entities) { try { addedEntitiesCount = addedEntitiesCount + AddFolderEntityQueueItems(userConnection, entity, entitySchemaName, queueId); } catch (Exception e) { errorMessages.AppendLine(e.Message); } } var result = new { addedEntitiesCount = addedEntitiesCount, errorMessages = errorMessages.ToString() }; return(ServiceStackTextHelper.Serialize(result)); }
/// <summary> /// Returns allowed activity results. /// </summary> /// <param name="userConnection">User connection.</param> /// <param name="activityId">ID of the activity.</param> /// <returns>Allowed values of the activity result.</returns> public static string GetAllowedActivityResults(UserConnection userConnection, Guid activityId) { var select = (Select) new Select(userConnection) .Column("AllowedResult") .From("Activity") .Where("Id").IsEqual(Column.Parameter(activityId)); var allowedResult = select.ExecuteScalar <string>(); if (string.IsNullOrEmpty(allowedResult)) { return("[]"); } EntitySchemaManager entitySchemaManager = userConnection.EntitySchemaManager; EntitySchema entitySchema = entitySchemaManager.GetInstanceByName("ActivityResult"); var esq = new EntitySchemaQuery(entitySchemaManager, entitySchema.Name) { UseAdminRights = false }; esq.PrimaryQueryColumn.IsAlwaysSelect = true; string columnName = entitySchema.GetPrimaryDisplayColumnName(); esq.AddColumn(columnName); esq.AddColumn("Category"); EntitySchemaQueryFilterCollection filters = esq.Filters; var allowedResultIds = ServiceStackTextHelper.Deserialize <string[]>(allowedResult); var columnParameters = new object[allowedResultIds.Length]; for (int i = 0; i < allowedResultIds.Length; i++) { var resultId = new Guid(allowedResultIds[i]); columnParameters[i] = resultId; } filters.Add(esq.CreateFilterWithParameters(FilterComparisonType.Equal, "Id", columnParameters)); EntityCollection entityCollection = esq.GetEntityCollection(userConnection); bool isFirstItem = true; var sb = new StringBuilder("["); foreach (Entity entity in entityCollection) { if (!isFirstItem) { sb.Append(","); } else { isFirstItem = false; } sb.AppendFormat("{{\"resultId\":\"{0}\",\"caption\":\"{1}\",\"categoryId\":\"{2}\"}}", entity.GetTypedColumnValue <Guid>("Id"), entity.GetTypedColumnValue <string>(columnName), entity.GetTypedColumnValue <Guid>("CategoryId")); } sb.Append("]"); return(sb.ToString()); }
public string GetSocialProfile(string socialMediaId, string socialNetworkName, string socialAccountId) { SocialProfile resultProfile = null; SocialCommutator commutator = null; if (string.IsNullOrEmpty(socialNetworkName)) { socialNetworkName = ((SocialNetwork)int.Parse(socialMediaId)).ToString(); } switch (socialNetworkName) { case "Facebook": commutator = new SocialCommutator(UserConnection, SocialNetwork.Facebook); break; case "Twitter": commutator = new SocialCommutator(UserConnection, SocialNetwork.Twitter); break; } if (commutator != null) { SocialNetwork AccessTokenExceptionNetworks = SocialNetwork.None; SocialNetwork ExceptionNetworks = SocialNetwork.None; commutator.ExceptionOccurred += delegate(ISocialNetwork network, Exception e) { if (e is AccessTokenExpired) { AccessTokenExceptionNetworks = (SocialNetwork)AccessTokenExceptionNetworks | (e as AccessTokenExpired).SocialNetwork; } else if (e is SocialNetworkException) { ExceptionNetworks = (SocialNetwork)ExceptionNetworks | (e as SocialNetworkException).SocialNetwork; } else { throw e; } }; var profile = commutator.GetProfile(socialAccountId); resultProfile = new SocialProfile(); resultProfile.SocialNetwork = socialNetworkName; if (profile == null && (AccessTokenExceptionNetworks != SocialNetwork.None || ExceptionNetworks != SocialNetwork.None)) { return(string.Format("{{\"accessTokenExNetworks\":\"{0}\", \"exeptionNetworks\":\"{1}\"}}", AccessTokenExceptionNetworks.ToString(), ExceptionNetworks.ToString())); } resultProfile.ProdileId = profile.Id; if (!string.IsNullOrEmpty(profile.Name)) { resultProfile.Name = profile.Name; } if (!string.IsNullOrEmpty(profile.Email)) { resultProfile.Email = profile.Email; } if (!string.IsNullOrEmpty(profile.PhoneNumber)) { resultProfile.Phone = profile.PhoneNumber; } if (!string.IsNullOrEmpty(profile.IM)) { resultProfile.Skype = profile.IM; } if (!string.IsNullOrEmpty(profile.BirthDay) && !profile.BirthDay.Contains("<")) { var birthDay = DateTime.Now; if (DateTime.TryParse(profile.BirthDay, out birthDay)) { resultProfile.BirthDate = birthDay.ToString("dd-MM-yyyy"); } } if (!string.IsNullOrEmpty(profile.Address)) { resultProfile.Address = profile.Address; } if (!string.IsNullOrEmpty(profile.Work)) { resultProfile.JobTitle = profile.Work; } if (!string.IsNullOrEmpty(profile.AboutMe)) { resultProfile.AboutMe = profile.AboutMe; } var gender = profile.Gender; if (gender != 0) { resultProfile.GenderId = profile.Gender == Terrasoft.Social.Gender.Male ? new Guid("EEAC42EE-65B6-DF11-831A-001D60E938C6") : new Guid("FC2483F8-65B6-DF11-831A-001D60E938C6"); resultProfile.Gender = GetNameById(UserConnection, "Gender", resultProfile.GenderId); } if (!string.IsNullOrEmpty(profile.Country)) { resultProfile.Country = profile.Country; var id = GetIdByName(UserConnection, "Country", profile.Country); if (id != Guid.Empty) { resultProfile.CountryId = id; } } if (!string.IsNullOrEmpty(profile.HomeTown)) { resultProfile.City = profile.HomeTown; var id = GetIdByName(UserConnection, "City", profile.HomeTown); if (id != Guid.Empty) { resultProfile.CityId = id; } } } return(ServiceStackTextHelper.Serialize(resultProfile)); }