コード例 #1
0
        protected override void OnInitialize()
        {
            if (IOHelper.CheckLinkExists(_vdsMetaFileId, _currentPath))
            {
                _groupId = H5G.open(_vdsMetaFileId, _currentPath);

                if (H5A.exists(_groupId, "unit") > 0)
                {
                    _unit = IOHelper.ReadAttribute <string>(_groupId, "unit").FirstOrDefault();
                }

                if (H5A.exists(_groupId, "transfer_function_set") > 0)
                {
                    _vdsMetaTransferFunctionSet = IOHelper.ReadAttribute <hdf_transfer_function_t>(_groupId, "transfer_function_set").ToList();
                }
                else
                {
                    _vdsMetaTransferFunctionSet = new List <hdf_transfer_function_t>();
                }

                H5G.close(_groupId);
            }
            else
            {
                _vdsMetaTransferFunctionSet = new List <hdf_transfer_function_t>();
            }
        }
コード例 #2
0
        public static void UpdateCampaignInfoSet()
        {
            long vdsFileId     = -1;
            long vdsMetaFileId = -1;
            long groupId       = -1;

            lock (_lock)
            {
                try
                {
                    if (File.Exists(_options.VdsFilePath))
                    {
                        vdsFileId     = H5F.open(_options.VdsFilePath, H5F.ACC_RDONLY);
                        vdsMetaFileId = H5F.open(_options.VdsMetaFilePath, H5F.ACC_RDONLY);

                        Program.CampaignInfoSet = GeneralHelper.GetCampaignInfoSet(vdsFileId, false);
                    }
                    else
                    {
                        Program.CampaignInfoSet = new List <CampaignInfo>();
                    }

                    Program.CampaignDescriptionSet = Program.CampaignInfoSet.ToDictionary(campaignInfo => campaignInfo.Name, campaignInfo =>
                    {
                        if (IOHelper.CheckLinkExists(vdsMetaFileId, campaignInfo.Name))
                        {
                            try
                            {
                                groupId = H5G.open(vdsMetaFileId, campaignInfo.Name);

                                if (H5A.exists(groupId, "description") > 0)
                                {
                                    return(IOHelper.ReadAttribute <string>(groupId, "description").First());
                                }
                            }
                            finally
                            {
                                if (H5I.is_valid(groupId) > 0)
                                {
                                    H5G.close(groupId);
                                }
                            }
                        }

                        return("no description available");
                    });
                }
                finally
                {
                    if (H5I.is_valid(vdsFileId) > 0)
                    {
                        H5F.close(vdsFileId);
                    }
                    if (H5I.is_valid(vdsMetaFileId) > 0)
                    {
                        H5F.close(vdsMetaFileId);
                    }
                }
            }
        }
コード例 #3
0
        private void Menu_2(Dictionary <string, string> settings) // edit variable name
        {
            long fileId;
            long groupId;

            string variableGroupPath;
            string attributeName;

            string[] attributeContentSet;

            List <string> filePathSet;

            //
            settings = this.PromptEditVariableNameData(settings);

            if (settings.ContainsKey("DirectoryPath"))
            {
                filePathSet = Directory.GetFiles(settings["DirectoryPath"], settings["SearchPattern"], settings["IncludeSubDirectories"] == "Yes" ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly).ToList();
            }
            else
            {
                filePathSet = new List <string>()
                {
                    settings["FilePath"]
                };
            }

            variableGroupPath   = settings["VariableGroupPath"];
            attributeName       = "name_set";
            attributeContentSet = new string[] { settings["VariableName"] };

            foreach (string filePath in filePathSet)
            {
                fileId = H5F.open(filePath, H5F.ACC_RDWR, 0);

                if (IOHelper.CheckLinkExists(fileId, variableGroupPath))
                {
                    groupId = H5G.open(fileId, variableGroupPath);

                    if (settings["AppendMode"] == "Append")
                    {
                        IOHelper.PrepareAttribute(groupId, attributeName, attributeContentSet, new ulong[] { H5S.UNLIMITED }, true);
                    }
                    else
                    {
                        IOHelper.WriteAttribute(groupId, attributeName, attributeContentSet);
                    }

                    // clean up
                    H5G.close(groupId);
                }

                // clean up
                H5F.close(fileId);
            }
        }
コード例 #4
0
        private void Menu_1(Dictionary <string, string> settings) // edit group name
        {
            long fileId;
            long groupId;

            string parentGroupPath;
            string oldGroupName;
            string newGroupName;

            List <string> filePathSet;

            //
            settings = this.PromptEditGroupNameData(settings);

            if (settings.ContainsKey("DirectoryPath"))
            {
                filePathSet = Directory.GetFiles(settings["DirectoryPath"], settings["SearchPattern"], settings["IncludeSubDirectories"] == "Yes" ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly).ToList();
            }
            else
            {
                filePathSet = new List <string>()
                {
                    settings["FilePath"]
                };
            }

            parentGroupPath = settings["ParentGroupPath"];
            oldGroupName    = settings["OldGroupName"];
            newGroupName    = settings["NewGroupName"];

            foreach (string filePath in filePathSet)
            {
                fileId = H5F.open(filePath, H5F.ACC_RDWR, 0);

                if (IOHelper.CheckLinkExists(fileId, parentGroupPath))
                {
                    groupId = H5G.open(fileId, parentGroupPath);

                    if (IOHelper.CheckLinkExists(groupId, oldGroupName))
                    {
                        H5L.move(groupId, oldGroupName, groupId, newGroupName);
                    }

                    // clean up
                    H5G.close(groupId);
                }

                // clean up
                H5F.close(fileId);
            }
        }
コード例 #5
0
        protected override void OnInitialize()
        {
            if (IOHelper.CheckLinkExists(_vdsMetaFileId, _currentPath))
            {
                _groupId = H5G.open(_vdsMetaFileId, _currentPath);

                if (H5A.exists(_groupId, "aggregate_function_set") > 0)
                {
                    _vdsMetaAggregateFunctionSet = IOHelper.ReadAttribute <hdf_aggregate_function_t>(_groupId, "aggregate_function_set").ToList();
                }
                else
                {
                    _vdsMetaAggregateFunctionSet = new List <hdf_aggregate_function_t>();
                }

                H5G.close(_groupId);
            }
            else
            {
                _vdsMetaAggregateFunctionSet = new List <hdf_aggregate_function_t>();
            }
        }
コード例 #6
0
        protected override void OnInitialize()
        {
            if (H5A.exists(_vdsLocationId, "tag_set") > 0)
            {
                _vdsTagSet = IOHelper.ReadAttribute <hdf_tag_t>(_vdsLocationId, "tag_set").ToList();
            }
            else
            {
                _vdsTagSet = new List <hdf_tag_t>();
            }

            if (IOHelper.CheckLinkExists(_vdsMetaFileId, _currentPath))
            {
                _groupId     = H5G.open(_vdsMetaFileId, _currentPath);
                _description = string.Empty;

                if (H5A.exists(_groupId, "description") > 0)
                {
                    _description = IOHelper.ReadAttribute <string>(_groupId, "description").First();
                }

                if (H5A.exists(_groupId, "tag_set") > 0)
                {
                    _vdsMetaTagSet = IOHelper.ReadAttribute <hdf_tag_t>(_groupId, "tag_set").ToList();
                }
                else
                {
                    _vdsMetaTagSet = new List <hdf_tag_t>();
                }

                H5G.close(_groupId);
            }
            else
            {
                _vdsMetaTagSet = new List <hdf_tag_t>();
            }
        }
コード例 #7
0
        public Task <string> GetCampaignDocumentation(string campaigInfoName)
        {
            long vdsMetaFileId = -1;

            string csvFileName;

            CampaignInfo  campaignInfo;
            List <string> groupNameSet;

            campaignInfo = Program.CampaignInfoSet.First(campaign => campaign.Name == campaigInfoName);

            return(Task.Run(() =>
            {
                this.CheckState();

                try
                {
                    if (File.Exists(_options.VdsMetaFilePath))
                    {
                        vdsMetaFileId = H5F.open(_options.VdsMetaFilePath, H5F.ACC_RDONLY);
                    }

                    csvFileName = Path.Combine(_options.SupportDirectoryPath, "EXPORT", $"OneDAS_{ campaignInfo.Name.ToLower().Replace("/", "_").TrimStart('_') }_{ Guid.NewGuid().ToString() }.csv");
                    groupNameSet = campaignInfo.VariableInfoSet.SelectMany(variableInfo => variableInfo.VariableGroupSet.Last().Split('\n')).Distinct().ToList();

                    using (StreamWriter streamWriter = new StreamWriter(new FileStream(csvFileName, FileMode.Create, FileAccess.Write, FileShare.Read), Encoding.UTF8))
                    {
                        // campaign header
                        streamWriter.WriteLine($"# { campaignInfo.Name.TrimStart('/').Replace("/", " / ") }");

                        // campaign description
                        streamWriter.WriteLine($"# { Program.CampaignDescriptionSet[campaigInfoName] }");

                        // header
                        streamWriter.WriteLine("Group;Name;Unit;Transfer function;Aggregate function;Guid");

                        // groups
                        foreach (string groupName in groupNameSet)
                        {
                            List <VariableInfo> groupedVariableInfoSet;

                            groupedVariableInfoSet = campaignInfo.VariableInfoSet.Where(variableInfo => variableInfo.VariableGroupSet.Last().Split('\n').Contains(groupName)).OrderBy(variableInfo => variableInfo.VariableNameSet.Last()).ToList();

                            // variables
                            groupedVariableInfoSet.ForEach(variableInfo =>
                            {
                                long variable_groupId = -1;

                                string transferFunction;
                                string aggregateFunction;
                                string groupPath;
                                string name;
                                string guid;
                                string unit;

                                List <hdf_transfer_function_t> transferFunctionSet;
                                List <hdf_aggregate_function_t> aggregateFunctionSet;

                                name = variableInfo.VariableNameSet.Last();
                                guid = variableInfo.Name;
                                unit = string.Empty;
                                transferFunctionSet = new List <hdf_transfer_function_t>();
                                aggregateFunctionSet = new List <hdf_aggregate_function_t>();

                                try
                                {
                                    groupPath = GeneralHelper.CombinePath(campaignInfo.Name, variableInfo.Name);

                                    if (H5I.is_valid(vdsMetaFileId) > 0 && IOHelper.CheckLinkExists(vdsMetaFileId, groupPath))
                                    {
                                        variable_groupId = H5G.open(vdsMetaFileId, groupPath);

                                        if (H5A.exists(variable_groupId, "unit") > 0)
                                        {
                                            unit = IOHelper.ReadAttribute <string>(variable_groupId, "unit").FirstOrDefault();
                                        }

                                        if (H5A.exists(variable_groupId, "transfer_function_set") > 0)
                                        {
                                            transferFunctionSet = IOHelper.ReadAttribute <hdf_transfer_function_t>(variable_groupId, "transfer_function_set").ToList();
                                        }

                                        if (H5A.exists(variable_groupId, "aggregate_function_set") > 0)
                                        {
                                            aggregateFunctionSet = IOHelper.ReadAttribute <hdf_aggregate_function_t>(variable_groupId, "aggregate_function_set").ToList();
                                        }
                                    }
                                }
                                finally
                                {
                                    if (H5I.is_valid(variable_groupId) > 0)
                                    {
                                        H5G.close(variable_groupId);
                                    }
                                }

                                // transfer function
                                transferFunction = string.Empty;

                                transferFunctionSet.ForEach(tf =>
                                {
                                    if (!string.IsNullOrWhiteSpace(transferFunction))
                                    {
                                        transferFunction += " | ";
                                    }

                                    transferFunction += $"{ tf.date_time }, { tf.type }, { tf.option }, { tf.argument }";
                                });

                                transferFunction = $"\"{ transferFunction }\"";

                                // aggregate function
                                aggregateFunction = string.Empty;

                                aggregateFunctionSet.ForEach(af =>
                                {
                                    if (!string.IsNullOrWhiteSpace(aggregateFunction))
                                    {
                                        aggregateFunction += " | ";
                                    }

                                    aggregateFunction += $"{ af.type }, { af.argument }";
                                });

                                aggregateFunction = $"\"{ aggregateFunction  }\"";

                                // write row
                                streamWriter.WriteLine($"{ groupName };{ name };{ unit };{ transferFunction };{ aggregateFunction };{ guid }");
                            });
                        }
                    }

                    return $"download/{ Path.GetFileName(csvFileName) }";
                }
                finally
                {
                    if (H5I.is_valid(vdsMetaFileId) > 0)
                    {
                        H5F.close(vdsMetaFileId);
                    }
                }
            }));
        }
コード例 #8
0
        public void WriteCampaignDocumentation(string directoryPath, CampaignInfo campaignInfo)
        {
            long campaign_groupId = -1;

            string description;
            string filePath;

            RestructuredTextWriter restructuredTextWriter;
            List <string>          groupNameSet;

            Console.Clear();

            groupNameSet = campaignInfo.VariableInfoSet.Select(variableInfo => variableInfo.VariableGroupSet.Last()).Distinct().ToList();
            filePath     = Path.Combine(directoryPath, $"{ campaignInfo.Name.ToLower().Replace("/", "_").TrimStart('_') }.rst");

            try
            {
                using (StreamWriter streamWriter = new StreamWriter(new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Read)))
                {
                    restructuredTextWriter = new RestructuredTextWriter(streamWriter);

                    // campaign header
                    restructuredTextWriter.WriteHeading(campaignInfo.Name.TrimStart('/').Replace("/", " / "), SectionHeader.Section);

                    // campaign description
                    restructuredTextWriter.WriteLine();

                    try
                    {
                        if (IOHelper.CheckLinkExists(_vdsMetaFileId, campaignInfo.Name))
                        {
                            campaign_groupId = H5G.open(_vdsMetaFileId, campaignInfo.Name);

                            if (H5A.exists(campaign_groupId, "description") > 0)
                            {
                                description = IOHelper.ReadAttribute <string>(campaign_groupId, "description").First();
                            }
                            else
                            {
                                description = "no description available";
                            }
                        }
                        else
                        {
                            description = "no description available";
                        }

                        restructuredTextWriter.WriteNote(description);
                    }
                    finally
                    {
                        if (H5I.is_valid(campaign_groupId) > 0)
                        {
                            H5G.close(campaign_groupId);
                        }
                    }

                    // groups
                    foreach (string groupName in groupNameSet)
                    {
                        RestructuredTextTable restructuredTextTable;

                        List <VariableInfo> groupedVariableInfoSet;

                        restructuredTextWriter.WriteLine();
                        restructuredTextWriter.WriteHeading(groupName, SectionHeader.SubSection);
                        restructuredTextWriter.WriteLine();

                        restructuredTextTable = new RestructuredTextTable(new List <string>()
                        {
                            "Name", "Unit", "Guid"
                        });
                        groupedVariableInfoSet = campaignInfo.VariableInfoSet.Where(variableInfo => variableInfo.VariableGroupSet.Last() == groupName).OrderBy(variableInfo => variableInfo.VariableNameSet.Last()).ToList();

                        // variables
                        groupedVariableInfoSet.ForEach(variableInfo =>
                        {
                            long variable_groupId = -1;

                            string groupPath;
                            string name;
                            string guid;
                            string unit;

                            List <hdf_transfer_function_t> transferFunctionSet;
                            List <hdf_aggregate_function_t> aggregateFunctionSet;

                            // name
                            name = variableInfo.VariableNameSet.Last();

                            if (name.Count() > 43)
                            {
                                name = $"{ name.Substring(0, 40) }...";
                            }

                            // guid
                            guid = $"{ variableInfo.Name.Substring(0, 8) }...";

                            // unit, transferFunctionSet, aggregateFunctionSet
                            unit = string.Empty;

                            try
                            {
                                groupPath = variableInfo.GetPath();

                                if (IOHelper.CheckLinkExists(_vdsMetaFileId, groupPath))
                                {
                                    variable_groupId = H5G.open(_vdsMetaFileId, groupPath);

                                    if (H5A.exists(variable_groupId, "unit") > 0)
                                    {
                                        unit = IOHelper.ReadAttribute <string>(variable_groupId, "unit").FirstOrDefault();
                                    }

                                    if (H5A.exists(variable_groupId, "transfer_function_set") > 0)
                                    {
                                        transferFunctionSet = IOHelper.ReadAttribute <hdf_transfer_function_t>(variable_groupId, "transfer_function_set").ToList();
                                    }

                                    if (H5A.exists(variable_groupId, "aggregate_function_set") > 0)
                                    {
                                        aggregateFunctionSet = IOHelper.ReadAttribute <hdf_aggregate_function_t>(variable_groupId, "aggregate_function_set").ToList();
                                    }
                                }
                            }
                            finally
                            {
                                if (H5I.is_valid(variable_groupId) > 0)
                                {
                                    H5G.close(variable_groupId);
                                }
                            }

                            //
                            restructuredTextTable.AddRow(new List <string> {
                                name, unit, guid
                            });

                            //transferFunctionSet.ForEach(x => streamWriter.Write($"{ x.date_time }, { x.type }, { x.option }, { x.argument } | "));
                            //aggregateFunctionSet.ForEach(x => streamWriter.Write($"{ x.type }, { x.argument } | "));
                        });

                        restructuredTextWriter.WriteTable(restructuredTextTable);
                        restructuredTextWriter.WriteLine();
                    }
                }

                Console.WriteLine($"The file has been successfully written to:\n{ filePath }");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            Console.WriteLine("\nPress any key to continue ...");
            Console.ReadKey();
        }