public static byte[] Serialize(IActivityLog activityLog)
        {
            List <Activity> list = activityLog.Query().Reverse <Activity>().ToList <Activity>();

            if (list.Count == 0)
            {
                return(Array <byte> .Empty);
            }
            byte[] array;
            using (MemoryStream memoryStream = new MemoryStream(list.Count * 128))
            {
                using (BinaryWriter binaryWriter = new BinaryWriter(memoryStream))
                {
                    binaryWriter.Write(1);
                    binaryWriter.Write(1);
                    binaryWriter.Write(0L);
                    List <ActivityLogSerializer.PropertySerializer> propertySerializers = ActivityLogSerializer.SerializeActivitySchema(binaryWriter);
                    binaryWriter.Write(list.Count);
                    foreach (Activity activity in list)
                    {
                        ActivityLogSerializer.SerializeActivity(binaryWriter, activity, propertySerializers);
                        if (memoryStream.Length > 10485760L)
                        {
                            throw new NotSupportedException(string.Format("Serialization of activity logs longer than {0} is not supported", 10485760));
                        }
                    }
                    array = new byte[memoryStream.Length];
                    Array.Copy(memoryStream.GetBuffer(), array, memoryStream.Length);
                }
            }
            return(array);
        }
 protected override void WriteResult(IConfigurable dataObject)
 {
     TaskLogger.LogEnter();
     try
     {
         if (dataObject != null)
         {
             ADUser            user         = (ADUser)dataObject;
             ExchangePrincipal mailboxOwner = ExchangePrincipal.FromADUser(user, null);
             using (MailboxSession mailboxSession = MailboxSession.OpenAsAdmin(mailboxOwner, CultureInfo.InvariantCulture, "Client=Management;Action=Get-MailboxActivityLog"))
             {
                 IActivityLog activityLog = ActivityLogFactory.Current.Bind(mailboxSession);
                 foreach (Activity activity in activityLog.Query())
                 {
                     base.WriteResult(new ActivityLogEntryPresentationObject(activity));
                 }
             }
         }
     }
     catch (StorageTransientException exception)
     {
         base.WriteError(exception, ErrorCategory.ReadError, null);
     }
     catch (StoragePermanentException exception2)
     {
         base.WriteError(exception2, ErrorCategory.ReadError, null);
     }
     finally
     {
         TaskLogger.LogExit();
     }
 }
Exemplo n.º 3
0
        IEnumerable <ReplayAction> IActionsSource.ReadActions(IActionWatermark watermark)
        {
            MrsTracer.Provider.Function("StorageActionsSource.ReadActions", new object[0]);
            IActivityLog        activityLog = ActivityLogFactory.Current.Bind(this.mailboxSession);
            List <ReplayAction> actionsIndescendingOrder = new List <ReplayAction>(100);

            foreach (Activity activity in activityLog.Query())
            {
                if (activity.ClientId.LoggedViaServerSideInstrumentation)
                {
                    IActionWatermark actionWatermark = new StorageActionWatermark(activity);
                    if (watermark != null && watermark.CompareTo(actionWatermark) >= 0)
                    {
                        break;
                    }
                    ReplayAction replayAction = this.TryConvertToAction(activity, actionWatermark);
                    if (replayAction != null)
                    {
                        actionsIndescendingOrder.Add(replayAction);
                    }
                }
            }
            for (int index = actionsIndescendingOrder.Count - 1; index >= 0; index--)
            {
                yield return(actionsIndescendingOrder[index]);
            }
            yield break;
        }