public LegacyCodeGenerationDriver(LanguageOption language, Version targetEntityFrameworkVersion)
        {
            Debug.Assert(
                EntityFrameworkVersion.IsValidVersion(targetEntityFrameworkVersion),
                "invalid targetEntityFrameworkVersion");

            _language = language;
            _targetEntityFrameworkVersion = targetEntityFrameworkVersion;
        }
        public static CodeGeneratorBase Create(LanguageOption language, Version targetEntityFrameworkVersion)
        {
            Debug.Assert(
                EntityFrameworkVersion.IsValidVersion(targetEntityFrameworkVersion),
                "invalid targetEntityFrameworkVersion");

            return targetEntityFrameworkVersion == EntityFrameworkVersion.Version1
                       ? (CodeGeneratorBase)new EntityClassGenerator(language)
                       : new EntityCodeGenerator(language, targetEntityFrameworkVersion);
        }
Esempio n. 3
0
        /// <summary>
        /// Generate views from the EDMX file
        /// </summary>
        /// <param name="edmxFile">File containing EDMX</param>
        /// <param name="languageOption">C# or VB</param>
        /// <returns>List of errors that occurred while building the mapping or while generating views</returns>
        public static IList<EdmSchemaError> GenerateViewsFromEdmx(FileInfo edmxFile, LanguageOption languageOption)
        {
            TextWriter viewsWriter = null;
            var ext = (languageOption == LanguageOption.GenerateCSharpCode) ? ".cs" : ".vb";
            var outputFile = GetFileNameWithNewExtension(edmxFile, ".Views" + ext);

            viewsWriter = new StreamWriter((string) outputFile);
            var edmxReader = new StreamReader(edmxFile.FullName);
            var errors = GenerateViewsFromEdmx(edmxReader, languageOption, viewsWriter);
            return errors;
        }
Esempio n. 4
0
        /// <summary>
        /// Generate views from the given EDMX TextReader
        /// </summary>
        /// <param name="edmxReader">TextReader providing the EDMX XML</param>
        /// <param name="languageOption">C# or VB</param>
        /// <param name="viewsWriter">TextWriter that the views will be written into.  If null, only validation will be performed.</param>
        /// <returns>List of errors that occurred while building the mapping or while validating/generating</returns>
        public static IList<EdmSchemaError> GenerateViewsFromEdmx(TextReader edmxReader, LanguageOption languageOption, TextWriter viewsWriter)
        {
            List<EdmSchemaError> allErrors = null;
            StorageMappingItemCollection mappingItemCollection = EdmMapping.BuildMapping(edmxReader, out allErrors);

            // generate views & write them out to a file
            var evg = new EntityViewGenerator(languageOption);
            var viewGenerationErrors = evg.GenerateViews(mappingItemCollection, viewsWriter);

            if (viewGenerationErrors != null) allErrors.AddRange(viewGenerationErrors);

            return allErrors;
        }
        /// <summary>
        /// Gets the LanguageOption value from string.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="defaultValue"></param>
        /// <param name="raiseException"></param>
        /// <returns></returns>
        public static LanguageOption ToLanguageOption(this string key, LanguageOption defaultValue = LanguageOption.En, bool raiseException = false)
        {
            var lookupLanguage = LookupLanguage;

            key = key.ToLowerInvariant();

            if (lookupLanguage.Values.Contains(key))
            {
                var pair = lookupLanguage.First(kvp => kvp.Value == key);
                return(pair.Key);
            }

            if (Enum.TryParse(key, true, out LanguageOption value))
            {
                return(value);
            }
            else
            {
                return(raiseException ? throw new ArgumentException($"{key} is not LanguageOption value.") : defaultValue);
            }
        }
Esempio n. 6
0
        public override object CreateInstance()
        {
            if (this.isInternal)
            {
                Command command = GlobalCommand.GlobalCmdManager.GetCommand((object)this.Id);
                if (command == null)
                {
                    return((object)null);
                }
                return((object)new CommandEntry(command));
            }
            if (this.label == null)
            {
                this.label = this.Id;
            }
            this.label = LanguageOption.GetValueBykey(this.label);
            Command command1 = this.CreateCommand();

            GlobalCommand.GlobalCmdManager.RegisterCommand(command1);
            return((object)new CommandEntry(command1));
        }
Esempio n. 7
0
        public static bool CodeGen(String edmxFile, LanguageOption languageOption, out String codeOut, out List<Object> errors)
        {
            codeOut = String.Empty;

            XDocument xdoc = XDocument.Load(edmxFile);
            XElement c = GetCsdlFromEdmx(xdoc);
            Version v = _namespaceManager.GetVersionFromEDMXDocument(xdoc);

            StringWriter sw = new StringWriter();

            errors = new List<Object>();

            //
            // code-gen uses different classes for V1 and V2 of the EF
            //
            if (v == EntityFrameworkVersions.Version1)
            {
                // generate code
                EntityClassGenerator codeGen = new EntityClassGenerator(languageOption);
                errors = codeGen.GenerateCode(c.CreateReader(), sw) as List<Object>;
            }
            else if (v == EntityFrameworkVersions.Version2)
            {
                EntityCodeGenerator codeGen = new EntityCodeGenerator(languageOption);
                errors = codeGen.GenerateCode(c.CreateReader(), sw) as List<Object>;
            }

            else if (v == EntityFrameworkVersions.Version3)
            {
                EntityCodeGenerator codeGen = new EntityCodeGenerator(languageOption);
                errors = codeGen.GenerateCode(c.CreateReader(), sw) as List<Object>;
            }

            // output errors
            if (errors != null)
                return true;

            codeOut = sw.ToString();
            return false;
        }
Esempio n. 8
0
        public static bool TryGetLanguageDeclaration(string line, out LanguageOption option)
        {
            int posUOSL;

            if ((posUOSL = line.IndexOf(" UOSL ")) > 0)
            {   // Try to extract language option from line
                int j = 0;
                for (int i = posUOSL + 6; i < line.Length; i++)
                {
                    if (j == 0 && char.IsLetter(line[i]))
                    {
                        j = i;
                    }
                    else if (j > posUOSL && !char.IsLetter(line[i]))
                    {
                        return(Enum.TryParse <LanguageOption>(line.Substring(j, i - j), true, out option));
                    }
                }
            }
            option = 0;
            return(false);
        }
Esempio n. 9
0
        public virtual void AddVar(Field field, ParsingContext context)
        {
            Field found = null;

            if (UOSLGrammar.Keywords.ContainsKey(field.Name) && context.GetOptions() == LanguageOption.Extended)
            {
                context.AddParserMessage(ParserErrorLevel.Info, field.Node.Span, "{0} is a keyword. It cannot be used as a Field name.", field.Name);
            }

            if (ScopeVars != null && (found = ScopeVars.FirstOrDefault(var => var.Name == field.Name)) != null)
            {
                LanguageOption Options = context.GetOptions();

                if (Options == LanguageOption.Extended)
                {
                    context.AddParserMessage(ParserErrorLevel.Error, field.Node.Span, "Field {0} is already declared as a different type.", field.Name);
                }
                else if (found.UoTypeToken != field.UoTypeToken)
                {
                    // This is OK in Native mode, but an warning in Enhanced mode
                    context.AddParserMessage(Options == LanguageOption.Native ? ParserErrorLevel.Warning : ParserErrorLevel.Error
                                             , field.Node.Span, "Field {0} is already declared as a different type, declaration ignored.", field.Name);
                }
                else
                {
                    context.AddParserMessage(ParserErrorLevel.Info, field.Node.Span, "Redeclaration of Field {0} ignored.", field.Name);
                }
            }
            if (found == null) // ignore redeclaraions
            {
                field.Scope = this;
                (m_LocalVars ?? (m_LocalVars = new List <Field>())).Add(field);
            }
            else
            {
                found.AddReference(this);
            }
        }
Esempio n. 10
0
        private static void CodeGen(FileInfo edmxFile, LanguageOption languageOption)
        {
            XDocument xdoc = XDocument.Load(edmxFile.FullName);
            XElement  c    = GetCsdlFromEdmx(xdoc);
            Version   v    = _namespaceManager.GetVersionFromEDMXDocument(xdoc);

            StringWriter           sw     = new StringWriter();
            IList <EdmSchemaError> errors = null;

            //
            // code-gen uses different classes for V1 and V2 of the EF
            //
            if (v == EntityFrameworkVersions.Version1)
            {
                // generate code
                EntityClassGenerator codeGen = new EntityClassGenerator(languageOption);
                errors = codeGen.GenerateCode(c.CreateReader(), sw);
            }
            else if (v == EntityFrameworkVersions.Version2)
            {
                EntityCodeGenerator codeGen = new EntityCodeGenerator(languageOption);
                errors = codeGen.GenerateCode(c.CreateReader(), sw);
            }
            else if (v == EntityFrameworkVersions.Version3)
            {
                EntityCodeGenerator codeGen = new EntityCodeGenerator(languageOption);
                errors = codeGen.GenerateCode(c.CreateReader(), sw, EntityFrameworkVersions.Version3);
            }

            // write out code-file
            string outputFileName = GetFileNameWithNewExtension(edmxFile,
                                                                GetFileExtensionForLanguageOption(languageOption));

            File.WriteAllText(outputFileName, sw.ToString());

            // output errors
            WriteErrors(errors);
        }
Esempio n. 11
0
    private void Awake()
    {
        dumpMemory = new char[UnityEngine.Random.Range(0, 500)];

        if (instance == null)
        {
            instance = this;
            DontDestroyOnLoad(this.gameObject);
        }
        //backendManager.ServerTimer();
        //PlayerPrefs.DeleteAll();
        //Current_Language = Application.systemLanguage.ToString();

        if (PlayerPrefs.GetInt("localized", 0) == 1)
        {
            LanguageOption.Initialize(SystemLanguage.English);
            Title_Image.sprite = Eng_Title_Image;
        }
        else if (PlayerPrefs.GetInt("localized", 0) == 2)
        {
            LanguageOption.Initialize(SystemLanguage.Korean);
            Title_Image.sprite = Kor_Title_Image;
        }
        else
        {
            if (Application.systemLanguage == SystemLanguage.Korean)
            {
                Title_Image.sprite = Kor_Title_Image;
            }
            else
            {
                Title_Image.sprite = Eng_Title_Image;
            }
            LanguageOption.Initialize(Application.systemLanguage);
        }
        User_ID_Text.text = "User ID : " + PlayerPrefs.GetString(DesignConstStorage.PlayerCustomID);
        Warning_Text.text = MyLocalization.Exchange("warning");
    }
Esempio n. 12
0
        public override void Init(ParsingContext context, ParseTreeNode treeNode)
        {
            base.Init(context, treeNode);

            LanguageOption Options = context.GetOptions();

            field = new Field(this, context, true);
            if (!Options.HasOption(LanguageOption.Constants))
            {
                context.AddParserMessage(ParserErrorLevel.Error, this.Span, "Constants are not valid for this source.");
            }
            else if (Assign == null || Assign.Expression.UoToken == null || !Assign.Expression.UoToken.IsLiteral)
            {
                if (Assign != null && Assign.Expression.AsString == "ExpressionList")
                {
                    foreach (ExpressionNode node in Assign.Expression.ChildNodes)
                    {
                        if (node.UoToken == null || !node.UoToken.IsLiteral)
                        {
                            context.AddParserMessage(ParserErrorLevel.Error, node.Span, "Constant list elements must be compile time constants.");
                        }
                    }

                    field.Value = Assign.Expression.ChildNodes.Select(node => new ConstantListElement(((ExpressionNode)node).UoToken, ((ExpressionNode)node).UoTypeToken));
                }
                else
                {
                    context.AddParserMessage(ParserErrorLevel.Error, Span, "Constants must be assigned a compile time constant value when declared.");
                    field.Value = "0";
                }
            }
            else
            {
                field.Value = Assign.Expression.UoToken.Value;
            }

            UOSLBase.AddMember(field, context);
        }
Esempio n. 13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="writer"></param>
        /// <param name="language"></param>
        public void Do(System.IO.TextReader reader, System.IO.TextWriter writer, LanguageOption language, bool hasNamespace)
        {
            Language = language;

            // set up the fix ups for each class.
            foreach (FixUp fixUp in this)
            {
                List <FixUp> fixUps = null;
                if (ClassFixUps.ContainsKey(fixUp.Class))
                {
                    fixUps = ClassFixUps[fixUp.Class];
                }
                else
                {
                    fixUps = new List <FixUp>();
                    ClassFixUps.Add(fixUp.Class, fixUps);
                }
                fixUps.Add(fixUp);
            }

            switch (Language)
            {
            case LanguageOption.GenerateVBCode:
                DoFixUpsForVB(reader, writer);
                break;

            case LanguageOption.GenerateCSharpCode:
                DoFixUpsForCS(reader, writer, hasNamespace);
                break;

            default:
                Debug.Assert(false, "Unexpected language value: " + Language.ToString());
                CopyFile(reader, writer);
                break;
            }
        }
Esempio n. 14
0
 /// <summary>
 /// Generate views from the given EDMX string.
 /// </summary>
 /// <param name="edmx">String containing EDMX XML</param>
 /// <param name="languageOption">C# or VB</param>
 /// <param name="viewsWriter">TextWriter to write the views into.</param>
 /// <returns>List of errors that occurred while building the mapping or while generating</returns>
 public static IList<EdmSchemaError> GenerateViewsFromEdmx(String edmx, LanguageOption languageOption, TextWriter viewsWriter)
 {
     var textReader = new StringReader(edmx);
     return GenerateViewsFromEdmx(textReader, languageOption, viewsWriter);
 }
Esempio n. 15
0
 public override string GenerateScript(LanguageOption options, int indentationlevel = 0)
 {
     return(Indenter(indentationlevel, "{0} {1}", Keyword.Member.Value, base.GenerateScript(options)));
 }
Esempio n. 16
0
 public override string GenerateScript(LanguageOption options, int indentationlevel = 0)
 {
     return(string.Format("{0} {1} {2}{3}\n{4}\n", DeclKeyword.Value, UoTypeToken.Value, Name.Text, Parameters.GenerateScript(options), Body.GenerateScript(options)));
 }
Esempio n. 17
0
 // protected virtual to allow mocking
 protected virtual CodeGeneratorBase CreateCodeGenerator(LanguageOption language, Version targetEntityFrameworkVersion)
 {
     return(CodeGeneratorBase.Create(language, targetEntityFrameworkVersion));
 }
        private void OptimizeContextEF5(
            LanguageOption languageOption,
            string baseFileName,
            StorageMappingItemCollection mappingCollection,
            SelectedItem selectedItem)
        {
            DebugCheck.NotEmpty(baseFileName);
            DebugCheck.NotNull(mappingCollection);

            OptimizeContextCore(
                languageOption,
                baseFileName,
                selectedItem,
                viewsPath =>
                {
                    var viewGenerator = new EntityViewGenerator(languageOption);
                    var errors = viewGenerator.GenerateViews(mappingCollection, viewsPath);
                    errors.HandleErrors(Strings.Optimize_SchemaError(baseFileName));
                });
        }
Esempio n. 19
0
 /// <summary>
 ///     This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.
 /// </summary>
 /// <param name="languageOption">This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.</param>
 public EntityClassGenerator(LanguageOption languageOption)
 {
     _entityClassGenerator = new Sded.EntityClassGenerator((Sded.LanguageOption)languageOption);
 }
Esempio n. 20
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="language"></param>
        /// <param name="line"></param>
        /// <returns></returns>
        public string Fix(LanguageOption language, string line)
        {
            FixMethod method = null;
            if ( language == LanguageOption.GenerateCSharpCode )
            {
                method = _CSFixMethods[(int)Type];
            }
            else if ( language == LanguageOption.GenerateVBCode )
            {
                method = _VBFixMethods[(int)Type];
            }

            if ( method != null )
            {
                line = method( line );
            }

            return line;
        }
Esempio n. 21
0
 public void GetLanguageFromFirstLetterTest(string value, LanguageOption expectedResult)
 {
     value.GetLanguageFromFirstLetter().Should().Be(expectedResult);
 }
 /// <summary>
 ///     This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.
 /// </summary>
 /// <param name="languageOption">This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.</param>
 public EntityClassGenerator(LanguageOption languageOption)
 {
     _entityClassGenerator = new Sded.EntityClassGenerator((Sded.LanguageOption)languageOption);
 }
 // protected virtual to allow mocking
 protected virtual CodeGeneratorBase CreateCodeGenerator(LanguageOption language, Version targetEntityFrameworkVersion)
 {
     return CodeGeneratorBase.Create(language, targetEntityFrameworkVersion);
 }
Esempio n. 24
0
 /// <summary>
 /// Parse the string to get the LanguageOption
 /// </summary>
 /// <param name="ext">String that should be either "cs" or "vb"</param>
 /// <param name="langOption">output parameter for returning LanguageOption</param>
 /// <returns>True if ext was successfully parsed into a LanguageOption, false otherwise</returns>
 public static bool ParseLanguageOption(string ext, out LanguageOption langOption)
 {
     langOption = LanguageOption.GenerateCSharpCode;
     if ("vb".Equals(ext, StringComparison.OrdinalIgnoreCase))
     {
         langOption = LanguageOption.GenerateVBCode;
         return true;
     }
     else if ("cs".Equals(ext, StringComparison.OrdinalIgnoreCase))
     {
         langOption = LanguageOption.GenerateCSharpCode;
         return true;
     }
     else
     {
         return false;
     }
 }
Esempio n. 25
0
        /// <summary>
        /// Write the pre-generated views file.
        /// </summary>
        /// <param name="viewsFileName">Name of the file to create.  If it exists, it is overwritten.</param>
        /// <param name="edmx">String containing the EDMX XML</param>
        /// <param name="hash">Hash code to put at the top of the views file</param>
        /// <param name="languageOption">Language (cs or vb) in which to write the views file</param>
        /// <returns>true if the write was successful, false if not.</returns>
        public bool WriteViewsFile(string viewsFileName, string edmx, string hash, LanguageOption languageOption)
        {
            bool result = true;
            try
            {
                var writer = new StreamWriter(viewsFileName, false);
                writer.WriteLine(HashPrefix + hash);

                var errors = GenerateViewsFromEdmx(edmx, languageOption, writer);
                if (Enumerable.Any(errors))
                {
                    var severe = LogErrors(errors);
                    result = (!severe);
                }
                writer.Close();
            }
            catch (Exception ex)
            {
                Log.LogErrorFromException(ex);
                result = false;
            }
            return result;
        }
Esempio n. 26
0
		private static void CodeGen(FileInfo edmxFile, LanguageOption languageOption)
		{
			XElement c = GetCsdlFromEdmx(XDocument.Load(edmxFile.FullName));

			// generate code
			StringWriter sw = new StringWriter();
			EntityClassGenerator codeGen = new EntityClassGenerator(languageOption);
			IList<EdmSchemaError> errors = codeGen.GenerateCode(c.CreateReader(), sw);

			// write out code-file
			string outputFileName = GetFileNameWithNewExtension(edmxFile,
				 GetFileExtensionForLanguageOption(languageOption));
			File.WriteAllText(outputFileName, sw.ToString());

			// output errors
			WriteErrors(errors);
		}
Esempio n. 27
0
 /// <summary>
 ///     This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.
 /// </summary>
 /// <param name="languageOption">This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.</param>
 /// <param name="targetEntityFrameworkVersion">This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.</param>
 public EntityCodeGenerator(LanguageOption languageOption, Version targetEntityFrameworkVersion)
 {
     _entityCodeGenerator          = new Sded.EntityCodeGenerator((Sded.LanguageOption)languageOption);
     _targetEntityFrameworkVersion = targetEntityFrameworkVersion;
 }
Esempio n. 28
0
 internal static ReflectionAdapter Create(LanguageOption language, Version targetEntityFrameworkVersion)
 {
     if (language == LanguageOption.GenerateCSharpCode)
     {
         if (targetEntityFrameworkVersion >= EntityFrameworkVersions.Latest)
         {
             return new ReflectionAdapter(CreateCSharpCodeGeneratorV3());
         }
         else
         {
             return new ReflectionAdapter(CreateCSharpCodeGeneratorV2());
         }
     }
     else
     {
         Debug.Assert(language == LanguageOption.GenerateVBCode, "Did you add a new option?");
         if (targetEntityFrameworkVersion >= EntityFrameworkVersions.Latest)
         {
             return new ReflectionAdapter(CreateVBCodeGeneratorV3());
         }
         else
         {
             return new ReflectionAdapter(CreateVBCodeGeneratorV2());
         }
     }
 }
Esempio n. 29
0
		private static string GetFileExtensionForLanguageOption(
				LanguageOption langOption)
		{
			if (langOption == LanguageOption.GenerateCSharpCode)
			{
				return ".cs";
			}
			else
			{
				return ".vb";
			}
		}
Esempio n. 30
0
        private EventBox CreateTable(string calegory, List <PropertyItem> propertyItem)
        {
            EventBox eventBox = new EventBox();
            Table    table    = new Table((uint)(propertyItem.Count + 1), 2u, false);
            Label    label    = new Label();

            label.HeightRequest = 16;
            table.Attach(label, 1u, 2u, 0u, 1u, AttachOptions.Expand, AttachOptions.Fill, 0u, 0u);
            label.Show();
            uint num = 1u;

            foreach (PropertyItem current in propertyItem)
            {
                ITypeEditor editor = this.em.GetEditor(current);
                Widget      widget;
                if (editor == null)
                {
                    widget = current.WidgetDate;
                }
                else
                {
                    current.TypeEditor = editor;
                    widget             = editor.ResolveEditor(current);
                }
                if (current.DiaplayName == "grid_sudoku_size" || current.DiaplayName == "Fill_color")
                {
                    if (widget == null)
                    {
                        num += 1u;
                    }
                    else
                    {
                        if (widget is Entry)
                        {
                            Entry entry = widget as Entry;
                            table.Add(entry);
                            entry.Show();
                        }
                        else
                        {
                            table.Add(widget);
                        }
                        widget.Show();
                        Table.TableChild tableChild = (Table.TableChild)table[widget];
                        tableChild.LeftAttach   = 0u;
                        tableChild.RightAttach  = 2u;
                        tableChild.TopAttach    = num;
                        tableChild.BottomAttach = num + 1u;
                        tableChild.XOptions     = (AttachOptions.Expand | AttachOptions.Fill);
                        tableChild.YOptions     = AttachOptions.Fill;
                        num += 1u;
                    }
                }
                else
                {
                    ContentLabel contentLabel = new ContentLabel(90);
                    contentLabel.SetLabelText(LanguageOption.GetValueBykey(current.DiaplayName));
                    table.Add(contentLabel);
                    contentLabel.Show();
                    Table.TableChild tableChild2 = (Table.TableChild)table[contentLabel];
                    tableChild2.TopAttach    = num;
                    tableChild2.BottomAttach = num + 1u;
                    tableChild2.XOptions     = AttachOptions.Fill;
                    tableChild2.YOptions     = AttachOptions.Fill;
                    if (widget == null)
                    {
                        num += 1u;
                    }
                    else
                    {
                        Alignment alignment = new Alignment(0.5f, 0.5f, 1f, 1f);
                        if (widget is Entry)
                        {
                            Entry entry = widget as Entry;
                            alignment.BottomPadding = 16u;
                            alignment.Add(entry);
                            entry.Show();
                            alignment.Show();
                            table.Add(alignment);
                        }
                        else
                        {
                            if (widget is INumberEntry)
                            {
                                if ((widget as INumberEntry).GetMenuVisble())
                                {
                                    alignment.BottomPadding = 8u;
                                }
                                else
                                {
                                    alignment.BottomPadding = 16u;
                                }
                            }
                            else
                            {
                                alignment.BottomPadding = 16u;
                            }
                            alignment.Add(widget);
                            widget.Show();
                            alignment.Show();
                            table.Add(alignment);
                        }
                        Table.TableChild tableChild = (Table.TableChild)table[alignment];
                        tableChild.LeftAttach   = 1u;
                        tableChild.RightAttach  = 2u;
                        tableChild.TopAttach    = num;
                        tableChild.BottomAttach = num + 1u;
                        tableChild.XOptions     = (AttachOptions.Expand | AttachOptions.Fill);
                        tableChild.YOptions     = AttachOptions.Fill;
                        num += 1u;
                    }
                }
            }
            table.ColumnSpacing = 10u;
            eventBox.Add(table);
            table.Show();
            eventBox.CanFocus = false;
            return(eventBox);
        }
        private void OptimizeContextCore(
            LanguageOption languageOption,
            string baseFileName,
            SelectedItem selectedItem,
            Action<string> generateAction)
        {
            DebugCheck.NotEmpty(baseFileName);

            var progressTimer = new Timer { Interval = 1000 };

            try
            {
                var selectedItemPath = (string)selectedItem.ProjectItem.Properties.Item("FullPath").Value;
                var viewsFileName = baseFileName
                    + ".Views"
                    + ((languageOption == LanguageOption.GenerateCSharpCode)
                        ? FileExtensions.CSharp
                        : FileExtensions.VisualBasic);
                var viewsPath = Path.Combine(
                    Path.GetDirectoryName(selectedItemPath),
                    viewsFileName);

                _package.DTE2.SourceControl.CheckOutItemIfNeeded(viewsPath);

                var progress = 1;
                progressTimer.Tick += (sender, e) =>
                    {
                        _package.DTE2.StatusBar.Progress(true, string.Empty, progress, 100);
                        progress = progress == 100 ? 1 : progress + 1;
                        _package.DTE2.StatusBar.Text = Strings.Optimize_Begin(baseFileName);
                    };

                progressTimer.Start();

                Task.Factory.StartNew(
                        () =>
                        {
                            generateAction(viewsPath);
                        })
                    .ContinueWith(
                        t =>
                        {
                            progressTimer.Stop();
                            _package.DTE2.StatusBar.Progress(false);

                            if (t.IsFaulted)
                            {
                                _package.LogError(Strings.Optimize_Error(baseFileName), t.Exception);

                                return;
                            }

                            selectedItem.ProjectItem.ContainingProject.ProjectItems.AddFromFile(viewsPath);
                            _package.DTE2.ItemOperations.OpenFile(viewsPath);

                            _package.DTE2.StatusBar.Text = Strings.Optimize_End(baseFileName, Path.GetFileName(viewsPath));
                        },
                        TaskScheduler.FromCurrentSynchronizationContext());
            }
            catch
            {
                progressTimer.Stop();
                _package.DTE2.StatusBar.Progress(false);

                throw;
            }
        }
Esempio n. 32
0
 internal void Populate(object objectItem, List <PropertyItem> itemList, int type = 0, object instance = null)
 {
     if (itemList.Count == 0 || objectItem == null)
     {
         this.expandTable = new Table(1u, 1u, false);
     }
     else
     {
         itemList.Sort((PropertyItem a, PropertyItem b) => a.Calegory.CompareTo(b.Calegory));
         List <string>            list  = new List <string>();
         List <CatagoryAttribute> list2 = new List <CatagoryAttribute>();
         Attribute[] customAttributes   = Attribute.GetCustomAttributes(objectItem.GetType(), true);
         for (int i = 0; i < customAttributes.Length; i++)
         {
             Attribute attribute = customAttributes[i];
             if (attribute is CatagoryAttribute)
             {
                 list2.Add(attribute as CatagoryAttribute);
             }
         }
         list2.Sort((CatagoryAttribute a, CatagoryAttribute b) => a.Order.CompareTo(b.Order));
         list2.RemoveAll((CatagoryAttribute w) => w.Group != type);
         if (itemList.FirstOrDefault <PropertyItem>().InstanceList.Count > 1)
         {
             list2.RemoveAll((CatagoryAttribute w) => w.Group == 1);
         }
         using (List <CatagoryAttribute> .Enumerator enumerator = list2.GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 CatagoryAttribute item         = enumerator.Current;
                 PropertyItem      propertyItem = itemList.FirstOrDefault((PropertyItem w) => w.Calegory == item.Catatory);
                 if (propertyItem != null)
                 {
                     list.Add(item.Catatory);
                 }
             }
         }
         this.expandTable = new Table((uint)list.Count, 1u, false);
         uint num = 0u;
         using (List <string> .Enumerator enumerator2 = list.GetEnumerator())
         {
             while (enumerator2.MoveNext())
             {
                 string item = enumerator2.Current;
                 List <PropertyItem> list3 = (from w in itemList
                                              where w.Calegory == item
                                              select w).ToList <PropertyItem>();
                 if (list3 != null)
                 {
                     list3.Sort((PropertyItem a, PropertyItem b) => (a.PropertyOrder ?? -10).CompareTo(b.PropertyOrder ?? -10));
                     Widget widget;
                     if (objectItem is IPropertyTitle)
                     {
                         CustomExpender customExpender = this.CreateExpand(LanguageOption.GetValueBykey(item), list3);
                         customExpender.ExpandCategory = item;
                         customExpender.ExpandChanged += new EventHandler <ExpandEvent>(this.expand_ExpandChanged);
                         widget = customExpender;
                         customExpender.Expanded = (this.category.FirstOrDefault((string w) => w == item) == null);
                         widget.CanFocus         = true;
                     }
                     else
                     {
                         widget = this.CreateTable(LanguageOption.GetValueBykey(item), list3);
                     }
                     this.expandTable.Attach(widget, 0u, 1u, num, num + 1u, AttachOptions.Expand | AttachOptions.Fill, AttachOptions.Fill, 0u, 0u);
                     widget.Show();
                     num += 1u;
                 }
             }
         }
     }
 }
        private void OptimizeContextEF6(
            LanguageOption languageOption,
            string baseFileName,
            dynamic mappingCollection,
            SelectedItem selectedItem,
            string contextTypeName)
        {
            DebugCheck.NotEmpty(baseFileName);

            OptimizeContextCore(
                languageOption,
                baseFileName,
                selectedItem,
                viewsPath =>
                {
                    var edmSchemaError = ((Type)mappingCollection.GetType()).Assembly
                        .GetType("System.Data.Entity.Core.Metadata.Edm.EdmSchemaError", true);
                    var listOfEdmSchemaError = typeof(List<>).MakeGenericType(edmSchemaError);
                    var errors = Activator.CreateInstance(listOfEdmSchemaError);
                    var views = ((Type)mappingCollection.GetType())
                        .GetMethod("GenerateViews", new[] { listOfEdmSchemaError })
                        .Invoke(mappingCollection, new[] { errors });

                    foreach (var error in (IEnumerable<dynamic>)errors)
                    {
                        if ((int)error.Severity == 1)
                        {
                            throw new EdmSchemaErrorException(Strings.Optimize_SchemaError(baseFileName));
                        }
                    }

                    var viewGenerator = languageOption == LanguageOption.GenerateVBCode
                        ? (IViewGenerator)new VBViewGenerator()
                        : new CSharpViewGenerator();
                    viewGenerator.ContextTypeName = contextTypeName;
                    viewGenerator.MappingHashValue = mappingCollection.ComputeMappingHashValue();
                    viewGenerator.Views = views;

                    File.WriteAllText(viewsPath, viewGenerator.TransformText());
                });
        }
Esempio n. 34
0
 public static Grammar GetGrammar(LanguageOption options)
 {
     return(grammars.ContainsKey(options) ? grammars[options] : new UOSLGrammar(options));
 }
Esempio n. 35
0
 public override string GenerateScript(LanguageOption options, int indentationlevel = 0)
 {
     return(TypeToken.ValueString);
 }
Esempio n. 36
0
        internal UOSLBase(LanguageOption options = LanguageOption.Native)
        {
            if (CanCache)
            {
                grammars[options] = this;
            }

            Options = options;

            this.DefaultNodeType = typeof(ScopedNode);

            #region Declare Terminals Here

            NonGrammarTerminals.Add(blockComment);
            NonGrammarTerminals.Add(lineComment);

            Identifier.AstNodeType = typeof(UoFieldExpressionNode);

            _L = ToTerm("L");
            MarkReservedWords("L");

            #endregion

            #region Functions
            TypedFunction.Rule    = Function_void | Function_int | Function_string | Function_ustring | Function_loc | Function_obj | Function_list;
            Function_void.Rule    = _void + _functionname_void;
            Function_int.Rule     = _int + _functionname_int;
            Function_string.Rule  = _string + _functionname_str;
            Function_ustring.Rule = _ustring + _functionname_ustr;
            Function_loc.Rule     = _loc + _functionname_loc;
            Function_obj.Rule     = _obj + _functionname_obj;
            Function_list.Rule    = _list + _functionname_list;
            #endregion

            #region Externals
            _any.SetFlag(TermFlags.IsKeyword);
            if (!Keywords.ContainsKey(_any.Text))
            {
                Keywords[_any.Text] = _any;
            }
            ExternalParam.Rule       = (_int | _string | _ustring | _loc | _obj | _list | _any | _void) + (ToTerm("&").Q()) + (Identifier.Q());
            ExternalParams.Rule      = MakeStarRule(ExternalParams, _comma, ExternalParam);
            Function_any.Rule        = _any + _functionname_void; // only valid for Core Commands
            ExternalDeclaration.Rule = ToTerm("external") + (Function_any | TypedFunction) + _openparen_punc + ExternalParams + _closeparen_punc + _semicolon;
            #endregion


            BracePair(_openbracket, _closebracket);
            BracePair(_openparen_op, _closeparen_op);
            BracePair(_openparen_punc, _closeparen_punc);
            BracePair(_openbrace, _closebrace);
            BracePair(_openchevron, _closechevron);

            this.Delimiters = "{}[](),:;+-*/%&|^!~<>=";
            this.MarkPunctuation(_semicolon, _comma, _openparen_punc, _closeparen_punc, _openbrace, _closebrace, _openbracket, _closebracket, _colon);

            RegisterOperators(-1, _assignment);
            RegisterOperators(1, _logicalnegation, _increment, _decrement);
            RegisterOperators(0, _plus, _minus, _multiply, _divide, _remainder, _isequal, _isnotequal, _lowerthen, _greaterthen, _lowerthenorequal,
                              _greaterthenorequal, _logicaland, _logicalor, _bitwiseexclusiveor);

            this.LanguageFlags = LanguageFlags.CreateAst;
        }
Esempio n. 37
0
 public override string GenerateScript(LanguageOption options, int indentationlevel = 0)
 {
     return(string.Format("{0}{1}{2}{3}{4}", Indenter(indentationlevel), Name.Text, Punct.LPara.Value, string.Join(",", Arguments.Select(arg => arg.GenerateScript(options))), Punct.RPara.Value));
 }
Esempio n. 38
0
 public override string GenerateScript(LanguageOption options, int indentationlevel = 0)
 {
     return(Indenter(indentationlevel, "{0}{1}", Declaration.GenerateScript(options), (Assign == null) ? string.Empty : Assign.GenerateScript(options)));
 }
Esempio n. 39
0
        public override void Init(ParsingContext context, ParseTreeNode treeNode)
        {
            base.Init(context, treeNode);

            LanguageOption Options = context.GetOptions();

            ParseTreeNode forBlock = treeNode.ChildNodes[1].FirstChild;

            if (forBlock.ChildNodes[0].ChildNodes.Count > 0 && forBlock.ChildNodes[0].FirstChild.ChildNodes.Count > 0)
            {
                LoopInitializer = StatementNode.GetStatement(forBlock.ChildNodes[0].FirstChild.FirstChild, context) as IStatement;
                if (LoopInitializer != null)
                {
                    ((ScopedNode)LoopInitializer).Parent = this;
                    ChildNodes.Add(((ScopedNode)LoopInitializer));
                }
            }

            if (forBlock.ChildNodes[1].ChildNodes.Count > 0 && forBlock.ChildNodes[1].FirstChild.ChildNodes.Count > 0)
            {
                LoopExpression = ExpressionNode.Reduce(forBlock.ChildNodes[1].FirstChild.FirstChild);
                if (LoopExpression is ScopedNode)
                {
                    ((ScopedNode)LoopExpression).Parent = this;
                    ChildNodes.Add(((ScopedNode)LoopExpression));
                }
            }

            if (forBlock.ChildNodes[2].ChildNodes.Count > 0 && forBlock.ChildNodes[2].FirstChild.ChildNodes.Count > 0)
            {
                LoopStatement = StatementNode.GetStatement(forBlock.ChildNodes[2].FirstChild.FirstChild, context) as IStatement;
                if (LoopStatement != null)
                {
                    ((ScopedNode)LoopStatement).Parent = this;
                    ChildNodes.Add(((ScopedNode)LoopStatement));
                }
            }

            ScopedNode LoopNode = StatementNode.GetStatement(treeNode.LastChild, context, false);

            Loop = LoopNode as IStatement;
            if (Loop != null)
            {
                ((ScopedNode)Loop).Parent = this;
                ChildNodes.Add(((ScopedNode)Loop));
            }
            else
            {
                context.AddParserMessage(ParserErrorLevel.Error, treeNode.LastChild.Span, "Loop statement is invalid.");
            }

            if (!Options.HasOption(LanguageOption.UnBracedLoopsIfs) && !(Loop is BlockNode))
            {
                context.AddParserMessage(ParserErrorLevel.Error, LoopNode.Span, "Statement must be enclosed in a block.");
            }

            if (LoopExpression == null || !(LoopInitializer is AssignmentNode || LoopInitializer is VariableDeclarationNode))
            {
                if (Options != LanguageOption.Extended) // Extended will be normalized without error
                {
                    if (!(LoopInitializer is AssignmentNode || LoopInitializer is VariableDeclarationNode || LoopInitializer == null))
                    {
                        context.AddParserMessage(ParserErrorLevel.Error, forBlock.ChildNodes[0].Span, "Loop initializer must be empty, or an assignment or declaration.");
                    }
                    if (LoopExpression == null)
                    {
                        context.AddParserMessage(ParserErrorLevel.Error, forBlock.ChildNodes[1].Span, "Loop expression cannot be empty.");
                    }
                }
                else
                {
                    context.AddParserMessage(ParserErrorLevel.Info, forBlock.ChildNodes[0].Span, "Invalid For loop will be converted to a While.");
                }
            }
        }
Esempio n. 40
0
		private static void CodeGen(FileInfo edmxFile, LanguageOption languageOption)
		{
			XDocument xdoc = XDocument.Load(edmxFile.FullName);
			Version v = _namespaceManager.GetVersionFromEDMXDocument(xdoc);
			XElement c = GetCsdlFromEdmx(xdoc);

			StringWriter sw = new StringWriter();
			IList<EdmSchemaError> errors = null;

			//
			// code-gen uses different classes for V1 and V2 of the EF 
			//
			if (v == EntityFrameworkVersions.Version1)
			{
				// generate code
				EntityClassGenerator codeGen = new EntityClassGenerator(languageOption);
				errors = codeGen.GenerateCode(c.CreateReader(), sw);
			}
			else if (v == EntityFrameworkVersions.Version2)
			{
				EntityCodeGenerator codeGen = new EntityCodeGenerator(languageOption);
				errors = codeGen.GenerateCode(c.CreateReader(), sw);
			}

			// write out code-file
			string outputFileName = GetFileNameWithNewExtension(edmxFile,
					GetFileExtensionForLanguageOption(languageOption));
			File.WriteAllText(outputFileName, sw.ToString());

			// output errors
			WriteErrors(errors);
		}
Esempio n. 41
0
 public static bool HasOption(this LanguageOption options, LanguageOption option)
 {
     return((options & option) == option);
 }
Esempio n. 42
0
 public string GetBody(MailBodyOption mailBodyOption, LanguageOption language, object content) =>
 mailBodyOption switch
 {
Esempio n. 43
0
        internal void LoadFile(string path, ScopedNode node, ParsingContext context, IDictionary <string, string> refDepends = null)
        {
            string curExt = context.CurrentParseTree.FileName == "<Source>" ? null : Path.GetExtension(context.CurrentParseTree.FileName);
            string fullpath
                = curExt == null ? null : Utils.FindFile(string.Format("{0}.{1}", path, curExt), context.CurrentParseTree.FileName)
                  ?? Utils.FindFile(path, context.CurrentParseTree.FileName)
                  ?? Utils.FindFile(string.Format("{0}.uosl", path), context.CurrentParseTree.FileName)
                  ?? Utils.FindFile(string.Format("{0}.uosl.q", path), context.CurrentParseTree.FileName);

            if (fullpath != null)
            {
                fullpath = (new FileInfo(fullpath)).FullName;

                FileInfo fi = new FileInfo(fullpath);

                ParseCache cache;

                if (!Inherits.TryGetValue(fullpath, out cache) || fi.LastWriteTime > cache.FileDate)
                {
                    Inherits[fullpath] = cache = new ParseCache(fi.LastWriteTime);

                    LanguageOption options = Utils.DetermineFileLanguage(fullpath, this.Options);

                    ParsingContext subcontext = new ParsingContext(new Parser(options == this.Options ? this : GetGrammar(options)));

                    using (StreamReader reader = new StreamReader(fullpath))
                    {
                        Inherits[fullpath] = cache = new ParseCache(fi.LastWriteTime, subcontext.Parser.Parse(reader.ReadToEnd(), fullpath));
                    }
                }

                if (refDepends != null)
                {
                    refDepends.Add(path, fullpath);
                }

                if (cache.Tree != null)
                {
                    if (cache.Tree.HasErrors())
                    {
                        foreach (ParserMessage error in cache.Tree.ParserMessages)
                        {
                            if (error is ExternalErrorMessage)
                            {
                                context.AddParserMessage(error);
                            }
                            else
                            {
                                context.AddParserMessage(new ExternalErrorMessage(fullpath, error.Level, error.Location, error.Message, error.ParserState));
                            }
                        }
                    }
                    if (cache.Tree.Root != null && cache.Tree.Root.AstNode != null)
                    {
                        if (((ScopedNode)cache.Tree.Root.AstNode).ScopeVars != null)
                        {
                            foreach (Field field in ((ScopedNode)cache.Tree.Root.AstNode).ScopeVars)
                            {
                                node.AddVar(field, context);
                            }
                        }
                        if (((ScopedNode)cache.Tree.Root.AstNode).TreeFuncs != null)
                        {
                            foreach (Method method in ((ScopedNode)cache.Tree.Root.AstNode).TreeFuncs)
                            {
                                AddFunc(method, context);
                            }
                        }

                        if (refDepends != null && cache.Tree.Root.FirstChild.AstNode is DeclarationsNode)
                        {
                            foreach (var kvp in ((DeclarationsNode)cache.Tree.Root.FirstChild.AstNode).Depends)
                            {
                                if (refDepends.ContainsKey(kvp.Key))
                                {
                                    context.AddParserMessage(ParserErrorLevel.Error, node.Span, "A recursion of inheritance detected occurred when parsing {0}.", kvp.Key);
                                }
                                else
                                {
                                    refDepends.Add(kvp.Key, kvp.Value);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                context.AddParserError("{0} Dependancy not found.", path);
            }
        }
 /// <summary>
 /// Create the instance of ViewGenerator with the given language option.
 /// </summary>
 /// <param name="languageOption">Language Option for generated code.</param>
 public EntityViewGenerator(LanguageOption languageOption)
 {
     m_languageOption = EDesignUtil.CheckLanguageOptionArgument(languageOption, "languageOption");
 }
Esempio n. 45
0
 public override string GenerateScript(LanguageOption options, int indentationlevel = 0)
 {
     return(Indenter(indentationlevel, "{0} {1}", UoTypeToken.Value, Name.Text));
 }
 private static string GetCodeGenerationDisabledComment(LanguageOption languageOption, string inputFileName)
 {
     if (LanguageOption.GenerateVBCode == languageOption)
     {
         return string.Format(CultureInfo.CurrentCulture, Strings.CodeGenerationDisabledCommentVB, inputFileName);
     }
     else
     {
         return string.Format(CultureInfo.CurrentCulture, Strings.CodeGenerationDisabledCommentCSharp, inputFileName);
     }
 }
Esempio n. 47
0
        public static bool ValidateAndGenerateViews(String edmxFile, LanguageOption languageOption, bool generateViews, out String viewsOut, out List<Object> errors)
        {
            viewsOut = String.Empty;

            XDocument xdoc = XDocument.Load(edmxFile);
            XElement c = GetCsdlFromEdmx(xdoc);
            XElement s = GetSsdlFromEdmx(xdoc);
            XElement m = GetMslFromEdmx(xdoc);
            Version v = _namespaceManager.GetVersionFromEDMXDocument(xdoc);

            // load the csdl
            XmlReader[] cReaders = { c.CreateReader() };
            IList<EdmSchemaError> cErrors = null;
            EdmItemCollection edmItemCollection =
                MetadataItemCollectionFactory.CreateEdmItemCollection(cReaders, out cErrors);

            // load the ssdl
            XmlReader[] sReaders = { s.CreateReader() };
            IList<EdmSchemaError> sErrors = null;
            StoreItemCollection storeItemCollection =
                MetadataItemCollectionFactory.CreateStoreItemCollection(sReaders, out sErrors);

            // load the msl
            XmlReader[] mReaders = { m.CreateReader() };
            IList<EdmSchemaError> mErrors = null;
            StorageMappingItemCollection mappingItemCollection = MetadataItemCollectionFactory.CreateStorageMappingItemCollection(edmItemCollection, storeItemCollection, mReaders, out mErrors);

            // either pre-compile views or validate the mappings
            IList<EdmSchemaError> viewGenerationErrors = null;
            if (generateViews)
            {
                // generate views
                EntityViewGenerator evg = new EntityViewGenerator(languageOption);
                using (var writer = new StringWriter())
                {
                    viewGenerationErrors = evg.GenerateViews(mappingItemCollection, writer, v);
                    viewsOut = writer.ToString();
                }
            }
            else
            {
                viewGenerationErrors = EntityViewGenerator.Validate(mappingItemCollection, v);
            }

            // write errors
            errors = new List<Object>();
            errors.AddRange(cErrors);
            errors.AddRange(sErrors);
            errors.AddRange(mErrors);
            errors.AddRange(viewGenerationErrors);
            if (errors.Count > 0)
                return true;

            return false;
        }
Esempio n. 48
0
        public void SetImage(object current, int num = 1, string rootType = "")
        {
            string str1 = string.Empty;

            if (current != null)
            {
                str1 = current.GetType().Name;
            }
            if (string.IsNullOrEmpty(str1))
            {
                str1 = "MultiObject";
            }
            this._imageWidget.Image = ImageIcon.GetIcon("CocoStudio.DefaultResource.ComponentResource." + str1.Substring(0, str1.Length - 6) + ".png");
            this._imageWidget.ShowAll();
            if (num > 1)
            {
                Label label = new Label();
                this.labelTable.Attach((Widget)label, 0U, 1U, 0U, 1U, AttachOptions.Expand, AttachOptions.Fill, 0U, 0U);
                label.Show();
                label.Text = string.Format("{0}{1}", (object)num, (object)LanguageInfo.ImageText);
            }
            else
            {
                foreach (object customAttribute in current.GetType().GetCustomAttributes(false))
                {
                    if (customAttribute is DisplayNameAttribute)
                    {
                        string str2 = LanguageOption.GetValueBykey((customAttribute as DisplayNameAttribute).DisplayName);
                        if (!string.IsNullOrEmpty(rootType))
                        {
                            str2 = rootType;
                        }
                        if (str2.Length > 8)
                        {
                            Label label1 = new Label();
                            Label label2 = new Label();
                            this.labelTable.Attach((Widget)label1, 0U, 1U, 0U, 1U, AttachOptions.Expand, AttachOptions.Fill, 0U, 0U);
                            this.labelTable.Attach((Widget)label2, 0U, 1U, 1U, 2U, AttachOptions.Expand, AttachOptions.Fill, 0U, 0U);
                            label1.Show();
                            label2.Show();
                            int num1 = 0;
                            for (int index = 1; index < str2.Length; ++index)
                            {
                                if ((int)str2[index] >= 65 && (int)str2[index] <= 90)
                                {
                                    num1 = index;
                                    break;
                                }
                            }
                            label1.Text = str2.Substring(0, num1);
                            label2.Text = str2.Substring(num1, str2.Length - num1);
                            break;
                        }
                        Label label = new Label();
                        this.labelTable.Attach((Widget)label, 0U, 1U, 0U, 1U, AttachOptions.Expand, AttachOptions.Fill, 0U, 0U);
                        label.Show();
                        label.Text = str2;
                        break;
                    }
                }
            }
        }
Esempio n. 49
0
 private static bool ParseLanguageOption(string arg, out LanguageOption langOption)
 {
     langOption = LanguageOption.GenerateCSharpCode;
     if ("vb".Equals(arg, StringComparison.OrdinalIgnoreCase))
     {
         langOption = LanguageOption.GenerateVBCode;
         return true;
     }
     else if ("cs".Equals(arg, StringComparison.OrdinalIgnoreCase))
     {
         langOption = LanguageOption.GenerateCSharpCode;
         return true;
     }
     else
     {
         ShowUsage();
         return false;
     }
 }
Esempio n. 50
0
		private static void ValidateAndGenerateViews(FileInfo edmxFile, LanguageOption languageOption, bool generateViews)
		{
			XDocument doc = XDocument.Load(edmxFile.FullName);
			XElement c = GetCsdlFromEdmx(doc);
			XElement s = GetSsdlFromEdmx(doc);
			XElement m = GetMslFromEdmx(doc);

			// load the csdl
			XmlReader[] cReaders = { c.CreateReader() };
			IList<EdmSchemaError> cErrors = null;
			EdmItemCollection edmItemCollection =
					MetadataItemCollectionFactory.CreateEdmItemCollection(cReaders, out cErrors);

			// load the ssdl 
			XmlReader[] sReaders = { s.CreateReader() };
			IList<EdmSchemaError> sErrors = null;
			StoreItemCollection storeItemCollection =
					MetadataItemCollectionFactory.CreateStoreItemCollection(sReaders, out sErrors);

			// load the msl
			XmlReader[] mReaders = { m.CreateReader() };
			IList<EdmSchemaError> mErrors = null;
			StorageMappingItemCollection mappingItemCollection =
					MetadataItemCollectionFactory.CreateStorageMappingItemCollection(
					edmItemCollection, storeItemCollection, mReaders, out mErrors);

			// either pre-compile views or validate the mappings
			IList<EdmSchemaError> viewGenerationErrors = null;
			if (generateViews)
			{
				// generate views & write them out to a file
				string outputFile =
						GetFileNameWithNewExtension(edmxFile, ".GeneratedViews" +
								GetFileExtensionForLanguageOption(languageOption));
				EntityViewGenerator evg = new EntityViewGenerator(languageOption);
				viewGenerationErrors =
						evg.GenerateViews(mappingItemCollection, outputFile);
			}
			else
			{
				viewGenerationErrors = EntityViewGenerator.Validate(mappingItemCollection);
			}

			// write errors
			WriteErrors(cErrors);
			WriteErrors(sErrors);
			WriteErrors(mErrors);
			WriteErrors(viewGenerationErrors);

		}
Esempio n. 51
0
 public EntityCodeGenerator(LanguageOption languageOption)
 {
     _languageOption = EDesignUtil.CheckLanguageOptionArgument(languageOption, "languageOption");
 }
 public override Task AddGeneratedClientCodeAsync(string metadataUri, string outputDirectory, LanguageOption languageOption, ServiceConfiguration serviceConfiguration)
 {
     AddedClientCode = true;
     return Task.CompletedTask;
 }
Esempio n. 53
0
        private void OptimizeContextCore(
            LanguageOption languageOption,
            string baseFileName,
            SelectedItem selectedItem,
            Action <string> generateAction)
        {
            DebugCheck.NotEmpty(baseFileName);

            var progressTimer = new Timer {
                Interval = 1000
            };

            try
            {
                var selectedItemPath = (string)selectedItem.ProjectItem.Properties.Item("FullPath").Value;
                var viewsFileName    = baseFileName
                                       + ".Views"
                                       + ((languageOption == LanguageOption.GenerateCSharpCode)
                        ? FileExtensions.CSharp
                        : FileExtensions.VisualBasic);
                var viewsPath = Path.Combine(
                    Path.GetDirectoryName(selectedItemPath),
                    viewsFileName);

                _package.DTE2.SourceControl.CheckOutItemIfNeeded(viewsPath);

                var progress = 1;
                progressTimer.Tick += (sender, e) =>
                {
                    _package.DTE2.StatusBar.Progress(true, string.Empty, progress, 100);
                    progress = progress == 100 ? 1 : progress + 1;
                    _package.DTE2.StatusBar.Text = Strings.Optimize_Begin(baseFileName);
                };

                progressTimer.Start();

                Task.Factory.StartNew(
                    () =>
                {
                    generateAction(viewsPath);
                })
                .ContinueWith(
                    t =>
                {
                    progressTimer.Stop();
                    _package.DTE2.StatusBar.Progress(false);

                    if (t.IsFaulted)
                    {
                        _package.LogError(Strings.Optimize_Error(baseFileName), t.Exception);

                        return;
                    }

                    selectedItem.ProjectItem.ContainingProject.ProjectItems.AddFromFile(viewsPath);
                    _package.DTE2.ItemOperations.OpenFile(viewsPath);

                    _package.DTE2.StatusBar.Text = Strings.Optimize_End(baseFileName, Path.GetFileName(viewsPath));
                },
                    TaskScheduler.FromCurrentSynchronizationContext());
            }
            catch
            {
                progressTimer.Stop();
                _package.DTE2.StatusBar.Progress(false);

                throw;
            }
        }
 /// <summary>
 ///     This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.
 /// </summary>
 /// <param name="languageOption">This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.</param>
 /// <param name="targetEntityFrameworkVersion">This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.</param>
 public EntityCodeGenerator(LanguageOption languageOption, Version targetEntityFrameworkVersion)
 {
     _entityCodeGenerator = new Sded.EntityCodeGenerator((Sded.LanguageOption)languageOption);
     _targetEntityFrameworkVersion = targetEntityFrameworkVersion;
 }