Exemple #1
0
        /// <summary>
        /// Resolves the integration type from the input, persists it to the DB, and adds it as an integration set from the given source.
        /// </summary>
        /// <param name="inputSource">The input to use for reading. It's registered to the api auth.</param>
        /// <param name="appAuth">The api auth to which to link the integration</param>
        /// <param name="name">The name of the type that will be created</param>
        /// <param name="persist">Whether the type should be saved</param>
        /// <returns></returns>
        public IIntegration AddIntegrationSource(
            IInputSource inputSource,
            ApiAuth appAuth,
            string name,
            string outputCollection = null)
        {
            var integration = inputSource.ResolveIntegrationDefinition() as Data.DataIntegration;

            if (integration == null)
            {
                throw new Exception("Could not resolve type!");
            }
            if (integration.Fields.Count == 0)
            {
                throw new InvalidOperationException("Integration needs to have at least 1 field.");
            }
            integration.APIKey = appAuth;
            if (!string.IsNullOrEmpty(outputCollection))
            {
                integration.Collection = outputCollection;
            }
            integration.FeaturesCollection = $"{integration.Collection}_features";
            if (!string.IsNullOrEmpty(name))
            {
                integration.Name = name;
            }
//            if (persist)
//            {
//                if (integration.APIKey == null) throw new Exception("Integration has no api key assigned!");
//                _integrationService.SaveOrFetchExisting(ref integration);
//            }
            AddIntegration(integration, inputSource);
            return(integration);
        }
            /// <summary>
            /// Gets the integration data type from this source
            /// </summary>
            /// <param name="fileSrc"></param>
            /// <returns></returns>
            public static Data.DataIntegration CreateFromSource(IInputSource fileSrc)
            {
                var structure = fileSrc.ResolveIntegrationDefinition();

                return(structure as Data.DataIntegration);
            }