Exemple #1
0
 /*
  * This constructor is for making a new Step from a GHStep
  */
 public Step(GHStep st)
 {
     this.FillFields(st);
 }
Exemple #2
0
        /*
         * Iterate through all steps and their lines, inserting them into the DB
         */
        private void InsertStepsAndLines(Guide parentGuide, GHStep[] steps, iFixitDataContext db)
        {
            //loop through all steps and attempt to insert them
            foreach (GHStep newStep in steps)
            {
                //see if it exists
                //Step sOld = db.StepsTable.FirstOrDefault(s => s.Title == newStep.title);
                Step sOld = DBHelpers.GetCompleteStep(parentGuide.GuideID, newStep.number, db);
                if (sOld == null)
                {
                    //insert it
                    sOld = new Step(newStep);
                    sOld.parentName = parentGuide.GuideID;
                    db.StepsTable.InsertOnSubmit(sOld);
                }
                else
                {
                    //update it
                    sOld.FillFields(newStep);
                }

                //go through all lines
                foreach (GHStepLines newLine in newStep.lines)
                {
                    Lines oldLine = db.LinesTable.FirstOrDefault(l => l.parentName == sOld.parentName + sOld.StepIndex);
                    if (oldLine == null)
                    {
                        //insert it
                        Lines l = new Lines(newLine);
                        l.parentName = sOld.parentName + sOld.StepIndex;
                        db.LinesTable.InsertOnSubmit(l);
                    }
                    else
                    {
                        //add it
                        oldLine.FillFields(newLine);
                        oldLine.parentName = sOld.parentName + sOld.StepIndex;
                    }
                }
            }
        }
Exemple #3
0
        public void FillFields(GHStep st)
        {
            this.StepIndex = st.number;
            this.Title = st.title;

            this.MediaType = st.media.type;

            if (st.media.type == Step.MediaType_Embed)
            {
                this.EmbedURL = st.media.embed.url;

                //process the URL to extract the real one we want
                Debug.WriteLine(this.EmbedURL);
                int start = this.EmbedURL.LastIndexOf("//");
                this.EmbedURL = "http://" + this.EmbedURL.Substring(start + "//".Length);
                Debug.WriteLine(this.EmbedURL);
            }
            else if (st.media.type == Step.MediaType_Image)
            {
                //add images (in a strange way...)
                this.Image1 = "";
                this.Image2 = "";
                this.Image3 = "";

                if (st.media.image != null)
                {
                    switch (st.media.image.Length)
                    {
                        default:
                            //no images, or we have no idea
                            break;

                        case 1:
                            this.Image1 = st.media.image[0].text;
                            break;

                        case 2:
                            this.Image1 = st.media.image[0].text;
                            this.Image2 = st.media.image[1].text;
                            break;

                        case 3:
                            this.Image1 = st.media.image[0].text;
                            this.Image2 = st.media.image[1].text;
                            this.Image3 = st.media.image[2].text;
                            break;
                    }
                }
            }

            //add each line
            foreach (GHStepLines l in st.lines)
            {
                Lines dbLine = new Lines(l);
                dbLine.parentName = this.parentName + this.StepIndex;
                this.Lines.Add(dbLine);
            }
        }