Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            //args = new string[1];
            //args[0] = "/i";

            // Initialize input arguments
            bool insolationOnly = false;

            foreach (var arg in args)
            {
                var    splitArg = arg.Split('=');
                string value    = "";

                if (splitArg != null && splitArg.Count() > 0)
                {
                    var command = splitArg[0].ToLower();
                    if (splitArg.Count() > 1)
                    {
                        value = splitArg[1].ToLower().Trim();
                    }

                    switch (command)
                    {
                    //interval
                    case "/i":
                        insolationOnly = true;
                        break;
                    }
                }
            }


            // create IPrincipal
            string directory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            string path      = Assembly.GetExecutingAssembly().Location + ".config";

            RemotingConfiguration.Configure(path, true);
            _sunPrincipal = SunPrincipalFactory.CreateSystemSunPrincipal(); // For SAM API calls
            _sePrincipal  = SEPrincipalFactory.CreateSystemSEPrincipal();   // For SMART API Calls


            // Get insolation path from Configuration
            //_insolationPath = System.Configuration.ConfigurationManager.AppSettings.Get("InsolationPath");
            _insolationPath = string.Format("{0}\\{1}\\", directory, "insolation");


            // JobStart Heading
            Console.WriteLine("--------------------------");
            Console.WriteLine("Reference Data Import Tool");
            Console.WriteLine("--------------------------");
            Console.WriteLine();
            Console.WriteLine("This tool is used to import Energy Estimates from SAM into SMART.");
            Console.WriteLine();


            // import reference data
            ImportInsolation();

            if (!insolationOnly)
            {
                ImportEnergyEstimates();
            }

            Console.WriteLine();
            Console.WriteLine();
        }
Ejemplo n.º 2
0
        private static void ImportInsolation()
        {
            SunPrincipal sunPrincipal = SunPrincipalFactory.CreateSystemSunPrincipal();

            SunPrincipal.ToCallContext(sunPrincipal);

            List <EnergyEstimateImportItem> energyImportItems = GetRefDataFromFile();

            try
            {
                string path = _insolationPath;

                if (!System.IO.Directory.Exists(path))
                {
                    System.IO.Directory.CreateDirectory(path);
                }

                DeleteAllFiles(path);

                Console.Write("Export insolation to files...");



                foreach (var energyImportItem in energyImportItems)
                {
                    Project project = ServiceManager.Projects.GetProjectForProjectNumber(energyImportItem.ProjectNumber);
                    EnergyEstimateHistory history = ServiceManager.Energy.GetEnergyEstimateHistoryForProjectID(project.ProjectID);

                    if (history != null)
                    {
                        history.EnergyEstimateMonthList.Sort((a, b) => a.Month.CompareTo(b.Month));

                        string projectName = project.ProjectName;
                        string projectNo   = project.ProjectNumber;

                        projectName = projectName.Replace(",", "-");
                        projectName = projectName.Replace("/", " ");
                        projectName = projectName.Replace("\\", " ");

                        // Check if there are reference insolation (GlobalInclined insolation) in SAM Energy Estimates
                        if (history.EnergyEstimateMonthList != null && history.EnergyEstimateMonthList[0].GlobalIncident != null)
                        {
                            // create csv file
                            string filename = string.Format("{0}", projectNo);
                            string file     = string.Format("{0}{1}.csv", path, filename);

                            StreamWriter sw = new StreamWriter(file);

                            foreach (var estimateMonth in history.EnergyEstimateMonthList)
                            {
                                int month = estimateMonth.Month;
                                sw.WriteLine("{0},{1}", estimateMonth.Month, estimateMonth.GlobalIncident);
                                //sw.WriteLine("{0},{1}", estimateMonth.Month, estimateMonth.GlobalHorizon);

                                sw.Flush();
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine(string.Format("{0}: No estimate", energyImportItem.ProjectNumber));
                    }
                }

                Console.Write("Done");
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                SunPrincipal.ClearCallContext();
            }
        }