ApplicabilityScopeDesign.cs :  » Development » devAdvantage » AnticipatingMinds » Genesis » KnowledgeManagement » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Development » devAdvantage 
devAdvantage » AnticipatingMinds » Genesis » KnowledgeManagement » ApplicabilityScopeDesign.cs
using System;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.Drawing.Design;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Collections;
using System.ComponentModel.Design;
using AnticipatingMinds.Genesis.CodeDOM;
using AnticipatingMinds.PlatformServices.Globalization;

namespace AnticipatingMinds.Genesis.KnowledgeManagement{
  public class StringCollectionTypeConverter : TypeConverter
  {
    public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
    {
      if(destinationType == typeof(string))
      {
        StringCollection stringCollection = value as StringCollection;
        if(stringCollection.Count == 0)
          return "(any)";
        
        int itemsProcessed = 0;
        string displayValue = "";
        foreach(string stringValue in stringCollection)
        {
          if(itemsProcessed != 0)
            displayValue += ",";
          
          displayValue += stringValue;
          itemsProcessed++;
          if(itemsProcessed == 3)
          {
            displayValue += "...";
            return displayValue;
          }
        }

        return displayValue;
      }
      return base.ConvertTo (context, culture, value, destinationType);
    }
  }

  public class RegExpTypeConverter : TypeConverter
  {
    public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
    {
      if(sourceType == typeof(string))
        return true;
      else
        return false;
    }

    public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
    {
      if(destinationType == typeof(string))
        return true;
      else
        return false;
    }


    public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
    {
      if(value.ToString() == "(any)" || value.ToString() == string.Empty)
        return null;
      else
        return new Regex(value.ToString());
    }

    public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
    {
      if(destinationType == typeof(string))
      {
        if(value == null)
          return "(any)";
        
        return (value as Regex).ToString();
      }

      return base.ConvertTo (context, culture, value, destinationType);
    }
  }


  public class MethodParameterApplicabilityScopeCollectionConverter : CollectionConverter
  {
    public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
    {
      if(destinationType == typeof(string) && value == null)
        return "(any)";
      else
        return base.ConvertTo (context, culture, value, destinationType);
    }
  }

  public class MethodParameterApplicabilityScopeCollectionEditor : CollectionEditor
  {
    public MethodParameterApplicabilityScopeCollectionEditor():base(typeof(MethodParameterApplicabilityScopeCollection))
    {
    }
    protected override object CreateInstance(System.Type itemType)
    {
      return new MethodParameterApplicabilityScope();
    }

    protected override System.Type CreateCollectionItemType()
    {
      return typeof ( MethodParameterApplicabilityScope );
    }

    protected override object SetItems(object editValue, object[] value)
    {
      if(editValue == null)
        editValue = new MethodParameterApplicabilityScopeCollection();

      return base.SetItems (editValue, value);
    }
    
    protected override object[] GetItems(object editValue)
    {
      return base.GetItems (editValue);
    }

    public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
    {
      object retValue = base.EditValue (context, provider, value);
      if(retValue == null || (retValue as MethodParameterApplicabilityScopeCollection).Count == 0)
      {
        if(MessageBox.Show(messagesResourceManager.GetString("AnyOrNoArgumentsQuestion"),messagesResourceManager.GetString("MethodArguments"),MessageBoxButtons.YesNo,MessageBoxIcon.Question) == DialogResult.Yes)
          return new MethodParameterApplicabilityScopeCollection();
        else
          return null;
      }
      else
      {
        return retValue;
      }
    }

    static AssemblyResourceManager messagesResourceManager = AssemblyResourceManager.GetInstance("AnticipatingMinds.Genesis.KnowledgeManagement.Messages");

  }

  public class StringCollectionEditor : CollectionEditor
  {
    public StringCollectionEditor():base(typeof(StringCollection))
    {
    }
    protected override object CreateInstance(System.Type 
      itemType)
    {
      return "" ;
    }

    protected override System.Type CreateCollectionItemType
      ()
    {
      return typeof ( string );
    }

    public override string ToString()
    {
      return "";
    }

  }

  public class ApplicabilityScopeEditor : UITypeEditor
  {
    [Flags]
    public enum AvailableScopeTypes
    {
      Type = 2,
      TypeReference = 4,
      TypeMember = 8,
      VariableDeclaration = 16,
      Location = 32
    }

    private AvailableScopeTypes scopeTypes = 0; 
    public ApplicabilityScopeEditor(AvailableScopeTypes scopeTypes)
    {
      this.scopeTypes = scopeTypes;
    }
    public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
    {
      return UITypeEditorEditStyle.Modal;
    }

    public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
    {

      ApplicabilityScopeProperties scopeProperties = new ApplicabilityScopeProperties();
      scopeProperties.AvailableScopes.Clear();
      if((scopeTypes & AvailableScopeTypes.Type) != 0)
      {
        scopeProperties.AvailableScopes.Add(new TypeApplicabilityScope());
        scopeProperties.AvailableScopes.Add(new ClassApplicabilityScope());
        scopeProperties.AvailableScopes.Add(new InterfaceApplicabilityScope());
        scopeProperties.AvailableScopes.Add(new StructApplicabilityScope());
        scopeProperties.AvailableScopes.Add(new EnumApplicabilityScope());
        scopeProperties.AvailableScopes.Add(new DelegateApplicabilityScope());
      }
      if((scopeTypes & AvailableScopeTypes.TypeReference) != 0)
      {
        scopeProperties.AvailableScopes.Add(new TypeReferenceApplicabilityScope());
      }


      if((scopeTypes & AvailableScopeTypes.TypeMember) != 0)
      {
        scopeProperties.AvailableScopes.Add(new FieldApplicabilityScope());
        scopeProperties.AvailableScopes.Add(new PropertyApplicabilityScope());
        scopeProperties.AvailableScopes.Add(new EventApplicabilityScope());
        scopeProperties.AvailableScopes.Add(new MethodApplicabilityScope());
      }
      
      if((scopeTypes & AvailableScopeTypes.VariableDeclaration) != 0)
        scopeProperties.AvailableScopes.Add(new VariableApplicabilityScope());

      if((scopeTypes & AvailableScopeTypes.Location) != 0)
        scopeProperties.AvailableScopes.Add(new FileApplicabilityScope());

      if(value != null)
        scopeProperties.SelectedScope = (value as ICloneable).Clone() as ApplicabilityScope;

      if(scopeProperties.ShowDialog() == DialogResult.OK)
        return scopeProperties.SelectedScope;
      else
        return value;
    }
  }

  public class TypeApplicabilityScopeEditor : ApplicabilityScopeEditor
  {
    public TypeApplicabilityScopeEditor():base(ApplicabilityScopeEditor.AvailableScopeTypes.Type)
    {
    }

  }

  public class TypeReferenceScopeEditor : ApplicabilityScopeEditor
  {
    public TypeReferenceScopeEditor():base(ApplicabilityScopeEditor.AvailableScopeTypes.TypeReference)
    {
    }

  }

  public class ApplicabilityScopeTypeConverter : ExpandableObjectConverter
  {
    public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
    {
      if(destinationType == typeof(string))
      {
        if(value == null)
          return "(any)";
        return (value as ApplicabilityScope).Description;
      }

      return base.ConvertTo (context, culture, value, destinationType);
    }

  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.