/// <summary>
        /// Создает индекс
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private XElement CreateIndex(IBSharpContext context)
        {
            var result  = new XElement("bsharp-index");
            var classes = context.Get(GetContextClassType()).ToArray();

            result.SetAttributeValue("count", classes.Length);
            foreach (var c in context.Get(GetContextClassType()))
            {
                var e = GetIndexElement(c);
                e.SetAttributeValue("uri", GetUri(c));
                result.Add((object)e);
            }
            return(result);
        }
        private Graph BuildGraph(IBSharpContext context) {
            
            var result = new Graph {
                RankDir = RankDirType.RL,
                Label = "Графическая структура проекта",
                DefaultNode = new Node {
                    FontName = "Consolas", 
                    Shape = NodeShapeType.Box3d,
                    FontSize = 8,
                    Style = NodeStyleType.Filled
                },
                DefaultEdge = new Node {
                    FontName = "Consolas",
                    FontSize = 8
                },
            };
            var visited= new List<IBSharpClass>();
            if (null != ((BSharpContext) context).Dictionaries) {
                foreach (var e in ((BSharpContext) context).Dictionaries) {
                    var node = new Node {Code = "d" + e.Key, Label = e.Key,SubgraphCode = "dicts",Shape = NodeShapeType.Mcircle};
                    result.AddNode(node);
                    foreach (var i in e.Value) {
                        result.AddEdge(new Edge {From = i.cls.FullName, To = "d" + e.Key, ArrowHead = ArrowType.Curve});
                    }
                }
            }
            foreach (var c in context.Get(BSharpContextDataType.Working)) {
                BuildClass(result,context, (BSharpClass)c, visited);
            }

            result.AutoTune();
            return result;
        }
Exemple #3
0
        /// <summary>
        /// Формирует один большой файл JSON  с рабочиим классами
        /// </summary>
        /// <param name="context"></param>
        public override void Execute(IBSharpContext context)
        {
            Project.Log.Info("start generate json module");
            using (var sw = new StreamWriter(OutFileName)) {
                sw.Write("[");
                var tojson            = new XmlToJsonConverter();
                var notformatedBuffer = new StringWriter();
                var formattedBuffer   = new StringWriter();
                foreach (var cls in context.Get(BSharpContextDataType.LibPkg))
                {
                    var converted = tojson.ConvertToJson(cls.Compiled, false);
                    notformatedBuffer.Write(converted);
                    converted = tojson.ConvertToJson(cls.Compiled, true);
                    formattedBuffer.Write(",");
                    formattedBuffer.Write(converted);
                }
                var hashbase = notformatedBuffer.ToString();
                var content  = formattedBuffer.ToString();

                sw.Write(tojson.ConvertToJson(new XElement(BSharpSyntax.Class,
                                                           new XAttribute("code", "__module"),
                                                           new XAttribute("fullcode", "__module"),
                                                           new XAttribute("prototype", "__sys"),
                                                           new XAttribute("hash", Convert.ToBase64String(MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(hashbase)))),
                                                           new XAttribute("timestamp", (DateTime.Now - new DateTime(2000, 1, 1)).TotalMilliseconds),
                                                           new XAttribute("user", Application.Current.Principal.CurrentUser.Identity.Name),
                                                           new XAttribute("host", Environment.MachineName)
                                                           ), true));
                sw.Write(content);
                sw.Write("]");
                sw.Flush();
            }
            Project.Log.Info("finish generate json module");
        }
Exemple #4
0
        private static void WriteOutConsoleMode(IBSharpContext ctx)
        {
            var result = new XElement("result");

            foreach (var cls in ctx.Get(BSharpContextDataType.Working))
            {
                var clsElement = new XElement("cls");
                clsElement.SetAttr("code", cls.FullName);
                clsElement.SetAttr("name", cls.Name);
                clsElement.SetAttr("ns", cls.Namespace);
                clsElement.SetAttr("prototype", cls.Prototype);
                clsElement.Add(cls.Compiled);
                result.Add(clsElement);
            }
            foreach (var error in ctx.GetErrors())
            {
                var errorElement = new XElement("error", new XAttribute("type", error.Type))
                {
                    Value = error.ToLogString()
                };
                if (null != error.LexInfo)
                {
                    var lex = new XElement("lexinfo", new XAttribute("file", error.LexInfo.File),
                                           new XAttribute("line", error.LexInfo.Line));
                    errorElement.Add(lex);
                }
                result.Add(errorElement);
            }

            Console.WriteLine(result.ToString());
        }
		/// <summary>
		/// 
		/// </summary>
		/// <param name="compiledProject"></param>
		/// <returns></returns>
		protected override IBSharpProject ConvertToBSharpBuilderProject(IBSharpContext compiledProject) {
			var projectClass = compiledProject.Get(Project.ProjectName);
			if (null != projectClass) {
				return GenerateProject(projectClass);
			}
			throw new Exception("cannot find project " + Project.ProjectName);
		}
Exemple #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="compiledProject"></param>
        /// <returns></returns>
        protected override IBSharpProject ConvertToBSharpBuilderProject(IBSharpContext compiledProject)
        {
            var projectClass = compiledProject.Get(Project.ProjectName);

            if (null != projectClass)
            {
                return(GenerateProject(projectClass));
            }
            throw new Exception("cannot find project " + Project.ProjectName);
        }
        private void HandleErrorStream(IBSharpContext context) {
            var errors = context.GetErrors();
            foreach (var c in context.Get(BSharpContextDataType.Working)) {
                var witherrors = errors.Any(_ => _.Class == c || _.AltClass == c || _.ClassName == c.FullName);
                if (witherrors) {
                    Project.Log.Warn("class " + c.FullName + " compiled with some errors");
                } else {
                    Project.Log.Debug("class " + c.FullName + " compiled");
                }

            }
        }
 /// <summary>
 /// Формирует ZIP пакет с индексированным исходным кодом пакета
 /// </summary>
 /// <param name="context"></param>
 public override void Execute(IBSharpContext context)
 {
     using (var pkg = Package.Open(PackageName, FileMode.Create)) {
         WriteManifest(context, pkg);
         WriteIndex(context, pkg);
         foreach (var cls in context.Get(GetContextClassType()))
         {
             WriteClass(cls, context, pkg);
         }
         pkg.Flush();
         pkg.Close();
     }
 }
        private void HandleErrorStream(IBSharpContext context)
        {
            var errors = context.GetErrors();

            foreach (var c in context.Get(BSharpContextDataType.Working))
            {
                var witherrors = errors.Any(_ => _.Class == c || _.AltClass == c || _.ClassName == c.FullName);
                if (witherrors)
                {
                    Project.Log.Warn("class " + c.FullName + " compiled with some errors");
                }
                else
                {
                    Project.Log.Debug("class " + c.FullName + " compiled");
                }
            }
        }
        private static XElement GetConfig(ConfigurationOptions options, IBSharpContext context)
        {
            XElement config = null;

            if (!string.IsNullOrWhiteSpace(options.Name))
            {
                var cls = context.Get(options.Name);
                if (null == cls)
                {
                    cls = context.ResolveAll(options.Name).FirstOrDefault();
                }
                if (null == cls)
                {
                    throw new Exception("cannot find given config name " + options.Name);
                }
                config = cls.Compiled;
            }
            return(config);
        }
        private Graph BuildGraph(IBSharpContext context)
        {
            var result = new Graph {
                RankDir     = RankDirType.RL,
                Label       = "Графическая структура проекта",
                DefaultNode = new Node {
                    FontName = "Consolas",
                    Shape    = NodeShapeType.Box3d,
                    FontSize = 8,
                    Style    = NodeStyleType.Filled
                },
                DefaultEdge = new Node {
                    FontName = "Consolas",
                    FontSize = 8
                },
            };
            var visited = new List <IBSharpClass>();

            if (null != ((BSharpContext)context).Dictionaries)
            {
                foreach (var e in ((BSharpContext)context).Dictionaries)
                {
                    var node = new Node {
                        Code = "d" + e.Key, Label = e.Key, SubgraphCode = "dicts", Shape = NodeShapeType.Mcircle
                    };
                    result.AddNode(node);
                    foreach (var i in e.Value)
                    {
                        result.AddEdge(new Edge {
                            From = i.cls.FullName, To = "d" + e.Key, ArrowHead = ArrowType.Curve
                        });
                    }
                }
            }
            foreach (var c in context.Get(BSharpContextDataType.Working))
            {
                BuildClass(result, context, (BSharpClass)c, visited);
            }

            result.AutoTune();
            return(result);
        }
Exemple #12
0
        /// <summary>
        ///     Подготавливает список целевых файлов с содержимым
        ///     для записи на диск
        /// </summary>
        /// <param name="context">Контекст компилятора</param>
        protected virtual void PrepareTargets(IBSharpContext context)
        {
            var targets = context.Get(DataType).ToArray();

            if (Project.OutputAttributes.HasFlag(BSharpBuilderOutputAttributes.SingleFile))
            {
                foreach (var t in targets.ToArray())
                {
                    var target = GenerateTarget(t);
                    WriteManager.Add(target);
                }
            }
            else
            {
                targets.ToArray().AsParallel().ForAll(_ =>
                {
                    var target = GenerateTarget(_);
                    WriteManager.Add(target);
                });
            }
        }
 private static IEnumerable <XElement> CollectReferencedDatabases(string theref, IBSharpContext context)
 {
     if (theref == "defaults")
     {
         foreach (var cls in context.ResolveAll("dbdef"))
         {
             if (cls.Compiled.Attr("isdefault").ToBool())
             {
                 yield return(cls.Compiled);
             }
         }
     }
     else
     {
         var db = context.Get(theref);
         if (null == db)
         {
             throw new Exception("cannot find db with cls name " + theref);
         }
         yield return(db.Compiled);
     }
 }
        /// <summary>
        ///     Подготавливает список целевых файлов с содержимым
        ///     для записи на диск
        /// </summary>
        /// <param name="context">Контекст компилятора</param>
        protected virtual void PrepareTargets(IBSharpContext context) {
			context.Get(DataType).ToArray().AsParallel().ForAll(_ =>{
				var target = GenerateTarget(_);
				WriteManager.Add(target);
			});
        }