Beispiel #1
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);
                    }
                }
            }));
        }
Beispiel #2
0
        protected override bool OnWaitForUserInput()
        {
            if (this.LastIndex >= 0)
            {
                Console.SetCursorPosition(1, this.LastIndex);
                Console.Write(" ");
            }

            if (this.SelectedIndex >= 0)
            {
                Console.SetCursorPosition(1, this.SelectedIndex);
                Console.Write("x");
            }

            switch (Console.ReadKey(true).Key)
            {
            case ConsoleKey.UpArrow:

                if (this.SelectedIndex > 0)
                {
                    this.LastIndex      = this.SelectedIndex;
                    this.SelectedIndex -= 1;
                }
                break;

            case ConsoleKey.DownArrow:

                if (this.SelectedIndex < _currentList.Count - 1)
                {
                    this.LastIndex      = this.SelectedIndex;
                    this.SelectedIndex += 1;
                }
                break;

            case ConsoleKey.Enter:
            case ConsoleKey.RightArrow:

                if (this.SelectedIndex >= 0)
                {
                    _vdsGroupId = H5G.open(_vdsLocationId, _currentList[this.SelectedIndex].Name);
                    new VdsMetaNavigator(_vdsGroupId, _vdsMetaFileId, GeneralHelper.CombinePath(_currentPath, _currentList[this.SelectedIndex].Name), _currentList[this.SelectedIndex].GetChildSet().ToList());
                    H5G.close(_vdsGroupId);
                    this.OnRedraw();
                }

                break;

            case ConsoleKey.D1:

                if (this.SelectedIndex >= 0 && _currentList[this.SelectedIndex] is CampaignInfo)
                {
                    _vdsGroupId = H5G.open(_vdsLocationId, _currentList[this.SelectedIndex].Name);
                    new CampaignNavigator(_vdsGroupId, _vdsMetaFileId, _currentList[this.SelectedIndex].Name);
                    H5G.close(_vdsGroupId);
                    this.OnRedraw();
                }

                break;

            case ConsoleKey.D2:

                if (this.SelectedIndex >= 0 && _currentList[this.SelectedIndex] is VariableInfo)
                {
                    VariableInfo variableInfo;

                    variableInfo = (VariableInfo)_currentList[this.SelectedIndex];
                    _vdsGroupId  = H5G.open(_vdsLocationId, _currentList[this.SelectedIndex].Name);
                    new TransferFunctionNavigator(_vdsGroupId, _vdsMetaFileId, GeneralHelper.CombinePath(_currentPath, variableInfo.Name), variableInfo.UnitSet, variableInfo.TransferFunctionSet);
                    H5G.close(_vdsGroupId);
                    this.OnRedraw();
                }

                break;

            case ConsoleKey.D3:

                if (this.SelectedIndex >= 0 && _currentList[this.SelectedIndex] is VariableInfo)
                {
                    _vdsGroupId = H5G.open(_vdsLocationId, _currentList[this.SelectedIndex].Name);
                    new AggregateFunctionNavigator(_vdsGroupId, _vdsMetaFileId, GeneralHelper.CombinePath(_currentPath, _currentList[this.SelectedIndex].Name));
                    H5G.close(_vdsGroupId);
                    this.OnRedraw();
                }

                break;

            case ConsoleKey.D:

                if (_currentList[this.SelectedIndex] is CampaignInfo)
                {
                    string directoryPath;

                    try
                    {
                        directoryPath = Program.PromptDirectoryPath(Directory.GetCurrentDirectory());

                        this.WriteCampaignDocumentation(directoryPath, (CampaignInfo)_currentList[this.SelectedIndex]);
                    }
                    catch
                    {
                        //
                    }

                    this.OnRedraw();
                }

                break;

            case ConsoleKey.P:

                _vdsGroupId = H5G.open(_vdsLocationId, _currentList[this.SelectedIndex].Name);
                new PurgeNavigator(_vdsLocationId, _vdsMetaFileId, _currentPath);
                H5G.close(_vdsGroupId);
                this.OnRedraw();

                break;

            case ConsoleKey.Escape:
            case ConsoleKey.LeftArrow:
                return(true);
            }

            return(false);
        }