Esempio n. 1
0
        public string ServiceCodeGen(CodeGenArgs args)
        {
            ICodeGenFactory codeGenfactory = ServiceContainer.CodeGenFactory;

            try
            {
                ICodeGenProvider codeGen = codeGenfactory.GetCodeGen(this, args.lang);
                return(codeGen.GenerateScript(args.comment, args.isDraft));
            }
            catch (Exception ex)
            {
                _OnError(ex);
                throw;
            }
        }
Esempio n. 2
0
        public string ServiceCodeGen(CodeGenArgs args)
        {
            lock (this._lockObj)
            {
                if (this._codeGenProviders == null)
                {
                    try
                    {
                        this._codeGenProviders = new ConcurrentDictionary <string, Func <ICodeGenProvider> >();
                        this.ConfigureCodeGen();
                    }
                    catch (Exception ex)
                    {
                        //if not properly initialized then reset to null
                        this._codeGenProviders = null;
                        this._OnError(ex);
                        throw;
                    }
                }
            }

            try
            {
                if (!this.IsCodeGenEnabled)
                {
                    throw new InvalidOperationException(ErrorStrings.ERR_CODEGEN_DISABLED);
                }

                var metadata = MetadataHelper.GetInitializedMetadata(this);

                Func <ICodeGenProvider> providerFactory = null;
                if (!this._codeGenProviders.TryGetValue(args.lang, out providerFactory))
                {
                    throw new InvalidOperationException(string.Format(ErrorStrings.ERR_CODEGEN_NOT_IMPLEMENTED,
                                                                      args.lang));
                }

                return(providerFactory().GetScript(args.comment, args.isDraft));
            }
            catch (Exception ex)
            {
                this._OnError(ex);
                throw;
            }
        }