Exemple #1
0
        public SmartTask(ApplicationDataContainer tasksContainer, string key)
        {
            ApplicationDataCompositeValue taskComposite = null;

            try
            {
                taskComposite = (ApplicationDataCompositeValue)tasksContainer.Values[key];
            }
            catch (Exception e)
            {
                Debug.WriteLine($"Error: {e} could not load taskComposite value from key: {key}");
                this.title = null;
                return;
            }
            if (taskComposite == null)
            {
                Debug.WriteLine($"Task storage composite value in {tasksContainer.Name} was null for: {key}");
                Debug.WriteLine($"Printing all ({tasksContainer.Values.Count}) values:");
                foreach (object val in tasksContainer.Values)
                {
                    Debug.WriteLine(val);
                }
                this.title = null;
                return;
            }
            // Create a new SmartTask object from program data stored in memory
            try
            {
                this.ID            = (uint)taskComposite["ID"];
                this.title         = (string)taskComposite["title"];
                this.taskType      = (TaskType)taskComposite["taskType"];
                this.repeatType    = (RepeatType)taskComposite["repeatType"];
                this.customRepeat  = null; //TODO: do this - taskComposite["customRepeat"];
                this.when          = DataStorageTransformations.DateTime_FromStorageString((string)taskComposite["when"]);
                this.duration      = DataStorageTransformations.TimeSpan_FromStorageString((string)taskComposite["duration"]);
                this.timeRemaining = DataStorageTransformations.TimeSpan_FromStorageString((string)taskComposite["timeRemaining"]);
                this.required      = (YN)taskComposite["required"];
                this.description   = (string)taskComposite["description"];
                this.url           = (string)taskComposite["url"];
            }
            catch (Exception e)
            {
                Debug.WriteLine($"Error when reading task from memory: {e}\nPrinting {taskComposite.Count} task values:");
                foreach (object val in taskComposite)
                {
                    Debug.WriteLine($"{val}");
                }
            }
        }
        public SmartSchedule(ApplicationDataContainer container, string scheduleID)
        {
            // Load an existing schedule from application data storage given its ID string
            taskSchedule    = new Dictionary <DateTime, LinkedList <SmartTask> >();
            startupSettings = container;
            try
            {
                // Retrieve the data from application memory (note: open existing)
                scheduleData = startupSettings.CreateContainer(scheduleID, ApplicationDataCreateDisposition.Existing);
            }
            catch (Exception e)
            {
                Debug.WriteLine($"Error {e.Message}: Schedule at {scheduleID} does not exist in local storage!");
                return;
            }
            // Fill in data from the container
            calID          = (uint)scheduleData.Values["calID"];
            numTasks       = (uint)scheduleData.Values["numTasks"];
            Title          = (string)scheduleData.Values["title"];
            color          = DataStorageTransformations.SolidColorBrush_FromStorageString((string)scheduleData.Values["color"]);
            dateCreated    = DataStorageTransformations.DateTime_FromStorageString((string)scheduleData.Values["dateCreated"]);
            tasksContainer = scheduleData.CreateContainer("tasks", ApplicationDataCreateDisposition.Existing);

            // Store and load tasks from memory!
            string taskKeys = (string)scheduleData.Values["storageKeys"];

            if (taskKeys.Length > 0)
            {
                // Only try to add tasks if a key exists
                storageKeys  = taskKeys.Split('`').ToList <string>();
                taskSchedule = new Dictionary <DateTime, LinkedList <SmartTask> >();
                foreach (string key in storageKeys.ToList())
                {
                    if (key.Length > 0)
                    {
                        SmartTask newTask = new SmartTask(tasksContainer, key);
                        if (newTask.title != null)
                        {
                            this.AddTask(newTask, false);
                        }
                    }
                }
            }
            else
            {
                storageKeys = new List <string>(); // Stored as one continuous string separated by spaces in memory
            }
        }
Exemple #3
0
        public void StoreTaskData(ApplicationDataContainer tasksContainer)
        {
            ApplicationDataCompositeValue currentTaskComposite = new ApplicationDataCompositeValue();

            currentTaskComposite["ID"]            = this.ID;
            currentTaskComposite["taskType"]      = (int)this.taskType;
            currentTaskComposite["repeatType"]    = (int)this.repeatType;
            currentTaskComposite["customRepeat"]  = "";
            currentTaskComposite["when"]          = DataStorageTransformations.DateTime_ToStorageString(this.when);
            currentTaskComposite["duration"]      = DataStorageTransformations.TimeSpan_ToStorageString(this.duration);
            currentTaskComposite["timeRemaining"] = DataStorageTransformations.TimeSpan_ToStorageString(this.timeRemaining);
            currentTaskComposite["required"]      = (int)this.required;
            currentTaskComposite["title"]         = this.title;
            currentTaskComposite["description"]   = this.description;
            currentTaskComposite["url"]           = this.url;
            currentTaskComposite["calendar"]      = this.calendar.StorageID();
            tasksContainer.Values[StorageID()]    = currentTaskComposite;
        }
        public SmartSchedule(ApplicationDataContainer container, uint id, string title, SolidColorBrush calColor)
        {
            // Create a new schedule - give it a title and store it in the filesystem!
            Title           = title;
            taskSchedule    = new Dictionary <DateTime, LinkedList <SmartTask> >();
            color           = calColor;
            dateCreated     = DateTime.Now;
            calID           = id;                  // Randomly created
            numTasks        = 0;
            storageKeys     = new List <string>(); // Stored as one continuous string separated by spaces in memory
            startupSettings = container;

            // Store the new schedule data in the application storage
            scheduleData = startupSettings.CreateContainer(StorageID(), ApplicationDataCreateDisposition.Always);

            // Add values to the app data storage
            scheduleData.Values["calID"]       = calID;
            scheduleData.Values["numTasks"]    = numTasks;
            scheduleData.Values["title"]       = Title;
            scheduleData.Values["color"]       = DataStorageTransformations.SolidColorBrush_ToStorageString(color);
            scheduleData.Values["dateCreated"] = DataStorageTransformations.DateTime_ToStorageString(dateCreated);
            scheduleData.Values["storageKeys"] = "";
            tasksContainer = scheduleData.CreateContainer("tasks", ApplicationDataCreateDisposition.Always);
        }