public void AddKnittingProject(string projectName, KnittingProject project)
        {
            XElement projectXml = GetKnittingProjects();
            List<XElement> projects = projectXml.Elements("Project").ToList();

            if(!projects.Any() || (projects.Elements("Name").Any(n => n.Value != projectName)))
            {
                XElement newProject = new XElement("Project",
                    new XElement("Name", project.ProjectName),
                    new XElement("Description", project.ProjectDescription),
                    new XElement("CurrentRowCount", project.CurrentRowCount),
                    new XElement("RowCounterColorRGB", project.RowCounterColorRGB));

                projectXml.Add(newProject);

                string projectPath = System.IO.Path.Combine(ApplicationSettingsManager.DATA_PATH, ApplicationSettingsManager.SAVEDPROJECTS_FILENAME);
                using(IsolatedStorageFileStream stream = ApplicationSettingsManager.UserStoreForApplication.OpenFile(projectPath, FileMode.Create, FileAccess.ReadWrite))
                {
                    using(StreamWriter writer = new StreamWriter(stream))
                    {
                        projectXml.Save(writer);
                    }
                }
            }
        }
Esempio n. 2
0
        public void CreateProject()
        {
            KnittingProject knittingProject = new KnittingProject
            {
                ProjectName = this.ProjectName,
                ProjectDescription = this.ProjectDescription,
                RowCounterColor = this.RowCounterColor,
                CurrentRowCount = 0
            };

            if(this.AppSettings.GetKnittingProjectByName(this.ProjectName) == null)
            {
                App.ViewModel.KnittingProjects.Insert(0, knittingProject);
                this.AppSettings.AddKnittingProject(this.ProjectName, knittingProject);
            }
        }
Esempio n. 3
0
        public WriteableBitmap CreateRowCounterBitmap(KnittingProject project)
        {
            uknit.Controls.RowCounterControl rowCounter = new uknit.Controls.RowCounterControl()
            {
                TensDigit = (project.CurrentRowCount / 10).ToString(),
                OnesDigit = (project.CurrentRowCount % 10).ToString(),
                Fill = project.RowCounterColor,
                NeedleWidth = 100,
                HorizontalAlignment = System.Windows.HorizontalAlignment.Center
            };

            rowCounter.Measure(new Size(400, 400));
            rowCounter.Arrange(new Rect(0, 0, 400, 400));

            WriteableBitmap tileBitmap = new WriteableBitmap(400, 400);
            tileBitmap.Render(rowCounter, null);
            tileBitmap.Invalidate();

            return tileBitmap;
        }
        public void ModifyKnittingProjectByName(string projectName, KnittingProject project)
        {
            XElement projectXml = GetKnittingProjects();
            XElement projectToModify = projectXml.Elements("Project").Where(p => p.Element("Name").Value == projectName).First();

            projectToModify.Element("Name").Value = project.ProjectName;
            projectToModify.Element("Description").Value = project.ProjectDescription;
            projectToModify.Element("CurrentRowCount").Value = project.CurrentRowCount.ToString();
            projectToModify.Element("RowCounterColorRGB").Value = project.RowCounterColorRGB;

            if(projectToModify.Element("IsPinnedToStart") == null)
            {
                projectToModify.Add(new XElement("IsPinnedToStart", project.IsPinnedToStart.ToString()));
            }
            else
            {
                projectToModify.Element("IsPinnedToStart").Value = project.IsPinnedToStart.ToString();
            }

            string projectPath = System.IO.Path.Combine(ApplicationSettingsManager.DATA_PATH, ApplicationSettingsManager.SAVEDPROJECTS_FILENAME);
            using(IsolatedStorageFileStream stream = ApplicationSettingsManager.UserStoreForApplication.OpenFile(projectPath, FileMode.Create, FileAccess.ReadWrite))
            {
                using(StreamWriter writer = new StreamWriter(stream))
                {
                    projectXml.Save(writer);
                }
            }
        }
        public KnittingProject GetKnittingProjectByName(string projectName)
        {
            KnittingProject knittingProject = null;
            XElement projectXml = GetKnittingProjects();
            XElement project = projectXml.Elements("Project").Where(p => p.Element("Name").Value == projectName).FirstOrDefault();

            if(project != null)
            {
                knittingProject = new KnittingProject
                    {
                        ProjectName = project.Element("Name").Value,
                        ProjectDescription = project.Element("Description").Value,
                        CurrentRowCount = int.Parse(project.Element("CurrentRowCount").Value),
                        RowCounterColor = StringToColorConverter.HexString2Color(project.Element("RowCounterColorRGB").Value),
                        IsPinnedToStart = project.Element("IsPinnedToStart") == null ? false : bool.Parse(project.Element("IsPinnedToStart").Value)
                    };
            }

            return knittingProject;
        }
Esempio n. 6
0
        private void InitializePage(string projectName)
        {
            this.ProjectName = projectName;
            this.PageTitle.Text = projectName;

            this.Project = this.AppSettings.GetKnittingProjectByName(projectName);

            this.CurrentRowCount = this.Project.CurrentRowCount;
            this.RowCounterControl.Fill = this.Project.RowCounterColor;

            this.TensDigit = (this.CurrentRowCount / 10).ToString();
            this.OnesDigit = (this.CurrentRowCount % 10).ToString();

            if(this.Project.IsPinnedToStart)
            {
                // Check to see if this is actually pinned.
                //  If yes, then change icon to unpin.
                //  In no, then skip the logic below and change IsPinnedToStart to false

                ApplicationBarIconButton pinButton = (ApplicationBarIconButton)ApplicationBar.Buttons[1];
                pinButton.Text = "unpin";
                pinButton.IconUri = new Uri("Content/Images/unpin.png", UriKind.Relative);
            }
        }