public async Task <ExecutionReport> GetOpenDSSScript(long rootId)
        {
            ExecutionReport executionReport = new ExecutionReport();

            var networkModelVersionDictionary = await this.stateManager.GetOrAddAsync <IReliableDictionary <string, long> >(ReliableCollectionNames.NetworkModelVersionDictionary);

            long lastSavedVersion = -1;

            using (var tx = this.stateManager.CreateTransaction())
            {
                var result = await networkModelVersionDictionary.TryGetValueAsync(tx, ReliableCollectionNames.NetworkModelVersionDictionary);

                if (result.HasValue)
                {
                    lastSavedVersion = result.Value;
                }
            }

            if (lastSavedVersion == -1)
            {
                string message = "There is no network model saved on model management service.";
                Logger.LogDebug(message);
                executionReport.Message = message;
                executionReport.Status  = ExecutionStatus.SUCCESS;
                return(executionReport);
            }

            var topologyResultDictionary = await this.stateManager.GetOrAddAsync <IReliableDictionary <long, TopologyResult> >(ReliableCollectionNames.TopologyResultDictionary);

            TopologyResult topologyResult = null;

            using (ITransaction tx = this.stateManager.CreateTransaction())
            {
                if (await topologyResultDictionary.GetCountAsync(tx) == 0)
                {
                    string message = "There is no topology model saved on model management service.";
                    Logger.LogDebug(message);
                    executionReport.Message = message;
                    executionReport.Status  = ExecutionStatus.SUCCESS;
                    return(executionReport);
                }

                var result = await topologyResultDictionary.TryGetValueAsync(tx, rootId);

                if (!result.HasValue)
                {
                    string message = $"Root id {rootId} is not presented in topology model";
                    Logger.LogError(message);
                    executionReport.Message = message;
                    executionReport.Status  = ExecutionStatus.ERROR;
                    return(executionReport);
                }

                topologyResult = result.Value;
            }

            Dictionary <long, ResourceDescription> networkModel = await GetAllNetworkModelElementsFromReliableDictionary(ReliableCollectionNames.NetworkModelDictinoary);

            OpenDSSScriptBuilder openDSSScriptBuilder = new OpenDSSScriptBuilder(networkModel, topologyResult);

            try
            {
                executionReport.Message = openDSSScriptBuilder.GenerateDSSScript();
                executionReport.Status  = ExecutionStatus.SUCCESS;
            }
            catch (Exception e)
            {
                string message = $"Generate DSS Script failed with error: {e.Message}";
                Logger.LogError(message, e);
                executionReport.Message = message;
            }

            return(executionReport);
        }
示例#2
0
 public OpenDSSScriptBuilder(Dictionary <long, ResourceDescription> resources, TopologyResult topology)
 {
     Resources          = resources;
     Topology           = topology;
     modelResourcesDesc = new ModelResourcesDesc();
 }