コード例 #1
0
            private IEnumerable <SimpleWriteCommand> Enumerable()
            {
                WriteCommand current = this;

                while (current != null)
                {
                    var compound = current as CompoundWrite;
                    if (compound != null)
                    {
                        current = compound.TailCommand;
                        yield return(compound.Head);
                    }

                    var simple = current as SimpleWriteCommand;
                    if (simple != null)
                    {
                        current = null;
                        yield return(simple);
                    }
                }
            }
コード例 #2
0
            internal static WriteCommand MergeTwoAtomicOperations(WriteCommand command, Slice argument)
            {
                // truncate/resize the previous value to the size of the add
                int size = argument.Count;
                var tmp  = PrepareValueForAtomicOperation(command.Value, size);

                switch (command.Type)
                {
                case Operation.AtomicAdd:
                {                         // do a littlee-endian ADD between the two buffers
                    BufferAdd(tmp, 0, argument.Array, argument.Offset, size);
                    break;
                }

                case Operation.AtomicBitAnd:
                {                         // do an AND between the two buffers
                    BufferBitAnd(tmp, 0, argument.Array, argument.Offset, size);
                    break;
                }

                case Operation.AtomicBitOr:
                {                         // do a OR between the two buffers
                    BufferBitOr(tmp, 0, argument.Array, argument.Offset, size);
                    break;
                }

                case Operation.AtomicBitXor:
                {                         // do a XOR between the two buffers
                    BufferBitXor(tmp, 0, argument.Array, argument.Offset, size);
                    break;
                }

                default:
                {                         // not supposed to happen
                    throw new InvalidOperationException();
                }
                }

                return(new WriteCommand(command.Type, command.Key, Slice.Create(tmp)));
            }
コード例 #3
0
        public void WriteCommandWithParamsTest()
        {
            // test WriteCommand with parameters with Guid as well
            var  command = new WriteCommand("with_params.in");
            Guid my_guid = new Guid("11A4801F-7977-4D3E-8D1E-6CA0BE52E604");

            command.AddCommands("TestSystem", "TestCmd", new string[] { "Param0", "Param1", "Param2" }, new string[] { "Value0", "Value1", my_guid.ToString() }, true, 2);
            command.Save();

            var cmnDocPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments);
            var filePath   = Path.Combine(cmnDocPath, "BpOmniaBridge", "temp_files", "with_params.in");

            Assert.AreEqual(true, File.Exists(filePath));

            var elements   = XDocument.Load(filePath).Element("OmniaXB").Element("TestSystem").Element("TestCmd").Elements();
            int num_params = 0;

            // test each parameter has the correct name and value
            // Important to test the GUID otherwise you get NACK from OMNIA
            foreach (XElement element in elements)
            {
                if (num_params == 2)
                {
                    Assert.AreEqual("Param" + num_params, element.Name);
                    Assert.AreEqual(new Guid(element.Value), my_guid);
                }
                else
                {
                    Assert.AreEqual("Param" + num_params, element.Name);
                    Assert.AreEqual("Value" + num_params, element.Value);
                }

                num_params += 1;
            }

            Assert.AreEqual(3, num_params);

            File.Delete(filePath);
        }
コード例 #4
0
        protected override void UpdateModuleCycle()
        {
            this.CycleCount++;
            { //Perform writing
                WriteCommand wCmd = Write_IFace.Get();
                int          no   = wCmd.No % EntryCount;
                if (wCmd.Enabled)
                {
                    Entries[no].Content = wCmd.Value;
                    Entries[no].WriteAccessCount++;
                }
                PreviousWrite = wCmd;
            }

            { //Count reading
                ReadCommand  rCmd = Read0_IFace.Get();
                WriteCommand wCmd = Write_IFace.Get();
                int          no   = rCmd.No % EntryCount;
                if (rCmd.Enabled && no != PreviousRead0.No && !(wCmd.Enabled && wCmd.No == no))
                {
                    Entries[no].ReadAccessCount++;
                }
                PreviousRead0 = rCmd;
            }
            { //Count reading
                ReadCommand  rCmd = Read1_IFace.Get();
                WriteCommand wCmd = Write_IFace.Get();
                int          no   = rCmd.No % EntryCount;
                if (rCmd.Enabled && no != PreviousRead1.No && !(wCmd.Enabled && wCmd.No == no))
                {
                    Entries[no].ReadAccessCount++;
                }
                PreviousRead1 = rCmd;
            }

            base.UpdateModuleCycle();
        }
 public RawWriteOperation(RawWriteOperation other)
 {
     // Notes: May want to switch to MemberwiseClone, for now those this is fine
     m_Command = other.m_Command;
 }
コード例 #6
0
 public CompoundWrite(SimpleWriteCommand head, WriteCommand tailCommand)
 {
     _head        = head;
     _tailCommand = tailCommand;
 }
コード例 #7
0
 public CompoundWrite Append(WriteCommand that)
 {
     return(that.Prepend(this));
 }
コード例 #8
0
ファイル: I2CUIDevice.cs プロジェクト: iKenndac/RCCarControl
 private void Write8BitRegister(WriteCommand register, byte value)
 {
     byte[] buf = new byte[2];
     buf[0] = (byte)register;
     buf[1] = value;
     WriteToDevice(buf);
 }
コード例 #9
0
ファイル: TcpConnection.cs プロジェクト: xyicheng/akka.net
 private PendingWrite CreatePendingBufferWrite(IActorRef commander, ByteString data, Tcp.Event ack, WriteCommand tail)
 {
     return(new PendingBufferWrite(this, SendArgs, Self, commander, data, ack, tail));
 }
コード例 #10
0
        public override BuildPipelineCodes Convert(BuildDependencyInformation buildInfo, out BuildCommandSet output)
        {
            StartProgressBar("Generating Build Commands", buildInfo.assetLoadInfo.Count);

            Hash128 hash = CalculateInputHash(buildInfo);

            if (UseCache && BuildCache.TryLoadCachedResults(hash, out output))
            {
                output = new BuildCommandSet();
                EndProgressBar();
                return(BuildPipelineCodes.SuccessCached);
            }

            var commands = new List <WriteCommand>();

            foreach (var bundle in buildInfo.bundleToAssets)
            {
                var command            = new WriteCommand();
                var explicitAssets     = new List <AssetLoadInfo>();
                var assetBundleObjects = new List <SerializationInfo>();
                var dependencies       = new HashSet <string>();

                foreach (var asset in bundle.Value)
                {
                    var assetInfo = buildInfo.assetLoadInfo[asset];
                    explicitAssets.Add(assetInfo);
                    if (!UpdateProgressBar(assetInfo.asset))
                    {
                        output = new BuildCommandSet();
                        EndProgressBar();
                        return(BuildPipelineCodes.Canceled);
                    }

                    dependencies.UnionWith(buildInfo.assetToBundles[asset]);

                    foreach (var includedObject in assetInfo.includedObjects)
                    {
                        if (!buildInfo.virtualAssets.Contains(asset) && buildInfo.objectToVirtualAsset.ContainsKey(includedObject))
                        {
                            continue;
                        }

                        assetBundleObjects.Add(new SerializationInfo
                        {
                            serializationObject = includedObject,
                            serializationIndex  = SerializationIndexFromObjectIdentifier(includedObject)
                        });
                    }

                    foreach (var referencedObject in assetInfo.referencedObjects)
                    {
                        if (referencedObject.filePath == kUnityDefaultResourcePath)
                        {
                            continue;
                        }

                        if (buildInfo.objectToVirtualAsset.ContainsKey(referencedObject))
                        {
                            continue;
                        }

                        if (buildInfo.assetLoadInfo.ContainsKey(referencedObject.guid))
                        {
                            continue;
                        }

                        assetBundleObjects.Add(new SerializationInfo
                        {
                            serializationObject = referencedObject,
                            serializationIndex  = SerializationIndexFromObjectIdentifier(referencedObject)
                        });
                    }

                    BuildUsageTagGlobal globalUsage;
                    if (buildInfo.sceneUsageTags.TryGetValue(asset, out globalUsage))
                    {
                        command.sceneBundle  = true;
                        command.globalUsage |= globalUsage;
                    }
                }

                dependencies.Remove(bundle.Key);
                assetBundleObjects.Sort(Compare);

                command.assetBundleName         = bundle.Key;
                command.explicitAssets          = explicitAssets;
                command.assetBundleDependencies = dependencies.OrderBy(x => x).ToList();
                command.assetBundleObjects      = assetBundleObjects;
                commands.Add(command);
            }

            output          = new BuildCommandSet();
            output.commands = commands;

            if (UseCache && !BuildCache.SaveCachedResults(hash, output))
            {
                BuildLogger.LogWarning("Unable to cache CommandSetProcessor results.");
            }

            if (!EndProgressBar())
            {
                return(BuildPipelineCodes.Canceled);
            }
            return(BuildPipelineCodes.Success);
        }
コード例 #11
0
#pragma warning restore 649

        /// <inheritdoc />
        public ReturnCode Run()
        {
            Dictionary <string, WriteCommand> fileToCommand;
            Dictionary <string, HashSet <ObjectIdentifier> > forwardObjectDependencies;
            Dictionary <string, HashSet <string> >           forwardFileDependencies;
            Dictionary <string, HashSet <GUID> >             reverseAssetDependencies;

            // BuildReferenceMap details what objects exist in other bundles that objects in a source bundle depend upon (forward dependencies)
            // BuildUsageTagSet details the conditional data needed to be written by objects in a source bundle that is in used by objects in other bundles (reverse dependencies)
            using (m_Log.ScopedStep(LogLevel.Info, $"Temporary Map Creations"))
            {
                fileToCommand             = m_WriteData.WriteOperations.ToDictionary(x => x.Command.internalName, x => x.Command);
                forwardObjectDependencies = new Dictionary <string, HashSet <ObjectIdentifier> >();
                forwardFileDependencies   = new Dictionary <string, HashSet <string> >();
                reverseAssetDependencies  = new Dictionary <string, HashSet <GUID> >();
                foreach (var pair in m_WriteData.AssetToFiles)
                {
                    GUID          asset = pair.Key;
                    List <string> files = pair.Value;

                    // The includes for an asset live in the first file, references could live in any file
                    forwardObjectDependencies.GetOrAdd(files[0], out HashSet <ObjectIdentifier> objectDependencies);
                    forwardFileDependencies.GetOrAdd(files[0], out HashSet <string> fileDependencies);

                    // Grab the list of object references for the asset or scene and add them to the forward dependencies hash set for this file (write command)
                    if (m_DependencyData.AssetInfo.TryGetValue(asset, out AssetLoadInfo assetInfo))
                    {
                        objectDependencies.UnionWith(assetInfo.referencedObjects);
                    }
                    if (m_DependencyData.SceneInfo.TryGetValue(asset, out SceneDependencyInfo sceneInfo))
                    {
                        objectDependencies.UnionWith(sceneInfo.referencedObjects);
                    }

                    // Grab the list of file references for the asset or scene and add them to the forward dependencies hash set for this file (write command)
                    // While doing so, also add the asset to the reverse dependencies hash set for all the other files it depends upon.
                    // We already ensure BuildReferenceMap & BuildUsageTagSet contain the objects in this write command in GenerateBundleCommands. So skip over the first file (self)
                    for (int i = 1; i < files.Count; i++)
                    {
                        fileDependencies.Add(files[i]);
                        reverseAssetDependencies.GetOrAdd(files[i], out HashSet <GUID> reverseDependencies);
                        reverseDependencies.Add(asset);
                    }
                }
            }

            // Using the previously generated forward dependency maps, update the BuildReferenceMap per WriteCommand to contain just the references that we care about
            using (m_Log.ScopedStep(LogLevel.Info, $"Populate BuildReferenceMaps"))
            {
                foreach (var operation in m_WriteData.WriteOperations)
                {
                    var internalName = operation.Command.internalName;

                    BuildReferenceMap referenceMap = m_WriteData.FileToReferenceMap[internalName];
                    if (!forwardObjectDependencies.TryGetValue(internalName, out var objectDependencies))
                    {
                        continue; // this bundle has no external dependencies
                    }
                    if (!forwardFileDependencies.TryGetValue(internalName, out var fileDependencies))
                    {
                        continue; // this bundle has no external dependencies
                    }
                    foreach (string file in fileDependencies)
                    {
                        WriteCommand dependentCommand = fileToCommand[file];
                        foreach (var serializedObject in dependentCommand.serializeObjects)
                        {
                            // Only add objects we are referencing. This ensures that new/removed objects to files we depend upon will not cause a rebuild
                            // of this file, unless are referencing the new/removed objects.
                            if (!objectDependencies.Contains(serializedObject.serializationObject))
                            {
                                continue;
                            }

                            referenceMap.AddMapping(file, serializedObject.serializationIndex, serializedObject.serializationObject);
                        }
                    }
                }
            }

            // Using the previously generate reverse dependency map, create the BuildUsageTagSet per WriteCommand to contain just the data that we care about
            using (m_Log.ScopedStep(LogLevel.Info, $"Populate BuildUsageTagSet"))
            {
                foreach (var operation in m_WriteData.WriteOperations)
                {
                    var internalName           = operation.Command.internalName;
                    BuildUsageTagSet fileUsage = m_WriteData.FileToUsageSet[internalName];
                    if (reverseAssetDependencies.TryGetValue(internalName, out var assetDependencies))
                    {
                        foreach (GUID asset in assetDependencies)
                        {
                            if (m_DependencyData.AssetUsage.TryGetValue(asset, out var assetUsage))
                            {
                                fileUsage.UnionWith(assetUsage);
                            }
                            if (m_DependencyData.SceneUsage.TryGetValue(asset, out var sceneUsage))
                            {
                                fileUsage.UnionWith(sceneUsage);
                            }
                        }
                    }
                    if (ReflectionExtensions.SupportsFilterToSubset)
                    {
                        fileUsage.FilterToSubset(m_WriteData.FileToObjects[internalName].ToArray());
                    }
                }
            }
            return(ReturnCode.Success);
        }
コード例 #12
0
        static async Task Run(Arguments arguments)
        {
            Log.Logger = new LoggerConfiguration()
                         .Enrich.FromLogContext()
                         .WriteTo.Console()
                         .CreateLogger();

            var serviceProvider = new ServiceCollection()
                                  .AddLogging(loggingBuilder => loggingBuilder.AddSerilog(dispose: true))
                                  .BuildServiceProvider();

            var loggerFactory = serviceProvider.GetService <ILoggerFactory>();

            var isAdministrator = OperatingSystem.IsAdministrator();

            if (!isAdministrator)
            {
                Console.WriteLine("Requires administrator rights!");
            }

            var commandHelper           = new CommandHelper();
            var physicalDrives          = (await GetPhysicalDrives(arguments)).ToList();
            var cancellationTokenSource = new CancellationTokenSource();

            switch (arguments.Command)
            {
            case Arguments.CommandEnum.List:
                var listCommand = new ListCommand(loggerFactory.CreateLogger <ListCommand>(), commandHelper, physicalDrives);
                listCommand.ListRead += (_, args) =>
                {
                    //
                    // await Task.Run(() =>
                    // {
                    //     Console.WriteLine(JsonSerializer.Serialize(physicalDrivesList, JsonSerializerOptions));
                    // });
                    InfoPresenter.PresentInfo(args.MediaInfos);
                };
                var listResult = await listCommand.Execute(cancellationTokenSource.Token);

                Console.WriteLine(listResult.IsSuccess ? "Done" : $"ERROR: Read failed, {listResult.Error}");
                break;

            case Arguments.CommandEnum.Info:
                var infoCommand = new InfoCommand(loggerFactory.CreateLogger <InfoCommand>(), commandHelper, physicalDrives, arguments.SourcePath);
                infoCommand.DiskInfoRead += (_, args) => { InfoPresenter.PresentInfo(args.MediaInfo); };
                var infoResult = await infoCommand.Execute(cancellationTokenSource.Token);

                Console.WriteLine(infoResult.IsSuccess ? "Done" : $"ERROR: Read failed, {infoResult.Error}");
                break;

            case Arguments.CommandEnum.Read:
                Console.WriteLine("Reading physical drive to image file");

                GenericPresenter.PresentPaths(arguments);

                var readCommand = new ReadCommand(loggerFactory.CreateLogger <ReadCommand>(), commandHelper, physicalDrives, arguments.SourcePath,
                                                  arguments.DestinationPath,
                                                  arguments.Size);
                readCommand.DataProcessed += (_, args) => { GenericPresenter.Present(args); };
                var readResult = await readCommand.Execute(cancellationTokenSource.Token);

                Console.WriteLine(readResult.IsSuccess ? "Done" : $"ERROR: Read failed, {readResult.Error}");
                break;

            case Arguments.CommandEnum.Convert:
                Console.WriteLine("Converting source image to destination image file");

                GenericPresenter.PresentPaths(arguments);

                var convertCommand = new ConvertCommand(loggerFactory.CreateLogger <ConvertCommand>(), commandHelper, arguments.SourcePath,
                                                        arguments.DestinationPath,
                                                        arguments.Size);
                convertCommand.DataProcessed += (_, args) => { GenericPresenter.Present(args); };
                var convertResult = await convertCommand.Execute(cancellationTokenSource.Token);

                Console.WriteLine(
                    convertResult.IsSuccess ? "Done" : $"ERROR: Convert failed, {convertResult.Error}");
                break;

            case Arguments.CommandEnum.Write:
                Console.WriteLine("Writing source image file to physical drive");

                GenericPresenter.PresentPaths(arguments);

                var writeCommand = new WriteCommand(loggerFactory.CreateLogger <WriteCommand>(), commandHelper, physicalDrives, arguments.SourcePath,
                                                    arguments.DestinationPath,
                                                    arguments.Size);
                writeCommand.DataProcessed += (_, args) => { GenericPresenter.Present(args); };
                var writeResult = await writeCommand.Execute(cancellationTokenSource.Token);

                Console.WriteLine(writeResult.IsSuccess ? "Done" : $"ERROR: Write failed, {writeResult.Error}");
                break;

            case Arguments.CommandEnum.Verify:
                Console.WriteLine("Verifying source image to destination");

                GenericPresenter.PresentPaths(arguments);

                var verifyCommand = new VerifyCommand(loggerFactory.CreateLogger <VerifyCommand>(), commandHelper, physicalDrives, arguments.SourcePath,
                                                      arguments.DestinationPath,
                                                      arguments.Size);
                verifyCommand.DataProcessed += (_, args) => { GenericPresenter.Present(args); };
                var verifyResult = await verifyCommand.Execute(cancellationTokenSource.Token);

                Console.WriteLine(verifyResult.IsSuccess ? "Done" : $"ERROR: Verify failed, {verifyResult.Error}");
                break;

            case Arguments.CommandEnum.Blank:
                Console.WriteLine("Creating blank image");
                Console.WriteLine($"Path: {arguments.SourcePath}");
                var blankCommand = new BlankCommand(loggerFactory.CreateLogger <BlankCommand>(), commandHelper, arguments.SourcePath, arguments.Size);
                var blankResult  = await blankCommand.Execute(cancellationTokenSource.Token);

                Console.WriteLine(blankResult.IsSuccess ? "Done" : $"ERROR: Blank failed, {blankResult.Error}");
                break;

            case Arguments.CommandEnum.Optimize:
                Console.WriteLine("Optimizing image file");
                Console.WriteLine($"Path: {arguments.SourcePath}");
                var optimizeCommand = new OptimizeCommand(loggerFactory.CreateLogger <OptimizeCommand>(), commandHelper, arguments.SourcePath);
                var optimizeResult  = await optimizeCommand.Execute(cancellationTokenSource.Token);

                Console.WriteLine(optimizeResult.IsSuccess
                        ? "Done"
                        : $"ERROR: Optimize failed, {optimizeResult.Error}");
                break;
            }
        }