Beispiel #1
0
        public override async Task <IDataToSent> TransformData(IDataToSent receiveData)
        {
            if (receiveData == null)
            {
                receiveData = new DataToSentTable();
            }
            var      jobUrl      = url + "/job/" + jobName + "/api/json";
            var      res         = new ReceiveRestFromFile(jobUrl);
            var      results     = CreateTable(receiveData);
            var      sw          = Stopwatch.StartNew();
            DateTime StartedDate = DateTime.UtcNow;

            try
            {
                var data = await res.TransformData(receiveData);

                results.Rows.Add("jenkinsjob", "/job/" + jobName + "/api/json", url, true, "", sw.ElapsedMilliseconds, "", null, StartedDate);
                return(data);
            }
            catch (Exception ex)
            {
                results.Rows.Add("jenkinsjob", "", url, false, null, sw.ElapsedMilliseconds, null, ex.Message, StartedDate);
            }
            return(receiveData);
        }
        public override async Task <IDataToSent> TransformData(IDataToSent receiveData)
        {
            if (receiveData == null)
            {
                receiveData = new DataToSentTable();
            }
            DataTable results     = CreateTable(receiveData);
            var       sw          = Stopwatch.StartNew();
            var       StartedDate = DateTime.UtcNow;

            try
            {
                var resp = NewConnection();
                using (resp)
                {
                    resp.ConnectionString = connectionString;
                    await resp.OpenAsync();

                    results.Rows.Add("receiverdatabaseserver", "", connectionString, true, resp.State, sw.ElapsedMilliseconds, resp.ServerVersion, null, StartedDate);
                }
            }
            catch (Exception ex)
            {
                results.Rows.Add("receiverdatabaseserver", "", connectionString, false, null, sw.ElapsedMilliseconds, null, ex.Message, StartedDate);
            }

            return(await Task.FromResult(receiveData));
        }
Beispiel #3
0
        public override async Task <IDataToSent> TransformData(IDataToSent receiveData)
        {
            if (receiveData == null)
            {
                receiveData = new DataToSentTable();
            }
            var       sw          = Stopwatch.StartNew();
            DataTable results     = CreateTable(receiveData);
            var       pingSender  = new Ping();
            var       StartedDate = DateTime.UtcNow;

            try
            {
                var reply = pingSender.Send(NameSite);

                results.Rows.Add("ping", "", NameSite, true, (int)reply.Status, reply.RoundtripTime.ToString(), reply.RoundtripTime.ToString(), null, StartedDate);
            }
            catch (Exception ex)
            {
                results.Rows.Add("ping", "", NameSite, false, null, sw.ElapsedMilliseconds, null, ex.Message, StartedDate);
            }


            return(await Task.FromResult(receiveData));
        }
Beispiel #4
0
        public override async Task <IDataToSent> TransformData(IDataToSent receiveData)
        {
            if (receiveData == null)
            {
                receiveData = new DataToSentTable();
            }

            DataTable dt = new DataTable
            {
                TableName = Path.GetDirectoryName(dirPath)
            };

            dt.Columns.Add(new DataColumn("FileName", typeof(string)));
            dt.Columns.Add(new DataColumn("FullFileName", typeof(string)));
            dt.Columns.Add(new DataColumn("Info", typeof(string)));

            foreach (string item in Directory.EnumerateFiles(dirPath))
            {
                try
                {
                    FileVersionInfo info = FileVersionInfo.GetVersionInfo(item);
                    dt.Rows.Add(new[] { Path.GetFileName(item), item, JsonConvert.SerializeObject(info) });
                }
                catch (Exception)
                {
                    //TODO: log
                }
            }
            int id = receiveData.AddNewTable(dt);

            receiveData.Metadata.AddTable(dt, id);
            return(await Task.FromResult(receiveData));
        }
Beispiel #5
0
        public override async Task <IDataToSent> TransformData(IDataToSent receiveData)
        {
            if (receiveData == null)
            {
                receiveData = new DataToSentTable();
            }

            JenkinsJson res = new JenkinsJson(url);

            System.Data.DataTable results = CreateTable(receiveData);
            Stopwatch             sw      = Stopwatch.StartNew();
            DateTime StartedDate          = DateTime.UtcNow;

            try
            {
                IDataToSent data = await res.TransformData(receiveData);

                results.Rows.Add("jenkinssite", "/api/json", url, true, "", sw.ElapsedMilliseconds, "", null, StartedDate);
                return(data);
            }
            catch (Exception ex)
            {
                results.Rows.Add("jenkinssite", "", url, false, null, sw.ElapsedMilliseconds, null, ex.Message, StartedDate);
            }
            return(receiveData);
        }
Beispiel #6
0
        public override async Task <IDataToSent> TransformData(IDataToSent receiveData)
        {
            if (receiveData == null)
            {
                receiveData = new DataToSentTable();
            }
            results     = CreateTable(receiveData);
            sw          = Stopwatch.StartNew();
            StartedDate = DateTime.UtcNow;
            try
            {
                process = new ProcessIntercept(FileName, Arguments);
                process.OutputDataReceived += new dia.DataReceivedEventHandler(Process_OutputDataReceived);
                process.ErrorDataReceived  += new dia.DataReceivedEventHandler(Process_ErrorDataReceived);
                //process.Exited += new System.EventHandler(Process_Exited);
                process.StartProcessAndWait();
            }
            catch (Exception ex)
            {
                results.Rows.Add("process", Arguments, FileName + Arguments, false, ex.Message, sw.ElapsedMilliseconds, "", ex.Message, StartedDate);
            }



            return(await Task.FromResult(receiveData));
        }
        public override async Task <IDataToSent> TransformData(IDataToSent receiveData)
        {
            if (receiveData == null)
            {
                receiveData = new DataToSentTable();
            }

            var file = new ReadFileToString
            {
                FileEnconding = Encoding.UTF8,
                FileToRead    = fileName
            };
            var data = await file.LoadData();

            var dt = new DataTable
            {
                TableName = "FileContents"
            };

            dt.Columns.Add(new DataColumn($"FilePath", typeof(string)));
            dt.Columns.Add(new DataColumn($"FileContents", typeof(string)));
            dt.Rows.Add(fileName, data);
            FastAddTable(receiveData, dt);
            return(receiveData);
        }
        public override async Task <IDataToSent> TransformData(IDataToSent receiveData)
        {
            if (receiveData == null)
            {
                receiveData = new DataToSentTable();
            }
            var dt = await FromSql(sql, "");

            FastAddTable(receiveData, dt);
            return(receiveData);
        }
        public override async Task <IDataToSent> TransformData(IDataToSent receiveData)
        {
            if (receiveData == null)
            {
                receiveData = new DataToSentTable();
            }
            var databasesString = "select database_id as id ,name from sys.databases";//2008+
            var databases       = await FromSql(databasesString, "databases");

            databases.TableName = "databases";
            FastAddTables(receiveData, databases);
            return(receiveData);
        }
Beispiel #10
0
        public override async Task <IDataToSent> TransformData(IDataToSent receiveData)
        {
            if (receiveData == null)
            {
                receiveData = new DataToSentTable();
            }
            var tr = new AHrefToTable();
            var dt = tr.TransformToTable(Content);

            var id = receiveData.AddNewTable(dt);

            receiveData.Metadata.AddTable(dt, id);
            return(await Task.FromResult(receiveData));
        }
        public override async Task <IDataToSent> TransformData(IDataToSent receiveData)
        {
            var file = new ReadFileToString
            {
                FileEnconding = this.Encoding,
                FileToRead    = this.File
            };

            var data = await file.LoadData();

            var doc = new HtmlDocument();

            doc.LoadHtml(data);
            var metas = doc.DocumentNode.SelectNodes("//head/meta");

            if ((metas?.Count ?? 0) == 0)
            {
                throw new ArgumentException("not found head meta");
            }

            var ret = new DataToSentTable();


            var dt = new DataTable
            {
                TableName = $"TableMeta"
            };

            dt.Columns.Add("meta_name");
            dt.Columns.Add("meta_content");
            if (metas != null)
            {
                foreach (var meta in metas)
                {
                    var attr = meta.Attributes;
                    if (!attr.Contains("name"))
                    {
                        continue;
                    }
                    var arr = new string[] { attr["name"].Value, attr["content"].Value };
                    dt.Rows.Add(arr);
                }
            }
            var id = ret.AddNewTable(dt);

            ret.Metadata.AddTable(dt, id);

            return(ret);
        }
Beispiel #12
0
        public override async Task <IDataToSent> TransformData(IDataToSent receiveData)
        {
            var ret = new DataToSentTable();

            var file = new ReadFileToString
            {
                FileEnconding = this.Encoding,
                FileToRead    = this.File
            };

            var data = await file.LoadData();

            bool web = file.FileType == FileType.Web;

            var startWeb = "";

            if (web)
            {
                var uri = new Uri(File);
                startWeb = uri.GetLeftPart(UriPartial.Authority);
            }
            var tr = new AHrefToTable();
            var dt = tr.TransformToTable(data);


            if (web)
            {
                foreach (DataRow item in dt.Rows)
                {
                    string val = item["href"]?.ToString();
                    if (val == null)
                    {
                        continue;
                    }

                    if (val.StartsWith("/"))
                    {
                        val = (startWeb + val).Replace("//", "/");
                    }
                    item["href"] = val;
                }
            }
            var id = ret.AddNewTable(dt);

            ret.Metadata.AddTable(dt, id);
            return(ret);
        }
Beispiel #13
0
        public override async Task <IDataToSent> TransformData(IDataToSent receiveData)
        {
            if (receiveData == null)
            {
                receiveData = new DataToSentTable();
            }
            var ass = Assembly.Load(fullAssemblyName);
            var dt  = new DataTable("types");

            dt.Columns.Add("FullName", typeof(string));
            dt.Columns.Add("Name", typeof(string));
            foreach (var item in ass.GetTypes())
            {
                dt.Rows.Add(item.FullName, item.Name);
            }
            FastAddTable(receiveData, dt);
            return(await Task.FromResult(receiveData));
        }
Beispiel #14
0
        public override async Task <IDataToSent> TransformData(IDataToSent receiveData)
        {
            var file = new ReadFileToString
            {
                FileEnconding = this.Encoding,
                FileToRead    = this.File
            };

            var data = await file.LoadData();

            var doc = new HtmlDocument();

            doc.LoadHtml(data);
            var nodes = doc.DocumentNode.SelectNodes(XPathExpression);

            //maybe return empty table?
            if ((nodes?.Count ?? 0) == 0)
            {
                throw new ArgumentException($"not found {XPathExpression}");
            }

            var ret = new DataToSentTable();

            int nrTable = 0;

            var dt = new DataTable
            {
                TableName = $"Table{nrTable}"
            };

            dt.Columns.Add("item");
            dt.Columns.Add("item_html");
            var id = ret.AddNewTable(dt);

            ret.Metadata.AddTable(dt, id);
            if (nodes != null)
            {
                foreach (var node in nodes)
                {
                    dt.Rows.Add(new[] { node.InnerText, node.OuterHtml });
                }
            }
            return(ret);
        }
Beispiel #15
0
        public override async Task <IDataToSent> TransformData(IDataToSent receiveData)
        {
            if (receiveData == null)
            {
                receiveData = new DataToSentTable();
            }
            var dt = new DataTable
            {
                TableName = Path.GetDirectoryName(PathFolder)
            };

            dt.Columns.Add(new DataColumn("FileName", typeof(string)));
            dt.Columns.Add(new DataColumn("FullFileName", typeof(string)));
            foreach (var item in Directory.GetFiles(PathFolder, Filter, this.SearchOption))
            {
                dt.Rows.Add(new[] { Path.GetFileName(item), item });
            }
            FastAddTable(receiveData, dt);
            return(await Task.FromResult(receiveData));
        }
Beispiel #16
0
        public override async Task <IDataToSent> TransformData(IDataToSent receiveData)
        {
            //var file = new ReadFileToString
            //{
            //    FileEnconding = this.Encoding,
            //    FileToRead = this.File
            //};

            //var data = await file.LoadData();
            var ret = new DataToSentTable();
            var dt  = new DataTable
            {
                TableName = $"XML"
            };

            dt.Columns.Add("Name");
            dt.Columns.Add("Value");
            dt.Columns.Add("OuterXML");
            XPathDocument document;

            try
            {
                document = new XPathDocument(File);
            }
            catch (Exception ex)
            {
                throw new ArgumentException($"cannot load {File} because {ex.Message}", ex);
            }
            var navig = document.CreateNavigator();
            var nodes = navig.Select(XPath);

            while (nodes.MoveNext())
            {
                var n = nodes.Current;
                dt.Rows.Add(new[] { n.Name, n.Value, n.OuterXml });
            }
            var id = ret.AddNewTable(dt);

            ret.Metadata.AddTable(dt, id);
            return(await Task.FromResult(ret));
        }
Beispiel #17
0
        public override async Task <IDataToSent> TransformData(IDataToSent receiveData)
        {
            if (receiveData == null)
            {
                receiveData = new DataToSentTable();
            }
            DataTable results = CreateTable(receiveData);
            var       sw      = Stopwatch.StartNew();
            var       ws      = WebRequest.Create(URL) as HttpWebRequest;

            ws.Method = Method;
            var StartedDate = DateTime.UtcNow;

            try
            {
                using (var resp = await ws.GetResponseAsync())
                {
                    var r    = resp as HttpWebResponse;
                    var sc   = (int)r.StatusCode;
                    var text = "";
                    if ((sc >= 200) && (sc <= 299))
                    {
                        using (var rs = r.GetResponseStream())
                        {
                            using (var sr = new StreamReader(rs))
                            {
                                text = await sr.ReadToEndAsync();
                            }
                        }
                    }
                    results.Rows.Add("webrequest", Method, URL, true, sc, sw.ElapsedMilliseconds, text, null, StartedDate);
                }
            }
            catch (Exception ex)
            {
                results.Rows.Add("webrequest", Method, URL, false, null, sw.ElapsedMilliseconds, null, ex.Message, StartedDate);
            }


            return(await Task.FromResult(receiveData));
        }
Beispiel #18
0
        public override async Task <IDataToSent> TransformData(IDataToSent receiveData)
        {
            output = new DataTable();
            output.Columns.Add(new DataColumn("message", typeof(string)));

            error = new DataTable();
            error.Columns.Add(new DataColumn("message", typeof(string)));

            var ret = new DataToSentTable();
            var id  = ret.AddNewTable(output);

            ret.Metadata.AddTable(output, id);
            id = ret.AddNewTable(error);
            ret.Metadata.AddTable(error, id);
            process = new ProcessIntercept(FileName, Arguments);
            process.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(Process_OutputDataReceived);
            process.ErrorDataReceived  += new System.Diagnostics.DataReceivedEventHandler(Process_ErrorDataReceived);
            process.Exited             += new System.EventHandler(Process_Exited);
            process.StartProcessAndWait();
            return(await Task.FromResult(ret));
        }
Beispiel #19
0
        public override async Task <IDataToSent> TransformData(IDataToSent receiveData)
        {
            var tables = await base.Find("//ul | //ol | //dl");

            if ((tables?.Count ?? 0) == 0)
            {
                throw new ArgumentException("not found ul, ol, dl");
            }

            var ret = new DataToSentTable();

            int nrTable = 0;

            foreach (var table in tables)
            {
                nrTable++;
                var dt = new DataTable
                {
                    TableName = $"Table{nrTable}"
                };

                dt.Columns.Add("li");
                dt.Columns.Add("li_html");

                var rows = table.SelectNodes("li");
                if (rows?.Count > 0)
                {
                    foreach (var row in rows)
                    {
                        dt.Rows.Add(row.InnerText, row.InnerHtml);
                    }
                }
                var id = ret.AddNewTable(dt);
                ret.Metadata.AddTable(dt, id);
            }
            return(ret);
        }
Beispiel #20
0
        public override async Task <IDataToSent> TransformData(IDataToSent receiveData)
        {
            if (receiveData == null)
            {
                receiveData = new DataToSentTable();
            }
            DataSet ds = FromJSon(await GetData());

            DataTable[] dt = ds.Tables.Cast <DataTable>().ToArray();
            FastAddTables(receiveData, dt);
            IMetadata meta = receiveData.Metadata;

            foreach (DataRelation rel in ds.Relations)
            {
                meta.Relations.Add(new Relation()
                {
                    IdTableParent = receiveData.FindAfterName(rel.ParentTable.TableName).Key,
                    IdTableChild  = receiveData.FindAfterName(rel.ChildTable.TableName).Key,
                    ColumnParent  = rel.ParentColumns.First().ColumnName,
                    ColumnChild   = rel.ChildColumns.First().ColumnName
                });
            }
            return(receiveData);
        }
        public override async Task <IDataToSent> TransformData(IDataToSent receiveData)
        {
            var tables = await base.Find("//table");

            if ((tables?.Count ?? 0) == 0)
            {
                throw new ArgumentException("not found tables");
            }

            var ret = new DataToSentTable();

            int nrTable = 0;

            foreach (var table in tables)
            {
                nrTable++;
                var dt = new DataTable
                {
                    TableName = $"Table{nrTable}"
                };

                string[] columnsNames = null;
                var      head         = table.SelectSingleNode("thead");
                if (head != null)
                {
                    var columns = head.SelectNodes("tr/th");
                    if ((columns?.Count ?? 0) == 0)
                    {
                        columns = head.SelectNodes("tr/td");
                    }
                    if (columns != null)
                    {
                        columnsNames = new string[columns.Count];
                        for (int i = 0; i < columns.Count; i++)
                        {
                            var colName = columns[i].InnerText;
                            columnsNames[i] = MakePretty(colName);
                        }
                    }
                }

                if ((columnsNames?.Length ?? 0) > 0)
                {
                    foreach (var item in columnsNames)
                    {
                        dt.Columns.Add(new DataColumn(item, typeof(string)));
                    }
                    foreach (var item in columnsNames)
                    {
                        dt.Columns.Add(new DataColumn(item + "_html", typeof(string)));
                    }
                }
                HtmlNodeCollection rows;

                var body = table.SelectSingleNode("tbody");
                if (body != null)
                {
                    rows = body.SelectNodes("tr");
                }
                else
                {
                    rows = table.SelectNodes("tr");
                }

                foreach (var row in rows)
                {
                    var cells = row.SelectNodes("td");
                    if ((cells?.Count ?? 0) == 0)
                    {
                        cells = row.SelectNodes("th");
                    }
                    if ((cells?.Count ?? 0) == 0)
                    {
                        continue;
                    }

                    if ((columnsNames?.Length ?? 0) == 0)
                    {
                        columnsNames = new string[cells.Count];
                        for (int i = 0; i < columnsNames.Length; i++)
                        {
                            var colName = cells[i].InnerText;
                            columnsNames[i] = MakePretty(cells[i].InnerText);
                        }
                        foreach (var item in columnsNames)
                        {
                            dt.Columns.Add(new DataColumn(item, typeof(string)));
                        }
                        foreach (var item in columnsNames)
                        {
                            dt.Columns.Add(new DataColumn(item + "_html", typeof(string)));
                        }
                        continue;
                    }
                    if ((cells?.Count ?? 0) == 0)
                    {
                        continue;
                    }
                    var arr = cells.Select(it => it.InnerText).ToList();
                    arr.AddRange(cells.Select(it => it.InnerHtml).ToArray());
                    dt.Rows.Add(arr.ToArray());
                }
                var id = ret.AddNewTable(dt);
                ret.Metadata.AddTable(dt, id);
            }
            return(ret);
        }
        public override async Task <IDataToSent> TransformData(IDataToSent receiveData)
        {
            var file = new ReadFileToString
            {
                FileEnconding = this.Encoding,
                FileToRead    = this.File
            };

            var data = await file.LoadData();

            bool web = file.FileType == FileType.Web;

            var ret = new DataToSentTable();

            var dt = new DataTable
            {
                TableName = $"TableLinks"
            };

            var regex = new Regex(Expression);
            var names = regex.
                        GetGroupNames().
                        Where(it => !int.TryParse(it, out var _)).
                        ToArray();

            foreach (var n in names)
            {
                dt.Columns.Add(new DataColumn(n, typeof(string)));
            }
            RegexOptions    options = RegexOptions.Multiline;
            MatchCollection matches = Regex.Matches(data, Expression, options);

            foreach (Match g in matches)
            {
                if (!g.Success)
                {
                    continue;
                }
                var item   = new string[names.Length];
                var groups = g.Groups;
                int i      = -1;
                foreach (var n in names)
                {
                    i++;
                    Group gr;
                    try
                    {
                        gr = groups[n];
                    }
                    catch
                    {
                        //TODO: log exception or put in exception table
                        continue;
                    }
                    if (gr.Success)
                    {
                        item[i] = gr.Value;
                    }
                }
                dt.Rows.Add(item);
            }
            var id = ret.AddNewTable(dt);

            ret.Metadata.AddTable(dt, id);
            return(ret);
        }
        public override async Task <IDataToSent> TransformData(IDataToSent receiveData)
        {
            if (!File.Exists(fileNameSln))
            {
                throw new FileNotFoundException(fileNameSln);
            }

            if (receiveData == null)
            {
                receiveData = new DataToSentTable();
            }
            var manager = new AnalyzerManager(fileNameSln);
            var sol     = manager.GetWorkspace().CurrentSolution;

            var dtSolution = new DataTable();

            dtSolution.TableName = "solutions";

            dtSolution.Columns.Add("Name", typeof(string));
            dtSolution.Columns.Add("FilePath", typeof(string));
            dtSolution.Columns.Add("Type", typeof(string));

            dtSolution.Rows.Add(Path.GetFileNameWithoutExtension(fileNameSln), fileNameSln);

            var dtProjects = new DataTable();

            dtProjects.TableName = "projects";
            dtProjects.Columns.Add("Id", typeof(string));
            dtProjects.Columns.Add("SolutionFilePath", typeof(string));
            dtProjects.Columns.Add("Name", typeof(string));
            dtProjects.Columns.Add("FilePath", typeof(string));
            dtProjects.Columns.Add("Type", typeof(string));


            var dtRelationProject = new DataTable();

            dtRelationProject.TableName = "projectReferences";
            dtRelationProject.Columns.Add("PrjId", typeof(string));
            dtRelationProject.Columns.Add("RefPrjId", typeof(string));

            var dtAssemblies = new DataTable();

            dtAssemblies.TableName = "assemblies";
            dtAssemblies.Columns.Add("Name", typeof(string));
            dtAssemblies.Columns.Add("DisplayNameToken", typeof(string));
            dtAssemblies.Columns.Add("FullName", typeof(string));
            dtAssemblies.Columns.Add("Version", typeof(string));

            var dtRelProjectAssemblies = new DataTable();

            dtRelProjectAssemblies.TableName = "projectAssemblies";
            dtRelProjectAssemblies.Columns.Add("PrjId", typeof(string));
            dtRelProjectAssemblies.Columns.Add("FullName", typeof(string));

            var existsAssemblies = new List <string>();

            foreach (var prj in sol.Projects)
            {
                var id = prj.Id.Id.ToString("N");
                dtProjects.Rows.Add(
                    id,
                    fileNameSln,
                    prj.Name,
                    prj.FilePath,
                    prj.GetType().Name
                    );
                foreach (var prjProjectReference in prj.ProjectReferences)
                {
                    dtRelationProject.Rows.Add(id, prjProjectReference.ProjectId.Id.ToString("N"));
                }

                var c = await prj.GetCompilationAsync();

                foreach (var referencedAssemblyName in c.ReferencedAssemblyNames)
                {
                    var fullName = referencedAssemblyName.GetDisplayName(true);
                    if (!existsAssemblies.Contains(fullName))
                    {
                        existsAssemblies.Add(fullName);
                        dtAssemblies.Rows.Add(referencedAssemblyName.Name,
                                              referencedAssemblyName.GetDisplayName(false),
                                              fullName,
                                              referencedAssemblyName.Version.ToString());
                    }

                    dtRelProjectAssemblies.Rows.Add(id, fullName);
                }
                //TODO: project.MetadataReferences
            }

            FastAddTables(receiveData, dtSolution, dtProjects, dtRelationProject, dtAssemblies, dtRelProjectAssemblies);

            return(receiveData);
        }
        public override async Task <IDataToSent> TransformData(IDataToSent receiveData)
        {
            if (receiveData == null)
            {
                receiveData = new DataToSentTable();
            }
            var tablesProperties = new DataTable("properties");

            var tablesString = $@"select t.object_id as id, s.name +'.'+ t.name as name from sys.tables t
                            inner join sys.schemas s on t.schema_id = s.schema_id order by 2 ";
            var newTables    = FromSql(tablesString, "tables");


            var viewsString = $@"select t.object_id as id, s.name +'.'+ t.name as name from sys.views t
                            inner join sys.schemas s on t.schema_id = s.schema_id order by 2 ";
            var newViews    = FromSql(viewsString, "views");

            var cols = $@"select cast(c.column_id as nvarchar) +'_'+ cast(c.object_id as varchar) as id, c.name,c.object_id as tableId,t.name as type  
                        
,case when coalesce(c.is_nullable,0) = 1 then 1
else 0
end as IS_NULLABLE
                        from sys.columns c
                        inner join sys.types t on t.system_type_id = c.system_type_id
           left join sys.tables o on o.object_id = c.object_id
						left join sys.views vw on vw.object_id = c.object_id

where len(coalesce(cast(o.object_id as varchar),cast(vw.object_id as varchar),''))>0              
order by 2";

            var newCols = FromSql(cols, "columns");
            var rels    = $@"select 

a.object_id as id , a.name,

b.parent_object_id,cast(b.parent_column_id as nvarchar)+'_'+ cast(b.parent_object_id as nvarchar) as parent_column_id,
b.referenced_object_id,cast(b.referenced_column_id as nvarchar) + '_'+ cast(b.referenced_object_id as nvarchar) as referenced_column_id


from sys.foreign_keys a
    join sys.foreign_key_columns b
                on a.object_id=b.constraint_object_id order by 2";
            var newRels = FromSql(rels, "relations");



            var keySql = @"SELECT
DISTINCT
OBJECT_ID(Table_Schema +'.'+ Constraint_Name) as id,
Table_Schema +'.'+ Constraint_Name AS name,
OBJECT_ID(Table_Schema +'.'+ TABLE_NAME) as tableId,
cast(c.column_id as varchar)+'_'+ cast(OBJECT_ID(Table_Schema +'.'+ TABLE_NAME) as varchar) as column_id,
o.type_desc
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
inner join sys.objects o on o.object_id = OBJECT_ID(Table_Schema +'.'+ Constraint_Name)
inner join sys.columns c on OBJECT_ID(Table_Schema +'.'+ TABLE_NAME) = c.object_id
and c.name =COLUMN_NAME";

            var newKeys = FromSql(keySql, "keys");
            await Task.WhenAll(newTables, newCols, newRels, newKeys, newViews);



            var props =
                "select t.object_id as id, 'tables' as TableName,t.* from sys.tables t inner join sys.schemas s on t.schema_id = s.schema_id";

            var propsNew = await FromSqlToProperties(props);

            tablesProperties.Merge(propsNew, true, MissingSchemaAction.Add);


            props =
                "select cast(c.column_id as nvarchar) +'_'+ cast(c.object_id as varchar) as id, 'columns' as TableName,c.* from sys.columns c inner join sys.tables o on o.object_id = c.object_id";

            propsNew = await FromSqlToProperties(props);

            tablesProperties.Merge(propsNew, true, MissingSchemaAction.Add);

            props    = @"SELECT 
cast(c.column_id as nvarchar) +'_'+ cast(c.object_id as varchar) as id, 
 'columns' as TableName,

schemacols.* FROM INFORMATION_SCHEMA.COLUMNS schemaCols
inner join sys.columns c on schemaCols.COLUMN_NAME = c.name
inner join sys.tables t on t.object_id = c.object_id and t.name = schemaCols.TABLE_NAME
inner join sys.schemas s on t.schema_id = s.schema_id and s.name = schemaCols.TABLE_SCHEMA
";
            propsNew = await FromSqlToProperties(props);

            tablesProperties.Merge(propsNew, true, MissingSchemaAction.Add);


            var ids = FastAddTables(receiveData, newTables.Result, newCols.Result, newRels.Result, newKeys.Result, tablesProperties, newViews.Result);
            var r   = new Relation();

            r.IdTableParent = ids[0];
            r.IdTableChild  = ids[1];
            r.ColumnParent  = "id";
            r.ColumnChild   = "databaseId";
            receiveData.Metadata.Relations.Add(r);

            r = new Relation();
            r.IdTableParent = ids[1];
            r.IdTableChild  = ids[2];
            r.ColumnParent  = "id";
            r.ColumnChild   = "tableId";
            receiveData.Metadata.Relations.Add(r);



            return(receiveData);
        }
Beispiel #25
0
        public override async Task <IDataToSent> TransformData(IDataToSent receiveData)
        {
            if (receiveData == null)
            {
                receiveData = new DataToSentTable();
            }

            var file = new ReadFileToString
            {
                FileEnconding = this.encoding,
                FileToRead    = this.fileNameYaml
            };

            var data = await file.LoadData();

            var yaml = new YamlDevOpsVisitor();

            yaml.LoadFromString(data);
            var jobs   = yaml.jobs;
            var dtJobs = new DataTable("jobs");

            dtJobs.Columns.Add(new DataColumn("name", typeof(string)));
            dtJobs.Columns.Add(new DataColumn("condition", typeof(string)));
            dtJobs.Columns.Add(new DataColumn("pool", typeof(string)));

            var dtSteps = new DataTable("steps");

            dtSteps.Columns.Add("jobName", typeof(string));
            dtSteps.Columns.Add(new DataColumn("displayName", typeof(string)));
            dtSteps.Columns.Add(new DataColumn("name", typeof(string)));
            dtSteps.Columns.Add(new DataColumn("value", typeof(string)));

            var dtDepends = new DataTable("jobDepends");

            dtDepends.Columns.Add("jobName", typeof(string));
            dtDepends.Columns.Add("jobNameDepends", typeof(string));

            int idJob = 0;

            foreach (var job in jobs)
            {
                idJob++;
                if (string.IsNullOrEmpty(job.Name))
                {
                    job.Name = $"NewJob{idJob}";
                }
                dtJobs.Rows.Add(job.Name, job.condition, job.pool.ToString());

                foreach (var step in job.Steps)
                {
                    dtSteps.Rows.Add(job.Name, step.DisplayName, step.Name, step.Value);
                }
                foreach (var name in job.DependsOn)
                {
                    dtDepends.Rows.Add(job.Name, name);
                }
            }
            var id = receiveData.AddNewTable(dtJobs);

            receiveData.Metadata.AddTable(dtJobs, id);

            id = receiveData.AddNewTable(dtSteps);
            receiveData.Metadata.AddTable(dtSteps, id);

            id = receiveData.AddNewTable(dtDepends);
            receiveData.Metadata.AddTable(dtDepends, id);

            return(await Task.FromResult(receiveData));
        }