/// <summary> /// Discovers schemas located in the users DB2 database /// </summary> /// <param name="request"></param> /// <param name="context"></param> /// <returns>Discovered schemas</returns> public override async Task <DiscoverSchemasResponse> DiscoverSchemas(DiscoverSchemasRequest request, ServerCallContext context) { Logger.SetLogPrefix("discover"); Logger.Info("Discovering Schemas..."); var sampleSize = checked ((int)request.SampleSize); DiscoverSchemasResponse discoverSchemasResponse = new DiscoverSchemasResponse(); // only return requested schemas if refresh mode selected if (request.Mode == DiscoverSchemasRequest.Types.Mode.All) { if (_server.Settings.DisableDiscovery) { Logger.Info("Discovery is disabled. Skipping."); return(new DiscoverSchemasResponse()); } // get all schemas try { var schemas = Discover.GetAllSchemas(_connectionFactory, _server.Settings, sampleSize); discoverSchemasResponse.Schemas.AddRange(await schemas.ToListAsync()); Logger.Info($"Schemas returned: {discoverSchemasResponse.Schemas.Count}"); return(discoverSchemasResponse); } catch (Exception e) { Logger.Error(e, e.Message, context); return(new DiscoverSchemasResponse()); } } try { var refreshSchemas = request.ToRefresh; Logger.Info($"Refresh schemas attempted: {refreshSchemas.Count}"); var schemas = Discover.GetRefreshSchemas(_connectionFactory, refreshSchemas, sampleSize); discoverSchemasResponse.Schemas.AddRange(await schemas.ToListAsync()); // return all schemas Logger.Info($"Schemas returned: {discoverSchemasResponse.Schemas.Count}"); return(discoverSchemasResponse); } catch (Exception e) { Logger.Error(e, e.Message, context); return(new DiscoverSchemasResponse()); } }
/// <summary> /// Discovers schemas located in the users Zoho CRM instance /// </summary> /// <param name="request"></param> /// <param name="context"></param> /// <returns>Discovered schemas</returns> public override async Task <DiscoverSchemasResponse> DiscoverSchemas(DiscoverSchemasRequest request, ServerCallContext context) { Logger.Info("Discovering Schemas..."); // get a schema for each module found DiscoverSchemasResponse discoverSchemasResponse = new DiscoverSchemasResponse(); Logger.Info("Schema discovery not supported"); return(discoverSchemasResponse); }
/// <summary> /// Discovers schemas located in the users Zoho CRM instance /// </summary> /// <param name="request"></param> /// <param name="context"></param> /// <returns>Discovered schemas</returns> public override async Task <DiscoverSchemasResponse> DiscoverSchemas(DiscoverSchemasRequest request, ServerCallContext context) { Logger.Info("Discovering Schemas..."); // get a schema for each module found DiscoverSchemasResponse discoverSchemasResponse = new DiscoverSchemasResponse(); // try // { // var schemas = await Discover.GetAllReadSchemas(_client, _server.Settings); // // discoverSchemasResponse.Schemas.AddRange(schemas); // } // catch (Exception e) // { // Logger.Error(e.Message); // throw; // } // // Logger.Info($"Schemas found: {discoverSchemasResponse.Schemas.Count}"); // // // only return requested schemas if refresh mode selected // if (request.Mode == DiscoverSchemasRequest.Types.Mode.Refresh) // { // var refreshSchemaIds = request.ToRefresh.Select(x => x.Id); // var schemas = // JsonConvert.DeserializeObject<Schema[]>( // JsonConvert.SerializeObject(discoverSchemasResponse.Schemas)); // discoverSchemasResponse.Schemas.Clear(); // discoverSchemasResponse.Schemas.AddRange(schemas.Where(x => refreshSchemaIds.Contains(x.Id))); // // // Logger.Debug($"Schemas found: {JsonConvert.SerializeObject(schemas)}"); // Logger.Debug($"Refresh requested on schemas: {refreshSchemaIds}"); // // Logger.Info($"Schemas returned: {discoverSchemasResponse.Schemas.Count}"); // return discoverSchemasResponse; // } // // // return all schemas otherwise // Logger.Info($"Schemas returned: {discoverSchemasResponse.Schemas.Count}"); return(discoverSchemasResponse); }
/// <summary> /// Discovers schemas located in the users Zoho CRM instance /// </summary> /// <param name="request"></param> /// <param name="context"></param> /// <returns>Discovered schemas</returns> public override async Task <DiscoverSchemasResponse> DiscoverSchemas(DiscoverSchemasRequest request, ServerCallContext context) { try { Logger.SetLogPrefix("discover"); Logger.Info("Discovering Schemas..."); DiscoverSchemasResponse discoverSchemasResponse = new DiscoverSchemasResponse(); discoverSchemasResponse.Schemas.AddRange(await Discover.GetAllSchemas(_client)); discoverSchemasResponse.Schemas.AddRange( await Discover.GetAllCustomSchemas(_client, _server.Settings.CustomSchemaList)); Logger.Info($"Schemas found: {discoverSchemasResponse.Schemas.Count}"); // only return requested schemas if refresh mode selected if (request.Mode == DiscoverSchemasRequest.Types.Mode.Refresh) { var refreshSchemas = request.ToRefresh; var schemas = JsonConvert.DeserializeObject <Schema[]>( JsonConvert.SerializeObject(discoverSchemasResponse.Schemas)); discoverSchemasResponse.Schemas.Clear(); discoverSchemasResponse.Schemas.AddRange(schemas.Join(refreshSchemas, schema => schema.Id, refreshSchema => refreshSchema.Id, (schema, refresh) => schema)); Logger.Debug($"Refresh requested on schemas: {JsonConvert.SerializeObject(refreshSchemas)}"); Logger.Info($"Schemas returned: {discoverSchemasResponse.Schemas.Count}"); return(discoverSchemasResponse); } // return all schemas otherwise Logger.Info($"Schemas returned: {discoverSchemasResponse.Schemas.Count}"); return(discoverSchemasResponse); } catch (Exception e) { Logger.Error(e, e.Message, context); return(new DiscoverSchemasResponse()); } }
/// <summary> /// Discovers schemas located in the users CouchDB instance /// </summary> /// <param name="request"></param> /// <param name="context"></param> /// <returns>Discovered schemas</returns> public override async Task <DiscoverSchemasResponse> DiscoverSchemas(DiscoverSchemasRequest request, ServerCallContext context) { Logger.SetLogPrefix("discover"); Logger.Info("Discovering Schemas..."); DiscoverSchemasResponse discoverSchemasResponse = new DiscoverSchemasResponse(); // only return requested schemas if refresh mode selected if (request.Mode == DiscoverSchemasRequest.Types.Mode.All) { Logger.Info("Plugin does not support auto schema discovery."); return(discoverSchemasResponse); } try { var refreshSchemas = request.ToRefresh; Logger.Info($"Refresh schemas attempted: {refreshSchemas.Count}"); var tasks = refreshSchemas.Select(GetSchemaProperties) .ToArray(); await Task.WhenAll(tasks); discoverSchemasResponse.Schemas.AddRange(tasks.Where(x => x.Result != null).Select(x => x.Result)); // return all schemas Logger.Info($"Schemas returned: {discoverSchemasResponse.Schemas.Count}"); return(discoverSchemasResponse); } catch (Exception e) { Logger.Error(e, e.Message, context); return(new DiscoverSchemasResponse()); } }
/// <summary> /// Discovers schemas located in the users Zoho CRM instance /// </summary> /// <param name="request"></param> /// <param name="context"></param> /// <returns>Discovered schemas</returns> public override async Task <DiscoverSchemasResponse> DiscoverSchemas(DiscoverSchemasRequest request, ServerCallContext context) { Logger.Info("Discovering Schemas..."); DiscoverSchemasResponse discoverSchemasResponse = new DiscoverSchemasResponse(); var isAuthed = await AuthorizeHttpClient(); if (!isAuthed) { return(discoverSchemasResponse); } // get to get a schema for each module found try { var rulesUrl = $"{_apiUri}/v3/mdm/merging/rules"; var rulesResp = await _injectedClient.GetAsync(rulesUrl); rulesResp.EnsureSuccessStatusCode(); dynamic rulesJson = JObject.Parse(await rulesResp.Content.ReadAsStringAsync()); foreach (dynamic rule in rulesJson.data) { var schema = new Schema { Id = rule.@object, Name = rule.@object, DataFlowDirection = Schema.Types.DataFlowDirection.Read }; // Add ID property schema.Properties.Add(new Property { Id = "ID", Name = "ID", Type = PropertyType.String, Description = "The global identifier", IsKey = true }); foreach (dynamic prop in rule.properties) { schema.Properties.Add(new Property { Id = prop.name, Name = prop.name, Type = GetPropertyType((string)prop.type) }); } discoverSchemasResponse.Schemas.Add(schema); } } catch (Exception e) { Logger.Error(e, e.Message, context); return(new DiscoverSchemasResponse()); } Logger.Info($"Schemas found: {discoverSchemasResponse.Schemas.Count}"); // only return requested schemas if refresh mode selected if (request.Mode == DiscoverSchemasRequest.Types.Mode.Refresh) { var refreshSchemaIds = request.ToRefresh.Select(x => x.Id); var schemas = JsonConvert.DeserializeObject <Schema[]>( JsonConvert.SerializeObject(discoverSchemasResponse.Schemas)); discoverSchemasResponse.Schemas.Clear(); discoverSchemasResponse.Schemas.AddRange(schemas.Where(x => refreshSchemaIds.Contains(x.Id))); Logger.Debug($"Schemas found: {JsonConvert.SerializeObject(schemas)}"); Logger.Debug($"Refresh requested on schemas: {refreshSchemaIds}"); Logger.Info($"Schemas returned: {discoverSchemasResponse.Schemas.Count}"); return(discoverSchemasResponse); } // return all schemas otherwise Logger.Info($"Schemas returned: {discoverSchemasResponse.Schemas.Count}"); return(discoverSchemasResponse); }
/// <summary> /// Discovers schemas located in the users Sage instance /// </summary> /// <param name="request"></param> /// <param name="context"></param> /// <returns>Discovered schemas</returns> public override async Task <DiscoverSchemasResponse> DiscoverSchemas(DiscoverSchemasRequest request, ServerCallContext context) { Logger.SetLogPrefix("discover"); Logger.Info("Discovering Schemas..."); DiscoverSchemasResponse discoverSchemasResponse = new DiscoverSchemasResponse(); // only return requested schemas if refresh mode selected if (request.Mode == DiscoverSchemasRequest.Types.Mode.Refresh) { try { var refreshSchemas = request.ToRefresh; Logger.Info($"Refresh schemas attempted: {refreshSchemas.Count}"); var tasks = refreshSchemas.Select((s) => { var metaJsonObject = JsonConvert.DeserializeObject <PublisherMetaJson>(s.PublisherMetaJson); // add insert schema if (metaJsonObject.Module.Contains("Insert")) { return(Task.FromResult(Discover.GetInsertSchemaForModule(metaJsonObject.Module))); } // add discover schema return(GetSchemaForModule(metaJsonObject.Module)); }) .ToArray(); await Task.WhenAll(tasks); discoverSchemasResponse.Schemas.AddRange(tasks.Where(x => x.Result != null).Select(x => x.Result)); // return all schemas Logger.Info($"Schemas returned: {discoverSchemasResponse.Schemas.Count}"); return(discoverSchemasResponse); } catch (Exception e) { Logger.Error(e, e.Message, context); return(new DiscoverSchemasResponse()); } } // attempt to get a schema for each module requested try { Logger.Info($"Schemas attempted: {_server.Settings.ModulesList.Length + Discover.GetTotalInsertSchemas()}"); var tasks = _server.Settings.ModulesList.Select(GetSchemaForModule) .ToArray(); await Task.WhenAll(tasks); discoverSchemasResponse.Schemas.AddRange(tasks.Where(x => x.Result != null).Select(x => x.Result)); // add insert schemas discoverSchemasResponse.Schemas.AddRange(Discover.GetAllInsertSchemas()); // return all schema Logger.Info($"Schemas returned: {discoverSchemasResponse.Schemas.Count}"); return(discoverSchemasResponse); } catch (Exception e) { Logger.Error(e, e.Message, context); return(new DiscoverSchemasResponse()); } }
/// <summary> /// Discovers schemas located in the RJG Website /// </summary> /// <param name="request"></param> /// <param name="context"></param> /// <returns>Discovered schemas</returns> public override async Task <DiscoverSchemasResponse> DiscoverSchemas(DiscoverSchemasRequest request, ServerCallContext context) { // Logger.SetLogPrefix("discover"); Logger.Info("Discovering Schemas..."); var discoverSchemasResponse = new DiscoverSchemasResponse(); // only return requested schemas if refresh mode selected if (request.Mode == DiscoverSchemasRequest.Types.Mode.Refresh) { try { var refreshSchemas = request.ToRefresh; Logger.Info($"Refresh schemas attempted: {refreshSchemas.Count}"); var tasks = refreshSchemas.Select((s) => { var endpoint = _endpointHelper.GetEndpointForName(s.Id); return(DiscoverSchema.GetSchemaForEndpoint(endpoint, _client)); }) .ToArray(); await Task.WhenAll(tasks); discoverSchemasResponse.Schemas.AddRange(tasks.Where(x => x.Result != null).Select(x => x.Result)); // return refresh schemas Logger.Info($"Schemas returned: {discoverSchemasResponse.Schemas.Count}"); return(discoverSchemasResponse); } catch (Exception e) { Logger.Error(e, e.Message, context); return(new DiscoverSchemasResponse()); } } // get all schemas try { Logger.Info($"Schemas attempted: {_endpointHelper.Endpoints.Count}"); var tasks = _endpointHelper.Endpoints.Select(e => DiscoverSchema.GetSchemaForEndpoint(e, _client)) .ToArray(); await Task.WhenAll(tasks); discoverSchemasResponse.Schemas.AddRange(tasks.Where(x => x.Result != null).Select(x => x.Result)); } catch (Exception e) { Logger.Error(e, e.Message, context); return(new DiscoverSchemasResponse()); } // return all schemas otherwise Logger.Info($"Schemas returned: {discoverSchemasResponse.Schemas.Count}"); return(discoverSchemasResponse); }
/// <summary> /// Discovers schemas located in the Salesforce instance /// </summary> /// <param name="request"></param> /// <param name="context"></param> /// <returns>Discovered schemas</returns> public override async Task <DiscoverSchemasResponse> DiscoverSchemas(DiscoverSchemasRequest request, ServerCallContext context) { Logger.SetLogPrefix("discover"); Logger.Info("Discovering Schemas..."); DiscoverSchemasResponse discoverSchemasResponse = new DiscoverSchemasResponse(); // handle query based schema try { if (request.Mode == DiscoverSchemasRequest.Types.Mode.Refresh && request.ToRefresh.Count == 1 && !string.IsNullOrWhiteSpace(request.ToRefresh.First().Query)) { discoverSchemasResponse.Schemas.Add( await Discover.GetSchemaForQuery(_client, request.ToRefresh.First(), request.SampleSize)); return(discoverSchemasResponse); } } catch (Exception e) { Logger.Error(e, e.Message, context); return(new DiscoverSchemasResponse()); } List <TabObject> tabsResponse; // get the tabs present in Salesforce try { Logger.Debug("Getting tabs..."); var response = await _client.GetAsync("/tabs"); response.EnsureSuccessStatusCode(); tabsResponse = JsonConvert.DeserializeObject <List <TabObject> >(await response.Content.ReadAsStringAsync()); } catch (Exception e) { Logger.Error(e, e.Message, context); return(new DiscoverSchemasResponse()); } // attempt to get a schema for each tab found try { Logger.Info($"Schemas attempted: {tabsResponse.Count}"); var tasks = tabsResponse .Select(t => Discover.GetSchemaForTab(_client, _fieldObjectsDictionary, t)) .ToArray(); await Task.WhenAll(tasks); discoverSchemasResponse.Schemas.AddRange(tasks.Where(x => x.Result != null).Select(x => x.Result)); } catch (Exception e) { Logger.Error(e, e.Message, context); return(new DiscoverSchemasResponse()); } Logger.Info($"Schemas found: {discoverSchemasResponse.Schemas.Count}"); // only return requested schemas if refresh mode selected if (request.Mode == DiscoverSchemasRequest.Types.Mode.Refresh) { var refreshSchemas = request.ToRefresh; var schemas = JsonConvert.DeserializeObject <Schema[]>( JsonConvert.SerializeObject(discoverSchemasResponse.Schemas)); discoverSchemasResponse.Schemas.Clear(); discoverSchemasResponse.Schemas.AddRange(schemas.Join(refreshSchemas, schema => schema.Id, refreshSchema => refreshSchema.Id, (schema, refresh) => schema)); Logger.Debug($"Schemas found: {JsonConvert.SerializeObject(schemas)}"); Logger.Debug($"Refresh requested on schemas: {JsonConvert.SerializeObject(refreshSchemas)}"); Logger.Info($"Schemas returned: {discoverSchemasResponse.Schemas.Count}"); return(discoverSchemasResponse); } // return all schemas otherwise Logger.Info($"Schemas returned: {discoverSchemasResponse.Schemas.Count}"); return(discoverSchemasResponse); }
/// <summary> /// Discovers schemas based on a query /// </summary> /// <param name="request"></param> /// <param name="context"></param> /// <returns>Discovered schemas</returns> public override async Task <DiscoverSchemasResponse> DiscoverSchemas(DiscoverSchemasRequest request, ServerCallContext context) { Logger.SetLogPrefix("discover"); Logger.Info("Discovering Schemas..."); var sampleSize = checked ((int)request.SampleSize); DiscoverSchemasResponse discoverSchemasResponse = new DiscoverSchemasResponse(); // only return requested schemas if refresh mode selected if (request.Mode == DiscoverSchemasRequest.Types.Mode.All) { // get all schemas try { await DiscoverSemaphoreSlim.WaitAsync(); var files = _server.Settings.GetAllFilesByRootPath(); Logger.Info($"Files attempted: {files.Count}"); var schemas = _server.Settings.RootPaths.Select(p => Discover.GetSchemasForDirectory(context, Utility.GetImportExportFactory(p.Mode), p, files[p.RootPathName()], sampleSize)).Select(l => l.Where(s => s != null)) .ToList(); discoverSchemasResponse.Schemas.AddRange(schemas.SelectMany(s => s)); Logger.Info($"Schemas returned: {discoverSchemasResponse.Schemas.Count}"); return(discoverSchemasResponse); } catch (Exception e) { Logger.Error(e, e.Message, context); return(new DiscoverSchemasResponse()); } finally { DiscoverSemaphoreSlim.Release(); } } try { await DiscoverSemaphoreSlim.WaitAsync(); var refreshSchemas = request.ToRefresh; Logger.Info($"Refresh schemas attempted: {refreshSchemas.Count}"); var files = _server.Settings.GetAllFilesByRootPath(); var conn = Utility.GetSqlConnection(Constants.DiscoverDbPrefix); if (sampleSize == 0) { sampleSize = 5; } foreach (var rootPath in _server.Settings.RootPaths) { var schemaName = Constants.SchemaName; var tableName = string.IsNullOrWhiteSpace(rootPath.Name) ? new DirectoryInfo(rootPath.RootPath).Name : rootPath.Name; Utility.LoadDirectoryFilesIntoDb( Utility.GetImportExportFactory(rootPath.Mode), conn, rootPath, tableName, schemaName, files[rootPath.RootPathName()], false, sampleSize, 1); } var schemas = refreshSchemas.Select(s => Discover.GetSchemaForQuery(context, s, sampleSize)) .ToArray(); discoverSchemasResponse.Schemas.AddRange(schemas.Where(x => x != null)); // return all schemas Logger.Info($"Schemas returned: {discoverSchemasResponse.Schemas.Count}"); return(discoverSchemasResponse); } catch (Exception e) { Logger.Error(e, e.Message, context); return(new DiscoverSchemasResponse()); } finally { DiscoverSemaphoreSlim.Release(); } }
/// <summary> /// Discovers schemas located in the users Zoho CRM instance /// </summary> /// <param name="request"></param> /// <param name="context"></param> /// <returns>Discovered schemas</returns> public override async Task <DiscoverSchemasResponse> DiscoverSchemas(DiscoverSchemasRequest request, ServerCallContext context) { Logger.Info("Discovering Schemas..."); DiscoverSchemasResponse discoverSchemasResponse = new DiscoverSchemasResponse(); ModuleResponse modulesResponse; // get the modules present in Zoho try { Logger.Debug("Getting modules..."); var response = await _client.GetAsync("https://www.zohoapis.com/crm/v2/settings/modules"); response.EnsureSuccessStatusCode(); Logger.Debug(await response.Content.ReadAsStringAsync()); modulesResponse = JsonConvert.DeserializeObject <ModuleResponse>(await response.Content.ReadAsStringAsync()); } catch (Exception e) { Logger.Error(e, e.Message, context); return(new DiscoverSchemasResponse()); } // attempt to get a schema for each module found try { Logger.Info($"Schemas attempted: {modulesResponse.modules.Length}"); var tasks = modulesResponse.modules.Select(GetSchemaForModule) .ToArray(); await Task.WhenAll(tasks); discoverSchemasResponse.Schemas.AddRange(tasks.Where(x => x.Result != null).Select(x => x.Result)); } catch (Exception e) { Logger.Error(e, e.Message, context); return(new DiscoverSchemasResponse()); } Logger.Info($"Schemas found: {discoverSchemasResponse.Schemas.Count}"); // only return requested schemas if refresh mode selected if (request.Mode == DiscoverSchemasRequest.Types.Mode.Refresh) { var refreshSchemas = request.ToRefresh; var schemas = JsonConvert.DeserializeObject <Schema[]>( JsonConvert.SerializeObject(discoverSchemasResponse.Schemas)); discoverSchemasResponse.Schemas.Clear(); discoverSchemasResponse.Schemas.AddRange(schemas.Join(refreshSchemas, GetModuleName, GetModuleName, (shape, refresh) => shape)); Logger.Debug($"Schemas found: {JsonConvert.SerializeObject(schemas)}"); Logger.Debug($"Refresh requested on schemas: {JsonConvert.SerializeObject(refreshSchemas)}"); Logger.Info($"Schemas returned: {discoverSchemasResponse.Schemas.Count}"); return(discoverSchemasResponse); } // return all schemas otherwise Logger.Info($"Schemas returned: {discoverSchemasResponse.Schemas.Count}"); return(discoverSchemasResponse); }