public void Apply(BinaryInfo binaryInfo)
        {
            var  messageJson = binaryInfo.jsonFormat;
            long id          = (long)messageJson["id"];

            LogUtilty.log("received id: " + id);
            FileStream fileStream;

            if (fileStreams.ContainsKey(id))
            {
                fileStream = fileStreams[id];
            }
            else
            {
                fileStream = new FileStream(@"D:\tmp\okay test\" + messageJson["fileName"], FileMode.Create, FileAccess.Write);
                fileStreams.Add(id, fileStream);
                LogUtilty.log("Created new file stream for location:" + @"D:\tmp\" + messageJson["fileName"]);
            }
            long frame       = (long)messageJson["frame"];
            long latestFrame = (long)messageJson["latestFrame"];

            byte[] binaryData = binaryInfo.binaryData;
            fileStream.Write(binaryData, binaryInfo.lengthToBody, binaryData.Length - binaryInfo.lengthToBody);
            if (frame == latestFrame)
            {
                fileStream.Close();
                fileStreams.Remove(id);
                LogUtilty.log("Closed stream and finished file writing, and removed from map");
            }
        }
        public static void apply(BinaryInfo binaryInfo)
        {
            string type = (string)binaryInfo.jsonFormat["type"];

            switch (type)
            {
            case "fileTransfer":
                fileReceiverManagerCommand.Apply(binaryInfo);
                break;

            default:
                throw new Exception("Not valid command: " + type);
            }
        }
Пример #3
0
        public void TestUploadAndCheckResult()
        {
            _ = string.IsNullOrEmpty(ConnStr) ? throw new IgnoreException($"{ConnStr} is empty") : ConnStr;

            var          binaryMan     = new BinaryMan(ConnStr, BlobContainerName, TableName);
            var          binaryName    = Guid.NewGuid().ToString("N");
            var          binaryVersion = new Version("1.0.4");
            const string binaryTag     = "1000";

            var binaryInfo = new BinaryInfo(binaryName, binaryVersion, binaryTag);

            Assert.IsEmpty(Task.Run(async() => await binaryMan.ListByName(binaryName)).Result);
            Assert.IsNull(Task.Run(async() => await binaryMan.GetBinaryInfo(binaryName, binaryVersion)).Result);

            var info = Task.Run(async() => await binaryMan.UploadFromFile(new FileInfo("mock.txt"), binaryName, binaryVersion, CancellationToken.None,
                                                                          binaryTag)).Result;

            Assert.IsNotEmpty(Task.Run(async() => await binaryMan.ListByName(binaryName)).Result);
            Assert.NotNull(Task.Run(async() => await binaryMan.GetBinaryInfo(binaryName, binaryVersion)).Result);

            Assert.Pass();
        }
Пример #4
0
        public void SerializeBinaryFileTest()
        {
            var info = new BinaryInfo();

            info.SetField1(1);
            info.SetField2(2);
            info.SetProperty2(4);
            info.Name = nameof(BinaryInfo);

            var path = "serialize_binary.dat".SetBasePath();

            path.SerializeBinaryFile(info);

            var info1 = path.DeserializeBinaryFile <BinaryInfo>();

            Assert.True(info.Field1Equals(info1));
            Assert.True(info.Property2Equals(info1));
            Assert.Equal(info.Field2, info1.Field2);
            Assert.Equal(info.Property1, info1.Property1);
            Assert.Equal(info.Name, info1.Name);

            path.FileDelete();
        }
Пример #5
0
    /// <summary>
    /// Calculate orbital data for binary star.
    /// </summary>
    /// <returns>
    /// <para>positionAngleDeg -- Position angle (degrees)</para>
    /// <para>separationArcsec -- Separation of binary members (arcseconds)</para>
    /// </returns>
    public (double positionAngleDeg, double separationArcsec) BinaryStarOrbit(double greenwichDateDay, int greenwichDateMonth, int greenwichDateYear, string binaryName)
    {
        var binaryInfo = BinaryInfo.GetBinaryInfo(binaryName);

        var yYears         = (greenwichDateYear + (PAMacros.CivilDateToJulianDate(greenwichDateDay, greenwichDateMonth, greenwichDateYear) - PAMacros.CivilDateToJulianDate(0, 1, greenwichDateYear)) / 365.242191) - binaryInfo.EpochPeri;
        var mDeg           = 360 * yYears / binaryInfo.Period;
        var mRad           = (mDeg - 360 * (mDeg / 360).Floor()).ToRadians();
        var eccentricity   = binaryInfo.Ecc;
        var trueAnomalyRad = PAMacros.TrueAnomaly(mRad, eccentricity);
        var rArcsec        = (1 - eccentricity * (PAMacros.EccentricAnomaly(mRad, eccentricity)).Cosine()) * binaryInfo.Axis;
        var taPeriRad      = trueAnomalyRad + binaryInfo.LongPeri.ToRadians();

        var y         = (taPeriRad).Sine() * ((binaryInfo.Incl).ToRadians()).Cosine();
        var x         = (taPeriRad).Cosine();
        var aDeg      = PAMacros.Degrees(y.AngleTangent2(x));
        var thetaDeg1 = aDeg + binaryInfo.PANode;
        var thetaDeg2 = thetaDeg1 - 360 * (thetaDeg1 / 360).Floor();
        var rhoArcsec = rArcsec * (taPeriRad).Cosine() / ((thetaDeg2 - binaryInfo.PANode).ToRadians()).Cosine();

        var positionAngleDeg = Math.Round(thetaDeg2, 1);
        var separationArcsec = Math.Round(rhoArcsec, 2);

        return(positionAngleDeg, separationArcsec);
    }
Пример #6
0
        public static string ToXml(BFLAN.Header header)
        {
            XmlRoot root = new XmlRoot();

            root.head = new Head();
            root.body = new Body();

            var generator = new Generator();

            root.head.generator = generator;
            generator.name      = "ST";
            generator.version   = "1.0"
            ;
            var create = new Create();

            root.head.create = create;
            create.date      = DateTime.Now.ToString("yyyy-MM-ddThh:mm:ss");

            BinaryInfo info = new BinaryInfo();

            info.layout.name     = header.AnimationTag.Name;
            info.version.major   = (byte)header.VersionMajor;
            info.version.minor   = (byte)header.VersionMinor;
            info.version.micro   = (byte)header.VersionMicro;
            info.version.micro2  = (byte)header.VersionMicro2;
            root.head.binaryInfo = info;

            AnimTag  tag      = new AnimTag();
            AnimInfo animInfo = new AnimInfo();

            if (header.AnimationInfo.Loop)
            {
                tag.animLoop = AnimLoopType.Loop;
            }

            tag.descendingBind = header.AnimationTag.ChildBinding;
            tag.name           = header.AnimationTag.Name;
            tag.fileName       = header.AnimationTag.Name;
            tag.startFrame     = header.AnimationTag.StartFrame;
            tag.endFrame       = header.AnimationTag.EndFrame;
            tag.group          = new Group[header.AnimationTag.Groups.Count];
            for (int i = 0; i < header.AnimationTag.Groups.Count; i++)
            {
                tag.group[i]      = new Group();
                tag.group[i].name = header.AnimationTag.Groups[i];
            }

            root.body.animTag[0] = tag;
            root.body.lan[0]     = animInfo;

            var bflanInfo   = header.AnimationInfo;
            var animContent = new AnimContent();

            animInfo.animContent    = new AnimContent[1];
            animInfo.animContent[0] = animContent;
            animInfo.startFrame     = bflanInfo.FrameSize;



            XmlWriterSettings settings = new XmlWriterSettings
            {
                Encoding    = Encoding.UTF8,
                Indent      = true,
                IndentChars = "  ",
            };


            XmlSerializerNamespaces ns = new XmlSerializerNamespaces();

            ns.Add("", "");

            XmlDocument    doc     = new XmlDocument();
            XmlDeclaration xmldecl = doc.CreateXmlDeclaration("1.0", null, null);

            xmldecl.Encoding   = "UTF-8";
            xmldecl.Standalone = "yes";

            var           stringWriter = new StringWriter();
            XmlSerializer serializer   = new XmlSerializer(typeof(XmlRoot));
            XmlWriter     output       = XmlWriter.Create(stringWriter, settings);

            serializer.Serialize(output, root, ns);
            return(stringWriter.ToString());
        }
Пример #7
0
        /// <summary>
        /// 指定されたディレクトリ以下を再帰的に探索し、バイナリ情報のリストを取得します。
        /// </summary>
        /// <param name="dir">探索するディレクトリ</param>
        /// <returns>検出したバイナリ情報のリスト</returns>
        private List <BinaryInfo> GetBinaryInfoList(DirectoryInfo dir, string targetConfig)
        {
            if (ConfigValues.IgnoreDirs.Contains(dir.Name))
            {
                return(new List <BinaryInfo>());
            }

            var pjInfoList = new List <BinaryInfo>();
            var deployDir  = new DirectoryInfo(ConfigValues.DeployPath);

            foreach (var projFile in dir.GetFiles("*.vbproj"))
            {
                try
                {
                    string pjName = IOPath.GetFileNameWithoutExtension(projFile.Name);

                    string targetCondition = string.Format(
                        "'$(Configuration)|$(Platform)' == '{0}|{1}'",
                        targetConfig, ConfigValues.TargetPlatform);

                    var root = XDocument.Load(projFile.FullName).Root;
                    var ns   = root.Name.Namespace;

                    var condPropGroup = (from e in root.Elements(ns + "PropertyGroup")
                                         where e.Attribute("Condition") != null &&
                                         e.Attribute("Condition").Value.Trim() == targetCondition
                                         select e
                                         ).FirstOrDefault();

                    if (condPropGroup == null)
                    {
                        targetCondition = string.Format(
                            "'$(Configuration)|$(Platform)' == '{0}|AnyCPU'",
                            targetConfig);

                        condPropGroup = (from e in root.Elements(ns + "PropertyGroup")
                                         where e.Attribute("Condition") != null &&
                                         e.Attribute("Condition").Value.Trim() == targetCondition
                                         select e
                                         ).FirstOrDefault();
                    }

                    var outputDir = new DirectoryInfo(IOPath.Combine(
                                                          projFile.Directory.FullName, condPropGroup.Element(ns + "OutputPath").Value));

                    var commonPropGroup = (from e in root.Elements(ns + "PropertyGroup")
                                           where e.Attribute("Condition") == null
                                           select e
                                           ).FirstOrDefault();

                    var buildedFileName =
                        commonPropGroup.Element(ns + "AssemblyName").Value +
                        (commonPropGroup.Element(ns + "OutputType").Value == "Library" ? ".dll" : ".exe");

                    var pjInfo = new BinaryInfo();
                    pjInfo.BuildedFile      = new FileInfo(IOPath.Combine(outputDir.FullName, buildedFileName));
                    pjInfo.DeployedFile     = new FileInfo(IOPath.Combine(deployDir.FullName, pjInfo.BinaryName));
                    pjInfo.ProjectDirectory = projFile.Directory;
                    pjInfo.OutputDirectory  = outputDir;
                    pjInfo.IsSelected       = false;

                    pjInfoList.Add(pjInfo);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }

            var childDirs = dir.GetDirectories();

            foreach (var childDir in childDirs)
            {
                pjInfoList.AddRange(GetBinaryInfoList(childDir, targetConfig));
            }

            return(pjInfoList);
        }
Пример #8
0
 public Binary(string name, byte[] data, BinaryInfo info)
 {
     Name = name;
     Data = data;
     Info = info;
 }
Пример #9
0
 public bool Property2Equals(BinaryInfo other)
 => Property2 == other.Property2;
Пример #10
0
 public bool Field1Equals(BinaryInfo other)
 => _field1 == other._field1;