예제 #1
0
        // Get all entity and remvoe older ones.
        public static List <SALsAEntity> CleanRecentEntity()
        {
            var allEntity = ListAllEntity();
            var icmEntity = ICM.GetIncidentsWithId(allEntity.Select(x => x.PartitionKey).ToList());

            foreach (SALsAEntity entity in allEntity)
            {
                if (icmEntity.ContainsKey(entity.PartitionKey))
                {
                    var status = icmEntity[entity.PartitionKey].Status;
                    if (status.Equals("Resolved", StringComparison.InvariantCultureIgnoreCase) && DateTime.Now.AddDays(Constants.TableStorageRecentDays) > entity.Timestamp)
                    {
                        TableOperation deleteOperation = TableOperation.Delete(entity);
                        Authentication.Instance.TableStorageClient.Execute(deleteOperation);
                    }
                }
                else
                {
                    if (DateTime.Now.AddDays(Constants.TableStorageRecentDays) > allEntity.Where(x => x.PartitionKey == x.PartitionKey).First().Timestamp)
                    {
                        TableOperation deleteOperation = TableOperation.Delete(entity);
                        Authentication.Instance.TableStorageClient.Execute(deleteOperation);
                    }
                }
            }
            allEntity.RemoveAll(x => DateTime.Now.AddDays(Constants.TableStorageRecentDays) > x.Timestamp);

            return(allEntity);
        }
예제 #2
0
        private Nullable <Guid> GetSubscriptionId(ICM icm)
        {
            try
            {
                // Look for the custom field "subscription"
                String subscriptionId = SALsA.GetInstance(Id).ICM.GetCustomField(Constants.AnalyzerSubscriptionIdField);

                // Look in the ICM field for the subscriptionId
                if (!CheckIfSubscriptionIdIsValid(subscriptionId))
                {
                    Log.Verbose("Failed to get SubscriptionId from CustomField");
                    subscriptionId = icm.CurrentICM.SubscriptionId;
                    // Look in the ICM description for the subscriptionId
                    if (!CheckIfSubscriptionIdIsValid(subscriptionId))
                    {
                        Log.Verbose("Failed to get SubscriptionId from SubscriptionId ICM Field");
                        // If we coudnt find it, fail it.
                        if (!CheckIfSubscriptionIdIsValid(subscriptionId))
                        {
                            Log.Error("Failed to find any SubscriptionId in the ICM");
                            throw new Exception("Failed to find valid SubscriptionId");
                        }
                    }
                }
                return(Guid.Parse(Utility.DecodeHtml(subscriptionId)));
            }
            catch (Exception ex)
            {
                Log.Error("Failed to find a valid subscription id for ICM : {0}", icm.CurrentICM.Id);
                Log.Exception(ex);
                return(null);
            }
        }
예제 #3
0
 public SALsAInstance(int icm)
 {
     Log.ResetLog();
     Log.Id           = icm;
     this.ICM         = new ICM(icm);
     this.TaskManager = new TaskManager(icm);
     this.State       = SALsAState.Running;
 }
예제 #4
0
        public bool PostICMHeader(string head = Constants.ICMInfoHeaderHtml)
        {
            string entry = head + "<br>" + Utility.UrlToHml(Constants.ICMInfoReportName, Constants.ICMInfoReportEndpoint + this.Id.ToString(), 24);

            Log.Verbose("Adding to ICM String {0}", entry);
            var discussion = ICM.GetICMDiscussion(this.Id);
            var cur        = SALsA.GetInstance(this.Id).ICM.CurrentICM;

            if (Constants.ICMTeamsDoNotRepostHeaderIfPreviouslyAlreadyPosted.Contains(
                    SALsA.GetInstance(this.Id).ICM.CurrentICM.OwningTeamId.Split('\\').First(),
                    StringComparer.InvariantCultureIgnoreCase) == true)
            {
                foreach (var de in discussion)
                {
                    if (de.SubmittedBy == Constants.ICMIdentityName || de.Text.Contains(Constants.ICMInfoHeaderHtml))
                    {
                        Log.Verbose("Did not add entry to ICM since already sent", this.Id);
                        return(false);
                    }
                }
            }
            else
            {
                var currentTime = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture);
                entry = String.Format("[{0}] {1}", currentTime, entry);
            }
            try
            {
                return(ICM.PostDiscussion(this.Id, entry));
            }
            catch (Exception ex)
            {
                Log.Error("Failed to add discussion element to ICM {0}", Id);
                Log.Exception(ex);
                return(false);
            }
        }