private IEnumerable <CalendarLogAnalysis> LoadMailboxLogs(IEnumerable <CalendarLog> logs)
        {
            if (this.principal == null)
            {
                throw new InvalidOperationException("The Analyzer was not provided with session objects during construction and cannot connect to the specified mailbox");
            }
            List <CalendarLogAnalysis> list = new List <CalendarLogAnalysis>();

            using (MailboxSession mailboxSession = StoreTasksHelper.OpenMailboxSession(this.principal, "Get-CalendarDiagnosticLogs"))
            {
                foreach (CalendarLog calendarLog in logs)
                {
                    CalendarLogId calendarLogId = calendarLog.Identity as CalendarLogId;
                    if (calendarLogId != null)
                    {
                        UriHandler uriHandler = new UriHandler(calendarLogId.Uri);
                        if (uriHandler.IsValidLink && !uriHandler.IsFileLink)
                        {
                            CalendarLogAnalysis calendarLogAnalysis = this.LoadFromMailbox(calendarLogId, uriHandler, mailboxSession);
                            if (calendarLogAnalysis != null)
                            {
                                list.Add(calendarLogAnalysis);
                            }
                        }
                    }
                }
            }
            return(list);
        }
Esempio n. 2
0
 public ValidationError[] Validate()
 {
     if (this.validationErrors == null)
     {
         List <ValidationError> list = new List <ValidationError>();
         if (this.Identity == null)
         {
             list.Add(new ObjectValidationError(Strings.CalendarLogIdentityNotSpecified, this.Identity, "Identity"));
         }
         else
         {
             UriHandler uriHandler = new UriHandler(this.id.Uri);
             if (!uriHandler.IsValidLink)
             {
                 list.Add(new ObjectValidationError(Strings.InvalidLogIdentityFormat(uriHandler.Uri.ToString()), this.Identity, "Identity"));
             }
             if (uriHandler.IsFileLink)
             {
                 FileInfo fileInfo = new FileInfo(uriHandler.Uri.LocalPath);
                 if (!fileInfo.Exists)
                 {
                     list.Add(new ObjectValidationError(Strings.CalendarLogFileDoesNotExist(uriHandler.Uri.ToString()), this.Identity, "Identity"));
                 }
             }
         }
         if (list.Count == 0)
         {
             this.validationErrors = ValidationError.None;
         }
     }
     return(this.validationErrors);
 }
        private CalendarLogAnalysis LoadFromMailbox(CalendarLogId id, UriHandler handler, MailboxSession session)
        {
            StoreObjectId       storeId = StoreObjectId.Deserialize(handler.Id);
            CalendarLogAnalysis result;

            using (Item item = Item.Bind(session, storeId))
            {
                IEnumerable <PropertyDefinition> displayProperties = AnalysisDetailLevels.GetDisplayProperties(this.detailLevel);
                item.Load(displayProperties.ToArray <PropertyDefinition>());
                result = new CalendarLogAnalysis(id, item, displayProperties);
            }
            return(result);
        }
Esempio n. 4
0
        protected override void InternalProcessRecord()
        {
            TaskLogger.LogEnter();
            CalendarLog calendarLog = this.CalendarLogs.FirstOrDefault <CalendarLog>();

            if (calendarLog == null)
            {
                return;
            }
            CalendarDiagnosticAnalyzer calendarDiagnosticAnalyzer;

            if (calendarLog.IsFileLink)
            {
                calendarDiagnosticAnalyzer = new CalendarDiagnosticAnalyzer(null, this.DetailLevel);
            }
            else
            {
                CalendarLogId calendarLogId = calendarLog.Identity as CalendarLogId;
                UriHandler    uriHandler    = new UriHandler(calendarLogId.Uri);
                string        host          = uriHandler.Host;
                SmtpAddress   address       = new SmtpAddress(uriHandler.UserName, host);
                if (!address.IsValidAddress)
                {
                    base.WriteError(new InvalidADObjectOperationException(Strings.Error_InvalidAddress((string)address)), ErrorCategory.InvalidData, null);
                }
                ExchangePrincipal principal = ExchangePrincipal.FromProxyAddress(ADSessionSettings.RootOrgOrSingleTenantFromAcceptedDomainAutoDetect(host), (string)address, RemotingOptions.AllowCrossSite);
                calendarDiagnosticAnalyzer = new CalendarDiagnosticAnalyzer(principal, this.DetailLevel);
            }
            try
            {
                CalendarLog[] array;
                if (!string.IsNullOrEmpty(this.GlobalObjectId))
                {
                    array = (from f in this.CalendarLogs
                             where f.CleanGlobalObjectId == this.GlobalObjectId
                             select f).ToArray <CalendarLog>();
                }
                else
                {
                    array = this.CalendarLogs;
                }
                CalendarLog[] calendarLogs             = array;
                IEnumerable <CalendarLogAnalysis> logs = calendarDiagnosticAnalyzer.AnalyzeLogs(calendarLogs);
                base.WriteObject(CalendarLogAnalysisSerializer.Serialize(logs, this.OutputAs, this.DetailLevel, true));
            }
            catch (InvalidLogCollectionException)
            {
                base.WriteError(new InvalidADObjectOperationException(Strings.Error_MultipleItemsFound), ErrorCategory.InvalidData, null);
            }
            TaskLogger.LogExit();
        }
        private CalendarLogAnalysis LoadFromFile(CalendarLogId id, UriHandler handler)
        {
            FileInfo fileInfo = new FileInfo(handler.Uri.LocalPath);

            if (fileInfo.Exists)
            {
                using (MessageItem messageItem = MessageItem.CreateInMemory(StoreObjectSchema.ContentConversionProperties))
                {
                    using (FileStream fileStream = fileInfo.OpenRead())
                    {
                        ItemConversion.ConvertMsgStorageToItem(fileStream, messageItem, new InboundConversionOptions(new EmptyRecipientCache(), null));
                        IEnumerable <PropertyDefinition> displayProperties = AnalysisDetailLevels.GetDisplayProperties(this.detailLevel);
                        return(new CalendarLogAnalysis(id, messageItem, displayProperties));
                    }
                }
            }
            throw new ArgumentException("Item argument cannot be resolved.", "item");
        }
        private IEnumerable <CalendarLogAnalysis> LoadMsgLogs(IEnumerable <CalendarLog> logs)
        {
            List <CalendarLogAnalysis> list = new List <CalendarLogAnalysis>();

            foreach (CalendarLog calendarLog in logs)
            {
                CalendarLogId calendarLogId = calendarLog.Identity as CalendarLogId;
                if (calendarLogId != null)
                {
                    UriHandler uriHandler = new UriHandler(calendarLogId.Uri);
                    if (uriHandler.IsValidLink && uriHandler.IsFileLink)
                    {
                        CalendarLogAnalysis calendarLogAnalysis = this.LoadFromFile(calendarLogId, uriHandler);
                        if (calendarLogAnalysis != null)
                        {
                            list.Add(calendarLogAnalysis);
                        }
                    }
                }
            }
            return(list);
        }