コード例 #1
0
        public static void UserRole_DefaultImplementation_ReturnsDefaultImplementation(IContainerAdapter container)
        {
            var mapper = new ContextMapper <Role>(container, new RoleProvider(Role.User));

            mapper.RegisterDefault <IService, DefaultImplementation>();

            var service = container.GetInstance(typeof(IService));

            Assert.IsInstanceOfType(service, typeof(DefaultImplementation));
        }
コード例 #2
0
ファイル: GpfmConverter.cs プロジェクト: jgera/WrapRec
        private string GetContextVector(Feedback f)
        {
            var ctx = ContextNames.Select(c => ContextMapper.ToInternalID(f.Attributes[c].Value).ToString()).ToList();

            if (ctx.Count > 0)
            {
                return(ctx.Aggregate((a, b) => a + "," + b));
            }
            else
            {
                return("1");
            }
        }
コード例 #3
0
        /// <summary>
        /// Saves the timestamp, process name and window title into the database.
        ///
        /// In case the user doesn't want the window title to be stored (For privacy reasons),
        /// it is obfuscated.
        /// </summary>
        /// <param name="window"></param>
        /// <param name="process"></param>
        internal static void InsertSnapshot(string window, string process)
        {
            if (Shared.Settings.AnonymizeSensitiveData)
            {
                var dto = new ContextDto {
                    Context = new ContextInfos {
                        ProgramInUse = process, WindowTitle = window
                    }
                };
                window = Dict.Anonymized + " " + ContextMapper.GetContextCategory(dto);  // obfuscate window title
            }

            Database.GetInstance().ExecuteDefaultQuery("INSERT INTO " + Settings.DbTable + " (time, window, process) VALUES (strftime('%Y-%m-%d %H:%M:%f', 'now', 'localtime'), " +
                                                       Database.GetInstance().Q(window) + ", " + Database.GetInstance().Q(process) + ")");
        }
コード例 #4
0
        /// <summary>
        /// Constructor of Monitor class
        /// </summary>
        /// <param name="context">Specify a context to have different contexts in different domains</param>
        /// <param name="name">Name of the new Monitor</param>
        public Monitor(Context.Monitor context, string name) : base(context)
        {
            ContextMapper = ctx => ctx ?? _defaultContext;

            if (!ContextMapper.Invoke(context).ObjectDictionary.TryGetValue(name, out _currentObject))
            {
                lock (ContextMapper.Invoke(context).LockerObject)
                {
                    if (!ContextMapper.Invoke(context).ObjectDictionary.TryGetValue(name, out _currentObject))
                    {
                        _currentObject = new object();
                        ContextMapper.Invoke(context).ObjectDictionary.TryAdd(name, _currentObject);
                    }
                }
            }
        }
コード例 #5
0
ファイル: Semaphore.cs プロジェクト: saeedmaghdam/DynaLock
        /// <summary>
        /// Constructor of Semaphore class
        /// </summary>
        /// <param name="context">Specify a context to have different contexts in different domains</param>
        /// <param name="name">Name of the new Semaphore</param>
        /// <param name="initialCount">The initial number of requests for the semaphore that can be granted concurrently.</param>
        /// <param name="maximumCount">The maximum number of requests for the semaphore that can be granted concurrently.</param>
        public Semaphore(Context.Semaphore context, string name, int initialCount, int maximumCount) : base(context)
        {
            ContextMapper = ctx => ctx ?? _defaultContext;

            if (!ContextMapper.Invoke(context).ObjectDictionary.TryGetValue(name, out var tempSemaphore))
            {
                lock (ContextMapper.Invoke(context).LockerObject)
                {
                    if (!ContextMapper.Invoke(context).ObjectDictionary.TryGetValue(name, out tempSemaphore))
                    {
                        _currentObject = new System.Threading.Semaphore(initialCount, maximumCount, name);
                        ContextMapper.Invoke(context).ObjectDictionary.TryAdd(name, _currentObject);
                    }
                }
            }

            if (tempSemaphore != null)
            {
                _currentObject = (System.Threading.Semaphore)tempSemaphore;
            }
        }
コード例 #6
0
        /// <summary>
        /// Constructor of AutoResetEvent class
        /// </summary>
        /// <param name="context">Specify a context to have different contexts in different domains</param>
        /// <param name="name">Name of the new AutoResetEvent</param>
        public AutoResetEvent(Context.AutoResetEvent context, string name) : base(context)
        {
            ContextMapper = ctx => ctx ?? _defaultContext;

            if (!ContextMapper.Invoke(context).ObjectDictionary.TryGetValue(name, out var tempSemaphore))
            {
                lock (ContextMapper.Invoke(context).LockerObject)
                {
                    if (!ContextMapper.Invoke(context).ObjectDictionary.TryGetValue(name, out tempSemaphore))
                    {
                        _currentObject = new System.Threading.AutoResetEvent(true);
                        ContextMapper.Invoke(context).ObjectDictionary.TryAdd(name, _currentObject);
                    }
                }
            }

            if (tempSemaphore != null)
            {
                _currentObject = (System.Threading.AutoResetEvent)tempSemaphore;
            }
        }
コード例 #7
0
ファイル: GpfmConverter.cs プロジェクト: jgera/WrapRec
        public override void Run()
        {
            var trainPointWriter = new StreamWriter(OutputPath + ".point");
            var trainPairWriter  = new StreamWriter(OutputPath + ".pair");
            var testWriter       = new StreamWriter(OutputPath + ".test");
            var testOrgWriter    = new StreamWriter(OutputPath + ".test.org");

            foreach (var f in Split.Train)
            {
                var mUserId    = UserMapper.ToInternalID(f.User.Id);
                var mItemId    = ContextMapper.ToInternalID(f.Item.Id);
                var nNegItemId = ContextMapper.ToInternalID(SampleItemId(f.User.Id));
                //var context = GetContextVector(f);

                trainPointWriter.WriteLine($"{mUserId},{mItemId},1");
                trainPointWriter.WriteLine($"{mUserId},{nNegItemId},-1");
                trainPairWriter.WriteLine($"{mUserId},{mItemId},{nNegItemId},1");
                trainPairWriter.WriteLine($"{mUserId},{nNegItemId},{mItemId},-1");
                //testWriter.WriteLine($"{mUserId},{mItemId},1");
                //testOrgWriter.WriteLine($"{f.User.Id},{f.Item.Id},1");
            }

            foreach (var f in Split.Test)
            {
                var mUserId = UserMapper.ToInternalID(f.User.Id);
                var mItemId = ContextMapper.ToInternalID(f.Item.Id);
                //var context = GetContextVector(f);

                testWriter.WriteLine($"{mUserId},{mItemId},1");
                testOrgWriter.WriteLine($"{f.User.Id},{f.Item.Id},1");
            }

            var c = Split.Container;

            foreach (var user in c.Users.Values)
            {
                int count = 0;
                foreach (var item in c.Items.Values.Shuffle().Take(100))
                {
                    if (!c.FeedbacksDic.ContainsKey(user.Id, item.Id))
                    {
                        var mappedUId    = UserMapper.ToInternalID(user.Id);
                        var mappedNegIId = ContextMapper.ToInternalID(item.Id);

                        testWriter.WriteLine($"{mappedUId},{mappedNegIId},-1");
                        testOrgWriter.WriteLine($"{user.Id},{item.Id},-1");
                        count++;

                        if (count == 1000)
                        {
                            break;
                        }
                    }
                }
            }

            trainPointWriter.Close();
            trainPairWriter.Close();
            testWriter.Close();
            testOrgWriter.Close();
        }
コード例 #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FluentContextMappingRegistrar{TContext}"/> class.
 /// </summary>
 /// <param name="mappings">The mappings.</param>
 /// <param name="contexts">The contexts.</param>
 public FluentContextMappingRegistrar(ContextMapper <TContext> mappings, params TContext[] contexts)
 {
     this.mappings = mappings;
     this.contexts = contexts;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MappedDependencyContextInstanceProvider{TContext}" /> class.
 /// </summary>
 /// <param name="user">The user.</param>
 /// <param name="mappings">The mappings.</param>
 /// <param name="container">The container.</param>
 public MappedDependencyContextInstanceProvider(IContextProvider <TContext> user, ContextMapper <TContext> mappings, IContainerAdapter container)
 {
     this.user      = user;
     this.mappings  = mappings;
     this.container = container;
 }