Пример #1
0
        public static void GenerateClass(ClassOptions classOptions, Manager manager)
        {
            var fields = manager.GetCrmEntityFields(classOptions.InternalName);

            if (fields.NotEmpty())
            {
                var stringBuilder = new StringBuilder();

                stringBuilder.Append($@"using System;
using System.Collections.Generic;
using System.Linq;
using Fluent.Crm;

namespace {classOptions.Namespace}
{{
        [CrmEntity(""{classOptions.InternalName}"")]
        public class {classOptions.ClassName}
        {{
");

                foreach (var field in fields)
                {
                    stringBuilder.Append(GetFieldProperty(field));
                }

                stringBuilder.Append($@"
        }}
}}");

                var filepath = GetFilepath(classOptions);
                File.WriteAllText(filepath, stringBuilder.ToString());
                Process.Start(filepath);
            }
        }
Пример #2
0
        public static void GenerateConstants(ClassOptions classOptions, Manager manager)
        {
            var fields = manager.GetCrmEntityFields(classOptions.InternalName);

            if (fields.NotEmpty())
            {
                var stringBuilder = new StringBuilder();

                stringBuilder.Append($@"using System;

namespace {classOptions.Namespace}
{{
        public class {classOptions.ClassName}
        {{
            public const string LogicalName = ""{classOptions.InternalName}"";
            public const string Id = ""{classOptions.InternalName}id"";");

                foreach (var field in fields)
                {
                    stringBuilder.Append(GetFieldConstant(field));
                }

                stringBuilder.Append($@"
        }}
}}");

                var filepath = GetFilepath(classOptions);
                File.WriteAllText(filepath, stringBuilder.ToString());
                Process.Start(filepath);
            }
        }
Пример #3
0
        public override void ReadValue(EndianReader reader)
        {
            IsEnabled = true;

            try
            {
                reader.Seek(ValueAddress, SeekOrigin.Begin);

                referenceValue = new TagReference(item.Module, reader);

                if (referenceValue.TagId != -1 && referenceValue.Tag == null)
                {
                    SelectedClass = ClassOptions[0];
                    SelectedItem  = TagOptions[0];
                }
                else
                {
                    SelectedClass = ClassOptions.FirstOrDefault(i => i.Label == referenceValue.Tag?.ClassName);
                    SelectedItem  = TagOptions.FirstOrDefault(i => i.Context != null && i.Context == referenceValue.Tag);
                }

                IsDirty = false;
            }
            catch { IsEnabled = false; }
        }
Пример #4
0
        Generate(SourceOptions options = SourceOptions.None, ClassOptions classOptions = ClassOptions.None)
        {
            ClassGenerator classes = new ClassGenerator()
            {
                Name = Name
            };

            // Class with many interfaces
            if (options.HasFlag(SourceOptions.ImplementsInterfaces) &&
                options.HasFlag(SourceOptions.BaseListMany))
            {
                classes.Interface1Name = Interface1Name;
                classes.Interface2Name = Interface2Name;
                classes.Interface3Name = Interface3Name;
                return(new KeyValuePair <string, IReadOnlyDictionary <string, string> >(
                           classes.ClassWithManyInterfaces, classes.ClassWithManyInterfacesAttributes));
            }

            // Class with interface
            if (options.HasFlag(SourceOptions.ImplementsInterfaces))
            {
                classes.Interface1Name = Interface1Name;
                return(new KeyValuePair <string, IReadOnlyDictionary <string, string> >(
                           classes.ClassWith1Interface, classes.ClassWith1InterfaceAttributes));
            }

            // Class with base class
            if (options.HasFlag(SourceOptions.HasInheritance))
            {
                classes.BaseClassName = BaseName;
                return(new KeyValuePair <string, IReadOnlyDictionary <string, string> >(
                           classes.ClassWithBaseClass, classes.ClassWithBaseClassAttributes));
            }

            // Empty elements
            if (options.HasFlag(SourceOptions.EmptyElements))
            {
                return(new KeyValuePair <string, IReadOnlyDictionary <string, string> >(
                           classes.VerySimpleClassWithEmptyMethods, classes.VerySimpleClassWithEmptyMethodsAttributes));
            }

            // Namespace
            if (options.HasFlag(SourceOptions.HasNamespace))
            {
                classes.NamespaceName = NamespaceName;
                return(new KeyValuePair <string, IReadOnlyDictionary <string, string> >(
                           classes.VerySimpleClassInNamespace, classes.VerySimpleClassInNamespaceAttributes));
            }

            // Simple class
            if (classOptions.HasFlag(ClassOptions.HasContent))
            {
                return(new KeyValuePair <string, IReadOnlyDictionary <string, string> >(
                           classes.SimpleClass, classes.SimpleClassAttributes));
            }
            return(new KeyValuePair <string, IReadOnlyDictionary <string, string> >(
                       classes.VerySimpleClass, classes.VerySimpleClassAttributes));
        }
Пример #5
0
        public void GenerateCSharpClass(CrmEntity crmEntity)
        {
            if (string.IsNullOrWhiteSpace(CacheManager.Namespace))
            {
                CacheManager.Namespace = ControlMod.InputBox("", "Please enter a namespace", CacheManager.Namespace);
            }

            Manager.GenerateCSharpClass(ClassOptions.FromCrmEntity(crmEntity, CacheManager.Namespace));
        }
Пример #6
0
        public void SavedCalledNames(ClassOptions options)
        {
            if (CalledNames is null || CalledNames.Count < 1)
            {
                return;
            }

            var contents = CalledNames.Select(s => s.ToString(isShowMask: false));

            var filePath = GlobalDefaults.GetCalledNamesConfigPath(options);

            filePath.WriteAllLines(contents);
        }
Пример #7
0
 public void OpenClass(string name, ClassOptions options = ClassOptions.None)
 {
     if (name == null)
         throw new PBException("class name is null, can't open class");
     string access = GetAccessString(options);
     if (access != null)
         _tw.Write("{0} ", access);
     if ((options & ClassOptions.Static) == ClassOptions.Static)
         _tw.Write("static ");
     if ((options & ClassOptions.Partial) == ClassOptions.Partial)
         _tw.Write("partial ");
     _tw.WriteLine("class {0}", name);
     _tw.WriteLine("{");
 }
Пример #8
0
        public List <string> GetData()
        {
            List <String> Data = new List <String> {
            };

            //checks for all checked blocks
            for (int i = 0; i < ClassOptions.Items.Count; i++)
            {
                if (ClassOptions.GetItemChecked(i))
                {
                    //This puts the selected checkbox strings into the list
                    Data.Add(ClassOptions.GetItemText(ClassOptions.Items[i]));
                }
            }
            return(Data);
        }
Пример #9
0
        public override void ReadValue(EndianReader reader)
        {
            IsBusy    = true;
            IsEnabled = true;

            try
            {
                reader.Seek(ValueAddress, SeekOrigin.Begin);

                referenceValue = new TagReference(context.Cache, reader);
                SelectedClass  = ClassOptions.FirstOrDefault(i => i.Label == referenceValue.Tag?.ClassName);
                SelectedItem   = TagOptions.FirstOrDefault(i => i.Context != null && i.Context == referenceValue.Tag);

                IsDirty = false;
            }
            catch { IsEnabled = false; }

            IsBusy = false;
        }
Пример #10
0
        private void GenerateCSharpConstants()
        {
            if (lstEntities.SelectedItems.Count > 0)
            {
                Wait();

                if (string.IsNullOrWhiteSpace(CacheManager.Namespace))
                {
                    CacheManager.Namespace = ControlMod.InputBox("", "Please enter a namespace", CacheManager.Namespace);
                }

                foreach (object item in lstEntities.SelectedItems)
                {
                    _crmManager.GenerateCSharpConstants(ClassOptions.FromCrmEntity((CrmEntity)item, CacheManager.Namespace));
                }

                Wait(false);
            }
        }
        public CalledNameWindow(MainWindowViewModel viewModel, ClassOptions options)
        {
            InitializeComponent();

            _timer  = new DispatcherTimer();
            _random = new Random(unchecked ((int)DateTime.Now.Ticks));

#pragma warning disable CS8629 // 可为 null 的值类型可为 null。
            tbxName.FontSize = (double)viewModel?.Settings?.Window?.StrikingFontSize;
#pragma warning restore CS8629 // 可为 null 的值类型可为 null。

            viewModel.CalledNames = viewModel.GetCalledNames(options);

            _viewModel = viewModel;
            _options   = options;

            _timer.Tick    += new EventHandler(_timer_Tick);
            _timer.Interval = TimeSpan.FromMilliseconds(100);
            _timer.Start();
        }
Пример #12
0
        public List <StudentOptions> GetCalledNames(ClassOptions options)
        {
            var list = new List <StudentOptions>();

            var filePath = GlobalDefaults.GetCalledNamesConfigPath(options);
            var lines    = filePath.ReadAllLines();

            if (lines.Length > 0)
            {
                foreach (var line in lines)
                {
                    var student = StudentOptions.FromString(line);
                    if (student is not null)
                    {
                        list.Add(student);
                    }
                }
            }

            return(list);
        }
Пример #13
0
        public void OpenClass(string name, ClassOptions options = ClassOptions.None)
        {
            if (name == null)
            {
                throw new PBException("class name is null, can't open class");
            }
            string access = GetAccessString(options);

            if (access != null)
            {
                _tw.Write("{0} ", access);
            }
            if ((options & ClassOptions.Static) == ClassOptions.Static)
            {
                _tw.Write("static ");
            }
            if ((options & ClassOptions.Partial) == ClassOptions.Partial)
            {
                _tw.Write("partial ");
            }
            _tw.WriteLine("class {0}", name);
            _tw.WriteLine("{");
        }
Пример #14
0
        private static string GetAccessString(ClassOptions options)
        {
            ClassOptions access = options & ClassOptions.AccessType;

            switch (access)
            {
            case ClassOptions.Public:
                return("public");

            case ClassOptions.Private:
                return("private");

            case ClassOptions.Protected:
                return("protected");

            case ClassOptions.Internal:
                return("internal");

            case ClassOptions.ProtectedInternal:
                return("protected internal");
            }
            return(null);
        }
Пример #15
0
        public NamespaceComposer AddClass(ClassOptions options)
        {
            if (!IsAtRoot())
            {
                throw new Exception("The namespace must be selected (which is root to the composer) to add a class to it.");
            }

            var template = new CreateClass()
            {
                Options = options
            };
            var code     = template.TransformText();
            var cu       = SyntaxFactory.ParseCompilationUnit(code).NormalizeWhitespace();
            var newClass = cu.DescendantNodes().OfType <ClassDeclarationSyntax>().First();

            var @namespace = CurrentNode as NamespaceDeclarationSyntax;

            @namespace = @namespace.AddMembers(newClass);

            Replace(CurrentNode, @namespace, null);

            return(this);
        }
Пример #16
0
        /// <summary>
        /// Generates the appropriate class given some options.
        /// </summary>
        /// <param name="options">The options.</param>
        /// <param name="classOptions">The options for classes.</param>
        /// <returns>
        /// A <see cref="KeyValuePair"/> where the first element is the source 
        /// string and the second element is the set of attributes.
        /// </returns>
        /// 
        /// TODO: Abstract with a wrapper type wrapping around KeyValuePair.
        public static KeyValuePair<string, IReadOnlyDictionary<string, string>> Generate(SourceOptions options = SourceOptions.None, ClassOptions classOptions = ClassOptions.None)
        {
            ClassGenerator classes = new ClassGenerator()
            {
                Name = Name
            };

            // Class with many interfaces
            if (options.HasFlag(SourceOptions.ImplementsInterfaces) &&
                options.HasFlag(SourceOptions.BaseListMany))
            {
                classes.Interface1Name = Interface1Name;
                classes.Interface2Name = Interface2Name;
                classes.Interface3Name = Interface3Name;
                return new KeyValuePair<string, IReadOnlyDictionary<string, string>>(
                    classes.ClassWithManyInterfaces, classes.ClassWithManyInterfacesAttributes);
            }

            // Class with interface
            if (options.HasFlag(SourceOptions.ImplementsInterfaces))
            {
                classes.Interface1Name = Interface1Name;
                return new KeyValuePair<string, IReadOnlyDictionary<string, string>>(
                    classes.ClassWith1Interface, classes.ClassWith1InterfaceAttributes);
            }

            // Class with base class
            if (options.HasFlag(SourceOptions.HasInheritance))
            {
                classes.BaseClassName = BaseName;
                return new KeyValuePair<string, IReadOnlyDictionary<string, string>>(
                    classes.ClassWithBaseClass, classes.ClassWithBaseClassAttributes);
            }

            // Empty elements
            if (options.HasFlag(SourceOptions.EmptyElements))
            {
                return new KeyValuePair<string, IReadOnlyDictionary<string, string>>(
                    classes.VerySimpleClassWithEmptyMethods, classes.VerySimpleClassWithEmptyMethodsAttributes);
            }

            // Namespace
            if (options.HasFlag(SourceOptions.HasNamespace))
            {
                classes.NamespaceName = NamespaceName;
                return new KeyValuePair<string, IReadOnlyDictionary<string, string>>(
                    classes.VerySimpleClassInNamespace, classes.VerySimpleClassInNamespaceAttributes);
            }

            // Simple class
            if (classOptions.HasFlag(ClassOptions.HasContent))
            {
                return new KeyValuePair<string, IReadOnlyDictionary<string, string>>(
                classes.SimpleClass, classes.SimpleClassAttributes);
            }
            return new KeyValuePair<string, IReadOnlyDictionary<string, string>>(
                classes.VerySimpleClass, classes.VerySimpleClassAttributes);
        }
Пример #17
0
 public void GenerateCSharpConstants(ClassOptions classOptions)
 {
     ClassGenerator.GenerateConstants(classOptions, this);
 }
Пример #18
0
 private static string GetFilepath(ClassOptions classOptions)
 {
     return(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), $@"{classOptions.ClassName}.cs"));
 }
Пример #19
0
 private static string GetAccessString(ClassOptions options)
 {
     ClassOptions access = options & ClassOptions.AccessType;
     switch (access)
     {
         case ClassOptions.Public:
             return "public";
         case ClassOptions.Private:
             return "private";
         case ClassOptions.Protected:
             return "protected";
         case ClassOptions.Internal:
             return "internal";
         case ClassOptions.ProtectedInternal:
             return "protected internal";
     }
     return null;
 }
Пример #20
0
 public CastrClass(TExistingClass existingClass,
                   ClassOptions classOptions)
 {
     _existingClass = existingClass;
     _classOptions  = classOptions;
 }