Exemplo n.º 1
0
        private static async Task CreateAlarmProtocolItems()
        {
            Container container = database.GetContainer("ProtocolAlarm_Test");

            if (container == null)
            {
                return;
            }

            string fileName = $"{FilePath}ALARM_PROTOCOL.csv";

            var csvData = File.ReadAllLines(fileName);

            foreach (string row in csvData.Skip(1).ToList())
            {
                string[] values = row.Split(',');

                // Create an item
                var item = new ProtocolAlarm
                {
                    id           = Guid.NewGuid().ToString().ToLower(),
                    Code         = Convert.ToInt32(values[2]),
                    EventOEMCode = Convert.ToString(values[1]),
                    ProtocolId   = Convert.ToString(values[0]),
                    Active       = Convert.ToString(values[6]) == "Y" ? 1 : 0,
                    Name         = Convert.ToString(values[7]),
                    Severity     = GetSeverity(Convert.ToString(values[5])),
                    CreatedOn    = DateTime.UtcNow,
                    CreatedBy    = string.Empty,
                    TenantId     = tenantId,
                    PartitionKey = tenantId
                };

                await CreateReadyLineItem(container, item);

                protocolAlarms.Add(item);
            }

            Console.WriteLine($"{fileName} processed successfully.");
        }
Exemplo n.º 2
0
        private static async Task CreateEventItems()
        {
            Container container = database.GetContainer(WencoContainer.Ids[7]);

            if (container == null)
            {
                return;
            }

            container.ReadContainerAsync().Result.Resource.IndexingPolicy.CompositeIndexes.Add(
                new Collection <CompositePath> {
                new CompositePath()
                {
                    Path = "/CeatedOn", Order = CompositePathSortOrder.Ascending
                },
                new CompositePath()
                {
                    Path = "/Type", Order = CompositePathSortOrder.Ascending
                },
                new CompositePath()
                {
                    Path = "/Status", Order = CompositePathSortOrder.Ascending
                }
            });

            string fileName = $"{FilePath}Event.csv";

            var csvData = File.ReadAllLines(fileName);

            var insertedProtocolAlarms = new List <EventWithAlarmId>();
            var eventDetails           = new List <EventDetail>();
            var events = new List <Event>();

            var rand = new Random();

            foreach (string row in csvData.Skip(1).ToList())
            {
                string[] values     = row.Split(',');
                int      assetIndex = rand.Next(0, 10);

                var protocolAlarm = protocolAlarms.FirstOrDefault(x => x.Code == Convert.ToInt32(values[5]));

                if (insertedProtocolAlarms.Exists(x => x.AlarmId == protocolAlarm.Code))
                {
                    var eventSummaryObj = insertedProtocolAlarms.FirstOrDefault(x => x.AlarmId == protocolAlarm.Code);
                    if (Convert.ToInt32(values[6]) == 0)   // in-active event
                    {
                        eventDetails.Where(x => x.AlarmId == protocolAlarm.Code).OrderByDescending(x => x.EventStartTime).Take(1).FirstOrDefault().EventEndTime = Convert.ToDateTime(values[4]);
                    }
                    else // active event
                    {
                        eventDetails.Add(new EventDetail
                        {
                            id             = Guid.NewGuid(),
                            EventStartTime = Convert.ToDateTime(values[4])
                        });
                    }
                }
                else
                {
                    var asset   = _assets.ElementAt(assetIndex);
                    var site    = _sites.ElementAt(0);
                    var eventid = Guid.NewGuid().ToString().ToLower();

                    // Create an Event item
                    events.Add(new Event
                    {
                        id           = eventid,
                        DocumentType = "Event",
                        AssetId      = asset.id,
                        Site         = new Site
                        {
                            id               = site.id,
                            Name             = site.Name,
                            OrganizationCode = site.OrganizationCode,
                            TenantId         = site.TenantId
                        },
                        Asset = new Asset
                        {
                            id           = asset.id,
                            Name         = asset.Name,
                            Description  = asset.Description,
                            AssetModelId = asset.AssetModelId,
                            AssetTypeId  = asset.AssetTypeId,
                            SiteId       = site.id
                        },
                        AssetModel = new AssetModel
                        {
                            id   = asset.AssetModelId,
                            Code = asset.AssetModelId,
                            Name = asset.AssetModelId
                        },
                        AssetType = new AssetType
                        {
                            id    = _assetTypes.FirstOrDefault(x => x.id == asset.AssetTypeId).id,
                            Value = _assetTypes.FirstOrDefault(x => x.id == asset.AssetTypeId).Value,
                            Label = _assetTypes.FirstOrDefault(x => x.id == asset.AssetTypeId).Label
                        },
                        ProtocolAlarm = new ProtocolAlarm
                        {
                            id           = protocolAlarm.id.ToLower(),
                            Code         = protocolAlarm.Code,
                            Name         = protocolAlarm.Name,
                            Severity     = protocolAlarm.Severity,
                            EventOEMCode = protocolAlarm.EventOEMCode,
                            ProtocolId   = protocolAlarm.ProtocolId,
                            Active       = protocolAlarm.Active
                        },
                        ProtocolId   = protocolAlarm.ProtocolId,
                        ProtocolType = proto
                                       EventOEMCode = protocolAlarm.EventOEMCode,
                        Type = ((Convert.ToInt32(values[5]) % 10000) < 10) ? "BOUNDRY" :
                               ((Convert.ToInt32(values[5]) % 10000) > 10 && (Convert.ToInt32(values[5]) % 10000) < 20) ? "VIRTUAL" :
                               ((Convert.ToInt32(values[5]) % 10000) > 20 && (Convert.ToInt32(values[5]) % 10000) < 40) ? "SAFETY" :
                               "OEM",
                        CreatedOn    = Convert.ToDateTime(values[4]),
                        Active       = Convert.ToInt32(values[6]) == 1 ? true : false,
                        Status       = "UN-ACK",
                        PartitionKey = $"{tenantId}-{asset.id}",
                        EventDetails = new List <EventDetail>()
                    });