Ejemplo n.º 1
0
        /// <summary>
        /// Always called after parsing is done (full or incremental)
        /// </summary>
        public override void UpdateCachedChildren()
        {
            RuleSets.Clear();
            CustomProperties.Clear();

            foreach (ParseItem child in Children)
            {
                if (child is RuleSet)
                {
                    RuleSets.Add((RuleSet)child);

                    if (((RuleSet)child).Block != null)
                    {
                        IEnumerable <Declaration> childCustomDecls = ((RuleSet)child).Block.CustomProperties;
                        CustomProperties.AddRange(childCustomDecls);
                    }
                }
            }

            // Don't cache the curly braces for the root stylesheet
            if (IsNestedBlock)
            {
                base.UpdateCachedChildren();
            }
        }
Ejemplo n.º 2
0
        public void AddCustomProperty(CustomProperties properties)
        {
            if ((PropertyTypes)PropertyType.SelectedIndex == PropertyTypes.Clear)
            {
                properties.Clear(PropertyKey.Text);
            }
            else
            {
                View view = PropertyValueHolder.Children[0];
                switch ((PropertyTypes)PropertyType.SelectedIndex)
                {
                case PropertyTypes.Boolean:
                    properties.Set(PropertyKey.Text, (view as Switch).IsToggled);
                    break;

                case PropertyTypes.Number:
                    if (!string.IsNullOrWhiteSpace((view as Editor).Text))
                    {
                        properties.Set(PropertyKey.Text, long.Parse((view as Editor).Text));
                    }
                    break;

                case PropertyTypes.DateTime:
                    DateTime date = new DateTime(DatePicker.Date.Year, DatePicker.Date.Month, DatePicker.Date.Day,
                                                 TimePicker.Time.Hours, TimePicker.Time.Minutes, TimePicker.Time.Seconds);
                    properties.Set(PropertyKey.Text, date);
                    break;

                case PropertyTypes.String:
                    properties.Set(PropertyKey.Text, (view as Editor).Text);
                    break;
                }
            }
        }
Ejemplo n.º 3
0
        public void TestClear()
        {
            var key = "test";
            CustomProperties properties = new CustomProperties();

            Assert.AreEqual(0, properties.Properties.Count);
            properties.Clear(key);
            Assert.AreEqual(1, properties.Properties.Count);
            FindProperty(properties.Properties, key, null);
        }
        public void TestClear()
        {
            var key = "test";
            CustomProperties properties = new CustomProperties();

            Assert.AreEqual(0, properties.Properties.Count);
            properties.Clear(key);
            Assert.AreEqual(1, properties.Properties.Count);
            Assert.IsNull(properties.Properties[key]);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Executes in two distinct scenarios.
        ///
        /// 1. If disposing is true, the method has been called directly
        /// or indirectly by a user's code via the Dispose method.
        /// Both managed and unmanaged resources can be disposed.
        ///
        /// 2. If disposing is false, the method has been called by the
        /// runtime from inside the finalizer and you should not reference (access)
        /// other managed objects, as they already have been garbage collected.
        /// Only unmanaged resources can be disposed.
        /// </summary>
        /// <param name="disposing"></param>
        /// <remarks>
        /// If any exceptions are thrown, that is fine.
        /// If the method is being done in a finalizer, it will be ignored.
        /// If it is thrown by client code calling Dispose,
        /// it needs to be handled by fixing the bug.
        ///
        /// If subclasses override this method, they should call the base implementation.
        /// </remarks>
        private void Dispose(bool disposing)
        {
            System.Diagnostics.Debug.WriteLineIf(!disposing, "****** Missing Dispose() call for " + GetType().Name + ". ****** ");
            // Must not be run more than once.
            if (m_isDisposed)
            {
                return;
            }

            if (disposing && !m_fBeingDisposed)
            {
                // JohnT: not game to try setting m_isDisposed this early, but we are in danger of getting a recursive
                // call when disposing the service manager, at least. Seems safest to set a flag so we never do this
                // stuff twice, even if we are called recursively (or repeatedly, but we already guard against that).
                m_fBeingDisposed = true;

                RaiseDisposing();

                // No, since it's a C# implementation.
                //if (m_viewsCache != null)
                //{
                //    Marshal.ReleaseComObject(m_viewsCache);
                //}
                m_objectsBeingDeleted.Clear();
                CustomProperties.Clear();

                if (m_serviceLocator != null)
                {
                    m_serviceLocator.WritingSystemManager.Save();
                }

                // Do NOT do this! It's disposable but often a static from FieldWorks, we are NOT responsible to dispose it.
                //if (m_threadHelper != null)
                //    m_threadHelper.Dispose();

                // NOTE: this needs to be last since it calls LcmCache.Dispose() which
                // sets all member variables to null.
                // This will also dispose all Singletons which includes m_serviceLocator.GetInstance<IDataSetup>()
                var serviceLocatorWrapper = m_serviceLocator as StructureMapServiceLocator;
                if (serviceLocatorWrapper != null)
                {
                    serviceLocatorWrapper.Dispose();
                }
            }

            // Dispose unmanaged resources here, whether disposing is true or false.

            // Main data members.
            m_lgwsFactory    = null;
            m_serviceLocator = null;

            m_isDisposed = true;
        }
Ejemplo n.º 6
0
        protected void SetProperty(string key, string value)
        {
            var prop = new CustomProperties();

            if (string.IsNullOrEmpty(value))
            {
                prop.Clear(key);
            }
            else
            {
                prop.Set(key, value);
            }

            MobileCenter.SetCustomProperties(prop);
        }
Ejemplo n.º 7
0
        public void TestKeyValidate()
        {
            var value1 = "test";
            var value2 = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
            var value3 = 1;
            var value4 = 100L;
            var value5 = 0.1f;
            var value6 = 0.1m;
            var value7 = 0.1;
            var value8 = false;
            CustomProperties properties = new CustomProperties();

            Assert.AreEqual(0, properties.Properties.Count);

            /* Null key. */
            string nullKey = null;

            properties.Set(nullKey, value1);
            properties.Set(nullKey, value2);
            properties.Set(nullKey, value3);
            properties.Set(nullKey, value4);
            properties.Set(nullKey, value5);
            properties.Set(nullKey, value6);
            properties.Set(nullKey, value7);
            properties.Set(nullKey, value8);
            properties.Clear(nullKey);
            Assert.AreEqual(0, properties.Properties.Count);

            /* Invalid key. */
            var invalidKey = "!";

            properties.Set(invalidKey, value1);
            properties.Set(invalidKey, value2);
            properties.Set(invalidKey, value3);
            properties.Set(invalidKey, value4);
            properties.Set(invalidKey, value5);
            properties.Set(invalidKey, value6);
            properties.Set(invalidKey, value7);
            properties.Set(invalidKey, value8);
            properties.Clear(invalidKey);
            Assert.AreEqual(0, properties.Properties.Count);

            /* Long key. */
            var longKey = new string('a', 129);

            properties.Set(longKey, value1);
            properties.Set(longKey, value2);
            properties.Set(longKey, value3);
            properties.Set(longKey, value4);
            properties.Set(longKey, value5);
            properties.Set(longKey, value6);
            properties.Set(longKey, value7);
            properties.Set(longKey, value8);
            properties.Clear(longKey);
            Assert.AreEqual(0, properties.Properties.Count);

            /* Empty keys. */
            properties.Set(string.Empty, value1);
            properties.Set(string.Empty, value2);
            properties.Set(string.Empty, value3);
            properties.Set(string.Empty, value4);
            properties.Set(string.Empty, value5);
            properties.Set(string.Empty, value6);
            properties.Set(string.Empty, value7);
            properties.Set(string.Empty, value8);
            properties.Clear(string.Empty);
            Assert.AreEqual(0, properties.Properties.Count);

            /* Normal keys. */
            properties.Set("t1", value1);
            properties.Set("t2", value2);
            properties.Set("t3", value3);
            properties.Set("t4", value4);
            properties.Set("t5", value5);
            properties.Set("t6", value6);
            properties.Set("t7", value7);
            properties.Set("t8", value8);
            properties.Clear("t9");
            Assert.AreEqual(9, properties.Properties.Count);

            /* Already contains keys. */
            properties.Set("t1", value1);
            properties.Set("t2", value2);
            properties.Set("t3", value3);
            properties.Set("t4", value4);
            properties.Set("t5", value5);
            properties.Set("t6", value6);
            properties.Set("t7", value7);
            properties.Set("t8", value8);
            properties.Clear("t9");
            Assert.AreEqual(9, properties.Properties.Count);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Clears all the properties from a defined object type.
 /// </summary>
 public static void ClearProperties()
 {
     CustomProperties.Clear();
 }
Ejemplo n.º 9
0
        /// <summary>
        ///     Allows you to populate the current line item object using a LineItemDTO instance
        /// </summary>
        /// <param name="dto">An instance of the line item from the REST API</param>
        public void FromDto(LineItemDTO dto)
        {
            if (dto == null)
            {
                return;
            }

            Id                   = dto.Id;
            StoreId              = dto.StoreId;
            LastUpdatedUtc       = dto.LastUpdatedUtc;
            BasePricePerItem     = dto.BasePricePerItem;
            LineTotal            = dto.LineTotal;
            AdjustedPricePerItem = dto.AdjustedPricePerItem;
            IsUserSuppliedPrice  = dto.IsUserSuppliedPrice;
            IsBundle             = dto.IsBundle;
            IsGiftCard           = dto.IsGiftCard;
            PromotionIds         = dto.PromotionIds;
            FreeQuantity         = dto.FreeQuantity;

            DiscountDetails.Clear();
            if (dto.DiscountDetails != null)
            {
                foreach (var detail in dto.DiscountDetails)
                {
                    var d = new DiscountDetail();
                    d.FromDto(detail);
                    DiscountDetails.Add(d);
                }
            }
            OrderBvin               = dto.OrderBvin ?? string.Empty;
            ProductId               = dto.ProductId ?? string.Empty;
            VariantId               = dto.VariantId ?? string.Empty;
            ProductName             = dto.ProductName ?? string.Empty;
            ProductSku              = dto.ProductSku ?? string.Empty;
            ProductShortDescription = dto.ProductShortDescription ?? string.Empty;
            Quantity         = dto.Quantity;
            QuantityReturned = dto.QuantityReturned;
            QuantityShipped  = dto.QuantityShipped;
            ShippingPortion  = dto.ShippingPortion;
            TaxRate          = dto.TaxRate;
            TaxPortion       = dto.TaxPortion;
            StatusCode       = dto.StatusCode ?? string.Empty;
            StatusName       = dto.StatusName ?? string.Empty;
            SelectionData.Clear();
            if (dto.SelectionData != null)
            {
                foreach (var op in dto.SelectionData)
                {
                    var o = new OptionSelection();
                    o.FromDto(op);
                    SelectionData.OptionSelectionList.Add(o);
                }
            }
            IsNonShipping         = dto.IsNonShipping;
            TaxSchedule           = dto.TaxSchedule;
            ProductShippingHeight = dto.ProductShippingHeight;
            ProductShippingLength = dto.ProductShippingLength;
            ProductShippingWeight = dto.ProductShippingWeight;
            ProductShippingWidth  = dto.ProductShippingWidth;
            CustomProperties.Clear();
            if (dto.CustomProperties != null)
            {
                foreach (var cpd in dto.CustomProperties)
                {
                    var prop = new CustomProperty();
                    prop.FromDto(cpd);
                    CustomProperties.Add(prop);
                }
            }
            ShipFromAddress.FromDto(dto.ShipFromAddress);
            ShipFromMode           = (ShippingMode)(int)dto.ShipFromMode;
            ShipFromNotificationId = dto.ShipFromNotificationId ?? string.Empty;
            ShipSeparately         = dto.ShipSeparately;
            ExtraShipCharge        = dto.ExtraShipCharge;
            ShippingCharge         = (ShippingChargeType)(int)dto.ShippingCharge;
        }
        public async Task CustomPropertiesClearTest()
        {
            // Set up HttpNetworkAdapter.
            var typeProperty       = "customProperties";
            var httpNetworkAdapter = new HttpNetworkAdapter();

            DependencyConfiguration.HttpNetworkAdapter = httpNetworkAdapter;
            var startServiceTask     = httpNetworkAdapter.MockRequestByLogType("startService");
            var customPropertiesTask = httpNetworkAdapter.MockRequestByLogType(typeProperty);

            // Start App Center.
            AppCenter.UnsetInstance();
            Analytics.UnsetInstance();
            AppCenter.LogLevel = LogLevel.Verbose;
            AppCenter.Start(Config.ResolveAppSecret(), typeof(Analytics));

            // Wait for "startService" log to be sent.
            await startServiceTask;

            // Enable Appcenter.
            await AppCenter.SetEnabledAsync(true);

            // Verify enabled.
            var isEnabled = await AppCenter.IsEnabledAsync();

            var isEnabledAnalytics = await Analytics.IsEnabledAsync();

            Assert.True(isEnabled);
            Assert.True(isEnabledAnalytics);

            // Set custom properties.
            var propertiesDictionary = new Dictionary <string, object>
            {
                { "keyBoolean", true },
                { "keyString", "value" },
                { "keyInt", 42 },
                { "keyDateTime", new DateTime() },
            };

            // Clear custom properties.
            var customPropertiesClear = new CustomProperties();

            foreach (var item in propertiesDictionary)
            {
                customPropertiesClear.Clear(item.Key);
            }
            AppCenter.SetCustomProperties(customPropertiesClear);

            // Wait for processing event.
            RequestData requestData = await customPropertiesTask;

            Assert.Equal("POST", requestData.Method);
            var eventLogsClear = requestData.JsonContent.SelectTokens($"$.logs[?(@.type == '{typeProperty}')]").ToList();

            // Verify the log sctructure.
            Assert.Equal(1, eventLogsClear.Count());
            var eventLogClear   = eventLogsClear[0];
            var propertiesClear = eventLogClear["properties"];

            Assert.NotNull(propertiesClear);
            Assert.Equal(4, propertiesClear.Count());

            // Verify initial dictionary has the values.
            foreach (var item in propertiesClear)
            {
                Assert.Equal((string)item.SelectToken("type"), "clear");
            }
            Assert.Equal(2, httpNetworkAdapter.CallCount);
        }