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);
        }
        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. 3
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();
        }
 internal CalendarLogAnalysis(CalendarLogId identity, Item item, IEnumerable <PropertyDefinition> loadedProperties)
 {
     if (item == null)
     {
         throw new ArgumentNullException("item");
     }
     if (loadedProperties == null)
     {
         throw new ArgumentNullException("loadedProperties");
     }
     this.identity         = identity;
     this.loadedProperties = loadedProperties;
     this.InitializeProperties(item);
 }
        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);
        }