예제 #1
0
        /// <summary>
        /// This method write snipt to a file
        /// Format in file
        /// Title:
        /// Lexer:
        /// IsPublic:
        /// Code: (new new line)        
        /// </summary>
        /// <param name="snipt"></param>
        private static void WriteSniptToFile(SniptObject snipt)
        {
            try
            {
                // Write the data to a file.
                System.IO.StreamWriter file = new System.IO.StreamWriter("D:\\SniptsFiles\\" + snipt.Slug + ".txt", false);

                StringBuilder dataToWrite = new StringBuilder();

                dataToWrite.Append("Title: " + snipt.Title);
                dataToWrite.Append("\n");
                dataToWrite.Append("Lexer: " + snipt.Lexer);
                dataToWrite.Append("\n");
                dataToWrite.Append("IsPublic: " + snipt.IsPublic);
                dataToWrite.Append("\n");
                dataToWrite.Append("Code: \n" + snipt.Code);

                file.WriteLine(dataToWrite.ToString());
                file.Close();
            }
            catch (IOException ioException)
            {
                // TODO : log/print message -
            }
        }
예제 #2
0
        /// <summary>
        /// Parse the given JToken object
        /// </summary>
        /// <param name="objectToken">JToken object to parse</param>
        /// <returns>SniptObject craeted from parse JToken object</returns>       
        private SniptObject ParseJObject(JToken objectToken)
        {
            SniptObject sniptObject = new SniptObject();

            foreach (JProperty propertyToken in objectToken.Children())
            {
                switch ((((JProperty)(propertyToken))).Name)
                {
                    case "absolute_url":
                        sniptObject.AbsoluteUrl = (((JProperty)(propertyToken))).Value.ToString();
                        break;
                    case "full_absolute_url":
                        sniptObject.FullAbsoluteUrl = (((JProperty)(propertyToken))).Value.ToString();
                        break;
                    case "embed_url":
                        sniptObject.EmbedUrl = (((JProperty)(propertyToken))).Value.ToString();
                        break;
                    case "resource_uri":
                        sniptObject.ResourceUri = (((JProperty)(propertyToken))).Value.ToString();
                        break;
                    case "id":
                        sniptObject.Id = Convert.ToInt32((((JProperty)(propertyToken))).Value.ToString());
                        break;
                    case "key":
                        sniptObject.Key = (((JProperty)(propertyToken))).Value.ToString();
                        break;
                    case "lexer":
                        sniptObject.Lexer = (((JProperty)(propertyToken))).Value.ToString();
                        break;
                    case "line_count":
                        sniptObject.LineCount = Convert.ToInt32((((JProperty)(propertyToken))).Value.ToString());
                        break;
                    case "slug":
                        sniptObject.Slug = (((JProperty)(propertyToken))).Value.ToString();
                        break;
                    case "title":
                        sniptObject.Title = (((JProperty)(propertyToken))).Value.ToString();
                        break;
                    case "code":
                        sniptObject.Code = (((JProperty)(propertyToken))).Value.ToString();
                        break;
                    case "public":
                        sniptObject.IsPublic = Convert.ToBoolean((((JProperty)(propertyToken))).Value.ToString());
                        break;
                    case "created":
                        sniptObject.CreateDate = (((JProperty)(propertyToken))).Value.ToString();
                        break;
                    case "modified":
                        sniptObject.ModifiedDate = (((JProperty)(propertyToken))).Value.ToString();
                        break;
                    default:
                        break;

                }
            }

            return sniptObject;
        }