Ejemplo n.º 1
0
        protected override async Task Execute()
        {
            await base.Execute();

            AssertFileExists(ConfigFileName);

            Console.WriteLine("Reading GIS data based on configuration: " + ConfigFileName + " (can take several minutes)...");

            var config = new TransformationConfig().LoadFromFile(ConfigFileName);

            var transformer = config.InitializeDataTransformer("test");

            ((CIMGraphWriter)transformer.GetFirstDataWriter()).DoNotRunPreCheckConnectivity();
            ((CIMGraphWriter)transformer.GetFirstDataWriter()).DoNotLogToTable();

            transformer.TransferData();

            var writer = (CIMGraphWriter)transformer.GetFirstDataWriter();
            var graph  = writer.GetCIMGraph();

            // Create folder if not exists
            if (!System.IO.Directory.Exists(base.ExportFolderName))
            {
                System.IO.Directory.CreateDirectory(base.ExportFolderName);
            }

            ExportEquipmentPsiFile(config, graph);
            ExportAssetPsiFile(config, graph);
        }
Ejemplo n.º 2
0
        protected override async Task Execute()
        {
            await base.Execute();

            AssertFileExists(ConfigFileName);

            Console.WriteLine("Creating full CIM network dump based on configuration: " + ConfigFileName);

            var config = new TransformationConfig().LoadFromFile(ConfigFileName);

            //config.DataReaders[0].ConfigParameters.Add(new ConfigParameter { Name = "Extent", Value = "548694,552348,6187246,6189391" });

            var transformer = config.InitializeDataTransformer("test");

            ((CIMGraphWriter)transformer.GetFirstDataWriter()).DoNotRunPreCheckConnectivity();
            ((CIMGraphWriter)transformer.GetFirstDataWriter()).DoNotLogToTable();

            transformer.TransferData();

            var writer = (CIMGraphWriter)transformer.GetFirstDataWriter();
            var graph  = writer.GetCIMGraph();

            var stopWatch = Stopwatch.StartNew();

            ExportEquipment(config, graph);
            ExportAsset(config, graph);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            if (args.Length < 6)
            {
                System.Console.Out.WriteLine("Usage: Gis2PowerFactoryBatchRunner.exe inputAdapterConfigFileName outputCimArchiveFolder outputCimArchiveName outputLogFile extent highVoltageOnly(true/false)");
                return;
            }

            try
            {
                string cimAdapterConfig = args[0];
                string cimArchiveFolder = args[1];
                string cimArchiveName   = args[2];
                Guid   cimModeRdfId     = Guid.Parse(args[3]);
                string logFileName      = args[4];
                string extent           = args[5];
                bool   highVoltageOnly  = false;

                if (args.Length == 7 && args[6].ToLower() == "true")
                {
                    highVoltageOnly = true;
                }

                var cimFileName = cimArchiveName + ".jsonl";

                Log.Logger = new LoggerConfiguration()
                             .WriteTo.File(logFileName, rollingInterval: RollingInterval.Day)
                             .WriteTo.Console()
                             .WriteTo.EventLog("NRGi.Gis2PowerFactoryBatchRunner", manageEventSource: true, restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Error)
                             .CreateLogger();

                Logger.WriteToConsole = true;

                var config = new TransformationConfig().LoadFromFile(cimAdapterConfig);

                // Sæt extent
                if (extent != null)
                {
                    config.DataReaders[0].ConfigParameters.Add(new ConfigParameter()
                    {
                        Name = "Extent", Value = extent
                    });
                }

                var transformer = config.InitializeDataTransformer("test");

                // Log ikke til database tabel, da vi køre på prod
                ((CIMGraphWriter)transformer.GetFirstDataWriter()).DoNotLogToTable();
                ((CIMGraphWriter)transformer.GetFirstDataWriter()).DoNotRunPreCheckConnectivity();

                transformer.TransferData();

                CIMGraphWriter writer = transformer.GetFirstDataWriter() as CIMGraphWriter;
                CIMGraph       graph  = writer.GetCIMGraph();

                // Serialize
                var serializer = config.InitializeSerializer("DAX") as IDAXSerializeable;

                var cimObjects = ((DAXCIMSerializer)serializer).GetIdentifiedObjects(CIMMetaDataManager.Repository, graph.CIMObjects, true, true, true).ToList();

                var pfWriter = new KonstantCimArchiveWriter(cimObjects, cimArchiveFolder, cimArchiveName, cimModeRdfId, highVoltageOnly);

                Logger.Log(LogLevel.Info, "Export to Power Factory CIM Archive: " + cimArchiveFolder + "\\" + cimArchiveName + ".zip finished.");
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }
        }
        /// <summary>
        /// Process the posted data according to transformation specification.
        /// If the writer (specificed in the transformation specification) is able to produce text or xml (i.e. geojson) that will be returned.
        /// If the writer (specificed in the transformation specification) is not able to produce output that can be returend (i.e. SQL writer), a http ok with no content will be return on successful completion.
        /// </summary>
        /// <returns></returns>
        public HttpResponseMessage Post(string specificationName, string projectName = null, string jobName = null, string userName = null)
        {
            Logger.Information("Incoming transformation command. TransformationSpecification='" + specificationName + "' JobName='" + jobName + "' ProjectName='" + projectName + "' UserName='******'");

            try
            {
                var httpRequest = HttpContext.Current.Request;

                System.IO.StreamReader reader = new System.IO.StreamReader(httpRequest.InputStream);
                string inputData = reader.ReadToEnd();

                if (inputData == null || inputData.Length == 0)
                {
                    Logger.Error("Input data cannot be null or length = 0!");
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Input data cannot be null. No data send in post request. Check if file is empty.", new JsonMediaTypeFormatter()));
                }

                string landLinkConfig = AppSettings.Get("LandLinkConfigFile");

                var config = new TransformationConfig().LoadFromFile(landLinkConfig);

                var transformer = config.InitializeDataTransformer(specificationName);

                if (transformer.GetSpecification().Type != null && transformer.GetSpecification().Type.ToLower() == "import" && jobName == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "jobName parameter must be set on import transformations", new JsonMediaTypeFormatter()));
                }

                var daxReader = transformer.GetFirstDataReader();

                // Log out first 200 bytes of input data
                int inputSubStringLen = 200;

                if (inputData.Length < inputSubStringLen)
                {
                    inputSubStringLen = inputData.Length;
                }

                Logger.Debug("Input data stream (max 200 bytes): " + inputData.Substring(0, inputSubStringLen));


                transformer.GetFirstDataReader().Open(inputData);

                transformer.TransferData(projectName, jobName, userName);

                var writer = transformer.GetFirstDataWriter();
                var transformationResult = writer.GetResult();

                if (transformationResult != null)
                {
                    int outputSubStringLen = 200;

                    if (transformationResult.Length < outputSubStringLen)
                    {
                        outputSubStringLen = transformationResult.Length;
                    }

                    Logger.Debug("Output data stream (max 200 bytes): " + transformationResult.Substring(0, outputSubStringLen));

                    HttpResponseMessage resp = new HttpResponseMessage(HttpStatusCode.OK);
                    resp.Content = new StringContent(transformationResult);
                    resp.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");

                    return(resp);
                }
                else
                {
                    return(new HttpResponseMessage(HttpStatusCode.OK));
                }
            }
            catch (Exception ex)
            {
                return(HttpErrorHelper.CreateHttpResponsForUnexpectedException(this, Logger, ex));
            }
        }