/// <summary>
        /// Add a single test document uploaded by the provided user and containing
        /// the provided properties.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="user"></param>
        /// <param name="documentTitle"></param>
        /// <param name="documentDescription"></param>
        /// <param name="authorName"></param>
        /// <param name="keywords"></param>
        /// <param name="isIndexed">Indicate if the document is indexed and is downloadable. Optional param set to true </param>
        /// <param name="categories"></param>
        public static void AddTestDocument(DsContext context, User user, string documentTitle, string documentDescription, string authorName, List <Category> categories = null, List <Keyword> keywords = null, bool isIndexed = true)
        {
            // Use current date as a mock for all the required date fields
            var currentDate = DateTime.Now;

            // only add the document if there is no such document inserted before based on the document title
            if (context.Documents.FirstOrDefault(x => x.Title == documentTitle) == null)
            {
                var document = new Document()
                {
                    AuthorName   = authorName,
                    Description  = documentDescription,
                    Title        = documentTitle,
                    User         = user,
                    Path         = "",
                    IsIndexed    = isIndexed,
                    DateCreated  = currentDate,
                    DateIndexed  = currentDate,
                    DateUploaded = currentDate,

                    Categories = ListUtilities.GetSublist(categories, _minCategories, _maxCategories > categories.Count ? categories.Count : _maxCategories),
                    Keywords   = ListUtilities.GetSublist(keywords, _minKeywords, _maxKeywords > keywords.Count ? keywords.Count : _maxKeywords),
                };

                context.Documents.AddOrUpdate(document);
            }
        }
示例#2
0
    private void cmdDelete_Click(object sender, EventArgs e)
    {
        int settingsId;
        int deletedIndex;

        if (lstReports.SelectedValue == string.Empty)
        {
            return;
        }

        if (lstReports.Items.Count == 1)
        {
            return;
        }

        settingsId = int.Parse(lstReports.SelectedValue);

        _db.SavedReports_Delete(settingsId);

        //Remove the report from the list
        deletedIndex = lstReports.SelectedIndex;
        lstReports.Items.Remove(lstReports.SelectedItem);

        //Select the next item
        lstReports.SelectedIndex =
            ListUtilities.GetItemIndexAfterDelete(lstReports.Items.Count, deletedIndex);

        loadSelected();
    }
示例#3
0
        private void MovePropertyDown(object sender, RoutedEventArgs e)
        {
            // Moving property down in the datagrid means the index increases

            // Gets the specification
            CategorySpecification catspec = ((FrameworkElement)sender).DataContext as CategorySpecification;

            // Gets the index of the specification
            int index = CategoryModel.CategorySpecifications.ToList().IndexOf(catspec);

            // If the spec is the last one in the list, it can't move down
            if (index < CategoryModel.CategorySpecifications.Count() - 1)
            {
                // Swaps the display order of the swapped specs
                CategoryModel.CategorySpecifications.ToList()[index].DisplayOrder     = index + 1;
                CategoryModel.CategorySpecifications.ToList()[index + 1].DisplayOrder = index;

                // Swaps the 2 specs in the list
                CategoryModel.CategorySpecifications
                    = ListUtilities <CategorySpecification> .Swap
                          (CategoryModel.CategorySpecifications.ToList(), index, index + 1);

                // Refreshes the grid
                BindCategorySpecificationsGrid();
            }
        }
示例#4
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values.Length != 2)
            {
                throw new ArgumentException("The 'values' argument should contain 2 objects.");
            }

            if (values[1] != null)
            {
                if (!values[1].GetType().IsGenericType || !(values[1].GetType().GetGenericArguments().First().GetType() is Type))
                {
                    throw new ArgumentException("The 'value' argument is not of the correct type.");
                }

                return(values[1]);
            }
            else if (values[0] != null)
            {
                if (!(values[0].GetType() is Type))
                {
                    throw new ArgumentException("The 'value' argument is not of the correct type.");
                }

                List <Type> types    = new List <Type>();
                Type        listType = ListUtilities.GetListItemType((Type)values[0]);
                if (listType != null)
                {
                    types.Add(listType);
                }

                return(types);
            }

            return(null);
        }
示例#5
0
        public IEnumerable <Break> FindByExternal(List <string> externalRef)
        {
            lock (_session)
            {
                var breaks = new List <Break>();
                int page   = 0;

                do
                {
                    List <string> pageExternalRefs = ListUtilities.GetPageItems(externalRef, 1000, page++);

                    if (pageExternalRefs.Count > 0)
                    {
                        breaks.AddRange(_session.GetAll <Break>(x =>
                                                                x.ExternalBreakRef.In(pageExternalRefs),
                                                                Breaks_ByManyFields.DefaultIndexName,
                                                                isMapReduce: false
                                                                )
                                        );
                    }
                    else
                    {
                        return(breaks);
                    }
                } while (true);
            }
        }
示例#6
0
        private void MovePropertyUp(object sender, RoutedEventArgs e)
        {
            // Moving property up in the datagrid means the index (and display order) decreases

            // Gets the specification
            CategorySpecification spec = ((FrameworkElement)sender).DataContext as CategorySpecification;

            // Gets the index of the specification
            int index = CategoryModel.CategorySpecifications.ToList().IndexOf(spec);

            // If its index is 0, then it can't move up
            if (index > 0)
            {
                // Swaps the display order of the swapped specs
                CategoryModel.CategorySpecifications.ToList()[index].DisplayOrder     = index - 1;
                CategoryModel.CategorySpecifications.ToList()[index - 1].DisplayOrder = index;

                // Swaps the specs in the list
                CategoryModel.CategorySpecifications
                    = ListUtilities <CategorySpecification> .Swap
                          (CategoryModel.CategorySpecifications.ToList(), index, index - 1);

                // Refreshes the category specification grid
                BindCategorySpecificationsGrid();
            }
        }
示例#7
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // First, we need to retrieve all data from the input parameters.
            // We'll start by declaring variables and assigning them starting values.

            List <Curve> curves  = new List <Curve>();
            List <int>   numSegs = new List <int>();
            bool         oneWay  = false;

            // Then we need to access the input parameters individually.
            // When data cannot be extracted from a parameter, we should abort this method.
            if (!DA.GetDataList(0, curves))
            {
                return;
            }
            if (!DA.GetDataList(1, numSegs))
            {
                return;
            }
            if (!DA.GetData(2, ref oneWay))
            {
                return;
            }

            // We should now validate the data and warn the user if invalid data is supplied.
            if (curves == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input Curves");
                return;
            }
            if (numSegs == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Define Segment Lists");
                return;
            }

            //***********Need to check if segments is greater than the limit of members**************

            //Define output lists. Generally create seperate methods in the core and output to these parametes.

            Dictionary <int, List <int> > temp = ListUtilities.MemberSegmentationInt(curves, numSegs, oneWay);

            foreach (KeyValuePair <int, List <int> > item in temp)
            {
                if (item.Key > Params.Output.Count)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Number of Lists Exceeds Outputs. Add Output Parameters or Right click and Match Outputs");
                    return;
                }
                else
                {
                    DA.SetDataList((item.Key - 1), item.Value);
                }
            }
            VariableParameterMaintenance();
            Params.OnParametersChanged();
            this.ExpireSolution(true);
        }
示例#8
0
 public void GetObjSize()
 {
     Assert.AreEqual(2, ListUtilities.GetObjSize(new string[] { "Hello", "test" }), "Correct object size of string[] did not work");
     Assert.AreEqual(-1, ListUtilities.GetObjSize("Hello"), "Correct object size of string did not work");
     Assert.AreEqual(4, ListUtilities.GetObjSize(new object[] { 2, "Hello", new string[][] { new string[] { "Hello" } }, new List <string> {
                                                                    "Test"
                                                                } }), "Correct object size of object[] did not work");
     Assert.AreNotEqual(5, ListUtilities.GetObjSize("Hello"), "Incorrect object size of string did not work");
 }
 public void SetSpiderWebPositions(List <Vector3> SpiderWebPositions)
 {
     ListUtilities.SortFromDistanceToAnObject(SpiderWebPositions, transform.position);
     SpiderWebPositions.Reverse();
     foreach (Vector3 position in SpiderWebPositions)
     {
         AddSpiderWebPosition(position);
     }
     SpiderGlobalBlackboard.Instance.AddKeyValue("spiderWebsManagement", this);
 }
示例#10
0
 public void SetFood(List <Vector3> foodPositions)
 {
     ListUtilities.SortFromDistanceToAnObject(foodPositions, transform.position);
     foodPositions.Reverse();
     foreach (Vector3 position in foodPositions)
     {
         AddFood(position);
     }
     AntGlobalBlackboard.Instance.AddKeyValue("foodManagement", this);
 }
        internal FrameworkElement GenerateChildrenEditorElement(PropertyItem propertyItem)
        {
            FrameworkElement editorElement      = null;
            DescriptorPropertyDefinitionBase pd = propertyItem.DescriptorDefinition;
            object      definitionKey           = null;
            Type        definitionKeyAsType     = definitionKey as Type;
            ITypeEditor editor = null;

            if (editor == null)
            {
                editor = pd.CreateAttributeEditor();
            }

            if (editor != null)
            {
                editorElement = editor.ResolveEditor(propertyItem);
            }


            if ((editorElement == null) && (definitionKey == null) && (propertyItem.PropertyDescriptor != null))
            {
                editorElement = this.GenerateCustomEditingElement(propertyItem.PropertyDescriptor.Name, propertyItem);
            }

            if (editorElement == null && definitionKeyAsType == null)
            {
                editorElement = this.GenerateCustomEditingElement(propertyItem.PropertyType, propertyItem);
            }

            if (editorElement == null)
            {
                if (propertyItem.IsReadOnly &&
                    !ListUtilities.IsListOfItems(propertyItem.PropertyType) &&
                    !ListUtilities.IsCollectionOfItems(propertyItem.PropertyType) &&
                    !ListUtilities.IsDictionaryOfItems(propertyItem.PropertyType))
                {
                    editor = new TextBlockEditor((propertyItem.PropertyDescriptor != null) ? propertyItem.PropertyDescriptor.Converter : null);
                }

                // Fallback: Use a default type editor.
                if (editor == null)
                {
                    editor = (definitionKeyAsType != null)
          ? PropertyGridUtilities.CreateDefaultEditor(definitionKeyAsType, null, propertyItem)
          : pd.CreateDefaultEditor(propertyItem);
                }

                Debug.Assert(editor != null);

                editorElement = editor.ResolveEditor(propertyItem);
            }

            return(editorElement);
        }
示例#12
0
        public void ListUtilitiesExtractBufferSuccess()
        {
            var buffer = new[]
            {
                1, 2, 3, 5, 6
            };

            var result        = ListUtilities.CreateFromBuffer(buffer);
            var extractBuffer = ListUtilities.ExtractBuffer(result);

            Debug.Assert(buffer == extractBuffer);
        }
示例#13
0
    private void PopulateControls()
    {
        IList <ContentMenuItem> originalList = DataAccessContext.ContentMenuItemRepository.GetByContentMenuID(
            StoreContext.Culture, RootID, "SortOrder", BoolFilter.ShowTrue);
        IList <ContentMenuItem> list = ListUtilities <ContentMenuItem> .CopyListDeep(originalList);

        foreach (ContentMenuItem item in list)
        {
            if (!item.LinksToContent())
            {
                item.Name = item.Name + "...";
            }
        }

        if (_rootID == DataAccessContext.Configurations.GetValue("TopContentMenu"))
        {
            uxList.Visible = false;
            uxContentMenuListTop.Visible = true;
            uxContentMenuListTop.Items.Clear();

            if (DataAccessContext.Configurations.GetBoolValue("RestrictAccessToShop") && !Page.User.Identity.IsAuthenticated)
            {
                return;
            }

            Culture         culture  = DataAccessContext.CultureRepository.GetOne("1");
            ContentMenuItem rootItem = DataAccessContext.ContentMenuItemRepository.GetOne(
                culture, ContentMenuItem.RootMenuItemID);

            MenuItem rootMenu = new MenuItem();
            rootMenu.Text        = ContentMenuItem.RootMenuItemName;
            rootMenu.NavigateUrl = UrlManager.GetContentMenuUrl(rootItem.ContentMenuItemID,
                                                                rootItem.UrlName);

            foreach (ContentMenuItem contentMenuItem in list)
            {
                rootMenu.ChildItems.Add(CreateMenuItemWithChildren(0, contentMenuItem));
            }
            uxContentMenuListTop.Items.Add(rootMenu);
            uxContentMenuListTop.Orientation = Orientation.Horizontal;
        }
        else
        {
            uxContentMenuListTop.Visible = false;
            uxList.Visible    = true;
            uxList.DataSource = list;
            uxList.DataBind();
        }
    }
示例#14
0
        public void ListUtilitiesCreateFromBufferSuccess()
        {
            var buffer = new[]
            {
                1, 2, 3, 5, 6
            };

            var result = ListUtilities.CreateFromBuffer(buffer);

            Debug.Assert(result.Count == buffer.Length);

            for (int i = 0; i < buffer.Length; i++)
            {
                Debug.Assert(result[i] == buffer[i]);
            }
        }
示例#15
0
        /// <summary>
        /// Return the buffer position that corresponds to the specified coordinate (which will be either a line number or a character position). The returned position may be
        /// on either the left or right difference snapshots.
        /// </summary>
        public SnapshotPoint BufferPositionFromSideBySideCoordinate(int coordinate)
        {
            //Convert the coordinate to a valid line number (0 ... line count - 1).
            coordinate = Math.Min(Math.Max(0, coordinate), (this.SideBySideLength - 1));

            ListUtilities.BinarySearch(_sideBySideEndAtDiff, (s) => (s - coordinate - 1), out int index);

            ITextSnapshotLine line;

            if (index >= this.Difference.LineDifferences.Differences.Count)
            {
                // We're in a match that follows the last difference (assuming there are any differences).
                // Count lines backwards from the end of the right buffer.
                var delta = this.SideBySideLength - coordinate;
                line = this.Difference.RightBufferSnapshot.GetLineFromLineNumber(this.Difference.RightBufferSnapshot.LineCount - delta);
            }
            else
            {
                // We either in a difference or in the match that preceeds a difference.
                // In either case, the sideBySideEnd corresponds to the start of the match.
                int sideBySideEnd = (index > 0) ? _sideBySideEndAtDiff[index - 1] : 0;

                int  delta = coordinate - sideBySideEnd;
                Span left;
                Span right;
                var  difference = this.Difference.LineDifferences.Differences[index];
                left  = difference.Left;
                right = difference.Right;
                if (difference.Before != null)
                {
                    left  = Span.FromBounds(difference.Before.Left.Start, difference.Left.End);
                    right = Span.FromBounds(difference.Before.Right.Start, difference.Right.End);
                }

                if (delta < right.Length)
                {
                    line = this.Difference.RightBufferSnapshot.GetLineFromLineNumber(right.Start + delta);
                }
                else
                {
                    Debug.Assert(delta < left.Length);
                    line = this.Difference.LeftBufferSnapshot.GetLineFromLineNumber(left.Start + delta);
                }
            }

            return(line.Start);
        }
示例#16
0
        protected override void ResolveValueBinding(PropertyItem propertyItem)
        {
            var type = propertyItem.PropertyType;

            Editor.ItemsSourceType = type;

            if (type.BaseType == typeof(System.Array))
            {
                Editor.ItemType = type.GetElementType();
            }
            else
            {
                Editor.ItemType = ListUtilities.GetListItemType(type);
            }

            base.ResolveValueBinding(propertyItem);
        }
    private IList <PaymentOption> GetPaymentMethodList()
    {
        IList <PaymentOption> paymentMethodList = DataAccessContext.PaymentOptionRepository.GetAll(
            AdminUtilities.CurrentCulture, BoolFilter.ShowTrue);

        IList <PaymentOption> list = ListUtilities <PaymentOption> .CopyList(paymentMethodList);

        // *** away add current payment method object although it's not enable
        PaymentOption paymentOption = DataAccessContext.PaymentOptionRepository.GetOne(AdminUtilities.CurrentCulture, CurrentPaymentName);

        if (!paymentOption.IsEnabled)
        {
            list.Add(paymentOption);
        }

        return(list);
    }
示例#18
0
    private void cmdDelete_Click(object sender, EventArgs e)
    {
        CustomReportComponent part;
        int deleteIndex;

        part = getSelectedPart();
        if (part == null)
        {
            return;
        }

        _db.ORManager.Delete(part);

        deleteIndex = lstReportParts.SelectedIndex;
        lstReportParts.Items.Remove(lstReportParts.SelectedItem);

        lstReportParts.SelectedIndex = ListUtilities.GetItemIndexAfterDelete(lstReportParts.Items.Count, deleteIndex);
    }
示例#19
0
        protected override void ResolveValueBinding(PropertyItem propertyItem)
        {
            var type = propertyItem.PropertyType;

            Editor.ItemsSourceType = type;

            var icollection = propertyItem.PropertyType.GetInterfaces().FirstOrDefault(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(ICollection <>));

            if (icollection != null)
            {
                Editor.ItemType = icollection.GetGenericArguments()[0];
            }
            else
            {
                Editor.ItemType = ListUtilities.GetListItemType(type);
            }

            base.ResolveValueBinding(propertyItem);
        }
示例#20
0
        public IEnumerable <User> GetByIds(List <int> ids)
        {
            ids = ids.Distinct().ToList();
            var users = new List <User>();
            int page  = 0;

            do
            {
                List <int> batch = ListUtilities.GetPageItems(ids, 1000, page++);

                if (batch.Count > 0)
                {
                    users.AddRange(_dbContext.Query <User>().Where(u => u.Id.In(batch)));
                }
                else
                {
                    return(users);
                }
            } while (true);
        }
示例#21
0
        private object GenerateEditableKeyValuePair(object source)
        {
            var sourceType = source.GetType();

            if ((sourceType.GetGenericArguments() == null) || (sourceType.GetGenericArguments().GetLength(0) != 2))
            {
                return(null);
            }

            var propInfoKey   = sourceType.GetProperty("Key");
            var propInfoValue = sourceType.GetProperty("Value");

            if ((propInfoKey != null) && (propInfoValue != null))
            {
                return(ListUtilities.CreateEditableKeyValuePair(propInfoKey.GetValue(source, null)
                                                                , sourceType.GetGenericArguments()[0]
                                                                , propInfoValue.GetValue(source, null)
                                                                , sourceType.GetGenericArguments()[1]));
            }
            return(null);
        }
示例#22
0
        public void ListUtilitiesExtractBufferSuccess2()
        {
            var buffer = new[]
            {
                1, 2, 3, 5, 6
            };

            var result = new List <int>();

            ListUtilities.UseBuffer(result, buffer);

            Debug.Assert(result.Count == buffer.Length);

            for (int i = 0; i < buffer.Length; i++)
            {
                Debug.Assert(result[i] == buffer[i]);
            }

            var extractBuffer = ListUtilities.ExtractBuffer(result);

            Debug.Assert(buffer == extractBuffer);
        }
    private void FixedUpdate()
    {
        if (gameController.IsMoving())
        {
            _waitTimeRemaining -= Time.fixedDeltaTime;
        }

        if (_waitTimeRemaining < 0f)
        {
            // generate random platforms
            var effectiveMinPlatformWidth    = Mathf.Lerp(MinPlatformWidth, HardMinPlatformWidth, gameController.DifficultyScale / gameController.MaxDifficultyScale);
            var effectiveMaxPlatformWidth    = Mathf.Lerp(MaxPlatformWidth, HardMaxPlatformWidth, gameController.DifficultyScale / gameController.MaxDifficultyScale);
            var effectiveAllowedReactionTime = Mathf.Lerp(allowedReactionTimeSeconds, HardAllowedReactionTimeSeconds, gameController.DifficultyScale / gameController.MaxDifficultyScale);
            var platformWidth   = Random.Range(effectiveMinPlatformWidth, effectiveMaxPlatformWidth);
            var platformObject  = ListUtilities.TakeRandom(PlatformPrefabs);
            var platformYOffset = ListUtilities.TakeRandom(SpawnableYOffsets);
            SpawnPlatform(platformObject, platformWidth, platformYOffset);
            Debug.Log(string.Format("Effective Spawn Parameters: {0}, {1}, {2}", effectiveMinPlatformWidth, effectiveMaxPlatformWidth, effectiveAllowedReactionTime));
            Debug.Log(string.Format("Spawned a {0} width platform, have to wait {1}s before spawning the next one", platformWidth, platformWidth / Mathf.Abs(gameController.GlobalGameMoveSpeed)));
            _waitTimeRemaining = (platformWidth / Mathf.Abs(gameController.GlobalGameMoveSpeed)) + allowedReactionTimeSeconds;
        }
    }
示例#24
0
    /// <summary>Chooses a random behaver currently in the scene</summary>
    /// <param name="excludedBehavers">Behavers that should be excluded</param>
    /// <returns>The random behaver</returns>
    public static Behaver GetRandomInScene(List <Behaver> excludedBehavers)
    {
        // Get a list of possible selections.
        List <Behaver> includedBehavers =
            ListUtilities.Negation(ref SceneBehavers, ref excludedBehavers);

        // Are there any selections available?
        if (includedBehavers.Count > 0)
        {
            // Shuffle the possible behavers and return the first index.
            ListUtilities.Shuffle(ref includedBehavers);
            return(includedBehavers[0]);
        }
        else
        {
            // Return null and warn if no behavers were found.
#if DEBUG
            Debug.LogWarning("Attempted to get a random behaver, but none were available.");
#endif
            return(null);
        }
    }
 public void OnItemSourceChanged(IEnumerable oldValue, IEnumerable newValue)
 {
     if (newValue != null)
     {
         var dict = newValue as IDictionary;
         if (dict != null)
         {
             // A Dictionary contains KeyValuePair that can't be edited.
             // We need to Add EditableKeyValuePairs from DictionaryEntries.
             foreach (DictionaryEntry item in dict)
             {
                 var keyType = (item.Key != null)
                   ? item.Key.GetType()
                   : (dict.GetType().GetGenericArguments().Count() > 0) ? dict.GetType().GetGenericArguments()[0] : typeof(object);
                 var valueType = (item.Value != null)
                   ? item.Value.GetType()
                   : (dict.GetType().GetGenericArguments().Count() > 1) ? dict.GetType().GetGenericArguments()[1] : typeof(object);
                 var editableKeyValuePair = ListUtilities.CreateEditableKeyValuePair(item.Key
                                                                                     , keyType
                                                                                     , item.Value
                                                                                     , valueType);
                 this.Items.Add(editableKeyValuePair);
             }
         }
         else
         {
             foreach (var item in newValue)
             {
                 if (item != null)
                 {
                     Items.Add(item);
                 }
             }
         }
     }
 }
示例#26
0
    private void PopulateControls()
    {
        SetPositionParameter();
        //_rootID = DataAccessContext.Configurations.GetValue( _rootMenu );

        IList <ContentMenuItem> originalList = DataAccessContext.ContentMenuItemRepository.GetByContentMenuID(
            StoreContext.Culture, _rootID, "SortOrder", BoolFilter.ShowTrue);
        IList <ContentMenuItem> list = ListUtilities <ContentMenuItem> .CopyListDeep(originalList);

        if (_menuType == "default")
        {
            foreach (ContentMenuItem item in list)
            {
                if (!item.LinksToContent())
                {
                    item.Name = item.Name + "...";
                }
            }

            uxList.Visible    = true;
            uxList.DataSource = list;
            uxList.DataBind();
        }
    }
示例#27
0
        internal static ITypeEditor CreateDefaultEditor(Type propertyType, TypeConverter typeConverter, PropertyItem propertyItem)
        {
            ITypeEditor editor = null;

            var context = new EditorTypeDescriptorContext(null, propertyItem.Instance, propertyItem.PropertyDescriptor);

            if ((typeConverter != null) &&
                typeConverter.GetStandardValuesSupported(context) &&
                typeConverter.GetStandardValuesExclusive(context) &&
                (propertyType != typeof(bool)) && (propertyType != typeof(bool?)))   //Bool type always have a BooleanConverter with standardValues : True/False.
            {
                var items = typeConverter.GetStandardValues(context);
                editor = new SourceComboBoxEditor(items, typeConverter);
            }
            else if (propertyType == typeof(string))
            {
                editor = new TextBoxEditor();
            }
            else if (propertyType == typeof(bool) || propertyType == typeof(bool?))
            {
                editor = new CheckBoxEditor();
            }
            else if (propertyType == typeof(decimal) || propertyType == typeof(decimal?))
            {
                editor = new DecimalUpDownEditor();
            }
            else if (propertyType == typeof(double) || propertyType == typeof(double?))
            {
                editor = new DoubleUpDownEditor();
            }
            else if (propertyType == typeof(int) || propertyType == typeof(int?))
            {
                editor = new IntegerUpDownEditor();
            }
            else if (propertyType == typeof(short) || propertyType == typeof(short?))
            {
                editor = new ShortUpDownEditor();
            }
            else if (propertyType == typeof(long) || propertyType == typeof(long?))
            {
                editor = new LongUpDownEditor();
            }
            else if (propertyType == typeof(float) || propertyType == typeof(float?))
            {
                editor = new SingleUpDownEditor();
            }
            else if (propertyType == typeof(byte) || propertyType == typeof(byte?))
            {
                editor = new ByteUpDownEditor();
            }
            else if (propertyType == typeof(sbyte) || propertyType == typeof(sbyte?))
            {
                editor = new SByteUpDownEditor();
            }
            else if (propertyType == typeof(uint) || propertyType == typeof(uint?))
            {
                editor = new UIntegerUpDownEditor();
            }
            else if (propertyType == typeof(ulong) || propertyType == typeof(ulong?))
            {
                editor = new ULongUpDownEditor();
            }
            else if (propertyType == typeof(ushort) || propertyType == typeof(ushort?))
            {
                editor = new UShortUpDownEditor();
            }
            else if (propertyType == typeof(DateTime) || propertyType == typeof(DateTime?))
            {
                editor = new DateTimeUpDownEditor();
            }
            else if ((propertyType == typeof(Color)) || (propertyType == typeof(Color?)))
            {
                editor = new ColorEditor();
            }
            else if (propertyType.IsEnum)
            {
                editor = new EnumComboBoxEditor();
            }
            else if (propertyType == typeof(TimeSpan) || propertyType == typeof(TimeSpan?))
            {
                editor = new TimeSpanUpDownEditor();
            }
            else if (propertyType == typeof(FontFamily) || propertyType == typeof(FontWeight) || propertyType == typeof(FontStyle) || propertyType == typeof(FontStretch))
            {
                editor = new FontComboBoxEditor();
            }
            else if (propertyType == typeof(Guid) || propertyType == typeof(Guid?))
            {
                editor = new MaskedTextBoxEditor()
                {
                    ValueDataType = propertyType, Mask = "AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA"
                }
            }
            ;
            else if (propertyType == typeof(char) || propertyType == typeof(char?))
            {
                editor = new MaskedTextBoxEditor()
                {
                    ValueDataType = propertyType, Mask = "&"
                }
            }
            ;
            else if (propertyType == typeof(object))
            {
                // If any type of object is possible in the property, default to the TextBoxEditor.
                // Useful in some case (e.g., Button.Content).
                // Can be reconsidered but was the legacy behavior on the PropertyGrid.
                editor = new TextBoxEditor();
            }
            else
            {
                var listType = ListUtilities.GetListItemType(propertyType);

                // A List of T
                if (listType != null)
                {
                    if (!listType.IsPrimitive && !listType.Equals(typeof(String)) && !listType.IsEnum)
                    {
                        editor = new Xceed.Wpf.Toolkit.PropertyGrid.Editors.CollectionEditor();
                    }
                    else
                    {
                        editor = new Xceed.Wpf.Toolkit.PropertyGrid.Editors.PrimitiveTypeCollectionEditor();
                    }
                }
                else
                {
                    var dictionaryType = ListUtilities.GetDictionaryItemsType(propertyType);
                    var collectionType = ListUtilities.GetCollectionItemType(propertyType);
                    // A dictionary of T or a Collection of T or an ICollection
                    if ((dictionaryType != null) || (collectionType != null) || typeof(ICollection).IsAssignableFrom(propertyType))
                    {
                        editor = new Xceed.Wpf.Toolkit.PropertyGrid.Editors.CollectionEditor();
                    }
                    else
                    {
                        // If the type is not supported, check if there is a converter that supports
                        // string conversion to the object type. Use TextBox in theses cases.
                        // Otherwise, return a TextBlock editor since no valid editor exists.
                        editor = (typeConverter != null && typeConverter.CanConvertFrom(typeof(string)))
                          ? (ITypeEditor) new TextBoxEditor()
                          : (ITypeEditor) new TextBlockEditor();
                    }
                }
            }

            return(editor);
        }
示例#28
0
        public void proxycheckStart()
        {
            Thread.CurrentThread.IsBackground = true;
            lstProxyThread.Add(Thread.CurrentThread);
            lstProxyThread = lstProxyThread.Distinct().ToList();
            Proxystatus    = DemoStagramPro.ClGlobul.ProxyList.Count;

            LoggerProxy("[ " + DateTime.Now + " ] => [ Process For Proxy Checking ]");

            int numberOfThreads = DemoStagramPro.ClGlobul.ProxyCheckNoOfThread;

            List <List <string> > list_Proxy = new List <List <string> >();

            list_Proxy = ListUtilities.Split(DemoStagramPro.ClGlobul.ProxyList, numberOfThreads);


            #region Modified Proxy Check
            ThreadPool.SetMaxThreads(50, 50);
            int counter = 0;
            try
            {
                foreach (string itemProxy in DemoStagramPro.ClGlobul.ProxyList)
                {
                    try
                    {
                        if (proxyStop)
                        {
                            return;
                        }
                        ThreadPool.QueueUserWorkItem(new WaitCallback(getpageSourceFromProxy), new object[] { itemProxy });
                    }
                    catch { }
                }
            }
            catch (Exception ex)
            { }
            #endregion

            #region Previous Proxy Check
            //foreach (List<string> list_Proxy_ in list_Proxy)
            //{
            //    foreach (string list_Proxy_Item in list_Proxy_)
            //    {
            //        lock (lockr_ThreadController)
            //        {
            //            try
            //            {
            //                if (count_ThreadController >= list_Proxy_.Count)
            //                {
            //                    Monitor.Wait(lockr_ThreadController);
            //                }

            //                string Proxy_Item = list_Proxy_Item.Remove(list_Proxy_Item.IndexOf(':'));

            //                Thread likerThread = new Thread(getpageSourceFromProxy);
            //                likerThread.Name = "workerThread_Liker_" + Proxy_Item;
            //                likerThread.IsBackground = true;

            //                likerThread.Start(new object[] { list_Proxy_Item });

            //                count_ThreadController++;
            //            }
            //            catch (Exception ex)
            //            {

            //            }
            //        }
            //    }
            //}
            #endregion
        }
示例#29
0
        internal static ITypeEditor CreateDefaultEditor(Type propertyType, TypeConverter typeConverter)
        {
            ITypeEditor editor = null;

            if (propertyType == typeof(string))
            {
                editor = new TextBoxEditor();
            }
            else if (propertyType == typeof(bool) || propertyType == typeof(bool?))
            {
                editor = new CheckBoxEditor();
            }
            else if (propertyType == typeof(decimal) || propertyType == typeof(decimal?))
            {
                editor = new DecimalUpDownEditor();
            }
            else if (propertyType == typeof(double) || propertyType == typeof(double?))
            {
                editor = new DoubleUpDownEditor();
            }
            else if (propertyType == typeof(int) || propertyType == typeof(int?))
            {
                editor = new IntegerUpDownEditor();
            }
            else if (propertyType == typeof(short) || propertyType == typeof(short?))
            {
                editor = new ShortUpDownEditor();
            }
            else if (propertyType == typeof(long) || propertyType == typeof(long?))
            {
                editor = new LongUpDownEditor();
            }
            else if (propertyType == typeof(float) || propertyType == typeof(float?))
            {
                editor = new SingleUpDownEditor();
            }
            else if (propertyType == typeof(byte) || propertyType == typeof(byte?))
            {
                editor = new ByteUpDownEditor();
            }
            else if (propertyType == typeof(sbyte) || propertyType == typeof(sbyte?))
            {
                editor = new SByteUpDownEditor();
            }
            else if (propertyType == typeof(uint) || propertyType == typeof(uint?))
            {
                editor = new UIntegerUpDownEditor();
            }
            else if (propertyType == typeof(ulong) || propertyType == typeof(ulong?))
            {
                editor = new ULongUpDownEditor();
            }
            else if (propertyType == typeof(ushort) || propertyType == typeof(ushort?))
            {
                editor = new UShortUpDownEditor();
            }
            else if (propertyType == typeof(DateTime) || propertyType == typeof(DateTime?))
            {
                editor = new DateTimeUpDownEditor();
            }
            else if ((propertyType == typeof(Color)))
            {
                editor = new ColorEditor();
            }
            else if (propertyType.IsEnum)
            {
                editor = new EnumComboBoxEditor();
            }
            else if (propertyType == typeof(TimeSpan) || propertyType == typeof(TimeSpan?))
            {
                editor = new TimeSpanUpDownEditor();
            }
            else if (propertyType == typeof(FontFamily) || propertyType == typeof(FontWeight) || propertyType == typeof(FontStyle) || propertyType == typeof(FontStretch))
            {
                editor = new FontComboBoxEditor();
            }
            else if (propertyType == typeof(Guid) || propertyType == typeof(Guid?))
            {
                editor = new MaskedTextBoxEditor()
                {
                    ValueDataType = propertyType, Mask = "AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA"
                }
            }
            ;
            else if (propertyType == typeof(char) || propertyType == typeof(char?))
            {
                editor = new MaskedTextBoxEditor()
                {
                    ValueDataType = propertyType, Mask = "&"
                }
            }
            ;
            else if (propertyType == typeof(object))
            {
                // If any type of object is possible in the property, default to the TextBoxEditor.
                // Useful in some case (e.g., Button.Content).
                // Can be reconsidered but was the legacy behavior on the PropertyGrid.
                editor = new TextBoxEditor();
            }
            else
            {
                Type listType = ListUtilities.GetListItemType(propertyType);

                if (listType != null)
                {
                    //Comment by Charley at 2014/7/23
                    //if (!listType.IsPrimitive && !listType.Equals(typeof(String)) && !listType.IsEnum)
                    //    editor = new CollectionEditor();
                    //else
                    //    editor = new PrimitiveTypeCollectionEditor();
                }
                else
                {
                    // If the type is not supported, check if there is a converter that supports
                    // string conversion to the object type. Use TextBox in theses cases.
                    // Otherwise, return a TextBlock editor since no valid editor exists.
                    editor = (typeConverter != null && typeConverter.CanConvertFrom(typeof(string)))
                      ? (ITypeEditor) new TextBoxEditor()
                      : (ITypeEditor) new TextBlockEditor();
                }
            }

            return(editor);
        }
        protected override void ResolveValueBinding(PropertyItem propertyItem)
        {
            var type = propertyItem.PropertyType;

            Editor.ItemsSourceType = type;

            if (propertyItem.DescriptorDefinition != null &&
                propertyItem.DescriptorDefinition.NewItemTypes != null &&
                propertyItem.DescriptorDefinition.NewItemTypes.Count > 0)
            {
                Editor.NewItemTypes = propertyItem.DescriptorDefinition.NewItemTypes;
            }
            else if (type.BaseType == typeof(System.Array))
            {
                Editor.NewItemTypes = new List <Type>()
                {
                    type.GetElementType()
                };
            }
            else
            {
                if ((propertyItem.DescriptorDefinition != null) &&
                    (propertyItem.DescriptorDefinition.NewItemTypes != null) &&
                    (propertyItem.DescriptorDefinition.NewItemTypes.Count > 0))
                {
                    Editor.NewItemTypes = propertyItem.DescriptorDefinition.NewItemTypes;
                }
                else
                {
                    //Check if we have a Dictionary
                    var dictionaryTypes = ListUtilities.GetDictionaryItemsType(type);
                    if ((dictionaryTypes != null) && (dictionaryTypes.Length == 2))
                    {
                        // A Dictionary contains KeyValuePair that can't be edited.
                        // We need to create EditableKeyValuePairs.
                        // Create a EditableKeyValuePair< TKey, TValue> type from dictionary generic arguments type
                        var editableKeyValuePairType = ListUtilities.CreateEditableKeyValuePairType(dictionaryTypes[0], dictionaryTypes[1]);
                        Editor.NewItemTypes = new List <Type>()
                        {
                            editableKeyValuePairType
                        };
                    }
                    else
                    {
                        //Check if we have a list
                        var listType = ListUtilities.GetListItemType(type);
                        if (listType != null)
                        {
                            Editor.NewItemTypes = new List <Type>()
                            {
                                listType
                            };
                        }
                        else
                        {
                            //Check if we have a Collection of T
                            var colType = ListUtilities.GetCollectionItemType(type);
                            if (colType != null)
                            {
                                Editor.NewItemTypes = new List <Type>()
                                {
                                    colType
                                };
                            }
                        }
                    }
                }
            }

            base.ResolveValueBinding(propertyItem);
        }