Exemple #1
0
    protected override void OnMyDialogOpening()
    {
        var    entityPage = Page as Sage.Platform.WebPortal.EntityPage;
        string providerId = String.Empty;

        if (entityPage != null)
        {
            IIntegration provider = EntityFactory.GetById <IIntegration>(entityPage.EntityContext.EntityID);
            providerId = provider.OAuthProvider.Id.ToString();
        }
        else
        {
            if (DialogService.DialogParameters.ContainsKey("ProviderId"))
            {
                providerId = (string)DialogService.DialogParameters["ProviderId"];
            }
        }
        AuthorizationServiceViewControllerBase.HandleDialogOpening(providerId, Page);
        txtUserName.Text = AuthorizationServiceViewControllerBase.GetProviderUserName(providerId);
        if (String.IsNullOrWhiteSpace(txtUserName.Text))
        {
            txtUserName.Text = GetUserEmail();
        }
        base.OnMyDialogOpening();
    }
Exemple #2
0
 public FieldEncoder(IIntegration ign)
 {
     _integration   = ign;
     _encodedFields = ign.Fields.Where(x => x.DataEncoding != FieldDataEncoding.None);
     _encoders      = _encodedFields.GroupBy(x => x.DataEncoding)
                      .Select(x => FieldEncoding.Factory.Create(ign, x.Key)).ToList();
 }
Exemple #3
0
            private static JArray GetFieldsOptions(IIntegration integration, Func <FieldDefinition, bool> fieldFilter = null)
            {
                var fields = new JArray();

                if (fieldFilter == null)
                {
                    fieldFilter = (x) => true;
                }
                foreach (var fld in integration.Fields.Where(fieldFilter))
                {
                    var isEncoded = fld.DataEncoding != FieldDataEncoding.None;
                    if (!isEncoded)
                    {
                        var jField = new JObject();
                        jField["name"] = fld.Name;
                        (fields).Add(jField);
                    }
                    else
                    {
                        var flds = GetEncodedFieldSubfields(integration, fld);
                        foreach (var encFld in flds)
                        {
                            fields.Add(encFld);
                        }
                    }
                }

                return(fields);
            }
Exemple #4
0
        /// <summary>
        /// Belirtilen entegrasyon tipi ile belirli filtreler ve sıralama özellikleriyle kur listesini belirtilen dosya türü ile export eder.
        /// </summary>
        /// <param name="integration">Entegrasyon yapılarak listenin döndürüleceği servis türünü belirtir.</param>
        /// <param name="export">Export edilecek dosya türünü belirtir.</param>
        /// <param name="currency">Elde edilmek istenilen kur bilgisini belirtir.</param>
        /// <param name="sortField">Sıralama yapılmak istenilen alanı belirtir.</param>
        /// <param name="sortDirection">Hangi yöne sıralama yapılacağını belirtir. Varsayılan Ascending 'tir.</param>
        /// <returns></returns>
        public BaseResponse <FileResult> Export(IIntegration integration, ICurrencyExport export, Currency?currency = null, SortField?sortField = null, SortDirection?sortDirection = SortDirection.Ascending)
        {
            var listResponse = List(integration, currency, sortField, sortDirection);

            var response = new BaseResponse <FileResult>
            {
                IsDone       = true,
                DataReceived = listResponse.DataReceived,
                ErrorMessage = listResponse.ErrorMessage
            };

            if (listResponse.IsDone &&
                listResponse.Data != null &&
                listResponse.Data.Any())
            {
                try
                {
                    response.Data = export.Convert(listResponse.Data);
                }
                catch (Exception ex)
                {
                    response.IsDone       = false;
                    response.ErrorMessage = ex.Message;
                }
            }

            return(response);
        }
Exemple #5
0
        public static IMongoCollection <T> GetMongoFeaturesCollection <T>(this IIntegration ign)
        {
            var tcol = ign.FeaturesCollection;
            var mcol = MongoHelper.GetCollection <T>(tcol);

            return(mcol);
        }
Exemple #6
0
        public WatchConfiguration AddConfiguration(string sourceFolder, IIntegration integration)
        {
            var configuration = new WatchConfiguration(createId(), Path.GetFullPath(sourceFolder), integration);

            ActivateConfiguration(configuration);
            Save();
            return(configuration);
        }
Exemple #7
0
 public CommandsManager(IIntegration client)
 {
     __client = client;
     __commands = new Dictionary<string, ICommand>();
     __modules = new Dictionary<IModule, bool>();
     __internalUserRoles = new Dictionary<string, PermissionType>();
     Console.Write("");
 }
Exemple #8
0
 public CommandsManager(IIntegration client)
 {
     __client            = client;
     __commands          = new Dictionary <string, ICommand>();
     __modules           = new Dictionary <IModule, bool>();
     __internalUserRoles = new Dictionary <string, PermissionType>();
     Console.Write("");
 }
Exemple #9
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="visitSession"></param>
        /// <param name="typedef"></param>
        /// <param name="apiId">The id of the api object.</param>
        /// <returns></returns>
        public static TDoc FromType <T, TDoc>(T visitSession, IIntegration typedef, long apiId)
            where TDoc : IIntegratedDocument, new()
        {
            var document = new TDoc();

            document.Document      = new Lazy <BsonDocument>(() => visitSession.ToBsonDocument());
            document.IntegrationId = typedef.Id;
            document.APIId         = apiId;
            return(document);
        }
Exemple #10
0
        public static Task DeleteAsync(this IIntegration integration,
                                       IRestRequestOptions options = null, CancellationToken cancellationToken = default)
        {
            // Fix for integrations coming from user connections not having the guild ID.
            Guard.IsNotDefault(integration.GuildId);

            var client = integration.GetRestClient();

            return(client.DeleteIntegrationAsync(integration.GuildId, integration.Id, options, cancellationToken));
        }
Exemple #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="input">Details about the type</param>
        /// <param name="source">The source from which to pull the input</param>
        public IHarvester <TDocument> AddIntegration(IIntegration input, IInputSource source)
        {
            if (input == null)
            {
                throw new ArgumentException(nameof(input));
            }
            var newSet = new IntegrationSet(input, source);

            IntegrationSets.Add(newSet);
            return(this);
        }
Exemple #12
0
        //        /// <summary>
        //        ///
        //        /// </summary>
        //        /// <param name="name">The name of the integration</param>
        //        /// <param name="appId">AppId key</param>
        //        /// <param name="source">The input source</param>
        //        /// <returns></returns>
        //        public DataIntegration AddIntegrationSource(string name, string appId, InputSource source)
        //        {
        //
        //            DataIntegration type = Integration.DataIntegration.Factory.CreateNamed(appId, name);
        //            _integrationService.SaveOrFetchExisting(ref type);
        //            this.AddIntegration(type, source);
        //            return type;
        //        }

        /// <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="integration"></param>
        /// <returns></returns>
        public void AddIntegrationSource(IInputSource inputSource, IIntegration integration)
        {
            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.");
            }
            AddIntegration(integration, inputSource);
        }
Exemple #13
0
        private void SetupCommands(IntegrationType type, IIntegration integration)
        {
            if (!CommandManagers.ContainsKey(type))
            {
                CommandManagers[type] = new CommandsManager(integration);
            }

            //BaseOwnerModule owner = new BaseOwnerModule(this);
            //owner.Install(CommandManagers[type]);

            //FunModule fModule = new FunModule();
            //fModule.Install(CommandManagers[type]);
        }
        private IIntegration GetIntegration(string integrationDllFile)
        {
            Assembly integration = Assembly.LoadFile(integrationDllFile);
            Type     type        = integration.GetType("EntryPoint");
            object   o           = Activator.CreateInstance(type); //todo check this

            if (o != null)
            {
                IIntegration theIntegration = (o as IEntryPoint).CreateIntegration();
                return(theIntegration);
            }
            return(null);
        }
Exemple #15
0
        private void CacheIntegration(object key, IIntegration integration)
        {
            CacheInstance(key, integration);

            if (!integration.User.HasValue)
            {
                return;
            }

            var user    = integration.User.Value;
            var userKey = KeyHelpers.CreateUserCacheKey(user.ID);

            Cache(userKey, user);
        }
Exemple #16
0
        /// <summary>
        /// Belirtilen entegrasyon tipi ile belirli filtreler ve sıralama özellikleriyle kur listesini döndürür.
        /// </summary>
        /// <param name="integration">Entegrasyon yapılarak listenin döndürüleceği servis türünü belirtir.</param>
        /// <param name="currency">Elde edilmek istenilen kur bilgisini belirtir.</param>
        /// <param name="sortField">Sıralama yapılmak istenilen alanı belirtir.</param>
        /// <param name="sortDirection">Hangi yöne sıralama yapılacağını belirtir. Varsayılan Ascending 'tir.</param>
        /// <returns></returns>
        public BaseResponse <IEnumerable <CurrencyRate> > List(IIntegration integration, Currency?currency = null, SortField?sortField = null, SortDirection?sortDirection = SortDirection.Ascending)
        {
            var response = new BaseResponse <IEnumerable <CurrencyRate> >();
            var xmlDoc   = integration.Get();

            if (xmlDoc != null)
            {
                response.DataReceived = true;

                try
                {
                    if (_data == null)
                    {
                        _data = integration.Parse(xmlDoc);
                    }

                    response.Data = _data;

                    #region Filters, Sorters

                    if (currency != null)
                    {
                        response.Data = response.Data.Where(c => c.CurrencyCode == (Currency)currency);
                    }

                    if (sortField != null)
                    {
                        var sorting = $"{sortField} {sortDirection.ToString().ToLower()}";
                        response.Data = response.Data.AsQueryable().OrderBy(sorting);
                    }

                    #endregion

                    response.IsDone = true;
                }
                catch (Exception ex)
                {
                    response.IsDone       = false;
                    response.ErrorMessage = ex.Message;
                }
            }
            else
            {
                response.DataReceived = false;
                response.ErrorMessage = "Data çekme gerçekleştirilemedi!";
            }

            return(response);
        }
Exemple #17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="options"></param>
        public DataImportTask(DataImportTaskOptions options)
        {
            _options = options;
            string tmpGuid = Guid.NewGuid().ToString();

            _harvester = new Harvester <T>(_options.ThreadCount);
            if (options.Integration != null)
            {
                if (options.Integration.Fields.Count == 0)
                {
                    throw new InvalidOperationException("Integration needs to have at least 1 field.");
                }
                _integration        = options.Integration;
                _integration.APIKey = _options.ApiKey;
                if (string.IsNullOrEmpty(_integration.FeaturesCollection))
                {
                    _integration.FeaturesCollection = $"{_integration.Collection}_features";
                }
                if (string.IsNullOrEmpty(_integration.Collection))
                {
                    _integration.Collection = tmpGuid;
                }
                _harvester.AddIntegration(options.Integration, _options.Source);
            }
            else
            {
                _integration = _harvester.AddIntegrationSource(_options.Source, _options.ApiKey,
                                                               _options.IntegrationName, tmpGuid);
            }

            var outCollection = new DestinationCollection(_integration.Collection, _integration.GetReducedCollectionName());

            OutputDestinationCollection = outCollection;
            if (options.TotalEntryLimit > 0)
            {
                _harvester.LimitEntries(options.TotalEntryLimit);
            }
            if (options.ShardLimit > 0)
            {
                _harvester.LimitShards(options.ShardLimit);
            }
            this.EncodeOnImport = options.EncodeInput;
            if (this.EncodeOnImport)
            {
                _encoder = FieldEncoder.Factory.Create(_integration);
            }
            // new OneHotEncoding(new FieldEncodingOptions { Integration = _integration });
        }
Exemple #18
0
            private static IEnumerable <JObject> GetEncodedFieldSubfields(IIntegration cl, FieldDefinition fld)
            {
                var encoding      = FieldEncoding.Factory.Create(cl, fld.DataEncoding);
                var encodedFields = encoding.GetFieldNames(fld);

                foreach (var encField in encodedFields)
                {
                    var newField = new JObject
                    {
                        { "name" as string, encField },
                        { "encoding" as string, fld.DataEncoding.ToString().ToLower() },
                        { "id", fld.Id }
                    };
                    yield return(newField);
                }
            }
Exemple #19
0
        public override void ExecuteCommand(IIntegration integration, IChannel channel, IMember member)
        {
            CommandArgs e = new CommandArgs();

            e.FromIntegration = integration.IntegrationName;
            e.Args            = this.Args;
            e.Author          = member;
            e.Channel         = channel;

            if ((int)CommandsManager.GetPermissionFromID(member.ID) >= (int)MinimumPermission)
            {
                Do.Invoke(e);
            }
            else
            {
                throw new UnauthorizedAccessException($"You have no permission to execute this command! (Minimum needed: {(MinimumPermission.ToString().Substring(MinimumPermission.ToString().IndexOf('.') + 1))})");
            }
        }
Exemple #20
0
        public static IDonutBuilder Create <TData>(Type donutType,
                                                   Type donutContextType,
                                                   IIntegration integration, IRedisCacher cacher, IServiceProvider serviceProvider)
            where TData : class, IIntegratedDocument
        {
            var builderType = typeof(DonutBuilder <, ,>).MakeGenericType(new Type[] { donutType, donutContextType, typeof(TData) });
            //DataIntegration integration, RedisCacher cacher, IServiceProvider serviceProvider
            var builderCtor = builderType.GetConstructor(new Type[]
                                                         { typeof(Data.DataIntegration), typeof(IRedisCacher), typeof(IServiceProvider) });

            if (builderCtor == null)
            {
                throw new Exception("DonutBuilder<> has invalid ctor parameters.");
            }
            var builder = Activator.CreateInstance(builderType, integration, cacher, serviceProvider);

            return(builder as IDonutBuilder);
        }
Exemple #21
0
 public FieldEncoding(FieldEncodingOptions options, FieldDataEncoding encoding)
 {
     this.Encoding = encoding;
     _options      = options;
     _integration  = _options.Integration;
     //var collection = MongoHelper.GetCollection(_integration.Collection);
     _targetFields = _integration.Fields.Where(x => x.DataEncoding == encoding).ToList();
     _fieldDict    = new Dictionary <string, ConcurrentDictionary <string, FieldExtra> >();
     foreach (var fld in TargetFields)
     {
         if (fld.Extras == null)
         {
             var dict1 = new ConcurrentDictionary <string, FieldExtra>();
             _fieldDict.Add(fld.Name, dict1);
             continue;
         }
         var dict = new ConcurrentDictionary <string, FieldExtra>(fld.Extras.Extra.ToDictionary(x => x.Value));
         _fieldDict[fld.Name] = dict;
     }
 }
Exemple #22
0
        /// <summary>
        /// Caches a value. Certain instance types may have specializations which cache more than one value from the
        /// instance.
        /// </summary>
        /// <param name="key">The cache key.</param>
        /// <param name="instance">The instance.</param>
        /// <typeparam name="TInstance">The instance type.</typeparam>
        public void Cache <TInstance>(object key, TInstance instance)
            where TInstance : class
        {
            Action cacheAction = instance switch
            {
                IWebhook webhook => () => CacheWebhook(key, webhook),
                ITemplate template => () => CacheTemplate(key, template),
                IIntegration integration => () => CacheIntegration(key, integration),
                IBan ban => () => CacheBan(key, ban),
                IGuildMember member => () => CacheGuildMember(key, member),
                IGuildPreview preview => () => CacheGuildPreview(key, preview),
                IGuild guild => () => CacheGuild(key, guild),
                IEmoji emoji => () => CacheEmoji(key, emoji),
                IInvite invite => () => CacheInvite(key, invite),
                IMessage message => () => CacheMessage(key, message),
                IChannel channel => () => CacheChannel(key, channel),
                _ => () => CacheInstance(key, instance)
            };

            cacheAction();
        }
Exemple #23
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public DonutScript ParseDonutScript(IIntegration ign)
        {
            _sourceIntegrations.Clear();
            DonutScript newScript = new DonutScript();

            Reader.DiscardToken(TokenType.Define);
            var newSymbolName = Reader.DiscardToken(TokenType.Symbol);

            newScript.Type      = new ScriptTypeInfo(newSymbolName.Value);
            _sourceIntegrations = ReadFrom();
            var orderBy     = ReadOrderBy();
            var expressions = ReadExpressions();

            newScript.StartingOrderBy = orderBy;
            foreach (var expression in expressions)
            {
                var expressionType = expression.GetType();
                if (expressionType == typeof(AssignmentExpression))
                {
                    newScript.Features.Add(expression as AssignmentExpression);
                }
                else if (expressionType == typeof(TargetExpression))
                {
                    var targetExpr   = expression as TargetExpression;
                    var targetFields = targetExpr.Attributes.Select(a => ign.Fields.FirstOrDefault(f => f.Name == a));
                    newScript.Targets = new List <ModelTarget>();
                    foreach (var targetField in targetFields)
                    {
                        ((List <ModelTarget>)newScript.Targets).Add(new ModelTarget(targetField));
                    }
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            newScript.AddIntegrations(_sourceIntegrations.Select(i => new Donut.Data.DataIntegration(i)).ToArray());

            return(newScript);
        }
 /// <summary>
 ///
 /// </summary>
 private void InitializeDataSets()
 {
     foreach (var dataSetInfo in _setFinder.FindDataSets(_context).Where(p => p.Setter != null))
     {
         var newSet = ((ISetCollection)_context).GetOrAddDataSet(_setSource, dataSetInfo.ClrType);
         //newSet.Name = dataSetInfo.Name;
         if (dataSetInfo.Attributes.FirstOrDefault(x => x.GetType() == typeof(SourceFromIntegration)) is
             SourceFromIntegration integrationSource)
         {
             IIntegration integration = _integrationService.GetByName(_context.ApiAuth, integrationSource.IntegrationName);
             if (integration == null)
             {
                 throw new Exception(
                           $"Integration data source unavailable: {integrationSource.IntegrationName}");
             }
             newSet.SetSource(integration.Collection);
             //newSet.SetAggregateKeys(integration.GetAggregateKeys());
             //var integration =
             //newSet.SetSource(integrationSource.IntegrationName);
         }
         dataSetInfo.Setter.SetClrValue(_context, newSet);
     }
 }
Exemple #25
0
        public static IDonutBuilder Create <TData>(DonutScript script,
                                                   IIntegration integration, IServiceProvider serviceProvider)
            where TData : class, IIntegratedDocument
        {
            if (string.IsNullOrEmpty(script.AssemblyPath))
            {
                return(null);
            }
            if (!File.Exists(script.AssemblyPath))
            {
                throw new Exception("Donut assembly not found!");
            }
            var asm                = Assembly.LoadFrom(script.AssemblyPath);
            var donutTypes         = asm.GetTypes();
            var donutType          = donutTypes.FirstOrDefault(x => x.IsInstanceOfType(typeof(IDonutfile)));
            var donutContextType   = donutTypes.FirstOrDefault(x => x.IsInstanceOfType(typeof(IDonutContext)));
            var featureEmitterType = donutTypes.FirstOrDefault(x => x.IsInstanceOfType(typeof(IDonutFeatureEmitter)));
            var cacher             = serviceProvider.GetService(typeof(IRedisCacher)) as IRedisCacher;
            var builder            = Create <TData>(donutType, donutContextType, integration, cacher, serviceProvider);

            builder.SetEmitterType(featureEmitterType);
            return(builder);
        }
Exemple #26
0
            public static FieldEncoding Create(IIntegration integration, FieldDataEncoding fldDataEncoding)
            {
                //TODO: Replace this with attributes.
                var ops = new FieldEncodingOptions {
                    Integration = integration
                };

                if (fldDataEncoding == FieldDataEncoding.OneHot)
                {
                    return(new OneHotEncoding(ops));
                }
                else if (fldDataEncoding == FieldDataEncoding.BinaryIntId)
                {
                    return(new BinaryCategoryEncoding(ops));
                }
                else if (fldDataEncoding == FieldDataEncoding.Id)
                {
                    return(new IdEncoding(ops));
                }
                else
                {
                    throw new NotImplementedException($"Field encoding not implemented: {fldDataEncoding}");
                }
            }
Exemple #27
0
            public static FieldEncoder Create(IIntegration ign)
            {
                var encoder = new FieldEncoder(ign);

                return(encoder);
            }
Exemple #28
0
 public void OnIntegrationExecuted(IIntegration integration)
 {
     Console.SetCursorPosition(0, Console.CursorTop);
     Console.WriteLine("    " + integration.ActionMessage);
     PrintPrompt();
 }
 public IntegrationCreatedEventArgs(
     IIntegration integration)
 {
     Integration = integration;
 }
Exemple #30
0
 public DataImportResult(HarvesterResult data, IMongoCollection <BsonDocument> collection, IIntegration integration)
 {
     this.Collection  = collection;
     this.Data        = data;
     this.Integration = integration;
 }
Exemple #31
0
 public IntegrationSet(IIntegration inputDef, IInputSource source)
 {
     this.Definition = inputDef;
     this.Source     = source;
     //Definition.Save();
 }