Пример #1
0
        private void Refresh()
        {
            if (!CheckCanExecuteCondition())
            {
                return;
            }

            base.SimpleWork(() =>
            {
                try
                {
                    using (var memsStream = new MemoryStream())
                    {
                        SharedMethods.CompileTable(this.SourceElement, _compilerInfos, memsStream);
                        memsStream.Seek(0, SeekOrigin.Begin);
                        return(Encoding.ASCII.GetString(memsStream.ToArray()));
                    }
                }
                catch (Exception e)
                {
                    return(e.Message);
                }
            }, s =>
            {
                this.Result = s;
            });
        }
Пример #2
0
        public void Compile()
        {
            var          path = "";
            DialogResult dirResult;

            dirResult = DialogResult.Retry;

            if (CommonFileDialog.IsPlatformSupported)
            {
                var dialog = new CommonOpenFileDialog();
                dialog.IsFolderPicker = true;
                ThreadSaveAction(
                    () =>
                {
                    dirResult = dialog.ShowDialog() == CommonFileDialogResult.Ok
                                                        ? DialogResult.OK
                                                        : DialogResult.Abort;
                });
                if (dirResult == DialogResult.OK)
                {
                    path = dialog.FileName;
                }
            }
            else
            {
                var dir = new FolderBrowserDialog();
                ThreadSaveAction(() => { dirResult = dir.ShowDialog(); });
                if (dirResult == DialogResult.OK)
                {
                    path = dir.SelectedPath;
                }
            }

            if (dirResult == DialogResult.OK)
            {
                TargetDir = path;
                foreach (var tableInfoModel in Tables)
                {
                    Status = string.Format("Compiling Table '{0}'", tableInfoModel.GetClassName());
                    SharedMethods.CompileTable(tableInfoModel, this);
                }

                foreach (var tableInfoModel in Views)
                {
                    Status = string.Format("Compiling View '{0}'", tableInfoModel.GetClassName());
                    SharedMethods.CompileTable(tableInfoModel, this);
                }
            }
        }
Пример #3
0
        public void Compile()
        {
            Console.WriteLine("Start compiling with selected options");

            var elements = Tables.Concat(Views);

            foreach (var tableInfoModel in elements)
            {
                SharedMethods.CompileTable(tableInfoModel, this);
            }

            foreach (var proc in StoredProcs)
            {
                if (proc.Exclude)
                {
                    continue;
                }

                var targetCsName = proc.GetClassName();
                var compiler     = new ProcedureCompiler(TargetDir, targetCsName);
                compiler.CompileHeader        = GenerateCompilerHeader;
                compiler.Namespace            = Namespace;
                compiler.GenerateConfigMethod = GenerateConfigMethod;
                compiler.TableName            = proc.NewTableName;
                if (proc.Parameter.ParamaterSpParams != null)
                {
                    foreach (var spParamter in proc.Parameter.ParamaterSpParams)
                    {
                        var targetType = DbTypeToCsType.GetClrType(spParamter.Type);
                        var spcName    = spParamter.Parameter.Replace("@", "");
                        compiler.AddProperty(spcName, targetType);
                    }
                }

                Console.WriteLine("Compile Procedure {0}", compiler.Name);
                compiler.Compile(new List <ColumInfoModel>(), SplitByType);
            }

            Console.WriteLine("Created all files");
        }
Пример #4
0
        public void Compile()
        {
            WinConsole.WriteLine("Start compiling with selected options");
            WinConsole.WriteLine("Please define a output Directory");
            if (string.IsNullOrWhiteSpace(TargetDir))
            {
                TargetDir = Program.AutoConsole.GetNextOption();
            }

            TargetDir = Path.GetFullPath(TargetDir);

            Console.WriteLine($"Selected '{TargetDir}'");
            if (TargetDir == "temp")
            {
                TargetDir = Path.GetTempPath();
            }

            if (string.IsNullOrEmpty(TargetDir) || !Directory.Exists(TargetDir))
            {
                WinConsole.WriteLine("Invalid Directory ...");
                return;
            }

            var elements = Tables.Concat(Views).ToArray();

            elements.AsParallel().ForAll(tableInfoModel =>
            {
                SharedMethods.CompileTable(tableInfoModel, this);
            });

            //foreach (var proc in StoredProcs)
            //{
            //	if (proc.Exclude)
            //	{
            //		continue;
            //	}

            //	var targetCsName = proc.GetClassName();
            //	var compiler = new ProcedureCompiler(TargetDir, targetCsName);
            //	compiler.CompileHeader = GenerateCompilerHeader;
            //	compiler.Namespace = Namespace;
            //	compiler.GenerateConfigMethod = GenerateConfigMethod;
            //	compiler.TableName = proc.NewTableName;
            //	if (proc.Parameter.ParamaterSpParams != null)
            //	{
            //		foreach (var spParamter in proc.Parameter.ParamaterSpParams)
            //		{
            //			var targetType = DbTypeToCsType.GetClrType(spParamter.Type);
            //			var spcName = spParamter.Parameter.Replace("@", "");
            //			compiler.AddProperty(spcName, targetType);
            //		}
            //	}

            //	WinConsole.WriteLine("Compile Procedure {0}", compiler.Name);
            //	compiler.Compile(new List<ColumInfoModel>(), SplitByType);
            //}

            if (_optionsIncludeInVsProject)
            {
                WinConsole.WriteLine("Update csproj file");
                WinConsole.WriteLine("Search for csproj file");
                var realPath = Path.GetFullPath(TargetDir)
                               .Split('\\');

                for (var index = 0; index < realPath.Length; index++)
                {
                    var fullPath = realPath.Take(realPath.Length - index).Aggregate((e, f) => e + "\\" + f);
                    WinConsole.WriteLine($"Search in: '{fullPath}'");
                    var hasCsProject = Directory.EnumerateFiles(fullPath, "*.csproj").FirstOrDefault();
                    if (!string.IsNullOrWhiteSpace(hasCsProject))
                    {
                        WinConsole.WriteLine($"Found csproj file '{hasCsProject}'");
                        using (var collection = new ProjectCollection())
                        {
                            var proj = collection.LoadProject(hasCsProject);
                            var inProjectFolderName = TargetDir.Remove(0, fullPath.Length);
                            var modified            = false;
                            var pocoFilesInProject  = proj
                                                      .Items
                                                      .Where(e => e.ItemType == "Compile")
                                                      .Select(e =>
                            {
                                var path = Path.GetDirectoryName(e.EvaluatedInclude)
                                           .Trim('\\');
                                return(new
                                {
                                    Item = e,
                                    ScopeOfFolder = path.Equals(inProjectFolderName.Trim('\\')),
                                    Path = e.EvaluatedInclude
                                });
                            })
                                                      .Where(e => e.ScopeOfFolder)
                                                      .ToDictionary(e => e.Path, e => e.Item);

                            var newElements = elements.Select(e =>
                                                              Path.Combine(inProjectFolderName.Trim('\\'), e.GetClassName() + ".cs"))
                                              .ToArray();

                            foreach (var newElement in pocoFilesInProject)
                            {
                                if (newElements.Contains(newElement.Key))
                                {
                                    continue;
                                }
                                proj.RemoveItem(newElement.Value);
                                modified = true;
                            }

                            foreach (var tableInfoModel in elements)
                            {
                                var pathOfNew = Path.Combine(inProjectFolderName.Trim('\\'), tableInfoModel.GetClassName() + ".cs");
                                if (pocoFilesInProject.ContainsKey(pathOfNew))
                                {
                                    continue;
                                }

                                proj.AddItem("Compile", pathOfNew);
                                modified = true;
                            }

                            if (modified)
                            {
                                proj.MarkDirty();
                                proj.Save(hasCsProject);
                            }
                        }

                        break;
                    }
                }
            }

            WinConsole.WriteLine("Created all files");
            RenderMenuAction();
        }