System.Data.DataRowCollection.Add(params object[])

Here are the examples of the csharp api System.Data.DataRowCollection.Add(params object[]) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

877 Examples 7

19 View Source File : Extension.cs
License : MIT License
Project Creator : Agenty

public static DataTable FileToTable(this string path, bool heading = true, char delimiter = '\t')
        {
            var table = new DataTable();
            string headerLine = File.ReadLines(path).FirstOrDefault(); // Read the first row for headings
            string[] headers = headerLine.Split(delimiter);
            int skip = 1;
            int num = 1;
            foreach (string header in headers)
            {
                if (heading)
                    table.Columns.Add(header);
                else
                {
                    table.Columns.Add("Field" + num); // Create fields header if heading is false
                    num++;
                    skip = 0; // Don't skip the first row if heading is false
                }
            }
            foreach (string line in File.ReadLines(path).Skip(skip))
            {
                if (!string.IsNullOrEmpty(line))
                {
                    table.Rows.Add(line.Split(delimiter));
                }
            }
            return table;
        }

19 View Source File : Extension.cs
License : MIT License
Project Creator : Agenty

public static DataTable FileToTable(this string path, bool heading = true, char delimiter = '\t', int offset = 0, int limit = 100000)
        {
            var table = new DataTable();
            string headerLine = File.ReadLines(path).FirstOrDefault(); // Read the first row for headings
            string[] headers = headerLine.Split(delimiter);
            int skip = 1;
            int num = 1;
            foreach (string header in headers)
            {
                if (heading)
                {
                    table.Columns.Add(header); 
                }
                else
                {
                    table.Columns.Add("Field" + num); // Create fields header if heading is false
                    num++;
                    skip = 0; // Don't skip the first row if heading is false
                }
            }

            foreach (string line in File.ReadLines(path).Skip(skip + offset).Take(limit))
            {
                if (!string.IsNullOrEmpty(line))
                {
                    table.Rows.Add(line.Split(delimiter));
                }
            }
            return table;
        }

19 View Source File : DataRowCollection.cs
License : Mozilla Public License 2.0
Project Creator : ahyahy

public osf.DataRow Add(DataRow p1)
        {
            M_DataRowCollection.Add(p1.M_DataRow);
            return p1;
        }

19 View Source File : JSON.cs
License : MIT License
Project Creator : AlenToma

private void ReadDataTable(List<object> rows, DataTable dt)
        {
            dt.BeginInit();
            dt.BeginLoadData();
            List<int> guidcols = new List<int>();
            List<int> datecol = new List<int>();
            List<int> bytearraycol = new List<int>();

            foreach (DataColumn c in dt.Columns)
            {
                if (c.DataType == typeof(Guid) || c.DataType == typeof(Guid?))
                    guidcols.Add(c.Ordinal);
                if (_params.UseUTCDateTime && (c.DataType == typeof(DateTime) || c.DataType == typeof(DateTime?)))
                    datecol.Add(c.Ordinal);
                if (c.DataType == typeof(byte[]))
                    bytearraycol.Add(c.Ordinal);
            }

            foreach (List<object> row in rows)
            {
                object[] v = new object[row.Count];
                row.CopyTo(v, 0);
                foreach (int i in guidcols)
                {
                    string s = (string)v[i];
                    if (s != null && s.Length < 36)
                        v[i] = new Guid(Convert.FromBase64String(s));
                }
                foreach (int i in bytearraycol)
                {
                    string s = (string)v[i];
                    if (s != null)
                        v[i] = Convert.FromBase64String(s);
                }
                if (_params.UseUTCDateTime)
                {
                    foreach (int i in datecol)
                    {
                        string s = (string)v[i];
                        if (s != null)
                            v[i] = JsonHelper.CreateDateTime(s, _params.UseUTCDateTime);
                    }
                }
                dt.Rows.Add(v);
            }

            dt.EndLoadData();
            dt.EndInit();
        }

19 View Source File : MKMMetaCard.cs
License : GNU Affero General Public License v3.0
Project Creator : alexander-pick

public void WriteItselfIntoTable(DataTable table, bool writeAllAttributes, MCFormat format, bool noSynonyms)
    {
      List<string> attributes = new List<string>();
      foreach (DataColumn dc in table.Columns) // first we collect all attributes that are already in the table
      {
        attributes.Add(GetAttribute(dc.ColumnName));
      }
      if (writeAllAttributes)
      {
        // if we are supposed to write even attributes that are not in the table yet,
        // for each such attribute create a new column and add the current value
        foreach (var att in data)
        {
          if (att.Value != "" && !table.Columns.Contains(att.Key))
          {
            if (noSynonyms)
            {
              // check if this attribute is a synonym, if it is, write it only if the "parent" (the main name) is non-empty
              if (synonyms.TryGetValue(att.Key, out var synonymRoot))
              {
                if (GetAttribute(synonymRoot) != "")
                  continue;
              }
            }
            DataColumn newColumn = new DataColumn(att.Key, typeof(string))
            {
              DefaultValue = ""
            };
            table.Columns.Add(newColumn);
            attributes.Add(att.Value);
          }
        }
      }
      DataRow dr = table.Rows.Add(attributes.ToArray());

      // do format-specific conversions
      if (format == MCFormat.Deckbox)
      {
        if (table.Columns.Contains(MCAttribute.Condition))
        {
          string temp = dr[MCAttribute.Condition].ToString();
          if (temp != "")
            dr[MCAttribute.Condition] = conditionsDeckboxDictionary[temp];
        }
        if (table.Columns.Contains(MCAttribute.Foil))
        {
          string temp = dr[MCAttribute.Foil].ToString();
          if (temp != "")
            dr[MCAttribute.Foil] = (temp == "true" ? "Foil" : "");
        }
        if (table.Columns.Contains(MCAttribute.Signed))
        {
          string temp = dr[MCAttribute.Signed].ToString();
          if (temp != "")
            dr[MCAttribute.Signed] = (temp == "true" ? "Signed" : "");
        }
        if (table.Columns.Contains(MCAttribute.Altered))
        {
          string temp = dr[MCAttribute.Altered].ToString();
          if (temp != "")
            dr[MCAttribute.Altered] = (temp == "true" ? "Altered" : "");
        }
      }
    }

19 View Source File : DBAction.cs
License : Apache License 2.0
Project Creator : aryice

public DataTable testBulkRowData(SqlBaseItemXml basemodel,string tablename)
        {
            DataTable bulkdata = DBConfig.GetTableStruct(basemodel, tablename);
            Random random = new Random();
            long rowmin = 0;
            long rowcurrent = 0;
            long rowmax = 0;
            int rownum = 10000;

            long rowidrrr = DBConfig.GetRowId(basemodel.Number);
            DBConfig.UpdateRowId(basemodel.Number,rownum);
            rowmin = rowidrrr + 1;
            rowmax = rowmin + rownum;
            rowcurrent = rowmin;
            for (int i = 0; i < rownum; i++)
            {
                DataRow newRow;
                newRow = bulkdata.NewRow();
                #region
                newRow["id"] = rowcurrent++;
                newRow["num1"] = rowcurrent / 100000;
                newRow["num2"] = random.Next(10000);
                newRow["num3"] = random.NextDouble();
                newRow["str11"] = tablename + i;
                #endregion
                bulkdata.Rows.Add(newRow);
            }
            return bulkdata;
        }

19 View Source File : DBRead.cs
License : Apache License 2.0
Project Creator : aryice

public DataTable GetList(SqlBaseItemXml basemodel,ConditionFieldModel condition, ref long sqlnum)
        {
            sqlnum = 0;
            long getmaxnum = 500;
            long getrowcount = 0;
            DataTable dt = new DataTable();
            DBRule serverrule = new DBRule();
            List<MatchServerList> serverlist = serverrule.GetMatchServer(basemodel, condition);

            if (serverlist != null && serverlist.Count > 0)
            {
                List<TaskDataParam> taskdataparam = new List<TaskDataParam>();
                foreach (var item in serverlist)
                {
                    var servermodel = DBConfig.GetServerItemXmlConfig(basemodel, item.ServerNumber);
                    if (servermodel != null)
                    {
                        TaskDataParam tempparam = new TaskDataParam();
                        tempparam.servername = servermodel.ServerName;
                        tempparam.dbtype = servermodel.DBType;
                        tempparam.connstr = DBProxyAction.GetConnStr(basemodel,servermodel);
                        tempparam.sqlstr = DBProxyAction.GetSqlList(servermodel, item, condition, getmaxnum);
                        taskdataparam.Add(tempparam);
                    }
                }
                Console.WriteLine("满足条件的数据库表:" + taskdataparam.Count);
                foreach (var itemparam in taskdataparam)
                {
                    Console.WriteLine("访问服务器:"+itemparam.servername);
                    var dttemp =DBProxy.GetDBHelper(itemparam.dbtype).GetDataDable(itemparam.connstr, itemparam.sqlstr);
                    sqlnum++;
                    if (dttemp != null && dttemp.Rows.Count>0)
                    {
                        var dttempcount = dttemp.Rows.Count;
                        if (getrowcount>0)
                        {
                            foreach (DataRow dtrow in dttemp.Rows)
                            {
                                if (getrowcount >= getmaxnum)
                                {
                                    return dt;
                                }
                                getrowcount++;
                                DataRow r = dt.NewRow();
                                r.ItemArray = dtrow.ItemArray;
                                dt.Rows.Add(r);

                            }
                        }
                        else
                        {
                            getrowcount = dttemp.Rows.Count;
                            dt = dttemp;
                        }
                    }
                    if (getrowcount >= getmaxnum)
                    {
                        return dt;
                    }
                }
            }
            return dt;
        }

19 View Source File : Profile.cs
License : MIT License
Project Creator : ASHTeam

public virtual DataSet GetDataSet()
		{
			VerifyName();
			
			string[] sections = GetSectionNames();
			if (sections == null)
				return null;
			
			DataSet ds = new DataSet(Name);
			
			// Add a table for each section
			foreach (string section in sections)
			{
				DataTable table = ds.Tables.Add(section);
				
				// Retrieve the column names and values
				string[] entries = GetEntryNames(section);
				DataColumn[] columns = new DataColumn[entries.Length];
				object[] values = new object[entries.Length];								

				int i = 0;
				foreach (string entry in entries)
				{
					object value = GetValue(section, entry);
				
					columns[i] = new DataColumn(entry, value.GetType());
					values[i++] = value;
				}
												
				// Add the columns and values to the table
				table.Columns.AddRange(columns);
				table.Rows.Add(values);								
			}
			
			return ds;
		}

19 View Source File : ClusterNaming.cs
License : MIT License
Project Creator : ASStoredProcedures

[SafeToPrepare(true)]
        public static DataTable DistinguishingCharacteristicsForClusters(string ModelName, bool MentionAttributeName)
        {
            Microsoft.replacedysisServices.AdomdServer.MiningModel model = Context.MiningModels[ModelName];
            if (model == null) throw new Exception("Model not found");
            if (model.Content.Count == 0) throw new Exception("Model not processed");
            DataTable tableReturn = new DataTable();
            tableReturn.Columns.Add("ID");
            tableReturn.Columns.Add("DistinguishingCharacteristics");
            tableReturn.Columns.Add("FullDescription");

            if (Context.ExecuteForPrepare) return tableReturn;

            DataTable tableAll = GetClusterCharacteristics(ModelName, "", 0.0005); //get the characteristics of the entire population
            int iMiscNodesCount = 0;
            DataTable[] tables = new DataTable[model.Content[0].Children.Count];
            int[] extraAttributes = new int[model.Content[0].Children.Count];
            Dictionary<string, int> dictDistinguishers = new Dictionary<string, int>();
            for (int i = 0; i< model.Content[0].Children.Count; i++)
            {
                int iExtraAttributesAdded = 0;
                MiningContentNode node = model.Content[0].Children[i];
                object[] row = new object[3];
                row[0] = node.Name;
                DataTable tableNode = (tables[i] ?? GetClusterCharacteristics(ModelName, node.Name, 0.0005));
                tables[i] = tableNode;
                StringBuilder sDistinguishers = new StringBuilder();
                foreach (DataRow dr in tableNode.Rows)
                {
                    if (MIN_PROBABILITY >= Convert.ToDouble(dr["Frequency "]) && iExtraAttributesAdded == extraAttributes[i]) break;

                    //find matching row and continue if this cluster is distinguished by this attribute/value pair
                    foreach (DataRow dr2 in tableAll.Rows)
                    {
                        if (Convert.ToString(dr2["Attributes"]) == Convert.ToString(dr["Attributes"]) && Convert.ToString(dr2["Values"]) == Convert.ToString(dr["Values"])) {
                            if (Convert.ToDouble(dr2["Frequency "]) + MIN_PERCENT_DIFFERENT_THAN_WHOLE < Convert.ToDouble(dr["Frequency "])) //the column name actually ends in a space!
                            {
                                if (sDistinguishers.Length > 0) sDistinguishers.Append("; ");
                                if (MentionAttributeName) sDistinguishers.Append(dr["Attributes"]).Append(" = ");
                                sDistinguishers.Append(dr["Values"]);
                                if (MIN_PROBABILITY >= Convert.ToDouble(dr["Frequency "])) iExtraAttributesAdded++;
                            }
                            break;
                        }
                    }
                }
                Context.CheckCancelled(); //could be a bit long running, so allow user to cancel
                if (sDistinguishers.Length == 0) sDistinguishers.Append("Miscellaneous ").Append(++iMiscNodesCount);
                if (dictDistinguishers.ContainsKey(sDistinguishers.ToString()) && extraAttributes[i] < tableAll.Rows.Count)
                {
                    //a cluster with the exact same description already exists, so add another attribute to it and to the current cluster
                    extraAttributes[dictDistinguishers[sDistinguishers.ToString()]]++;
                    extraAttributes[i]++;
                    tableReturn.Rows.Clear();
                    dictDistinguishers.Clear();
                    i = -1; //reset loop
                }
                else
                {
                    row[1] = sDistinguishers.ToString();
                    row[2] = node.Description;
                    tableReturn.Rows.Add(row);
                }
            }
            return tableReturn;
        }

19 View Source File : DimensionHealthCheck.cs
License : MIT License
Project Creator : ASStoredProcedures

[AdomdServer.SafeToPrepare(true)]
        public static DataTable ListDimensionsWithErrors()
        {
            DataTable tableReturn = new DataTable();
            tableReturn.Columns.Add("Dimension");
            if (AdomdServer.Context.ExecuteForPrepare) return tableReturn;

            Server server = new Server();
            server.Connect("*");
            foreach (Dimension d in server.Databases.GetByName(AdomdServer.Context.CurrentDatabaseName).Dimensions)
            {
                DimensionError[] errors = Check(d);
                if (errors.Length > 0)
                {
                    tableReturn.Rows.Add(new object[] { d.Name });
                }
            }
            server.Disconnect();
            return tableReturn;
        }

19 View Source File : FileSystemCache.cs
License : MIT License
Project Creator : ASStoredProcedures

public static System.Data.DataTable GetFileSystemCacheBytes()
        {
            System.Data.DataTable tableReturn = new System.Data.DataTable();
            tableReturn.Columns.Add("Cache Bytes", typeof(long));
            tableReturn.Columns.Add("Cache GB", typeof(decimal));
            tableReturn.Columns.Add("Cache Bytes Peak", typeof(long));
            tableReturn.Columns.Add("Cache GB Peak", typeof(decimal));
            tableReturn.Columns.Add("Standby Cache Bytes", typeof(long));
            tableReturn.Columns.Add("Standby Cache GB", typeof(decimal));

            System.Diagnostics.PerformanceCounter pcCacheBytes = new System.Diagnostics.PerformanceCounter("Memory", "Cache Bytes", true);
            System.Diagnostics.PerformanceCounter pcCacheBytesPeak = new System.Diagnostics.PerformanceCounter("Memory", "Cache Bytes Peak", true);

            float fltCacheBytes = pcCacheBytes.NextValue();
            float fltCacheBytesPeak = pcCacheBytesPeak.NextValue();

            float? fltStandbyCacheBytes = null;

            try
            {
                System.Diagnostics.PerformanceCounter pcStandbyCacheBytes = new System.Diagnostics.PerformanceCounter("Memory", "Standby Cache Normal Priority Bytes", true);
                fltStandbyCacheBytes = pcStandbyCacheBytes.NextValue();
                pcStandbyCacheBytes.Close();
            }
            catch { }

            pcCacheBytes.Close();
            pcCacheBytesPeak.Close();

            object[] row = new object[] { 
                (long)fltCacheBytes, 
                decimal.Round((decimal)(fltCacheBytes / 1024 / 1024 / 1024), 2), 
                (long)fltCacheBytesPeak, 
                decimal.Round((decimal)(fltCacheBytesPeak / 1024 / 1024 / 1024), 2), 
                (fltStandbyCacheBytes==null?null:fltStandbyCacheBytes), 
                (fltStandbyCacheBytes==null?(decimal?)null:(decimal?)decimal.Round((decimal)(fltStandbyCacheBytes / 1024 / 1024 / 1024), 2))
            };

            tableReturn.Rows.Add(row);
            return tableReturn;
        }

19 View Source File : ListFunctions.cs
License : MIT License
Project Creator : ASStoredProcedures

[SafeToPrepare(true)]
        public static DataTable replacedemblyVersion()
        {
            // build the structure for the datatable which is returned
            DataTable dtVersion = new DataTable();
            dtVersion.Columns.Add("Version", typeof(string));
            dtVersion.Columns.Add("Major", typeof(int));
            dtVersion.Columns.Add("Minor", typeof(int));
            dtVersion.Columns.Add("Build", typeof(int));
            dtVersion.Columns.Add("Revision", typeof(int));

            Version v = typeof(FunctionLister).replacedembly.GetName().Version;
            object[] arrRowValues = new object[] { v.ToString(), v.Major, v.Minor, v.Build, v.Revision };
            dtVersion.Rows.Add(arrRowValues);

            return dtVersion;
        }

19 View Source File : SerialReceiver.cs
License : MIT License
Project Creator : atakansarioglu

private bool ProcessReceivedLine(string receivedLine, ref BBCodeBase bbCodeBase, ref DataTable dataTable)
        {
            // Decode the message.
            string decodedMessage = bbCodeBase.GetDecodedMessage(receivedLine);

            // Check message length.
            if (decodedMessage != "")
            {
                // Add time.
                dataTable.Rows.Add(new object[] { DateTime.Now.ToString("HH:mm:ss.ffffff"), decodedMessage });

                // Return true.
                return true;
            }
            else
            {
                // Return false.
                return false;
            }
        }

19 View Source File : MdmDataProvider.cs
License : MIT License
Project Creator : Azure

public async Task<IEnumerable<DataTable>> GetMultipleTimeSeriesAsync(DateTime startTimeUtc, DateTime endTimeUtc, Sampling sampling, IEnumerable<Tuple<string, string, IEnumerable<KeyValuePair<string, string>>>> definitions, int seriesResolutionInMinutes = 1, AggregationType aggregationType = AggregationType.Automatic)
        {
            // Create sampling type.
            var samplingType = sampling.ToSamplingType();

            // Create time series definition.
            var _definitions = new List<TimeSeriesDefinition<MetricIdentifier>>();
            foreach (var def in definitions)
            {
                _definitions.Add(
                    new TimeSeriesDefinition<MetricIdentifier>(
                        new MetricIdentifier(_configuration.MonitoringAccount, def.Item1, def.Item2),
                        def.Item3
                ));
            }

            var series = await _mdmClient.GetMultipleTimeSeriesAsync(
                startTimeUtc,
                endTimeUtc,
                samplingType.ToArray(),
                _definitions,
                seriesResolutionInMinutes,
                aggregationType);

            var result = new List<DataTable>();

            AddMdmInformationToMetadata(definitions,
                startTimeUtc,
                endTimeUtc,
                seriesResolutionInMinutes);

            // Generate data table.
            foreach (var serie in series)
            {
                foreach (var s in samplingType)
                {
                    var table = new DataTable();
                    table.Columns.Add("TimeStamp", typeof(DateTime));
                    table.Columns.Add("Metric", typeof(string));
                    table.Columns.Add(s.ToString(), typeof(double));

                    foreach (var point in serie.GetDatapoints(s))
                    {
                        table.Rows.Add(new object[] { point.TimestampUtc, serie.Definition.Id.MetricName, point.Value });
                    }

                    result.Add(table);
                }
            }

            return result;
        }

19 View Source File : LogAnalyticsClientBase.cs
License : MIT License
Project Creator : Azure

private DataTable ResultAsDataTable(QueryResults results)
        {
            DataTable dataTable = new DataTable("results");
            dataTable.Clear();

            dataTable.Columns.AddRange(results.Tables[0].Columns.Select(s => new DataColumn(s.Name, TypeConverter.StringToType(s.Type))).ToArray());
            var rows = results.Tables[0].Rows.Select(s => dataTable.NewRow().ItemArray = s.ToArray());
            foreach (var i in rows) 
            {
                dataTable.Rows.Add(MakeRow(i, dataTable).ToArray());
            }

            return dataTable;
        }

19 View Source File : MockKustoClient.cs
License : MIT License
Project Creator : Azure

private Task<DataTable> GetFakeTenantIdResults()
        {
            DataTable table = new DataTable();

            table.Columns.AddRange(new DataColumn[]
            {
                new DataColumn("Tenant", typeof(string)),
                new DataColumn("PublicHost", typeof(string))
            });

            table.Rows.Add(new string[2] { Guid.NewGuid().ToString(), "fakestamp.cloudapp.net" });

            return Task.FromResult(table);
        }

19 View Source File : MockKustoClient.cs
License : MIT License
Project Creator : Azure

private Task<DataTable> GetLatestDeployment()
        {
            DataTable table = new DataTable();

            table.Columns.AddRange(new DataColumn[]
            {
                new DataColumn("LatestDeployment", typeof(DateTime))
            });

            table.Rows.Add(new object[] { DateTime.UtcNow });

            return Task.FromResult(table);
        }

19 View Source File : MockLogAnalyticsClient.cs
License : MIT License
Project Creator : Azure

private DataTable ResultAsDataTable(QueryResults results)
        {
            DataTable dataTable = new DataTable("results");
            dataTable.Clear();

            dataTable.Columns.AddRange(results.Tables[0].Columns.Select(s => new DataColumn(s.Name)).ToArray());
            var rows = results.Tables[0].Rows.Select(s => dataTable.NewRow().ItemArray = s.ToArray());
            foreach (var i in rows) { dataTable.Rows.Add(i); }

            return dataTable;
        }

19 View Source File : AppInsightEnablement.cs
License : MIT License
Project Creator : Azure

public static DiagnosticData AddAppInsightsEnablement(this Response response, string resourceUri)
        {

            if (string.IsNullOrWhiteSpace(resourceUri))
            {
                throw new ArgumentNullException(nameof(resourceUri));
            }

            resourceUri = resourceUri.ToLower();
            if (!ValidateResourceUri(resourceUri))
            {
                throw new ArgumentException("resourceUri not in the correct format");
            }

            var table = new DataTable();
            table.Columns.Add(new DataColumn("ResourceUri", typeof(string)));
            table.Rows.Add(new object[] { resourceUri });

            var diagData = new DiagnosticData()
            {
                Table = table,
                RenderingProperties = new Rendering(RenderingType.AppInsightEnablement)
            };

            response.Dataset.Add(diagData);
            return diagData;
        }

19 View Source File : ApplicationInsight.cs
License : MIT License
Project Creator : Azure

public static DiagnosticData AddApplicationInsightsViewList(this Response response, List<AppInsightsOperationContext> applicationInsightsList)
        {
            if (applicationInsightsList == null || !applicationInsightsList.Any())
                throw new ArgumentNullException("Parameter applicationInsightsList is null or contains no elements.");

            var table = new DataTable();
            table.Columns.Add("replacedle", typeof(string));
            table.Columns.Add("Description", typeof(string));
            table.Columns.Add("Query", typeof(string));
            table.Columns.Add("PortalBladeInfo", typeof(BladeInfo));
            table.Columns.Add("RenderingProperties", typeof(Rendering));
            table.Columns.Add("DataTable", typeof(DataTableResponseObject));

            foreach (AppInsightsOperationContext context in applicationInsightsList)
            {
                table.Rows.Add(
                    context.replacedle,
                    context.Description,
                    context.Query,
                    context.PortalBladeInfo,
                    context.RenderingProperties,
                    context.DataTable
                    );
            }

            var diagnosticData = new DiagnosticData()
            {
                Table = table,
                RenderingProperties = new Rendering(RenderingType.AppInsight)
            };

            response.Dataset.Add(diagnosticData);
            return diagnosticData;
        }

19 View Source File : Card.cs
License : MIT License
Project Creator : Azure

public static DiagnosticData AddCards(this Response response, List<Card> cards)
        {
            var table = new DataTable();
            table.Columns.Add(new DataColumn("replacedle", typeof(string)));
            table.Columns.Add(new DataColumn("Icon", typeof(string)));
            table.Columns.Add(new DataColumn("Descriptions", typeof(string)));
            table.Columns.Add(new DataColumn("ActionType", typeof(string)));
            table.Columns.Add(new DataColumn("ActionValue", typeof(string)));

            cards.ForEach(card =>
            {
                table.Rows.Add(new object[] {
                    card.replacedle,
                    card.Icon,
                    JsonConvert.SerializeObject(card.Descriptions),
                    JsonConvert.SerializeObject(card.ActionType),
                    card.ActionValue
              });
            });

            var diagData = new DiagnosticData()
            {
                Table = table,
                RenderingProperties = new Rendering(RenderingType.Card)
            };

            response.Dataset.Add(diagData);
            return diagData;
        }

19 View Source File : ChangeAnalysis.cs
License : MIT License
Project Creator : Azure

public static DiagnosticData AddChangeSets(this Response response, List<ChangeSetResponseModel> changeSets)
        {
            // Even if there are no change sets found, we want to add the rendering type to UI so the user has option to scan for changes.
            if (changeSets == null || changeSets.Count <= 0)
            {
                var emptyData = new DiagnosticData
                {
                    Table = new DataTable(),
                    RenderingProperties = new Rendering(RenderingType.ChangeSets)
                    {
                        replacedle = string.Empty
                    }
                };

                response.Dataset.Add(emptyData);
                return emptyData;
            }

            DataTable results = new DataTable();
            results.TableName = "ChangeSets";
            results.Columns.Add(new DataColumn("ChangeSetId"));
            results.Columns.Add(new DataColumn("ResourceId"));
            results.Columns.Add(new DataColumn("Source"));
            results.Columns.Add(new DataColumn("TimeStamp"));
            results.Columns.Add(new DataColumn("TimeWindow"));
            results.Columns.Add(new DataColumn("InitiatedBy"));
            results.Columns.Add(new DataColumn("LastScanTime"));
            results.Columns.Add(new DataColumn("Inputs", typeof(List<ResourceChangesResponseModel>)));
            changeSets.ForEach(changeSet =>
            {
                results.Rows.Add(new object[]
                {
                    changeSet.ChangeSetId,
                    changeSet.ResourceId,
                    changeSet.Source,
                    changeSet.TimeStamp,
                    changeSet.TimeWindow,
                    changeSet.InitiatedBy
                });
            });

            var latestRow = results.Rows[0];
            latestRow[6] = changeSets[0].LastScanInformation != null ? changeSets[0].LastScanInformation.TimeStamp : string.Empty;
            latestRow[7] = changeSets[0].ResourceChanges ?? changeSets[0].ResourceChanges;
            var diagData = new DiagnosticData()
            {
                Table = results,
                RenderingProperties = new Rendering(RenderingType.ChangeSets)
                {
                    replacedle = string.Empty
                }
            };

            response.Dataset.Add(diagData);
            return diagData;
        }

19 View Source File : ChangeAnalysis.cs
License : MIT License
Project Creator : Azure

public static DiagnosticData AddOnboardingView(this Response response, string onboardingText = null)
        {
            var table = new DataTable();
            table.Columns.Add(new DataColumn("OnboardingText", typeof(string)));
            table.Rows.Add(new object[] { onboardingText });

            var diagData = new DiagnosticData()
            {
                Table = table,
                RenderingProperties = new Rendering(RenderingType.ChangereplacedysisOnboarding)
            };

            response.Dataset.Add(diagData);
            return diagData;
        }

19 View Source File : DataSummary.cs
License : MIT License
Project Creator : Azure

public static DiagnosticData AddDataSummary(this Response response, List<DataSummary> dataSummaryPoints, string replacedle = null, string description = null)
        {
            if (dataSummaryPoints == null || !dataSummaryPoints.Any())
            {
                return null;
            }

            DataTable table = new DataTable("Data Summary");

            table.Columns.AddRange(new DataColumn[]
            {
                new DataColumn("Name", typeof(string)),
                new DataColumn("Value", typeof(string)),
                new DataColumn("Color", typeof(string))
            });

            dataSummaryPoints.ForEach(item =>
            {
                table.Rows.Add(new string[]
                {
                    item.Name,
                    item.Value,
                    item.Color
                });
            });

            var summaryData = new DiagnosticData()
            {
                Table = table,
                RenderingProperties = new Rendering(RenderingType.DataSummary)
                {
                    replacedle = replacedle,
                    Description = description
                }
            };

            response.Dataset.Add(summaryData);

            return summaryData;
        }

19 View Source File : Downtime.cs
License : MIT License
Project Creator : Azure

public static DiagnosticData AddDownTimes(this Response response, IEnumerable<DownTime> downtimes)
        {
            if (downtimes is null)
            {
                throw new ArgumentNullException(nameof(downtimes));
            }

            if (!downtimes.Any())
            {
                throw new ArgumentException("downtimes contains no elements");
            }
            var table = new DataTable();
            table.Columns.Add("StartTime", typeof(DateTime));
            table.Columns.Add("EndTime", typeof(DateTime));
            table.Columns.Add("DownTimeLabel");
            table.Columns.Add("IsSelected", typeof(bool));

            foreach (var d in downtimes)
            {
                table.Rows.Add(
                    d.StartTime, 
                    d.EndTime, 
                    d.DownTimeLabel,
                    d.IsSelected);
            }

            var diagData = new DiagnosticData()
            {
                Table = table,
                RenderingProperties = new Rendering(RenderingType.DownTime)
            };

            response.Dataset.Add(diagData);
            return diagData;
        }

19 View Source File : Dropdown.cs
License : MIT License
Project Creator : Azure

public static DiagnosticData AddDropdownView(this Response response, Dropdown dropdownView, string replacedle, DropdownType type = DropdownType.Legacy, DropdownPosition position = DropdownPosition.FloatLeft)
        {
            var table = new DataTable();
            table.Columns.Add(new DataColumn("Label", typeof(string)));
            table.Columns.Add(new DataColumn("Key", typeof(string)));
            table.Columns.Add(new DataColumn("Selected", typeof(bool)));
            table.Columns.Add(new DataColumn("Value", typeof(string)));
            table.Columns.Add(new DataColumn("DropdownType", typeof(string)));
            table.Columns.Add(new DataColumn("DropdownPosition", typeof(string)));

            foreach (var item in dropdownView.Data)
            {
                List<DiagnosticDataApiResponse> dataSet = item.Item3.Dataset.Select(entry =>
                    new DiagnosticDataApiResponse()
                    {
                        RenderingProperties = entry.RenderingProperties,
                        Table = entry.Table.ToDataTableResponseObject()
                    }).ToList();

                table.Rows.Add(new object[] {
                    dropdownView.Label,
                    item.Item1,
                    item.Item2,
                    JsonConvert.SerializeObject(dataSet, new JsonSerializerSettings
                    {
                        ContractResolver = new CamelCasePropertyNamesContractResolver()
                    }),
                    type,
                    position
                });
            }


            var diagData = new DiagnosticData()
            {
                Table = table,
                RenderingProperties = new Rendering(RenderingType.DropDown)
                {
                    replacedle = replacedle ?? string.Empty
                }
            };

            response.Dataset.Add(diagData);
            return diagData;
        }

19 View Source File : Email.cs
License : MIT License
Project Creator : Azure

public static DiagnosticData AddEmail(this Response response, Email email)
        {
            if (email == null || string.IsNullOrWhiteSpace(email.Content)) return null;

            DataTable table = new DataTable("Data Summary");

            table.Columns.AddRange(new DataColumn[]
            {
                new DataColumn("Content", typeof(string))
            });

            table.Rows.Add(new string[]
            {
                email.Content
            });

            var diagnosticData = new DiagnosticData()
            {
                Table = table,
                RenderingProperties = new Rendering(RenderingType.Email)
            };

            response.Dataset.Add(diagnosticData);

            return diagnosticData;
        }

19 View Source File : Form.cs
License : MIT License
Project Creator : Azure

public static DiagnosticData AddForms(this Response response, List<Form> forms)
        {
            if (forms == null)
            {
                return null;
            }

            var table = new DataTable();
            table.TableName = "Forms";
            table.Columns.Add(new DataColumn("FormId", typeof(int)));
            table.Columns.Add(new DataColumn("Formreplacedle", typeof(string)));
            table.Columns.Add(new DataColumn("Inputs", typeof(List<FormInputBase>)));
            forms.ForEach(form =>
            {
                table.Rows.Add(new object[]
                {
                    form.FormId,
                    form.Formreplacedle,
                    form.FormInputs,
                });
            });

            var diagData = new DiagnosticData()
            {
                Table = table,
                RenderingProperties = new Rendering(RenderingType.Form)
                {
                    replacedle = string.Empty
                }
            };
            response.Dataset.Add(diagData);
            return diagData;
        }

19 View Source File : Guage.cs
License : MIT License
Project Creator : Azure

public static DiagnosticData AddGuages(this Response response, List<Guage> guages, GuageRenderDirection renderDirection)
        {
            if (guages == null || !guages.Any())
                throw new ArgumentNullException("Paramter List<Guage> is null or contains no elements.");

            var table = new DataTable();
            table.Columns.Add("RenderDirection", typeof(int));
            table.Columns.Add("Size", typeof(int));
            table.Columns.Add("FillColor", typeof(int));
            table.Columns.Add("PercentFilled", typeof(double));
            table.Columns.Add("DisplayValue", typeof(string));
            table.Columns.Add("Label", typeof(string));
            table.Columns.Add("Description", typeof(string));

            foreach (Guage g in guages)
            {
                table.Rows.Add(
                    JsonConvert.SerializeObject(renderDirection),
                    JsonConvert.SerializeObject(g.Size),
                    g.Status,
                    g.PercentFilled,
                    g.DisplayValue,
                    g.Label,
                    g.Description
                    );
            }

            var diagData = new DiagnosticData()
            {
                Table = table,
                RenderingProperties = new Rendering(RenderingType.Guage)
            };
            response.Dataset.Add(diagData);
            return diagData;
        }

19 View Source File : Insight.cs
License : MIT License
Project Creator : Azure

public static DiagnosticData AddInsights(this Response response, List<Insight> insights, string replacedle = null, string description = null)
        {
            if (insights == null || !insights.Any())
            {
                return null;
            }

            DataTable table = new DataTable();

            table.Columns.AddRange(new DataColumn[]
            {
                new DataColumn("Status", typeof(string)),
                new DataColumn("Message", typeof(string)),
                new DataColumn("Data.Name", typeof(string)),
                new DataColumn("Data.Value", typeof(string)),
                new DataColumn("Expanded", typeof(string)),
                new DataColumn(nameof(Insight.Solutions), typeof(string))
            });

            insights.ForEach(insight =>
            {
                foreach (var solution in insight.Solutions ?? Enumerable.Empty<Solution>())
                {
                    solution.DetectorId = response.Metadata.Id;
                    solution.IsInternal = response.IsInternalCall;
                }

                if (insight.Body == null || !insight.Body.Keys.Any())
                {
                    table.Rows.Add(new string[]
                    {
                        insight.Status.ToString(),
                        insight.Message,
                        string.Empty,
                        string.Empty,
                        insight.IsExpanded.ToString(),
                        JsonConvert.SerializeObject(insight.Solutions)
                    });
                }
                else
                {
                    // This duplicates all other insight properties for each KVP in Body
                    foreach (KeyValuePair<string, string> entry in insight.Body)
                    {
                        table.Rows.Add(new string[]
                        {
                            insight.Status.ToString(),
                            insight.Message,
                            entry.Key,
                            entry.Value,
                            insight.IsExpanded.ToString(),
                            JsonConvert.SerializeObject(insight.Solutions)
                        });
                    }
                }
            });

            var diagnosticData = new DiagnosticData()
            {
                Table = table,
                RenderingProperties = new Rendering(RenderingType.Insights)
                {
                    replacedle = replacedle,
                    Description = description
                }
            };

            response.Dataset.Add(diagnosticData);

            response.Insights.AddRange(insights);

            return diagnosticData;
        }

19 View Source File : KeystoneComponent.cs
License : MIT License
Project Creator : Azure

public static DiagnosticData AddKeystoneComponent(this Response response, KeystoneInsight keystoneInsight)
        {
            try
            {
                if (keystoneInsight.Status == null || string.IsNullOrWhiteSpace(keystoneInsight.replacedle) || string.IsNullOrWhiteSpace(keystoneInsight.Description))
                {
                    throw new Exception("Required attributes Status, replacedle, and Description cannot be null or empty for KeystoneInsight.");
                }
                if (DateTime.Compare(keystoneInsight.ExpiryDate, DateTime.UtcNow) <= 0)
                {
                    throw new Exception("Invalid ExpiryDate, ExpiryDate should be greater than current UTC datetime.");
                }
                var table = new DataTable();
                table.Columns.Add("Content", typeof(string));
                DataRow newRow = table.NewRow();
                newRow["Content"] = JsonConvert.SerializeObject(keystoneInsight);
                table.Rows.Add(newRow);
                var diagData = new DiagnosticData()
                {
                    Table = table,
                    RenderingProperties = new Rendering(RenderingType.KeystoneComponent)
                };
                response.Dataset.Add(diagData);
                return diagData;
            }
            catch (Exception ex)
            {
                throw new Exception("Keystone Insight validation failed: " + ex.ToString());
            }
        }

19 View Source File : Markdown.cs
License : MIT License
Project Creator : Azure

public static DiagnosticData AddMarkdownView(this Response response, string markdown, bool enableEmailButtons, string replacedle = null, bool isContainerNeeded = true)
        {
            var table = new DataTable();
            table.Columns.Add(new DataColumn("Markdown", typeof(string)));
            table.Rows.Add(new object[] { markdown });
            var diagData = new DiagnosticData()
            {
                Table = table,
                RenderingProperties = new MarkdownRendering()
                {
                    EnableEmailButtons = enableEmailButtons,
                    replacedle = replacedle,
                    IsContainerNeeded = isContainerNeeded
                }
            };

            response.Dataset.Add(diagData);
            return diagData;
        }

19 View Source File : Notification.cs
License : MIT License
Project Creator : Azure

public static DiagnosticData AddNotification(this Response response, Notification notification)
        {
            try
            {
                if (notification.Status == null || string.IsNullOrWhiteSpace(notification.replacedle))
                {
                    throw new Exception("Required attributes Status and replacedle cannot be null or empty for Notification.");
                }

                if (DateTime.Compare(notification.ExpiryDate, notification.StartDate) <= 0)
                {
                    throw new Exception("Invalid StartDate and ExpiryDate, ExpiryDate should be greater than StartDate.");
                }

                if (DateTime.Compare(notification.ExpiryDate, DateTime.UtcNow) <= 0)
                {
                    throw new Exception("Invalid ExpiryDate, ExpiryDate should be greater than current UTC datetime.");
                }

                var table = new DataTable();


                table.Columns.AddRange(new DataColumn[]
                {
                new DataColumn("Status", typeof(string)),
                new DataColumn("replacedle", typeof(string)),
                new DataColumn("Description", typeof(string)),
                new DataColumn("Solution", typeof(string)),
                new DataColumn("Expanded", typeof(string)),
                new DataColumn("StartDate", typeof(string)),
                new DataColumn("ExpiryDate", typeof(string))
                });

                table.Rows.Add(new string[]
                     {
                            notification.Status.ToString(),
                            notification.replacedle,
                            notification.Description,
                            JsonConvert.SerializeObject(notification.Solution),
                            notification.IsExpanded.ToString(),
                            JsonConvert.SerializeObject(notification.StartDate),
                            JsonConvert.SerializeObject(notification.ExpiryDate),
                     });

                var diagData = new DiagnosticData()
                {
                    Table = table,
                    RenderingProperties = new Rendering(RenderingType.Notification)
                };
                response.Dataset.Add(diagData);
                return diagData;
            }
            catch (Exception ex)
            {
                throw new Exception("Notification validation failed: " + ex.ToString());
            }
        }

19 View Source File : ResiliencyReportData.cs
License : MIT License
Project Creator : Azure

public static DiagnosticData AddResiliencyReportData(this Response response, ResiliencyReportData resiliencyReportData)
        {
            if (response == null || resiliencyReportData == null)
            {
                return null;
            }
            var table = new DataTable();

            table.Columns.Add(new DataColumn("ResiliencyReport", typeof(string)));
            string jsonResiliencyReport = JsonConvert.SerializeObject(resiliencyReportData, Formatting.Indented);
            table.Rows.Add(jsonResiliencyReport);

            string jsonResiliencyResourceList = JsonConvert.SerializeObject(resiliencyReportData.GetResiliencyResourceList(), Formatting.Indented);
            table.Rows.Add(jsonResiliencyResourceList);

            for (int siteNum = 0; siteNum < resiliencyReportData.GetResiliencyResourceList().GetLength(0); siteNum++)
            {
                string jsonResiliencyFeaturesList = JsonConvert.SerializeObject(resiliencyReportData.GetResiliencyResourceList()[siteNum].GetResiliencyFeaturesList(), Formatting.Indented);
                table.Rows.Add(jsonResiliencyFeaturesList);

            }

            var diagnosticData = new DiagnosticData()
            {
                Table = table,
                RenderingProperties = new Rendering(RenderingType.Report)
            };
            response.Dataset.Add(diagnosticData);
            return diagnosticData;
        }

19 View Source File : SearchComponent.cs
License : MIT License
Project Creator : Azure

public static DiagnosticData AddSearch(this Response response, string customQueryString = null, bool detectorSearchEnabled=true, bool webSearchEnabled=true, DetectorSearchConfiguration detectorSearchConfiguration=null, WebSearchConfiguration webSearchConfiguration=null)
        {
            var table = new DataTable();
            table.Columns.Add("DetectorSearchEnabled", typeof(bool));
            table.Columns.Add("WebSearchEnabled", typeof(bool));
            table.Columns.Add("DetectorSearchConfiguration", typeof(string));
            table.Columns.Add("WebSearchConfiguration", typeof(string));
            table.Columns.Add("CustomQueryString", typeof(string));
            DataRow newRow = table.NewRow();
            newRow["DetectorSearchEnabled"] = detectorSearchEnabled;
            newRow["WebSearchEnabled"] = webSearchEnabled;
            newRow["DetectorSearchConfiguration"] = detectorSearchConfiguration != null? JsonConvert.SerializeObject(detectorSearchConfiguration): JsonConvert.SerializeObject(new DetectorSearchConfiguration());
            newRow["WebSearchConfiguration"] = webSearchConfiguration != null? JsonConvert.SerializeObject(webSearchConfiguration): JsonConvert.SerializeObject(new WebSearchConfiguration());
            newRow["CustomQueryString"] = customQueryString;
            table.Rows.Add(newRow);
            var diagData = new DiagnosticData()
            {
                Table = table,
                RenderingProperties = new Rendering(RenderingType.SearchComponent)
            };
            response.Dataset.Add(diagData);
            return diagData;
        }

19 View Source File : Section.cs
License : MIT License
Project Creator : Azure

public static DiagnosticData AddSections(this Response response, List<Section> sections)
        {
            var table = new DataTable();
            table.Columns.Add(new DataColumn("replacedle", typeof(string)));
            table.Columns.Add(new DataColumn("Value", typeof(string)));
            table.Columns.Add(new DataColumn("Expanded", typeof(string)));
            foreach (var section in sections)
            {
                List<DiagnosticDataApiResponse> dataSet = section.Data.Dataset.Select(entry =>
                    new DiagnosticDataApiResponse()
                    {
                        RenderingProperties = entry.RenderingProperties,
                        Table = entry.Table.ToDataTableResponseObject()
                    }).ToList();
                table.Rows.Add(new object[]
                {
                    section.replacedle ?? string.Empty,
                    JsonConvert.SerializeObject(dataSet, new JsonSerializerSettings
                    {
                        ContractResolver = new CamelCasePropertyNamesContractResolver()
                    }),
                    section.IsExpanded.ToString()
                }); ;
            }

            var diagData = new DiagnosticData()
            {
                Table = table,
                RenderingProperties = new Rendering(RenderingType.Section)

            };


            response.Dataset.Add(diagData);
            return diagData;
        }

19 View Source File : SummaryCard.cs
License : MIT License
Project Creator : Azure

public static DiagnosticData AddSummaryCards(this Response response, List<SummaryCard> summaryCards)
        {
            if (summaryCards == null || !summaryCards.Any())
            {
                throw new ArgumentException("Paramter List<SummaryCard> is null or contains no elements.");
            }

            var table = new DataTable();
            table.Columns.Add("Status", typeof(string));
            table.Columns.Add("replacedle", typeof(string));
            table.Columns.Add("Message", typeof(string));
            table.Columns.Add("Description", typeof(string));
            table.Columns.Add("Link", typeof(string));
            table.Columns.Add("ActionType", typeof(string));

            foreach (var summaryCard in summaryCards)
            {
                DataRow nr = table.NewRow();
                nr["Status"] = summaryCard.Status;
                nr["replacedle"] = summaryCard.replacedle;
                nr["Message"] = summaryCard.Message;
                nr["Description"] = summaryCard.Description;
                nr["Link"] = summaryCard.OnClickActionLink;
                nr["ActionType"] = summaryCard.OnClickActionType;
                table.Rows.Add(nr);
                //table.Rows.Add(summaryCard.Status,summaryCard.replacedle,summaryCard.Message,summaryCard.Description);
            }

            var diagData = new DiagnosticData()
            {
                Table = table,
                RenderingProperties = new Rendering(RenderingType.SummaryCard)
            };
            response.Dataset.Add(diagData);
            return diagData;
        }

19 View Source File : Tab.cs
License : MIT License
Project Creator : Azure

public static DiagnosticData AddTabs(this Response response, List<Tab> tabs, string replacedle = null)
        {
            var table = new DataTable();
            table.Columns.Add(new DataColumn("Label", typeof(string)));
            table.Columns.Add(new DataColumn("Icon", typeof(string)));
            table.Columns.Add(new DataColumn("ShowItemCount", typeof(bool)));
            table.Columns.Add(new DataColumn("ItemCountValue", typeof(int)));
            table.Columns.Add(new DataColumn("Value", typeof(string)));
            table.Columns.Add(new DataColumn("NeedsAttention", typeof(bool)));

            foreach (var tab in tabs)
            {
                List<DiagnosticDataApiResponse> dataSet = tab.Data.Dataset.Select(entry =>
                    new DiagnosticDataApiResponse()
                    {
                        RenderingProperties = entry.RenderingProperties,
                        Table = entry.Table.ToDataTableResponseObject()
                    }).ToList();

                table.Rows.Add(new object[] {
                    tab.Label ?? string.Empty,
                    tab.Icon,
                    tab.ShowItemCount,
                    tab.ItemCountValue,
                    JsonConvert.SerializeObject(dataSet, new JsonSerializerSettings
                    {
                        ContractResolver = new CamelCasePropertyNamesContractResolver()
                    }),
                    tab.NeedsAttention
                });
            }

            var diagData = new DiagnosticData()
            {
                Table = table,
                RenderingProperties = new Rendering(RenderingType.Tab)
                {
                    replacedle = replacedle ?? string.Empty
                }
            };

            response.Dataset.Add(diagData);
            return diagData;
        }

19 View Source File : DataTableResponseObject.cs
License : MIT License
Project Creator : Azure

public static DataTable ToDataTable(this DataTableResponseObject dataTableResponse)
        {
            if (dataTableResponse == null)
            {
                throw new ArgumentNullException("dataTableResponse");
            }

            var dataTable = new DataTable(dataTableResponse.TableName);

            dataTable.Columns.AddRange(dataTableResponse.Columns.Select(column => new DataColumn(column.ColumnName, GetColumnType(column.DataType))).ToArray());

            for (int i = 0; i < dataTableResponse.Rows.GetLength(0); i++)
            {
                var row = dataTable.NewRow();
                for (int j = 0; j < dataTable.Columns.Count; j++)
                {
                    row[j] = dataTableResponse.Rows[i, j] ?? DBNull.Value;
                }

                dataTable.Rows.Add(row);
            }

            return dataTable;
        }

19 View Source File : DataTableResponseObject.cs
License : MIT License
Project Creator : Azure

public static DataTable ToAppInsightsDataTable(this AppInsightsDataTableResponseObject appInsightsDataTableResponse)
        {
            if (appInsightsDataTableResponse == null)
            {
                throw new ArgumentNullException("appInsightsDataTableResponse");
            }

            var dataTable = new DataTable(appInsightsDataTableResponse.Name);
            dataTable.Columns.AddRange(appInsightsDataTableResponse.Columns.Select(column => new DataColumn(column.Name, GetColumnType(column.Type))).ToArray());

            for (int i = 0; i < appInsightsDataTableResponse.Rows.GetLength(0); i++)
            {
                var row = dataTable.NewRow();
                for (int j = 0; j < dataTable.Columns.Count; j++)
                {
                    row[j] = MaskPII(appInsightsDataTableResponse.Rows[i, j]) ?? DBNull.Value;
                }

                dataTable.Rows.Add(row);
            }

            return dataTable;
        }

19 View Source File : Utilities.cs
License : MIT License
Project Creator : Azure

public static DataTable GetSlotEvents(string slotName, Dictionary<string, List<RuntimeSitenameTimeRange>> slotTimeRanges, DataTable siteEventsTable, string siteColumnName = "SiteName", string timeStampColumnName = "TIMESTAMP")
        {
            var dt = new DataTable();
            var columns = siteEventsTable.Columns.Cast<DataColumn>().Select(dc => new DataColumn(dc.ColumnName, dc.DataType, dc.Expression, dc.ColumnMapping)).ToArray();
            List<RuntimeSitenameTimeRange> timeRangeForSlot;

            if (slotTimeRanges.ContainsKey(slotName.ToLower()))
            {
                timeRangeForSlot = slotTimeRanges[slotName];
            }
            else
            {
                throw new ArgumentException($"{slotName} is not an existing slot for this site. ");
            }

            try
            {
                dt.Columns.AddRange(columns);

                foreach (DataRow row in siteEventsTable.Rows)
                {
                    var siteName = (string)row[siteColumnName];
                    var timeStamp = (DateTime)row[timeStampColumnName];

                    foreach (var slotTimeRangeInfo in timeRangeForSlot)
                    {
                        if (siteName.Equals(slotTimeRangeInfo.RuntimeSitename, StringComparison.CurrentCultureIgnoreCase) && timeStamp >= slotTimeRangeInfo.StartTime && timeStamp <= slotTimeRangeInfo.EndTime)
                        {
                            dt.Rows.Add(row.ItemArray);
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to get runtime slotmap table.", ex);
            }

            return dt;
        }

19 View Source File : SupportTopicService.cs
License : MIT License
Project Creator : Azure

private async Task<DataTable> GetSupportTopicList(DataProviderContext dataProviderContext)
        {
            if (!_configuration.IsPublicAzure())
            {
                if (_configuration.GetSection("SupportTopicMap").GetChildren().Count() == 0)
                {
                    throw new Exception("Support topic map is empty.");
                }

                DataTable supportTopicTable = new DataTable();
                supportTopicTable.Columns.Add("SupportTopicId", typeof(string));
                supportTopicTable.Columns.Add("ProductId", typeof(string));
                supportTopicTable.Columns.Add("SupportTopicPath", typeof(string));
                
                var supportTopicList = _configuration.GetSection("SupportTopicMap").GetChildren();
                if(supportTopicList.Any() == true)
                {
                    foreach(var supportTopicEntry in supportTopicList)
                    {
                        string supportTopicId = supportTopicEntry.GetSection("SupportTopicId").Value;
                        string productId = supportTopicEntry.GetSection("ProductId").Value;
                        string supportTopicPath = supportTopicEntry.GetSection("supportTopicPath").Value;
                        if(!string.IsNullOrWhiteSpace(supportTopicId) && !string.IsNullOrWhiteSpace(productId) && !string.IsNullOrWhiteSpace(supportTopicPath) )
                        {
                            supportTopicTable.Rows.Add(supportTopicId, productId, supportTopicPath);
                        }
                    }
                }

                return supportTopicTable;
            }
            else
            {
                Guid requestIdGuid = Guid.NewGuid();
                var dp = new DataProviders.DataProviders(dataProviderContext);
                return await dp.Kusto.ExecuteClusterQuery(GetSupportTopicKustoQuery(), "azsupportfollower.westus2", "AzureSupportability", requestIdGuid.ToString(), operationName: "PopulateSupportTopicCache");
            }
        }

19 View Source File : KustoDeserializationTests.cs
License : MIT License
Project Creator : Azure

[Fact]
        public void TestKustoDataTableConverter()
        {
            var dt = new DataTable();

            // When arrays or objects come from kusto they have column type 'object'
            // and come as types JArray and JObject respectively

            dt.Columns.Add("String", typeof(string));
            dt.Columns.Add("Array", typeof(object));
            dt.Columns.Add("Object", typeof(object));

            var arr = new JArray(new string[] { "test" });
            var obj = JObject.FromObject(new { Test = "Test" });

            dt.Rows.Add("test", arr, obj);

            var table = dt.ToDataTableResponseObject();

            var serialized = JsonConvert.SerializeObject(table);

            var deserialized = JsonConvert.DeserializeObject<DataTableResponseObject>(serialized);

            var dataTable = deserialized.ToDataTable();

            replacedert.Equal(dt.Rows[0][0].ToString(), dataTable.Rows[0][0].ToString());

            replacedert.Equal(((JArray)dt.Rows[0][1]).ToObject<string[]>(), ((JArray)dataTable.Rows[0][1]).ToObject<string[]>());

            replacedert.Equal(dt.Rows[0][2], dataTable.Rows[0][2]);
        }

19 View Source File : DataTableUtilityTests.cs
License : MIT License
Project Creator : Azure

[Fact]
        public void TestDataTableToDataTableResponseObject()
        {
            var table = new DataTable();
            table.Columns.AddRange(new DataColumn[]
            {
                new DataColumn("SampleString", typeof(string)),
                new DataColumn("SampleDateTime", typeof(DateTime)),
                new DataColumn("SampleInt", typeof(int))
            });

            table.Rows.Add(new object[] { "Sample String", DateTime.Now, 32 });

            var convertedTable = table.ToDataTableResponseObject();

            var columns = convertedTable.Columns.ToArray();

            replacedert.Equal("String", columns[0].DataType);
            replacedert.Equal("DateTime", columns[1].DataType);
            replacedert.Equal("Int32", columns[2].DataType);

            replacedert.Equal<int>(1, convertedTable.Rows.GetLength(0));
            replacedert.Equal<int>(3, convertedTable.Rows.GetLength(1));
        }

19 View Source File : DataTableUtilityTests.cs
License : MIT License
Project Creator : Azure

[Fact]
        public void TestDataTableToDataTableResponseObjectAndBack()
        {
            var table = new DataTable();
            table.Columns.AddRange(new DataColumn[]
            {
                new DataColumn("SampleString", typeof(string)),
                new DataColumn("SampleDateTime", typeof(DateTime)),
                new DataColumn("SampleInt", typeof(int))
            });

            var now = DateTime.Now;
            var dateTime = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);

            table.Rows.Add(new object[] { "Sample String", dateTime, 32 });

            var dataTableResponseObject = table.ToDataTableResponseObject();

            var dataTableConvertedBack = dataTableResponseObject.ToDataTable();

            for (int i = 0; i < table.Columns.Count; i++)
            {
                replacedert.Equal(table.Columns[i].ColumnName, dataTableConvertedBack.Columns[i].ColumnName);
                replacedert.Equal(table.Columns[i].DataType, dataTableConvertedBack.Columns[i].DataType);
            }

            var expectedFirstRow = table.Rows[0].ItemArray;
            var actualFirstRow = dataTableConvertedBack.Rows[0].ItemArray;

            replacedert.Equal(expectedFirstRow.Length, actualFirstRow.Length);

            for (int i = 0; i < expectedFirstRow.Length; i++)
            {
                replacedert.Equal(expectedFirstRow[i], actualFirstRow[i]);
            }
        }

19 View Source File : DataFileReader.cs
License : MIT License
Project Creator : Azure

private DataSet LoadData(ISystemContext context, DateTime baseline, StreamReader reader) {
            var dataset = CreateDataSet();

            var messageContext = new ServiceMessageContext();

            if (context != null) {
                messageContext.NamespaceUris = context.NamespaceUris;
                messageContext.ServerUris = context.ServerUris;
                messageContext.Factory = context.EncodeableFactory;
            }
            else {
                messageContext.NamespaceUris = ServiceMessageContext.GlobalContext.NamespaceUris;
                messageContext.ServerUris = ServiceMessageContext.GlobalContext.ServerUris;
                messageContext.Factory = ServiceMessageContext.GlobalContext.Factory;
            }

            var sourceTimeOffset = 0;
            var serverTimeOffset = 0;
            StatusCode status = StatusCodes.Good;
            var recordType = 0;
            var modificationTimeOffet = 0;
            var modificationUser = string.Empty;
            var valueType = BuiltInType.String;
            var value = Variant.Null;
            var annotationTimeOffet = 0;
            var annotationUser = string.Empty;
            var annotationMessage = string.Empty;
            var lineCount = 0;

            while (!reader.EndOfStream) {
                var line = reader.ReadLine();

                // check for end or error.
                if (line == null) {
                    break;
                }

                // ignore blank lines.
                line = line.Trim();
                lineCount++;

                if (string.IsNullOrEmpty(line)) {
                    continue;
                }

                // ignore commented out lines.
                if (line.StartsWith("//", StringComparison.CurrentCulture)) {
                    continue;
                }

                // get source time.
                if (!ExtractField(lineCount, ref line, out sourceTimeOffset)) {
                    continue;
                }

                // get server time.
                if (!ExtractField(lineCount, ref line, out serverTimeOffset)) {
                    continue;
                }

                // get status code.
                if (!ExtractField(lineCount, ref line, out status)) {
                    continue;
                }

                // get modification type.
                if (!ExtractField(lineCount, ref line, out recordType)) {
                    continue;
                }

                // get modification time.
                if (!ExtractField(lineCount, ref line, out modificationTimeOffet)) {
                    continue;
                }

                // get modification user.
                if (!ExtractField(lineCount, ref line, out modificationUser)) {
                    continue;
                }

                if (recordType >= 0) {
                    // get value type.
                    if (!ExtractField(lineCount, ref line, out valueType)) {
                        continue;
                    }

                    // get value.
                    if (!ExtractField(lineCount, ref line, messageContext, valueType, out value)) {
                        continue;
                    }
                }
                else {
                    // get annotation time.
                    if (!ExtractField(lineCount, ref line, out annotationTimeOffet)) {
                        continue;
                    }

                    // get annotation user.
                    if (!ExtractField(lineCount, ref line, out annotationUser)) {
                        continue;
                    }

                    // get annotation message.
                    if (!ExtractField(lineCount, ref line, out annotationMessage)) {
                        continue;
                    }
                }

                // add values to data table.
                var dataValue = new DataValue {
                    WrappedValue = value,
                    SourceTimestamp = baseline.AddMilliseconds(sourceTimeOffset),
                    ServerTimestamp = baseline.AddMilliseconds(serverTimeOffset),
                    StatusCode = status
                };

                DataRow row = null;

                if (recordType == 0) {
                    row = dataset.Tables[0].NewRow();

                    row[0] = dataValue.SourceTimestamp;
                    row[1] = dataValue.ServerTimestamp;
                    row[2] = dataValue;
                    row[3] = valueType;
                    row[4] = (value.TypeInfo != null) ? value.TypeInfo.ValueRank : ValueRanks.Any;

                    dataset.Tables[0].Rows.Add(row);
                }

                else if (recordType > 0) {
                    row = dataset.Tables[1].NewRow();

                    row[0] = dataValue.SourceTimestamp;
                    row[1] = dataValue.ServerTimestamp;
                    row[2] = dataValue;
                    row[3] = valueType;
                    row[4] = (value.TypeInfo != null) ? value.TypeInfo.ValueRank : ValueRanks.Any;
                    row[5] = recordType;

                    var info = new ModificationInfo {
                        UpdateType = (HistoryUpdateType)recordType,
                        ModificationTime = baseline.AddMilliseconds(modificationTimeOffet),
                        UserName = modificationUser
                    };
                    row[6] = info;

                    dataset.Tables[1].Rows.Add(row);
                }

                else if (recordType < 0) {
                    row = dataset.Tables[2].NewRow();

                    var annotation = new Annotation {
                        AnnotationTime = baseline.AddMilliseconds(annotationTimeOffet),
                        UserName = annotationUser,
                        Message = annotationMessage
                    };
                    dataValue.WrappedValue = new ExtensionObject(annotation);

                    row[0] = dataValue.SourceTimestamp;
                    row[1] = dataValue.ServerTimestamp;
                    row[2] = dataValue;
                    row[3] = valueType;
                    row[4] = (value.TypeInfo != null) ? value.TypeInfo.ValueRank : ValueRanks.Any;
                    row[5] = annotation;

                    dataset.Tables[2].Rows.Add(row);
                }

                dataset.AcceptChanges();
            }

            return dataset;
        }

19 View Source File : ReportGenerator.cs
License : MIT License
Project Creator : Azure

public DataRow GenerateFluidLevelTestReport() {
            lock (_dataset) {
                var row = _dataset.Tables[0].NewRow();

                row[0] = Guid.NewGuid().ToString();
                row[1] = DateTime.UtcNow;

                var index = GetRandom(0, kWellUIDs.Length - 1);
                row[2] = kWellNames[index];
                row[3] = kWellUIDs[index];

                row[4] = DateTime.UtcNow.AddHours(-GetRandom(0, 10));
                row[5] = GetRandom(kTestReasons);
                row[6] = GetRandom(0, 1000);
                row[7] = GetRandom(kUnitLengths);
                row[8] = GetRandom(kTesters);

                _dataset.Tables[0].Rows.Add(row);
                _dataset.AcceptChanges();
                return row;
            }
        }

19 View Source File : ReportGenerator.cs
License : MIT License
Project Creator : Azure

public DataRow GenerateInjectionTestReport() {
            lock (_dataset) {
                var row = _dataset.Tables[1].NewRow();

                row[0] = Guid.NewGuid().ToString();
                row[1] = DateTime.UtcNow;

                var index = GetRandom(0, kWellUIDs.Length - 1);
                row[2] = kWellNames[index];
                row[3] = kWellUIDs[index];

                row[4] = DateTime.UtcNow.AddHours(-GetRandom(0, 10));
                row[5] = GetRandom(kTestReasons);
                row[6] = GetRandom(0, 1000);
                row[7] = GetRandom(kUnitTimes);
                row[8] = GetRandom(kInjectionFluids);

                _dataset.Tables[1].Rows.Add(row);
                _dataset.AcceptChanges();

                return row;
            }
        }

19 View Source File : ReferenceServerUtils.cs
License : MIT License
Project Creator : Azure

public static DataSet EmptyQueue(DataSet dataset) {
            if (dataset == null) {
                dataset = new DataSet();
                dataset.Tables.Add("MonitoredItems");

                dataset.Tables[0].Columns.Add("Id", typeof(uint));
                dataset.Tables[0].Columns.Add("Timestamp", typeof(string));
                dataset.Tables[0].Columns.Add("EventType", typeof(string));
                dataset.Tables[0].Columns.Add("NodeId", typeof(NodeId));
                dataset.Tables[0].Columns.Add("MonitoringMode", typeof(MonitoringMode));
                dataset.Tables[0].Columns.Add("SamplingInterval", typeof(double));
                dataset.Tables[0].Columns.Add("QueueSize", typeof(uint));
                dataset.Tables[0].Columns.Add("DiscardOldest", typeof(bool));
                dataset.Tables[0].Columns.Add("Filter", typeof(string));
                dataset.Tables[0].Columns.Add("Value", typeof(Variant));
                dataset.Tables[0].Columns.Add("StatusCode", typeof(StatusCode));
                dataset.Tables[0].Columns.Add("SourceTimestamp", typeof(string));
                dataset.Tables[0].Columns.Add("ServerTimestamp", typeof(string));

                dataset.Tables[0].DefaultView.Sort = "Timestamp";
            }

            lock (_events) {
                while (_events.Count > 0) {
                    var e = _events.Dequeue();

                    var row = dataset.Tables[0].NewRow();

                    row[0] = e.ServerHandle;
                    row[1] = e.Timestamp.ToLocalTime().ToString("HH:mm:ss.ffffff");
                    row[2] = e.EventType.ToString();
                    row[3] = e.NodeId;

                    if (e.Parameters != null) {
                        row[4] = e.MonitoringMode;
                        row[5] = e.Parameters.SamplingInterval;
                        row[6] = e.Parameters.QueueSize;
                        row[7] = e.Parameters.DiscardOldest;

                        if (e.Parameters.Filter != null) {
                            row[8] = e.Parameters.Filter.ToString();
                        }
                    }

                    if (e.Value != null) {
                        row[9] = e.Value.WrappedValue;
                        row[10] = e.Value.StatusCode;
                        row[11] = e.Value.ServerTimestamp.ToLocalTime().ToString("HH:mm:ss.fff");
                        row[12] = e.Value.ServerTimestamp.ToLocalTime().ToString("HH:mm:ss.fff");
                    }

                    dataset.Tables[0].Rows.Add(row);
                }
            }

            dataset.AcceptChanges();
            return dataset;
        }

19 View Source File : Test0.cs
License : MIT License
Project Creator : Azure-Samples

[FunctionName("Test0")]
        public static async Task RunAsync(
            [EventHubTrigger("%EventHubName%", Connection = "EventHubsConnectionString", ConsumerGroup = "%ConsumerGroup%")] EventData[] eventHubData, 
            ParreplacedionContext parreplacedionContext, 
            ILogger log)
        {
            var procedureName = Environment.GetEnvironmentVariable("AzureSQLProcedureName");
            var payloadName = "payloadType" + (procedureName.EndsWith("_mo") ? "_mo" : "");

            var payload = new DataTable(payloadName);
            payload.Columns.Add("EventId", typeof(string));
            payload.Columns.Add("ComplexData", typeof(string));
            payload.Columns.Add("Value", typeof(decimal));
            payload.Columns.Add("DeviceId", typeof(string));
            payload.Columns.Add("DeviceSequenceNumber", typeof(long));
            payload.Columns.Add("Type", typeof(string));
            payload.Columns.Add("CreatedAt", typeof(string));
            payload.Columns.Add("EnqueuedAt", typeof(DateTime));
            payload.Columns.Add("ProcessedAt", typeof(DateTime));
            payload.Columns.Add("ParreplacedionId", typeof(int));

            Stopwatch sw = new Stopwatch();
            sw.Start();            

            foreach (var data in eventHubData)
            {
                string message = Encoding.UTF8.GetString(data.Body.Array);                    
                var json = JsonConvert.DeserializeObject<JObject>(message, new JsonSerializerSettings() { DateParseHandling = DateParseHandling.None } );                

                payload.Rows.Add(
                    json["eventId"].ToString(),
                    JsonConvert.SerializeObject(JObject.Parse(json["complexData"].ToString()), Formatting.None),
                    decimal.Parse(json["value"].ToString()),
                    json["deviceId"].ToString(),
                    json["deviceSequenceNumber"],
                    json["type"].ToString(),
                    json["createdAt"].ToString(),
                    data.SystemProperties.EnqueuedTimeUtc,
                    DateTime.UtcNow,
                    parreplacedionContext.RuntimeInformation.ParreplacedionId
                );
            }

            try
            {
                var conn = new SqlConnection(Environment.GetEnvironmentVariable("AzureSQLConnectionString"));
                await conn.ExecuteAsync(procedureName, new { @payload = payload.AsTableValuedParameter() }, commandType: CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                // Retry and/or manage failure, for simplicity just logging the error now
                log.LogError($"{ex} - {ex.Message}");
            }

            sw.Stop();

            string logMessage = $"[Test0] T:{eventHubData.Length} doc - E:{sw.ElapsedMilliseconds} msec";
            if (eventHubData.Length > 0)
            {
                logMessage += $" - AVG:{(sw.ElapsedMilliseconds / eventHubData.Length):N3} msec";
            }

            log.LogInformation(logMessage);
        }

See More Examples