public void Remove(string key)
        {
            string fn = GetFullPath(key);

            Logger.Debug("Removing cache file from  " + fn);
            var f1 = DeleteFile(fn);

            Logger.Debug("Removed cache file from " + fn);
        }
        public void Remove(string key)
        {
            Logger.Debug("Removing cache key " + key + " for type " + typeof(T).ToString());
            internalValue        = default(T);
            internalValueCreated = DateTime.MinValue;
            var f1 = DeleteFile(GetFullPath(key, true));
            var f2 = DeleteFile(GetFullPath(key, false));

            Logger.Debug("Removed cache key " + key + " for type " + typeof(T).ToString() + " with success: f1:" + f1.ToString() + " & f2: " + f2.ToString());
        }
        public void Init()
        {
            ESTraceLogger.Debug($"AWS_S3CacheProvider Init: Starting");
            if (client == null)
            {
                lock (_lockconnections)
                {
                    if (connections.ContainsKey(this.AWS_S3Servers.First()))
                    {
                        client = connections[this.AWS_S3Servers.First()];
                    }
                    else
                    {
                        client = new AmazonS3Client(
                            this.AccessKey,
                            this.SecretKey,
                            new AmazonS3Config()
                        {
                            AuthenticationRegion = Region,                // Should match the `MINIO_REGION` environment variable.
                            ServiceURL           = AWS_S3Servers.First(), // replace http://localhost:9000 with URL of your MinIO server
                            ForcePathStyle       = true                   // MUST be true to work correctly with MinIO server
                        }
                            );
                        connections.Add(this.AWS_S3Servers.First(), client);

                        var buckList = client.ListBucketsAsync().Result;
                        if (buckList?.Buckets?.Any(m => m.BucketName == this.Bucket) == false)
                        {
                            ESTraceLogger.Debug($"AWS_S3CacheProvider Init: Bucket {this.AWS_S3Servers.First()} / {this.Bucket} doesn't exist. Creating new one");
                            try
                            {
                                var res = client.PutBucketAsync(this.Bucket).Result;
                            }
                            catch (Exception e)
                            {
                                ESTraceLogger.Fatal($"AWS_S3CacheProvider: Created db error {e.Message}", e);
                                throw new ApplicationException($"Cannot created AWS_S3  {this.AWS_S3Servers.First()} / {this.Bucket}");
                            }
                        }
                    }
                    ESTraceLogger.Debug($"AWS_S3CacheProvider Init: Bucket {this.AWS_S3Servers.First()} / {this.Bucket} is live.");
                    cleaning.Elapsed += Cleaning_Elapsed;
                    cleaning.Start();
                }
            }
        }
예제 #4
0
        protected BaseCache(ICacheProvider <TResult> cacheProvider, TimeSpan expires, string cacheKey, System.Func <object, TResult> contentFunc, object parameters)
        {
            this.contentInfo.Function        = contentFunc;
            this.contentInfo.Parameters      = parameters;
            this.contentInfo.Created         = DateTime.UtcNow;
            this.contentInfo.ExpiresInterval = expires;

            if (string.IsNullOrEmpty(cacheKey))
            {
                cacheKey = Guid.NewGuid().ToString();
            }
            this.cacheKey = cacheKey;

            this.provider = cacheProvider;
            Logger.Debug("initiating type:" + typeof(TResult).ToString() + " key:" + cacheKey);
            this.provider.Init();
        }
예제 #5
0
        public void Upgrade()
        {
            IDictionary <Version, MemberInfo> upgradingMethods = HelperStuff.GetAvailableDatabaseUpgradeMethods(this._member);
            IList <MemberInfo> beforeUpgradeMethods            = HelperStuff.GetBeforeUpgradeMethods(this._member);
            IList <MemberInfo> afterUpgradeMethods             = HelperStuff.GetAfterUpgradeMethods(this._member);

            logger.Debug("Starting transaction.");
            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew))
            {
                Version versionOfDatabase = GetVersionOfDatabase();
                logger.Debug("Current version of database is {versionOfDatabase}.", versionOfDatabase);

                Version versionOfLibrary = HelperStuff.GetVersionOfLibrary(this._member);
                logger.Debug("Current version of library is {versionOfLibrary}.", versionOfLibrary);

                var methodsForProcessing = upgradingMethods
                                           .Where(m => m.Key > versionOfDatabase && m.Key <= versionOfLibrary)
                                           .OrderBy(m => m.Key);

                foreach (var item in beforeUpgradeMethods)
                {
                    logger.Debug("Running Before Upgrade method with Name: {beforeUpgradeMethods}.", item.Name);
                    HelperStuff.ExecuteDatabaseUpgraderReflectionMethodWithParameters(item, this);
                }

                foreach (var item in methodsForProcessing)
                {
                    logger.Debug("Running Upgrade method {methodName} {methodVersion}", item.Value.Name, item.Key.ToString(4));
                    HelperStuff.ExecuteDatabaseUpgraderReflectionMethodWithParameters(item.Value, this);
                }

                foreach (var item in afterUpgradeMethods)
                {
                    logger.Debug("Running Upgrade method {afterUpgradeMethods} ", item.Name);
                    HelperStuff.ExecuteDatabaseUpgraderReflectionMethodWithParameters(item, this);
                }

                // if there was some update, set version
                if (methodsForProcessing.Count() > 0)
                {
                    // should I place here upgrade method version or library version???
                    // for now I'm using method version, 'cause it can be added new method for version and not incrementing library version (which is weird, but ...)
                    Version upgradedToVersion = methodsForProcessing.Last().Key;
                    logger.Info("Writing new database version {upgradedToVersion}.", upgradedToVersion.ToString(4));
                    SetVersionOfDatabase(upgradedToVersion);
                }

                logger.Debug("Commiting transaction.");
                ts.Complete();

                if (this._connection.State != ConnectionState.Closed)
                {
                    this._connection.Close();
                }
            }
        }
예제 #6
0
 private void logger_Debug(string msg, Exception ex = null)
 {
     try
     {
         if (!this.DontLogAnything)
         {
             WebLogger.Debug(msg, ex);
         }
     }
     catch
     {
     }
 }
예제 #7
0
        public void Init()
        {
            ESTraceLogger.Debug($"ElasticCacheProvider Init: Starting");
            if (client == null)
            {
                var pool = new Elasticsearch.Net.StaticConnectionPool(
                    this.ElasticServers
                    .Where(m => !string.IsNullOrWhiteSpace(m))
                    .Select(u => new Uri(u))
                    );
                var settings = new ConnectionSettings(pool)
                               .DefaultIndex(this.DBName)
                               .DisableAutomaticProxyDetection(false)
                               .RequestTimeout(TimeSpan.FromMilliseconds(60000))
                               .SniffLifeSpan(null)
                               .OnRequestCompleted(call =>
                {
                    // log out the request and the request body, if one exists for the type of request
                    if (call.RequestBodyInBytes != null)
                    {
                        ESTraceLogger.Debug($"{call.HttpMethod}\t{call.Uri}\t" +
                                            $"{Encoding.UTF8.GetString(call.RequestBodyInBytes)}");
                    }
                    else
                    {
                        ESTraceLogger.Debug($"{call.HttpMethod}\t{call.Uri}\t");
                    }
                })
                ;
                if (System.Diagnostics.Debugger.IsAttached || Devmasters.Config.GetWebConfigValue("ESDebugDataEnabled") == "true")
                {
                    settings = settings.DisableDirectStreaming();
                }

                client = new ElasticClient(settings);
                IndexSettings set = new IndexSettings();
                set.NumberOfReplicas = this.NumberOfReplicas;
                set.NumberOfShards   = this.NumberOfShards;
                IndexState idxSt = new IndexState();
                idxSt.Settings = set;

                ESTraceLogger.Debug($"ElasticCacheProvider Init: Check Elastic DB {client.ConnectionSettings.DefaultIndex}");
                var resExists = client.Indices.Exists(client.ConnectionSettings.DefaultIndex);
                //if (resExists.IsValid == false)
                //{
                //    ESTraceLogger.Fatal($"ElasticCacheProvider: Cannot check db existance {resExists.ServerError?.ToString()}", resExists.OriginalException);
                //    throw new ApplicationException("Cannot check Elastic DB");
                //}
                if (resExists.Exists == false)
                {
                    ESTraceLogger.Debug($"ElasticCacheProvider Init: DB {client.ConnectionSettings.DefaultIndex} doesn't exist. Creating new one");

                    var res = client.Indices.Create(client.ConnectionSettings.DefaultIndex,
                                                    i => i.InitializeUsing(idxSt)
                                                    .Map <Bag <T> >(map => map.AutoMap().DateDetection(false))
                                                    );
                    if (res.IsValid == false)
                    {
                        ESTraceLogger.Fatal($"ElasticCacheProvider: Created db error {res.ServerError?.ToString()}", res.OriginalException);
                        throw new ApplicationException("Cannot created Elastic DB");
                    }
                }
                ESTraceLogger.Debug($"ElasticCacheProvider Init: DB {client.ConnectionSettings.DefaultIndex} is live.");
                cleaning.Elapsed += Cleaning_Elapsed;
                cleaning.Start();
            }
        }