Пример #1
0
        private static void Initialise(string[] args)
        {
            JustSettings js          = new JustSettings();
            string       templateDir = string.Empty;
            string       pathToFiles = "doc/user-story/";
            string       jiraHostUri = string.Empty;

            for (int i = 1; i < args.Length; i++)
            {
                if (args[i].ToLower() == "-t")
                {
                    templateDir = args[i + 1];
                }
                else if (args[i].ToLower() == "-p")
                {
                    pathToFiles = args[i + 1];
                }
                else if (args[i].ToLower() == "-j")
                {
                    jiraHostUri = args[i + 1];
                }
            }

            if (String.IsNullOrEmpty(jiraHostUri))
            {
                throw new ApplicationException("ERROR: You must specify the Jira anchor point with the '-j' option");
            }

            if (!String.IsNullOrEmpty(templateDir))
            {
                js.Template = templateDir;

                FileInfo fi = new FileInfo(js.Template);
                if (!fi.Exists)
                {
                    Console.WriteLine($"WARNING: the template '{js.Template}' does not exist at present. This will become a fatal error if you try to create a new entry without it!");
                }
            }

            js.Path       = pathToFiles;
            js.JiraAnchor = jiraHostUri;

            JsonSerializer serializer = new JsonSerializer();

            serializer.ContractResolver = new CamelCasePropertyNamesContractResolver();
            serializer.Converters.Add(new JavaScriptDateTimeConverter());
            serializer.NullValueHandling = NullValueHandling.Ignore;
            serializer.Formatting        = Formatting.Indented;

            using (StreamWriter sw = new StreamWriter($"just-settings.json"))
            {
                using (JsonWriter writer = new JsonTextWriter(sw))
                {
                    serializer.Serialize(writer, js);
                }
            }
        }
Пример #2
0
        public JustDocument(JustSettings settings)
        {
            _settings   = settings;
            CreatedBy   = "Unknown";
            CreatedDate = DateTime.Now;

            if (String.IsNullOrEmpty(_settings.Template))
            {
                _template = "# _TITLE\r\n\r\n## _CREATEDBY on _DATE\r\n\r\n## Reference\r\n\r\n_URL\r\n## Description\r\n\r\n_DESCRIPTION\r\n\r\n";
            }
            else
            {
                ReadTemplate(_settings.Template);
            }
        }
Пример #3
0
        private static JustSettings ReadSettings()
        {
            JustSettings js = null;

            JsonSerializer serializer = new JsonSerializer();

            serializer.ContractResolver = new CamelCasePropertyNamesContractResolver();
            serializer.Converters.Add(new JavaScriptDateTimeConverter());
            serializer.NullValueHandling = NullValueHandling.Ignore;
            serializer.Formatting        = Formatting.Indented;

            using (StreamReader sr = new StreamReader($"just-settings.json"))
            {
                using (JsonReader reader = new JsonTextReader(sr))
                {
                    js = serializer.Deserialize <JustSettings>(reader);
                }
            }

            if (js == null)
            {
                throw new ApplicationException("ERROR: no just-settings.json found in current directory.\r\n\r\nDid you run\r\n\r\n\tjust init beforehand?");
            }

            // NOTE(ian): File.Exists doesn't work on network share or UNC paths
            FileInfo fi     = new FileInfo(js.Template);
            bool     exists = fi.Exists;

            if (!String.IsNullOrEmpty(js.Template) && !exists)
            {
                throw new ApplicationException($"ERROR: the template '{js.Template}' specified does not exist!");
            }

            if (!Directory.Exists(js.Path))
            {
                Directory.CreateDirectory(js.Path);
            }

            return(js);
        }