Example #1
0
    private Dictionary <string, object> GetFilter()
    {
        var filter = Populator.GetFilter();

        if (!string.IsNullOrEmpty(txtOrderNo.Text))
        {
            filter.Add("OrderCode", txtOrderNo.Text);
        }
        if (!string.IsNullOrEmpty(txtActivityNo.Text))
        {
            filter.Add("ActivityCode", txtActivityNo.Text);
        }
        if (!string.IsNullOrEmpty(txtName.Text))
        {
            filter.Add("Name LIKE '%" + txtName.Text + "%' AND 1", 1);
        }
        if (!string.IsNullOrEmpty(txtCustomerName.Text))
        {
            filter.Add("CustomerName LIKE '%" + txtCustomerName.Text + "%' AND 1", 1);
        }
        if (ddlType.SelectedIndex > 0)
        {
            filter.Add("ActivityTypeID", ddlType.SelectedValue);
        }
        if (ddlStatus.SelectedIndex > 0)
        {
            filter.Add("ActivityStatusID", ddlStatus.SelectedValue);
        }

        return(filter);
    }
Example #2
0
    private Dictionary <string, object> GetFilter()
    {
        var filter = Populator.GetFilter();

        if (!string.IsNullOrEmpty(txtContactCode.Text))
        {
            filter.Add("ContactCode", txtContactCode.Text);
        }
        if (!string.IsNullOrEmpty(txtName.Text))
        {
            filter.Add("Name LIKE '%" + txtName.Text + "%' AND 1", 1);
        }
        if (!string.IsNullOrEmpty(txtSurname.Text))
        {
            filter.Add("Surname LIKE '%" + txtSurname.Text + "%' AND 1", 1);
        }
        if (!string.IsNullOrEmpty(txtTitle.Text))
        {
            filter.Add("Title LIKE '%" + txtTitle.Text + "%' AND 1", 1);
        }
        if (!string.IsNullOrEmpty(txtCompany.Text))
        {
            filter.Add("CustomerName LIKE '%" + txtCompany.Text + "%' AND 1", 1);
        }
        if (!string.IsNullOrEmpty(txtEmail.Text))
        {
            filter.Add("Email", txtEmail.Text);
        }
        if (!string.IsNullOrEmpty(txtGSM.Text))
        {
            filter.Add("GSM", txtGSM.Text);
        }

        return(filter);
    }
Example #3
0
    private Dictionary <string, object> GetFilter()
    {
        var filter = Populator.GetFilter();

        if (!string.IsNullOrEmpty(txtOrderNo.Text))
        {
            filter.Add("OrderCode", txtOrderNo.Text);
        }
        if (!string.IsNullOrEmpty(txtContactName.Text))
        {
            filter.Add("ContactName LIKE '%" + txtContactName.Text + "%' AND 1", 1);
        }
        if (!string.IsNullOrEmpty(txtCustomerName.Text))
        {
            filter.Add("CustomerName LIKE '%" + txtCustomerName.Text + "%' AND 1", 1);
        }
        if (ddlType.SelectedIndex > 0)
        {
            filter.Add("OrderTypeID", ddlType.SelectedValue);
        }
        if (ddlStatus.SelectedIndex > 0)
        {
            filter.Add("OrderStatusID", ddlStatus.SelectedValue);
        }
        if (dt1.HasDate)
        {
            filter.Add("OrderDate>", dt1.SelectedDate.ToDBDate());
        }
        if (dt2.HasDate)
        {
            filter.Add("OrderDate<", dt2.SelectedDate.ToDBDate());
        }

        return(filter);
    }
Example #4
0
 /// <inheritdoc />
 protected override object InternalPopulate(string key, Populator populator)
 {
     return(innerCache.Populate(partitionPrefix + key, delegate(string prefixedKey, out CacheOptions options)
     {
         return populator(key, out options);
     }));
 }
Example #5
0
        private object PopulateWithSentinel(string key, Populator populator, Sentinel sentinel)
        {
            CacheOptions options;
            object       populatedValue = populator(key, out options);

            lock (items)
            {
                CacheItem item;
                if (items.TryGetValue(key, out item) && item.Value == sentinel)
                {
                    if (populatedValue != null)
                    {
                        DateTime expirationTime = options.GetUtcExpirationTimeRelativeToNow();

                        items[key] = new CacheItem(populatedValue, expirationTime);
                        if (expirationTime < nextExpirationTime)
                        {
                            nextExpirationTime = expirationTime;
                        }
                    }
                    else
                    {
                        items.Remove(key);
                    }
                }

                Monitor.PulseAll(items);
            }

            return(populatedValue);
        }
Example #6
0
    private void InitData()
    {
        var Filters = Populator.GetFilter();

        Filters.Add("TypeCode", "GenderTypeID");
        var arrType = ParamsManager.GetParamssByFilter(Filters);

        ddlGender.BindData(arrType, "TypeName", "ObjectValue");

        Filters.Clear();
        var arrCustomers = CustomerManager.GetAllCustomers();

        ddlCustomerID.BindData(arrCustomers, "Name", "CustomerID");

        if (ContactID > 0)
        {
            Contact oContact = ContactManager.GetContactByID(ContactID);
            if (oContact != null)
            {
                //this.txtContactCode.Text = oContact.ContactCode;
                //this.ddlMemberID.Select(oContact.MemberID);
                this.txtName.Text    = oContact.Name;
                this.txtSurname.Text = oContact.Surname;
                this.txtTitle.Text   = oContact.Title;
                this.txtPhone.Text   = oContact.Phone;
                this.txtGSM.Text     = oContact.GSM;
                this.ddlCustomerID.Select(oContact.CustomerID);
                //this.ddlAddressID.Select(oContact.AddressID);
                this.ddlGender.Select(oContact.Gender);
                this.txtEmail.Text       = oContact.Email;
                this.txtDescription.Text = oContact.Description;
            }
        }
    }
Example #7
0
        /// <inheritdoc />
        protected override object InternalGetOrPopulate(string key, Populator populator)
        {
            Sentinel sentinel = null;

            try
            {
                lock (items)
                {
                    object existingValue = GetOrWaitUntilPopulatedInsideLock(key);
                    if (existingValue != null)
                    {
                        return(existingValue);
                    }

                    sentinel   = new Sentinel();
                    items[key] = new CacheItem(sentinel, DateTime.MaxValue);
                }

                return(PopulateWithSentinel(key, populator, sentinel));
            }
            catch (Exception)
            {
                if (sentinel != null)
                {
                    RemoveSentinel(key, sentinel);
                }
                throw;
            }
        }
Example #8
0
        public void SendPersonalMessageTest()
        {
            string username  = "******";
            var    populator = new Populator();
            var    career    = populator.GetCareer(username);

            repMock.Setup(m => m.GetAll())
            .Returns(new List <Career>()
            {
                career
            }.AsQueryable());

            var message = new PersonalMessageVM()
            {
                username = username,
                Name     = "sender",
                Email    = "*****@*****.**",
                Message  = "very cool test"
            };

            worker.SavePersonalMessage(message);

            Assert.AreEqual(1, career.VisitorMessages.Count);

            var savedMessage = career.VisitorMessages.First();

            Assert.AreEqual(message.Name, savedMessage.SenderName);
            Assert.AreEqual(message.Email, savedMessage.SenderEmailAddress);
            Assert.AreEqual(message.Message, savedMessage.Message);
        }
Example #9
0
        public void Populate_ForwardsToInnerCache()
        {
            CacheOptions options = CacheOptions.AbsoluteExpiration(DateTime.UtcNow);

            Populator populator = delegate(string key, out CacheOptions populatedOptions)
            {
                populatedOptions = options;
                Assert.AreEqual("key", key);
                return("value");
            };

            Expect.Call(mockInnerCache.Populate("partition:key", null))
            .Constraints(Is.Equal("partition:key"), Is.NotSame(populator))
            .Do((PopulateDelegate) delegate(string actualKey, Populator actualPopulator)
            {
                CacheOptions populatedOptions;
                object populatedValue = actualPopulator(actualKey, out populatedOptions);
                Assert.AreEqual("value", populatedValue);
                Assert.AreEqual(options, populatedOptions);
                return("value");
            });
            Mocks.ReplayAll();

            Assert.AreEqual("value", Cache.Populate("key", populator));
        }
Example #10
0
        public void PopulatorReturnNonZeroClasses()
        {
            Populator populator = new Populator();

            List <Type> types = populator.GetTypes();

            Assert.IsNotEmpty(types);
        }
Example #11
0
    private Dictionary <string, object> GetFilter()
    {
        var filter = Populator.GetFilter();

        //if (dt1.HasDate) filter.Add("CreateDate>", dt1.SelectedDate.ToDBDate());
        //if (dt2.HasDate) filter.Add("CreateDate<", dt2.SelectedDate.ToDBDate());

        return(filter);
    }
        public IList <DropDownEntry <string> > GetItems(Func <string, string> translator = null)
        {
            var entries = Populator.Invoke();

            return((from DropDownEntry <string> entry in entries
                    let code = entry.Code
                               let description = entry.Description
                                                 let translatedDesctiption = translator == null ? description : translator.Invoke(description)
                                                                             select new DropDownEntry <string>(code, translatedDesctiption)).ToArray());
        }
Example #13
0
    private Dictionary<string, object> GetFilter()
    {
        var filter = Populator.GetFilter();
        if (!string.IsNullOrEmpty(txtProductCode.Text)) filter.Add("ProductCode", txtProductCode.Text);
        if (!string.IsNullOrEmpty(txtReferenceNo.Text)) filter.Add("ReferenceNo", txtReferenceNo.Text);
        if (!string.IsNullOrEmpty(txtName.Text)) filter.Add("ProductName LIKE '%" + txtName.Text + "%' AND 1", 1);
        if (!string.IsNullOrEmpty(txtGroup.Text)) filter.Add("ProductGroup LIKE '%" + txtGroup.Text + "%' AND 1", 1); ;

        return filter;
    }
Example #14
0
        public static void Run(HospitalContext db, IUIManager uiManager)
        {
            string options = "Options:" + Environment.NewLine +
                             "Sign In: email password name speciality" + Environment.NewLine +
                             "Log In: email password" + Environment.NewLine +
                             "Exit";
            Doctor doctor = null;

            while (true)
            {
                uiManager.WriteLine(options);
                string[] commandParts = uiManager.ReadLine().Split(' ');

                switch (commandParts[0])
                {
                case "Sign":
                    string email      = commandParts[2];
                    string password   = commandParts[3];
                    string name       = commandParts[4];
                    string speciality = commandParts[5];

                    doctor = Populator.AddDoctor(db, name, speciality, email, password);

                    if (doctor == null)
                    {
                        uiManager.WriteLine("Failed to sign!!");
                    }
                    else
                    {
                        uiManager.WriteLine("Successfully signed!!");
                    }
                    break;

                case "Log":
                    email    = commandParts[2];
                    password = commandParts[3];

                    doctor = Authorization.LogIn(db, email, password);
                    if (doctor == null)
                    {
                        uiManager.WriteLine("Failed to loggin!!");
                    }
                    else
                    {
                        uiManager.WriteLine("Successfully logged!!");
                    }
                    break;

                case "Exit": return;
                }

                uiManager.ReadLine();
                uiManager.Clean();
            }
        }
Example #15
0
        /// <inheritdoc />
        protected override object InternalGetOrPopulate(string key, Populator populator)
        {
            object value = InternalGet(key);

            if (value != null)
            {
                return(value);
            }

            return(InternalPopulate(key, populator));
        }
Example #16
0
        /// <inheritdoc />
        public object Populate(string key, Populator populator)
        {
            if (key == null)
                throw new ArgumentNullException("key");
            if (key.Length == 0)
                throw new ArgumentException("Key must not be empty.", "keys");
            if (populator == null)
                throw new ArgumentNullException("populator");

            return InternalPopulate(key, populator);
        }
Example #17
0
 public void TestDeclareTypeOfByParameter()
 {
     using (var wrapper = new TestReaderWrapper<NullableDateTimeType>("SELECT NULL"))
     {
         var populator = new Populator<EmptyPocoTest0, SqlDataReader>(wrapper.Reader);
         var cb = new CodeBaseBody<EmptyPocoTest0, SqlDataReader>(populator);
         cb.DeclareTypeOf(typeof (int));
         Assert.IsTrue(cb.OpCodes.Count == 0);
         Assert.IsTrue(cb.TypesToLocalOffset.ContainsKey(typeof (int)));
     }
 }
Example #18
0
    private void InitForm()
    {
        var Filters = Populator.GetFilter();

        Filters.Add("TypeCode", "MemberTypeID");
        var arrType = ParamsManager.GetParamssByFilter(Filters);

        ddlType.BindData(arrType, "TypeName", "ObjectValue");
        ddlType.InsertChooseItem();
        grdData.Visible = false;
    }
        public void Execute(IServiceProvider serviceProvider)
        {
            //Extract the tracing service for use in debugging sandboxed plug-ins.
            ITracingService tracingService =
                (ITracingService)serviceProvider.GetService(typeof(ITracingService));

            // Obtain the execution context from the service provider.
            IPluginExecutionContext context = (IPluginExecutionContext)
                                              serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            var service = serviceFactory.CreateOrganizationService(context.UserId);
            OrganizationServiceContext ctx = new OrganizationServiceContext(service);
            FaultException             ex1 = new FaultException();

            //throw new InvalidPluginExecutionException("asdfsd", ex1);


            // The InputParameters collection contains all the data passed in the message request.
            if (context.InputParameters.Contains("Target") &&
                context.InputParameters["Target"] is EntityReference)
            {
                // Obtain the target entity from the input parameters.
                EntityReference entityRef  = (EntityReference)context.InputParameters["Target"];
                Entity          preEntity  = (Entity)context.PreEntityImages["names"];
                var             entityName = preEntity.GetAttributeValue <string>("fp_name");

                if (entityRef.LogicalName != "fp_fieldnamepopulator")
                {
                    return;
                }

                try
                {
                    var populator = new Populator(service, entityName);

                    if (!populator.destroyPluginSteps())
                    {
                        throw new InvalidPluginExecutionException("Something went wrong", ex1);
                    }
                }

                catch (FaultException <OrganizationServiceFault> ex)
                {
                    throw new InvalidPluginExecutionException("An error occurred in the Field Name Populator plug-in.", ex);
                }

                catch (Exception ex)
                {
                    tracingService.Trace("Field Name Populator Plugin: {0}", ex.ToString());
                    throw;
                }
            }
        }
Example #20
0
        public void CheckIfItsPopulated()      // Populates Database if it hasnt been poped yet
        {                                      //               (P. 04-04-2015)
            enetConnection.Open();
            List <Employee> employeeList = DataAccess.GetAllEmployees(enetConnection);

            enetConnection.Close();
            if (employeeList.Count() < 8)         // if there curr are less than 8 employees
            {
                Populator myPopulator = new Populator();
                myPopulator.Run(enetConnection);
                Debug.WriteLine(" Sample Items were added to Database");
            }
        }
Example #21
0
        public RentALimoContext() : base(ConnectionString)
        {
            if (!Database.Exists())
            {
                Database.Create();

                var pop = new Populator(new PopuleerRepo());
                pop.Populeer();
            }
            Database.Log = s => Debug.WriteLine(s);
            Configuration.LazyLoadingEnabled   = false;
            Configuration.ProxyCreationEnabled = false;
        }
Example #22
0
        public void Populate_ConcurrentPopulateIsCalledEveryTimeAndSeesOwnValues(bool useGetOrPopulate,
                                                                                 int numberOfConsumers)
        {
            ManualResetEvent sem      = new ManualResetEvent(false);
            int       populationCount = 0;
            Populator populator       = delegate(string key, out CacheOptions options)
            {
                if (populationCount == 0)
                {
                    sem.Set();
                    Thread.Sleep(200);
                }

                populationCount += 1;
                Assert.AreEqual("key", key);
                options = CacheOptions.NoExpiration;
                return("value" + Thread.CurrentThread.ManagedThreadId);
            };

            // Prepare a bunch of threads to concurrently populate the same key.
            // They should all see their own populated values when released
            // regardless of what the others are doing.
            Procedure proc = delegate
            {
                sem.WaitOne();
                Assert.AreEqual("value" + Thread.CurrentThread.ManagedThreadId,
                                Cache.Populate("key", populator));
            };

            IAsyncResult[] consumers = new IAsyncResult[numberOfConsumers];
            for (int i = 0; i < numberOfConsumers; i++)
            {
                consumers[i] = proc.BeginInvoke(null, this);
            }

            // Now actually go populate it.
            Assert.AreEqual("value" + Thread.CurrentThread.ManagedThreadId,
                            useGetOrPopulate ? Cache.GetOrPopulate("key", populator) :
                            Cache.Populate("key", populator));

            // Wait for the consumers to finish and ensure they did not fail.
            foreach (IAsyncResult consumer in consumers)
            {
                proc.EndInvoke(consumer);
            }

            // Ensure population happened the expected number of times.
            Assert.AreEqual(1 + numberOfConsumers, populationCount);
        }
Example #23
0
        /// <inheritdoc />
        protected override object InternalPopulate(string key, Populator populator)
        {
            CacheOptions options;
            object       value = populator(key, out options);

            if (value != null)
            {
                InternalSet(key, value, options);
            }
            else
            {
                InternalRemove(key);
            }

            return(value);
        }
Example #24
0
        public void TestInitializeValueTypeOfByParameter()
        {
            using (var wrapper = new TestReaderWrapper<NullableDateTimeType>("SELECT NULL"))
            {
                var populator = new Populator<EmptyPocoTest0, SqlDataReader>(wrapper.Reader);
                var cb = new CodeBaseBody<EmptyPocoTest0, SqlDataReader>(populator);

                cb.InitializeValueTypeOf(typeof (int));
                Assert.AreEqual(1, cb.TypesToLocalOffset.Count);
                Assert.IsTrue(cb.TypesToLocalOffset.ContainsKey(typeof (int)));
                Assert.AreEqual(2, cb.OpCodes.Count);
                // TODO: Not a fan of binding to the opcode generation here.
                Assert.AreEqual(OpCodes.Initobj, cb.OpCodes.First().OpCode);
                Assert.AreEqual(OpCodes.Ldloca_S, cb.OpCodes.Last().OpCode);
            }
        }
Example #25
0
        private object PopulateWithSentinel(string key, Populator populator, Sentinel sentinel)
        {
            CacheOptions options;
            object       value = populator(key, out options);

            if (value != null)
            {
                sentinel.FinishedWithValue(value);
                ReplaceSentinel(key, value, options, sentinel);
            }
            else
            {
                RemoveSentinel(key, sentinel);
            }

            return(value);
        }
Example #26
0
        public void TestCall01()
        {
            using (var wrapper = new TestReaderWrapper<NullableDateTimeType>("SELECT NULL"))
            {
                var populator = new Populator<EmptyPocoTest0, SqlDataReader>(wrapper.Reader);
                var cb = new CodeBaseBody<EmptyPocoTest0, SqlDataReader>(populator);

                var method = typeof (int).GetMethod("ToString", BindingFlags.Public | BindingFlags.Instance, null,
                                                    Type.EmptyTypes, null);
                Assert.IsNotNull(method);
                var mb = cb.Call(method);
                Assert.IsNotNull(mb);
                Assert.AreEqual(1, cb.TypesToArguments.Count, "Argument count mismatch.");
                Assert.AreEqual(0, cb.TypesToLocalOffset.Count, "Local count mismatch.");
                Assert.AreEqual(mb.MethodInfo, method, "Method mutation.");
            }
        }
Example #27
0
        /// <inheritdoc />
        protected override object InternalGetOrPopulate(string key, Populator populator)
        {
            // Check if value has already been populated.
            object value = GetOrWaitUntilPopulated(key);

            if (value != null)
            {
                return(value);
            }

            Sentinel sentinel = new Sentinel();

            try
            {
                // Add a sentinel into the cache unless some other thread has managed
                // to squeeze in here first.
                value = innerCache.Add(key, sentinel, null, ASPNetCache.NoAbsoluteExpiration, ASPNetCache.NoSlidingExpiration,
                                       CacheItemPriority.NotRemovable, null);

                if (value == null)
                {
                    // The sentinel was added.
                    return(PopulateWithSentinel(key, populator, sentinel));
                }
                else
                {
                    // The sentinel was not added.
                    // That means some other thread has set the value or begun population
                    // in the meantime so we have to handle each case.
                    sentinel = value as Sentinel;
                    if (sentinel != null)
                    {
                        value = sentinel.WaitUntilFinished();
                    }

                    return(value);
                }
            }
            catch (Exception ex)
            {
                sentinel.FinishedWithException(ex);
                RemoveSentinel(key, sentinel);

                throw;
            }
        }
Example #28
0
        /// <inheritdoc />
        public object GetOrPopulate(string key, Populator populator)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            if (key.Length == 0)
            {
                throw new ArgumentException("Key must not be empty.", "keys");
            }
            if (populator == null)
            {
                throw new ArgumentNullException("populator");
            }

            return(InternalGetOrPopulate(key, populator));
        }
Example #29
0
        public void GetCareerTest()
        {
            string username = "******";

            var populator = new Populator();
            var career    = populator.GetCareer(username);

            repMock.Setup(m => m.GetAll())
            .Returns(new List <Career>()
            {
                career
            }.AsQueryable());

            var actual = worker.GetCareer(username);

            Assert.IsNotNull(actual);
            Assertor.AreSame(career, actual);
        }
Example #30
0
        /// <inheritdoc />
        protected override object InternalPopulate(string key, Populator populator)
        {
            Sentinel sentinel = new Sentinel();

            try
            {
                innerCache.Insert(key, sentinel, null, ASPNetCache.NoAbsoluteExpiration, ASPNetCache.NoSlidingExpiration,
                                  CacheItemPriority.NotRemovable, null);

                return(PopulateWithSentinel(key, populator, sentinel));
            }
            catch (Exception ex)
            {
                sentinel.FinishedWithException(ex);
                RemoveSentinel(key, sentinel);

                throw;
            }
        }
Example #31
0
    private void InitForm()
    {
        //dt1.SelectedDate = DateTime.Today.AddDays(-7d);
        //dt2.SelectedDate = DateTime.Today;
        var Filters = Populator.GetFilter();

        Filters.Add("TypeCode", "ActivityTypeID");
        var arrType = ParamsManager.GetParamssByFilter(Filters);

        ddlType.BindData(arrType, "TypeName", "ObjectValue");
        ddlType.InsertChooseItem();

        Filters = Populator.GetFilter();
        Filters.Add("TypeCode", "ActivityStatusID");
        var arrStatus = ParamsManager.GetParamssByFilter(Filters);

        ddlStatus.BindData(arrStatus, "TypeName", "ObjectValue");
        ddlStatus.InsertChooseItem();

        grdData.Visible = false;
    }
Example #32
0
    private Dictionary <string, object> GetFilter()
    {
        var filter = Populator.GetFilter();

        if (!string.IsNullOrEmpty(txtName.Text))
        {
            filter.Add("Name LIKE '%" + txtName.Text + "%' AND 1", 1);
        }
        if (!string.IsNullOrEmpty(txtSurname.Text))
        {
            filter.Add("Surname LIKE '%" + txtSurname.Text + "%' AND 1", 1);
        }
        if (!string.IsNullOrEmpty(txtEmail.Text))
        {
            filter.Add("Email LIKE '%" + txtEmail.Text + "%' AND 1", 1);
        }
        if (ddlType.SelectedIndex > 0)
        {
            filter.Add("MemberTypeID", ddlType.SelectedValue);
        }

        return(filter);
    }
Example #33
0
    private Dictionary <string, object> GetFilter()
    {
        var filter = Populator.GetFilter();

        if (!string.IsNullOrEmpty(txtCustomerCode.Text))
        {
            filter.Add("CustomerCode", txtCustomerCode.Text);
        }
        if (!string.IsNullOrEmpty(txtReference.Text))
        {
            filter.Add("ReferenceNo", txtReference.Text);
        }
        if (!string.IsNullOrEmpty(txtName.Text))
        {
            filter.Add("Name LIKE '%" + txtName.Text + "%' AND 1", 1);
        }
        if (!string.IsNullOrEmpty(txtPhone.Text))
        {
            filter.Add("ReferenceNo", txtReference.Text);
        }

        return(filter);
    }
Example #34
0
        /// <inheritdoc />
        protected override object InternalPopulate(string key, Populator populator)
        {
            Sentinel sentinel = null;

            try
            {
                lock (items)
                {
                    sentinel   = new Sentinel();
                    items[key] = new CacheItem(sentinel, DateTime.MaxValue);
                }

                return(PopulateWithSentinel(key, populator, sentinel));
            }
            catch (Exception)
            {
                if (sentinel != null)
                {
                    RemoveSentinel(key, sentinel);
                }
                throw;
            }
        }
Example #35
0
        /// <inheritdoc />
        protected override object InternalPopulate(string key, Populator populator)
        {
            CacheOptions options;
            object value = populator(key, out options);

            if (value != null)
            {
                InternalSet(key, value, options);
            }
            else
            {
                InternalRemove(key);
            }

            return value;
        }
Example #36
0
        public void TestNewByParameter()
        {
            using (var wrapper = new TestReaderWrapper<NullableDateTimeType>("SELECT NULL"))
            {
                var populator = new Populator<FdwDataObjectInheritancePocoTest0, SqlDataReader>(wrapper.Reader);
                var cb = new CodeBaseBody<FdwDataObjectInheritancePocoTest0, SqlDataReader>(populator);

                var ctor =
                    typeof (FdwDataObjectInheritancePocoTest0).GetConstructor(
                        BindingFlags.Public | BindingFlags.Instance, null, new[] {typeof (int)}, null);
                Assert.IsNotNull(ctor);
                cb.New(ctor);
                Assert.AreEqual(1, cb.OpCodes.Count, "Opcode count mismatch.");
                Assert.AreEqual(cb.OpCodes.Peek().OpCode, OpCodes.Newobj, "Opcode type mismatch.");
            }
        }
Example #37
0
 /// <inheritdoc />
 protected override object InternalPopulate(string key, Populator populator)
 {
     CacheOptions options;
     return populator(key, out options);
 }
Example #38
0
 public void TestJumpTo()
 {
     using (var wrapper = new TestReaderWrapper<NullableDateTimeType>("SELECT NULL"))
     {
         var populator = new Populator<EmptyPocoTest0, SqlDataReader>(wrapper.Reader);
         var cb = new CodeBaseBody<EmptyPocoTest0, SqlDataReader>(populator);
         cb.JumpTo(OpCodes.Nop, new Label());
         Assert.AreEqual(1, cb.OpCodes.Count, "Opcode count mismatch.");
         Assert.AreEqual(cb.OpCodes.Peek().OpCode, OpCodes.Nop, "Opcode type mismatch.");
     }
 }
Example #39
0
        /// <inheritdoc />
        protected override object InternalPopulate(string key, Populator populator)
        {
            Sentinel sentinel = new Sentinel();
            try
            {
                innerCache.Insert(key, sentinel, null, ASPNetCache.NoAbsoluteExpiration, ASPNetCache.NoSlidingExpiration,
                    CacheItemPriority.NotRemovable, null);

                return PopulateWithSentinel(key, populator, sentinel);
            }
            catch (Exception ex)
            {
                sentinel.FinishedWithException(ex);
                RemoveSentinel(key, sentinel);

                throw;
            }
        }
 public void TestInitialize()
 {
     this.tableTypeCacheMock = new Mock<TableTypeCache>((Func<TableTypeCache, ITableTypeCacheService>)(x => null));
     this.attributeDecorator = new StandardAttributeDecorator(x => this.tableTypeCacheMock.Object, this.GetType().Assembly, null);
     this.populator = new Populator(this.attributeDecorator);
 }
Example #41
0
        private object PopulateWithSentinel(string key, Populator populator, Sentinel sentinel)
        {
            CacheOptions options;
            object value = populator(key, out options);

            if (value != null)
            {
                sentinel.FinishedWithValue(value);
                ReplaceSentinel(key, value, options, sentinel);
            }
            else
            {
                RemoveSentinel(key, sentinel);
            }

            return value;
        }
Example #42
0
        /// <inheritdoc />
        protected override object InternalGetOrPopulate(string key, Populator populator)
        {
            object value = InternalGet(key);
            if (value != null)
                return value;

            return InternalPopulate(key, populator);
        }
Example #43
0
        /// <inheritdoc />
        protected override object InternalGetOrPopulate(string key, Populator populator)
        {
            // Check if value has already been populated.
            object value = GetOrWaitUntilPopulated(key);
            if (value != null)
                return value;

            Sentinel sentinel = new Sentinel();
            try
            {
                // Add a sentinel into the cache unless some other thread has managed
                // to squeeze in here first.
                value = innerCache.Add(key, sentinel, null, ASPNetCache.NoAbsoluteExpiration, ASPNetCache.NoSlidingExpiration,
                    CacheItemPriority.NotRemovable, null);

                if (value == null)
                {
                    // The sentinel was added.
                    return PopulateWithSentinel(key, populator, sentinel);
                }
                else
                {
                    // The sentinel was not added.
                    // That means some other thread has set the value or begun population
                    // in the meantime so we have to handle each case.
                    sentinel = value as Sentinel;
                    if (sentinel != null)
                        value = sentinel.WaitUntilFinished();

                    return value;
                }
            }
            catch (Exception ex)
            {
                sentinel.FinishedWithException(ex);
                RemoveSentinel(key, sentinel);

                throw;
            }
        }
Example #44
0
 /// <inheritdoc />
 protected override object InternalPopulate(string key, Populator populator)
 {
     return innerCache.Populate(partitionPrefix + key, delegate(string prefixedKey, out CacheOptions options)
     {
         return populator(key, out options);
     });
 }
Example #45
0
 /// <summary>
 /// Internal implementation of <see cref="Populate(string, Populator)" />.
 /// All parameters have been validated by the base class.
 /// </summary>
 /// <param name="key">The cache key</param>
 /// <param name="populator">The populator</param>
 /// <returns>The value or null if the populator did not produce a value</returns>
 protected abstract object InternalPopulate(string key, Populator populator);
Example #46
0
        private object PopulateWithSentinel(string key, Populator populator, Sentinel sentinel)
        {
            CacheOptions options;
            object populatedValue = populator(key, out options);

            lock (items)
            {
                CacheItem item;
                if (items.TryGetValue(key, out item) && item.Value == sentinel)
                {
                    if (populatedValue != null)
                    {
                        DateTime expirationTime = options.GetUtcExpirationTimeRelativeToNow();

                        items[key] = new CacheItem(populatedValue, expirationTime);
                        if (expirationTime < nextExpirationTime)
                            nextExpirationTime = expirationTime;
                    }
                    else
                    {
                        items.Remove(key);
                    }
                }

                Monitor.PulseAll(items);
            }

            return populatedValue;
        }
Example #47
0
        /// <inheritdoc />
        protected override object InternalPopulate(string key, Populator populator)
        {
            Sentinel sentinel = null;
            try
            {
                lock (items)
                {
                    sentinel = new Sentinel();
                    items[key] = new CacheItem(sentinel, DateTime.MaxValue);
                }

                return PopulateWithSentinel(key, populator, sentinel);
            }
            catch (Exception)
            {
                if (sentinel != null)
                    RemoveSentinel(key, sentinel);
                throw;
            }
        }
Example #48
0
        /// <inheritdoc />
        protected override object InternalGetOrPopulate(string key, Populator populator)
        {
            Sentinel sentinel = null;
            try
            {
                lock (items)
                {
                    object existingValue = GetOrWaitUntilPopulatedInsideLock(key);
                    if (existingValue != null)
                        return existingValue;

                    sentinel = new Sentinel();
                    items[key] = new CacheItem(sentinel, DateTime.MaxValue);
                }

                return PopulateWithSentinel(key, populator, sentinel);
            }
            catch (Exception)
            {
                if (sentinel != null)
                    RemoveSentinel(key, sentinel);
                throw;
            }
        }