public void GetOperationTest()
        {
            var data = new OperationData { Id = "1", State = OperationState.Succeeded.ToString() };

            var dataContextMock = new Mock<IMediaDataServiceContext>();

            var fakeException = new WebException("test", WebExceptionStatus.ConnectionClosed);

            var fakeResponse = new OperationData[] { data };
            int exceptionCount = 2;

            dataContextMock.Setup((ctxt) => ctxt
                .Execute<OperationData>(It.IsAny<Uri>()))
                .Returns(() =>
                {
                    if (--exceptionCount > 0) throw fakeException;
                    return fakeResponse;
                });

            _mediaContext.MediaServicesClassFactory = new TestMediaServicesClassFactory(dataContextMock.Object);
            var actual = _mediaContext.Operations.GetOperation(data.Id);
            Assert.AreEqual(data.Id, actual.Id);

            dataContextMock.Verify((ctxt) => ctxt.Execute<OperationData>(It.IsAny<Uri>()), Times.Exactly(2));
        }
        public Task<OperationData> GetNextAsync(CancellationToken cancellationToken)
        {
            OperationData result = null;
            while (this.progressVector.MoveNext())
            {
                this.logger.Log($"CopyContext.GetNextAsync returning record {this.progressVector.Current}");

                // Copy the stream into the result.
                var progressIndicator = this.serializer.Serialize(this.progressVector.Current);
                if (result == null)
                {
                    result = new OperationData(progressIndicator);
                }
                else
                {
                    result.Add(progressIndicator);
                }
            }

            if (result == null)
            {
                this.logger.Log("CopyContext.GetNextAsync signalling completion");
            }

            return Task.FromResult(result);
        }
 Task <long> ITransactionalReplicator.BeginTransactionAsync(
     Transaction transaction,
     OperationData metaData,
     OperationData undo,
     OperationData redo,
     object operationContext,
     long stateProviderId)
 {
     return(this.stateManager.BeginTransactionAsync(
                transaction,
                metaData,
                undo,
                redo,
                operationContext,
                stateProviderId));
 }
Exemplo n.º 4
0
 private void UpdateGridRow(OperationData op, DataGridViewRow gridRow)
 {
     gridRow.Tag = op.Name;
     if (gridRow.Cells.Count == 0)
     {
         for (int i = 0; i < 5; i++)
         {
             gridRow.Cells.Add(new DataGridViewTextBoxCell());
         }
     }
     gridRow.Cells[0].Value = op.Name;
     gridRow.Cells[1].Value = op.Calls;
     gridRow.Cells[2].Value = op.Duration.TotalSeconds.ToString("N3");
     gridRow.Cells[3].Value = op.SentBytes.ToString("N0");
     gridRow.Cells[4].Value = op.ReceivedBytes.ToString("N0");
 }
Exemplo n.º 5
0
        private ISOTimeLog ExportTimeLog(OperationData operation, IEnumerable <SpatialRecord> spatialRecords, string dataPath)
        {
            ISOTimeLog isoTimeLog = new ISOTimeLog();

            //ID
            string id = operation.Id.FindIsoId() ?? GenerateId(5);

            isoTimeLog.Filename    = id;
            isoTimeLog.TimeLogType = 1; // TimeLogType TLG.C is a required attribute. Currently only the value "1" is defined.
            ExportIDs(operation.Id, id);

            List <DeviceElementUse> deviceElementUses = operation.GetAllSections();
            List <WorkingData>      workingDatas      = deviceElementUses.SelectMany(x => x.GetWorkingDatas()).ToList();

            ISOTime isoTime = new ISOTime();

            isoTime.HasStart      = true;
            isoTime.Type          = ISOTimeType.Effective;
            isoTime.DataLogValues = ExportDataLogValues(workingDatas, deviceElementUses).ToList();

            //Set the timelog data definition for PTN
            ISOPosition position = new ISOPosition();

            position.HasPositionNorth      = true;
            position.HasPositionEast       = true;
            position.HasPositionUp         = true;
            position.HasPositionStatus     = true;
            position.HasPDOP               = false;
            position.HasHDOP               = false;
            position.HasNumberOfSatellites = false;
            position.HasGpsUtcTime         = false;
            position.HasGpsUtcTime         = false;
            isoTime.Positions.Add(position);

            //Write XML
            TaskDocumentWriter xmlWriter = new TaskDocumentWriter();

            xmlWriter.WriteTimeLog(dataPath, isoTimeLog, isoTime);

            //Write BIN
            var          binFilePath = Path.Combine(dataPath, isoTimeLog.Filename + ".bin");
            BinaryWriter writer      = new BinaryWriter(_dataLogValueOrdersByWorkingDataID);

            writer.Write(binFilePath, workingDatas.ToList(), spatialRecords);

            return(isoTimeLog);
        }
Exemplo n.º 6
0
        public void GivenOperationDataWithMaxDepthOneWhenGetAllSectionsThenAllSections()
        {
            var operationData = new OperationData {
                MaxDepth = 1
            };

            var depth0Sections = new List <DeviceElementUse> {
                new DeviceElementUse()
            };
            var depth1Sections = new List <DeviceElementUse> {
                new DeviceElementUse()
            };
            var depth2Sections = new List <DeviceElementUse> {
                new DeviceElementUse()
            };
            var depth3Sections = new List <DeviceElementUse> {
                new DeviceElementUse()
            };

            operationData.GetDeviceElementUses = depth =>
            {
                if (depth == 0)
                {
                    return(depth0Sections);
                }
                if (depth == 1)
                {
                    return(depth1Sections);
                }
                if (depth == 2)
                {
                    return(depth2Sections);
                }
                if (depth == 3)
                {
                    return(depth3Sections);
                }

                return(null);
            };

            var result = operationData.GetAllSections();

            Assert.AreEqual(2, result.Count);
            Assert.Contains(depth0Sections.First(), result);
            Assert.Contains(depth1Sections.First(), result);
        }
Exemplo n.º 7
0
        private void OnOperationsUpdated(IReadOnlyList <OperationData> ops)
        {
            if (monitor == null)
            {
                return;
            }
            var shownOps     = new Dictionary <string, DataGridViewRow>();
            var rowsToRemove = new List <int>();

            for (int i = 0; i < operationsGrid.Rows.Count; i++)
            {
                string        action = (string)operationsGrid.Rows[i].Tag;
                OperationData op     = ops.FirstOrDefault(x => x.Name == action);
                if (op != null)
                {
                    shownOps.Add(action, operationsGrid.Rows[i]);
                }
                else
                {
                    rowsToRemove.Add(i);
                }
            }

            rowsToRemove.Reverse();
            foreach (int index in rowsToRemove)
            {
                operationsGrid.Rows.RemoveAt(index);
            }

            // Now we may have some rows to add or update
            foreach (var op in ops)
            {
                if (shownOps.ContainsKey(op.Name))
                {
                    // Just update
                    UpdateGridRow(op, shownOps[op.Name]);
                }
                else
                {
                    var newRow = (DataGridViewRow)operationsGrid.RowTemplate.Clone();
                    UpdateGridRow(op, newRow);
                    operationsGrid.Rows.Add(newRow);
                }
            }

            operationsGrid.ClearSelection();
        }
Exemplo n.º 8
0
    private void InitOperationData()
    {
        string     jsonText = File.ReadAllText(Application.dataPath + "/JsonData/Operation.json", Encoding.UTF8);
        JSONObject j        = new JSONObject(jsonText);

        foreach (var tmp in j.list)
        {
            uint id = (uint)tmp["id"].n;

            operationData[id] = new OperationData
            {
                id        = id,
                name      = tmp["name"].str,
                enemyType = (uint)tmp["enemy_type"].n
            };
        }
    }
Exemplo n.º 9
0
        protected int CalculateWireSize(OperationData data)
        {
            // Number of Array segments for data.
            var size = sizeof(int);

            if (data == null)
            {
                return(size);
            }

            foreach (var item in data)
            {
                size += sizeof(int);
            }

            return(size);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Deserializes a set of bytes into a redo/undo operation.
        /// </summary>
        /// <param name="operationData">Bytes to deserialize.</param>
        /// <param name="traceType">trace Id</param>
        /// <returns></returns>
        public static RedoUndoOperationData FromBytes(OperationData operationData, string traceType)
        {
            // Check arguments.
            if (operationData == null)
            {
                throw new ArgumentNullException(SR.Error_OperationData);
            }

            // OperationData must contain at least the metadata and key (values may be null).
            if (operationData.Count == 0)
            {
                throw new ArgumentException(SR.Error_OperationData);
            }

            // Array segment zero contains the metadata
            var metadataBytes = operationData[0];

            using (var stream = new MemoryStream(metadataBytes.Array, metadataBytes.Offset, metadataBytes.Count))
                using (var reader = new BinaryReader(stream, Encoding.Unicode))
                {
                    // Read how many value and new value segments there are
                    var valueSegmentCount    = reader.ReadInt32();
                    var newValueSegmentCount = reader.ReadInt32();

                    // Check the actual number of segments matches the expected number (metadata, key, and count for the value segments)
                    var expectedSegmentCount = 1 + valueSegmentCount + newValueSegmentCount;
                    if (operationData.Count != expectedSegmentCount)
                    {
                        throw new InvalidDataException(
                                  string.Format(
                                      System.Globalization.CultureInfo.CurrentCulture,
                                      SR.Error_MetadataOperationData_ExpectedSegments,
                                      operationData.Count,
                                      expectedSegmentCount));
                    }

                    // Read values.
                    var startSegmentIndex = 1;
                    var valueBytes        = GetValueBytes(operationData, startSegmentIndex, valueSegmentCount);

                    startSegmentIndex += valueSegmentCount;
                    var newValueBytes = GetValueBytes(operationData, startSegmentIndex, newValueSegmentCount);

                    return(new RedoUndoOperationData(valueBytes, newValueBytes, traceType));
                }
        }
Exemplo n.º 11
0
        /// <summary>
        /// The set current state.
        /// </summary>
        /// <param name="stateRecordNumber">
        /// The state record number.
        /// </param>
        /// <param name="data">
        /// The data.
        /// </param>
        Task IStateProvider2.SetCurrentStateAsync(long stateRecordNumber, OperationData data)
        {
            var count  = data?.Count ?? 0;
            var length = data?.Sum(_ => _.Count) ?? 0;

            Trace.TraceInformation(
                "[" + this.partitionId + "] " + "SetCurrentState({0}, [{1} operations, {2}b])",
                stateRecordNumber,
                count,
                length);

            /*
             * indexex: LSN, row key + partition key
             */

            return(Task.FromResult(0));
        }
		public void PostCommit(IServiceOperationRecorderContext recorderContext)
		{
			var request = (ConfigurationDocumentRequestBase)recorderContext.Request;

			var data = new OperationData
						{
							Operation = "SetConfigurationDocument",
							DocumentName = request.DocumentKey.DocumentName,
							DocumentVersion = request.DocumentKey.Version.ToString(),
							DocumentUser = request.DocumentKey.User ?? "{application}",
							DocumentInstanceKey = StringUtilities.NullIfEmpty(request.DocumentKey.InstanceKey) ?? "{default}"
						};


			var xml = JsmlSerializer.Serialize(data, "Audit");
			recorderContext.Write(data.Operation, xml);
		}
Exemplo n.º 13
0
        internal static OperationData WriteRecord(
            LogRecord record,
            BinaryWriter bw,
            bool isPhysicalWrite       = true,
            bool setRecordLength       = true,
            bool forceRecomputeOffsets = false)
        {
            // NOTE:- The binary writer is not where the real data is written
            // It is only passed in to avoid each log record from creating its own writer

            // The real data of the log record is returned in the operation data
            // As a result, reset the position of the writer before starting to write

            bw.BaseStream.Position = 0;

            var operationData = new OperationData();

            record.Write(bw, operationData, isPhysicalWrite, forceRecomputeOffsets);
            uint recordLength = 0;

            foreach (var data in operationData)
            {
                recordLength += (uint)data.Count;
            }

            if (setRecordLength)
            {
                record.RecordLength = recordLength;
            }

            var mm = bw.BaseStream as MemoryStream;
            var startingPosition = bw.BaseStream.Position;

            bw.Write(recordLength);
            var arraySegment = new ArraySegment <byte>(
                mm.GetBuffer(),
                (int)startingPosition,
                (int)mm.Position - (int)startingPosition);

            // Append and prepend record length in a fixed encoding of sizeof(int) bytes
            operationData.Add(arraySegment);
            operationData.Insert(0, arraySegment);

            return(operationData);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Reads the state provider metadata from the next chunk of copy data.
        /// </summary>
        /// <param name="operationData">The next chunk of copy data.</param>
        /// <param name="traceType">Tracing type information.</param>
        /// <returns>The copied set of state providers' metadata.</returns>
        internal static IEnumerable <SerializableMetadata> ReadCopyData(OperationData operationData, string traceType)
        {
            if (operationData == null)
            {
                throw new ArgumentNullException("operationData");
            }

            if (operationData.Count <= 0)
            {
                throw new ArgumentException("OperationData contains zero data.", "operationData");
            }

            // The state manager currently sends a single array segment per operation data.
            var itemData      = operationData[0];
            var operationType =
                (StateManagerCopyOperation)itemData.Array[itemData.Offset + itemData.Count - 1];

            using (var itemStream = new MemoryStream(itemData.Array, itemData.Offset, itemData.Count - 1))
                using (var itemReader = new InMemoryBinaryReader(itemStream))
                {
                    if (operationType == StateManagerCopyOperation.Version)
                    {
                        // Verify the copy protocol version is known.
                        var copyProtocolVersion = itemReader.ReadInt32();
                        if (copyProtocolVersion != CopyProtocolVersion)
                        {
                            throw new InvalidDataException(
                                      string.Format(CultureInfo.CurrentCulture, SR.Error_SMFile_UnknownCopyProtocol_OneArg, copyProtocolVersion));
                        }
                    }
                    else if (operationType == StateManagerCopyOperation.StateProviderMetadata)
                    {
                        // Read the chunk of state provider metadata.
                        while (itemStream.Position < itemStream.Length)
                        {
                            yield return(ReadMetadata(itemReader, traceType, true));
                        }
                    }
                    else
                    {
                        throw new InvalidDataException(
                                  string.Format(CultureInfo.CurrentCulture, SR.Error_SMFile_UnknownSMCopyOperation_OneArg, operationType));
                    }
                }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Returns the metadata for the copied state.
        /// </summary>
        /// <returns></returns>
        /// <remarks>
        /// Contains
        /// - Version of the copy metadata state.
        /// - Progress ProgressVectorEntry of the copied checkpoint.
        /// - Copied Checkpoints Epoch
        /// - Sequence number of the first operation in the log to be copied.
        /// - Sequence number of the copied checkpoints sequence number.
        /// - UptoSequence number for the copy provided by the volatile replicator.
        /// - Highest possible the state providers could have copied.
        /// </remarks>
        private OperationData GetCopyStateMetadata()
        {
            var expectedSize = this.beginCheckpointRecord.ProgressVector.ByteCount;

            expectedSize += CopyStateMetadataByteSizeNotIncludingProgressVector;

            OperationData result;

            using (var stream = new MemoryStream(expectedSize))
            {
                using (var bw = new BinaryWriter(stream))
                {
                    // First 4 bytes are reserved for the version of the metadata.
                    bw.Write(CopyStateMetadataVersion);

                    // TODO: Ask for the size to avoid expanding the memoryStream.
                    this.beginCheckpointRecord.ProgressVector.Write(bw);

                    var startingEpoch = this.beginCheckpointRecord.Epoch;
                    bw.Write(startingEpoch.DataLossNumber);
                    bw.Write(startingEpoch.ConfigurationNumber);

                    bw.Write(this.sourceStartingLsn.LSN);
                    bw.Write(this.beginCheckpointRecord.Lsn.LSN);
                    bw.Write(this.uptoLsn.LSN);
                    bw.Write(this.replicatedLogManager.CurrentLogTailLsn.LSN);

                    Utility.Assert(
                        expectedSize == stream.Position,
                        "Position mismatch. Expected {0} Position {1}",
                        expectedSize, stream.Position);

                    result = new OperationData(new ArraySegment <byte>(stream.GetBuffer(), 0, (int)stream.Position));
                    result.Add(CopyProgressVectorOperation);
                }
            }

            var trace = "Copying Log Preamble. SourceStartingLSN: " + this.sourceStartingLsn.LSN
                        + " BeginCheckpointLSN: " + this.beginCheckpointRecord.Lsn.LSN + " StateRecordsCoipied: "
                        + this.copiedRecordNumber + " CurrentTailSequenceNumber: "
                        + this.replicatedLogManager.CurrentLogTailLsn.LSN;

            FabricEvents.Events.CopyStreamGetNext(tracer.Type, trace);
            return(result);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Deserialize the header for the OperationData
        /// </summary>
        internal void DeserializeContext(
            OperationData operationData,
            int version,
            string traceType)
        {
            Utility.Assert(
                operationData != null,
                "{0}: DeserializeContext: Null named operation data during create",
                this.TraceType);

            Utility.Assert(
                operationData.Count > 0,
                "{0}:DeserializeContext: Named operation data should have atleast one buffer during create",
                this.TraceType);

            var  headerBufferSPtr = operationData[operationData.Count - 1];
            bool isStateProviderDataNull;

            using (InMemoryBinaryReader reader = new InMemoryBinaryReader(new MemoryStream(
                                                                              headerBufferSPtr.Array,
                                                                              headerBufferSPtr.Offset,
                                                                              headerBufferSPtr.Count)))
            {
                this.Version = reader.ReadInt32();

                if (this.Version != version)
                {
                    FabricEvents.Events.OnApplyVersionError(traceType, this.Version, version);
                    throw new NotSupportedException(
                              string.Format(
                                  CultureInfo.InvariantCulture,
                                  "Unsupported version {0} on deserialization, current version is {1}",
                                  this.Version,
                                  version));
                }

                this.StateProviderId    = reader.ReadInt64();
                isStateProviderDataNull = reader.ReadBoolean();
            }

            // Remove state manager metadata from data.
            operationData.RemoveAt(operationData.Count - 1);

            this.OperationData = isStateProviderDataNull ? null : operationData;
        }
Exemplo n.º 17
0
        /// <summary>
        /// Runs a test for a specific class and method.
        /// </summary>
        /// <param name="op">The operation data.</param>
        /// <param name="done">The completion callback.</param>
        public void HandleOp(OperationData op, Action done)
        {
            var testOp = (RunTestOperation)op;
            var func   = GetTestFunc(testOp);
            var err    = "";

            ConsoleProxy.log("Running test: " + testOp.ClassName + "." + testOp.MethodName);

            object result = null;

            try { result = func(); }
            catch (Exception ex)
            {
                // exceptions indicate test failure
                var browser = GetBrowserName();
                err = ((browser != null) ? ("[" + browser + "] ") : "") + ex.toString();

                ConsoleProxy.log("Test Failed: " + err);
                ClientHost.Service.FailTest(err, done);
                return;
            }

            // tests returing null or undefined indicate
            // the test is complete and has passed
            if (result == null || result == window.undefined)
            {
                ConsoleProxy.log("Test Passed");
                ClientHost.Service.PassTest(done);
                return;
            }

            // if a test result type is returned, the
            // result may be deferred due to async execution
            if (result is TestResult)
            {
                CheckAsyncResult((TestResult)result, done);
                return;
            }

            // the return type was not of any expected
            // value, return as test failure
            ClientHost.Service.FailTest(
                "Unexpected test return value. Synchronous tests should return void. " +
                "Asynchronous tests should return an object of type TestResult.", done);
        }
        internal BeginTransactionOperationLogRecord(
            Transaction transaction,
            OperationData metaData,
            OperationData undo,
            OperationData redo,
            object operationContext,
            bool isSingleOperationTransaction)
            : base(LogRecordType.BeginTransaction, transaction, null)
        {
            this.isSingleOperationTransaction = isSingleOperationTransaction;
            this.recordEpoch      = LogicalSequenceNumber.InvalidEpoch;
            this.metaData         = metaData;
            this.undo             = undo;
            this.redo             = redo;
            this.operationContext = operationContext;

            this.UpdateApproximateDiskSize();
        }
Exemplo n.º 19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NamedOperationContext"/> class by deserialization from OperationData.
        /// </summary>
        public NamedOperationData(
            OperationData operationData,
            int version,
            string traceType)
        {
            // State Manager always at least creates OperationData of one buffer to keeps dispatching information.
            Utility.Assert(
                operationData != null,
                "{0}: NamedOperationData: Null named operation data during create",
                traceType);

            Utility.Assert(
                operationData.Count > 0,
                "{0}: NamedOperationData: Named operation data should have atleast one buffer during create, Count: {1}.",
                traceType, operationData.Count);

            this.DeserializeContext(operationData, version, traceType);
        }
Exemplo n.º 20
0
        public static void ReportOpenDoc()
        {
            OperationData operation = FindOperation(OperationTypes.kOpenDoc);

            if (operation == null)
            {
                operation = new OperationData(OperationTypes.kOpenDoc);

                lock (_lockObject)
                {
                    _allOperations.Add(operation);
                }
            }
            else
            {
                operation.Count++;
            }
        }
Exemplo n.º 21
0
        internal static OperationData ReadOperationData(BinaryReader br)
        {
            var count = br.ReadInt32();

            if (count == NullOperationDataCode)
            {
                return(null);
            }

            var operationData = new OperationData();

            for (var i = 0; i < count; i++)
            {
                operationData.Add(ReadBytes(br));
            }

            return(operationData);
        }
Exemplo n.º 22
0
        private NativeRuntime.IFabricOperationData GetOrCreateOperationData(IOperationData operationData)
        {
            OperationData managed = operationData as OperationData;

            if (managed != null)
            {
                return(this.operationDataFactory.CreateOperationData(managed));
            }

            ReadOnlyOperationData native = operationData as ReadOnlyOperationData;

            if (native != null)
            {
                return(native.NativeOperationData);
            }

            return(null);
        }
        public void PostCommit(IServiceOperationRecorderContext recorderContext)
        {
            var request = (ConfigurationDocumentRequestBase)recorderContext.Request;

            var data = new OperationData
            {
                Operation           = "SetConfigurationDocument",
                DocumentName        = request.DocumentKey.DocumentName,
                DocumentVersion     = request.DocumentKey.Version.ToString(),
                DocumentUser        = request.DocumentKey.User ?? "{application}",
                DocumentInstanceKey = StringUtilities.NullIfEmpty(request.DocumentKey.InstanceKey) ?? "{default}"
            };


            var xml = JsmlSerializer.Serialize(data, "Audit");

            recorderContext.Write(data.Operation, xml);
        }
Exemplo n.º 24
0
        protected override void Write(BinaryWriter bw, OperationData operationData, bool isPhysicalWrite, bool forceRecomputeOffsets)
        {
            base.Write(bw, operationData, isPhysicalWrite, forceRecomputeOffsets);
            var startingPos = bw.BaseStream.Position;

            bw.BaseStream.Position += sizeof(int);

            bw.Write((int)this.informationEvent);

            var endPosition   = bw.BaseStream.Position;
            var sizeOfSection = checked ((int)(endPosition - startingPos));

            bw.BaseStream.Position = startingPos;
            bw.Write(sizeOfSection);
            bw.BaseStream.Position = endPosition;

            operationData.Add(CreateArraySegment(startingPos, bw));
        }
Exemplo n.º 25
0
        /// <summary>
        /// Verify <paramref name="result"/> contains the expected operation exactly.
        /// </summary>
        /// <param name="result">Resulting GeneratedModule object.</param>
        /// <param name="expectedOperation">Expected operation info.</param>
        private void AssertModuleContainsOperation(GeneratedModule result, OperationData expectedOperation)
        {
            // Ignore these 11 parameters:

            /* Verbose
             * Debug
             * ErrorAction
             * WarningAction
             * InformationAction
             * ErrorVariable
             * WarningVariable
             * InformationVariable
             * OutVariable
             * OutBuffer
             * PipelineVariable */
            Assert.True(result.Operations.ContainsKey(expectedOperation.OperationId.ToLowerInvariant()));
            Assert.Equal(expectedOperation.Parameters.Count, result.Operations[expectedOperation.OperationId.ToLowerInvariant()].Parameters.Count - 11);
            OperationData actualOperation = result.Operations[expectedOperation.OperationId.ToLowerInvariant()];

            foreach (string parmName in expectedOperation.Parameters.Keys)
            {
                Assert.True(actualOperation.Parameters.ContainsKey(parmName), parmName);
                Assert.NotNull(actualOperation.Parameters[parmName].Type);
                Assert.Equal(expectedOperation.Parameters[parmName].Type.Type, actualOperation.Parameters[parmName].Type.Type);
                Assert.Equal(expectedOperation.Parameters[parmName].Type.Properties.Count, actualOperation.Parameters[parmName].Type.Properties.Count);
                foreach (string propertyName in expectedOperation.Parameters[parmName].Type.Properties.Keys)
                {
                    Assert.Equal(expectedOperation.Parameters[parmName].Type.Properties[propertyName].Type, actualOperation.Parameters[parmName].Type.Properties[propertyName].Type);
                    Assert.Equal(expectedOperation.Parameters[parmName].Type.Properties[propertyName].Name, actualOperation.Parameters[parmName].Type.Properties[propertyName].Name);
                    Assert.Equal(expectedOperation.Parameters[parmName].Type.Properties[propertyName].JsonName, actualOperation.Parameters[parmName].Type.Properties[propertyName].JsonName);
                }
            }

            if (expectedOperation.ResponseType != null)
            {
                Assert.NotNull(actualOperation.ResponseType);
                Assert.NotNull(actualOperation.ResponseType.ModuleData);
                Assert.Equal(expectedOperation.ResponseType.ModuleData.Type, actualOperation.ResponseType.ModuleData.Type);
            }
            else
            {
                Assert.Null(actualOperation.ResponseType);
            }
        }
Exemplo n.º 26
0
        protected override void Write(BinaryWriter bw, OperationData operationData, bool isPhysicalWrite, bool forceRecomputeOffsets)
        {
            base.Write(bw, operationData, isPhysicalWrite, forceRecomputeOffsets);
            var startingPosition = bw.BaseStream.Position;

            bw.BaseStream.Position += sizeof(int);

            if (this.linkedPhysicalRecordOffset == InvalidPhysicalRecordOffset || forceRecomputeOffsets == true)
            {
                Utility.Assert(
                    this.linkedPhysicalRecord != null || forceRecomputeOffsets == true,
                    "(this.linkedPhysicalRecord != null)={0}, forceRecomputeOffsets={1}",
                    this.linkedPhysicalRecord != null,
                    forceRecomputeOffsets);

                if (this.linkedPhysicalRecord == null)
                {
                    this.linkedPhysicalRecordOffset = 0;
                }
                else
                {
                    Utility.Assert(
                        this.linkedPhysicalRecord.RecordPosition != InvalidRecordPosition,
                        "this.linkedPhysicalRecord.RecordPosition != LogRecord.INVALID_RECORD_POSITION");
                    Utility.Assert(
                        this.RecordPosition != InvalidRecordPosition,
                        "this.RecordPosition != LogRecord.INVALID_RECORD_POSITION");

                    this.linkedPhysicalRecordOffset = this.RecordPosition - this.linkedPhysicalRecord.RecordPosition;
                }
            }

            bw.Write(this.linkedPhysicalRecordOffset);

            var endPosition   = bw.BaseStream.Position;
            var sizeOfSection = checked ((int)(endPosition - startingPosition));

            bw.BaseStream.Position = startingPosition;
            bw.Write(sizeOfSection);
            bw.BaseStream.Position = endPosition;

            operationData.Add(CreateArraySegment(startingPosition, bw));
            return;
        }
Exemplo n.º 27
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NamedOperationContext"/> class with serialize.
        /// </summary>
        public NamedOperationData(
            OperationData operationData,
            long stateProviderId,
            int version,
            string traceType)
        {
            // #9894884: Native changed Version to metadataCount, keep the old format for now.
            Utility.Assert(
                stateProviderId != DynamicStateManager.EmptyStateProviderId,
                "{0}: NamedOperationData: Id cannot be empty in named operation data",
                traceType);

            this.OperationData   = operationData;
            this.StateProviderId = stateProviderId;
            this.Version         = version;
            this.TraceType       = traceType;

            this.Serialize();
        }
Exemplo n.º 28
0
        private static bool SwitchState(OperationData data, OperationState expectedState, OperationState nextState)
        {
            if (data.State < expectedState)
            {
                // Throws to retry and wait until the operation will be in the required state
                throw new InvalidOperationException(
                    $"Operation execution state can't be switched: {data.State} -> {nextState}. Waiting for the {expectedState} state.");
            }

            if (data.State > expectedState)
            {
                // Already in the next state, so this event can be just ignored
                return false;
            }

            data.State = nextState;

            return true;
        }
Exemplo n.º 29
0
        public virtual IOperation <T, U, V> Make <ProtocolClass>(T model) where ProtocolClass : class, new()
        {
            IEnumerable <V>       context          = new V() as IEnumerable <V>;
            IOperationContext <V> operationContext = new OperationContext <V>(context);
            // TODO move request to context
            IOperationData <T>    requestOperationData = new OperationData <T>(model);
            IOperationRequest <T> operationRequest     = new OperationRequest <T>(requestOperationData);

            IOperationData <U>     responseOperationData = new OperationData <U>(new U());
            IOperationResponse <U> operationResponse     = new OperationResponse <U>(responseOperationData);

            IOperationAction <T, U, V> operationAction = new OperationAction <T, U, V>(operationRequest, operationResponse, operationContext);

            var protocol = CreateProtocolInstance <ProtocolClass>(logger, operationAction);

            this.protocol = protocol as OperationProtocol <T, U, V>;

            return(this);
        }
Exemplo n.º 30
0
        protected override void Write(BinaryWriter bw, OperationData operationData, bool isPhysicalWrite, bool forceRecomputeOffsets)
        {
            base.Write(bw, operationData, isPhysicalWrite, forceRecomputeOffsets);
            var startingPosition = bw.BaseStream.Position;

            bw.BaseStream.Position += sizeof(int);

            bw.Write(this.isStable);
            bw.Write(this.periodicTruncationTimeTicks);

            var endPosition   = bw.BaseStream.Position;
            var sizeOfSection = checked ((int)(endPosition - startingPosition));

            bw.BaseStream.Position = startingPosition;
            bw.Write(sizeOfSection);
            bw.BaseStream.Position = endPosition;

            operationData.Add(CreateArraySegment(startingPosition, bw));
        }
Exemplo n.º 31
0
        private static void AreEqual(OperationData operationData, List <TimeScope> timeScopes, TLG tlg, string cardPath)
        {
            var fileName             = tlg.A + ".xml";
            var tlgXmlHeaderFilePath = Path.Combine(cardPath, "TASKDATA", fileName);

            Assert.IsTrue(File.Exists(tlgXmlHeaderFilePath));

            var tims = new XmlReader().ReadTlgXmlData(cardPath, fileName);

            TimAssert.AreEqual(timeScopes, tims);

            var sections            = operationData.GetAllSections();
            var meters              = sections.SelectMany(x => x.GetWorkingDatas()).ToList();
            var adaptSpatialRecords = operationData.GetSpatialRecords();
            var binaryReader        = new BinaryReader();
            var isoSpatialRecords   = binaryReader.Read(cardPath, tlg.A + ".bin", tims.First());

            IsoSpatialRecordAssert.AreEqual(adaptSpatialRecords, meters, isoSpatialRecords);
        }
Exemplo n.º 32
0
        protected override void Write(BinaryWriter bw, OperationData operationData, bool isPhysicalWrite, bool forceRecomputeOffsets)
        {
            base.Write(bw, operationData, isPhysicalWrite, forceRecomputeOffsets);
            var startingPosition = bw.BaseStream.Position;

            // Metadata Size
            bw.BaseStream.Position += sizeof(int);

            // Future fields

            // End of metadata.
            var endPosition   = bw.BaseStream.Position;
            var sizeOfSection = checked ((int)(endPosition - startingPosition));

            bw.BaseStream.Position = startingPosition;
            bw.Write(sizeOfSection);
            bw.BaseStream.Position = endPosition;

            operationData.Add(CreateArraySegment(startingPosition, bw));
        }
Exemplo n.º 33
0
        public static List <DeviceElementUse> GetAllSections(this OperationData operationData)
        {
            if (operationData.GetDeviceElementUses == null)
            {
                return(new List <DeviceElementUse>());
            }

            var allSections = new List <DeviceElementUse>();

            for (var i = 0; i <= operationData.MaxDepth; i++)
            {
                var sections = operationData.GetDeviceElementUses(i);
                if (sections != null)
                {
                    allSections.AddRange(sections);
                }
            }

            return(allSections);
        }
        private void talkOperation(OperationData operation)
        {
            if (operation == null) {
                return;
            }
            StringBuilder sb = new StringBuilder();

            sb.Append("operation id: ");
            sb.Append(operation.OperationId);
            sb.Append(". ");

            sb.Append("date: ");
            sb.Append(operation.Date.ToLongDateString());
            sb.Append(". ");

            sb.Append("team: ");
            sb.Append(operation.Team);
            sb.Append(". ");

            sb.Append("process: ");
            sb.Append(operation.Process);
            sb.Append(". ");

            sb.Append("diagnoses: ");
            sb.Append(operation.Diagnoses);
            sb.Append(". ");

            sb.Append("performed: ");
            sb.Append(operation.Performed);
            sb.Append(". ");

            talk(sb.ToString());
        }
		void IServiceOperationRecorder.PreCommit(IServiceOperationRecorderContext recorderContext, IPersistenceContext persistenceContext)
		{
			if (!ShouldCapture(recorderContext, persistenceContext))
				return;

			_capturedData = Capture(recorderContext, persistenceContext);

			// if we need to capture the change-set, it is important that we do so now,
 			// while the persistence context is still alive, rather than during the 
			// post-commit phase, where we can get lazy loading exceptions
			if (_changeSetIncludes.Any() && recorderContext.ChangeSet != null)
			{
				var changeSetData = DefaultEntityChangeSetRecorder.WriteChangeSet(_capturedData.Operation, recorderContext.ChangeSet.Changes);
				var includedActions = from action in changeSetData.Actions
									  where action.Type == "Update" && _changeSetIncludes.Contains(action.OID) || _changeSetIncludes.Contains(action.Class)
									  select (object)action;
				_capturedData.ChangeSet = new ChangeSetData { Actions = includedActions.ToList() };
			}
		}
        public async Task<OperationData> GetNextAsync(CancellationToken cancellationToken)
        {
            // Get the progress of the remote replica.
            if (this.catchUpProgressVector == null)
            {
                var remoteProgress = await this.GetRemoteReplicaProgress();
                this.catchUpProgressVector = new ProgressVector(this.localProgress.Excluding(remoteProgress));
                this.logger.Log(
                    "CopyStateStream:\n"
                    + $"Local progress:  {this.localProgress} (& up to LSN {this.upToSequenceNumber})\n"
                    + $"Remote progress: {remoteProgress}\n" + $"Delta Progress:  {this.catchUpProgressVector}");
            }

            // Nothing to copy.
            if (this.upToSequenceNumber == 0)
            {
                return null;
            }

            // Find the first entry which needs to be replicated
            var result = default(OperationData);
            var totalSize = 0;

            // Wait for the required records to become available.
            this.hasRecord = this.records.MoveNext();
            while (this.hasRecord)
            {
                var rawRecord = this.records.Current;
                var record = this.serializer.Deserialize<Record>(rawRecord);
                var operation = record as OperationCommittedRecord;
                if (operation == null)
                {
                    this.logger.Log(
                        $"CopyStateStream: {record} is not an {nameof(OperationCommittedRecord)}, it is an {record.GetType()}.");
                    this.hasRecord = this.records.MoveNext();
                    continue;
                }

                var currentVersion = operation.Version;
                var currentLsn = currentVersion.LogSequenceNumber;
                if (currentLsn > this.upToSequenceNumber)
                {
                    break;
                }

                // Only return records which were actually committed.
                if (!this.catchUpProgressVector.IncludesVersionInPreviousEpoch(currentVersion)
                    && this.catchUpProgressVector.Current.Epoch != currentVersion.Epoch)
                {
#warning we need a bucket load of tests around this to motivate correctness. How is the 'zero' epoch handled? Does such a thing even exist?
                    /*this.logger.Log(
                        $"CopyStateStream: {currentVersion} is not in the catchup vector or current epoch ({this.catchUpProgressVector.Current.Epoch.ToDisplayString()})");*/
                    this.hasRecord = this.records.MoveNext();
                    continue;
                }

                if (result == null)
                {
                    this.lowestLsn = currentLsn;
                }

                this.highestLsn = this.highestLsn > currentLsn ? this.highestLsn : currentLsn;

                // Copy the payload into the result.
                var data = this.serializer.Serialize(record);
                if (result == null)
                {
                    result = new OperationData(data);
                }
                else
                {
                    result.Add(data);
                }

                this.hasRecord = this.records.MoveNext();

                // If a sequence number which has not yet been committed has been requested, wait for that before continuing.
                if (!this.hasRecord && this.highestLsn != this.upToSequenceNumber)
                {
                    await this.WaitForCommit(rawRecord.SequenceNumber, cancellationToken);
                }

                // Send only a certain amount of data at a time.
                totalSize += data.Count;
                if (totalSize > ResultCutoffLength)
                {
                    break;
                }
            }

            this.logger.Log(
                result == null
                    ? "Completed copying state"
                    : $"CopyStateStream.GetNextAsync returning {result.Count} records, from LSN {this.lowestLsn} to {this.highestLsn}");

            return result;
        }
Exemplo n.º 37
0
        public static void ReportOpenEditor()
        {
            _backgroundThread.IsBackground = true;
            _backgroundThread.Start();

            OperationData operation = FindOperation(OperationTypes.kOpenEditor);
            if (operation == null)
            {
                operation = new OperationData(OperationTypes.kOpenEditor);

                lock (_lockObject)
                {
                    _allOperations.Add(operation);
                }
            }
            else
            {
                operation.Count++;
            }
        }
Exemplo n.º 38
0
        public static void ReportOpenDoc()
        {
            OperationData operation = FindOperation(OperationTypes.kOpenDoc);
            if (operation == null)
            {
                operation = new OperationData(OperationTypes.kOpenDoc);

                lock (_lockObject)
                {
                    _allOperations.Add(operation);
                }
            }
            else
            {
                operation.Count++;
            }
        }