Exemple #1
0
        public static void Add(string funcId, object entity, SerializedForm <TResult> result, CacheParams cacheParams, params object[] parameters)
        {
            rwLock.EnterWriteLock();
            try
            {
                if (!MemoizationTable.ContainsKey(funcId))
                {
                    MemoizationTable.Add(funcId, new List <MemoizationEntry <TResult> >());
                }

                MemoizationTable[funcId].Add(new MemoizationEntry <TResult>
                {
                    FuncId      = funcId,
                    Instance    = entity,
                    Result      = result,
                    Params      = parameters,
                    CacheParams = cacheParams,
                    TimeAdded   = DateTime.Now
                });
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
        }
    /// <summary>
    /// Serialize the contents of this level progress into a string.
    /// </summary>
    public string Serialize()
    {
        var serializedForm = new SerializedForm();

        serializedForm.currentLevelId = currentLevelId;
        serializedForm.lastLevelId    = lastLevelId;
        foreach (var entry in levelStatus)
        {
            serializedForm.levelStatus.Add(new SerializedForm.Item(entry.Key, (int)entry.Value));
        }
        foreach (var entry in groupStatus)
        {
            serializedForm.groupStatus.Add(new SerializedForm.Item(entry.Key, (int)entry.Value));
        }

        XmlSerializer     serializer = new XmlSerializer(typeof(SerializedForm));
        XmlWriterSettings settings   = new XmlWriterSettings();

        settings.Encoding           = new UnicodeEncoding(false, false); // no BOM in a .NET string
        settings.Indent             = false;
        settings.OmitXmlDeclaration = false;

        using (StringWriter textWriter = new StringWriter()) {
            using (XmlWriter xmlWriter = XmlWriter.Create(textWriter, settings)) {
                serializer.Serialize(xmlWriter, serializedForm);
            }
            return(textWriter.ToString());
        }
    }
Exemple #3
0
		public TaskList(SerializedForm serializedForm) {
			if (serializedForm == null)
				return;
			this.Unserialize(serializedForm);
			this.generateProjects();
			this.currentProjectFinishedTime = this.calcCurrentProjectFinishedTime();
		}
        public void SerializeForm(Form form)
        {
            foreach (Culture culture in this.requestHandler.Storage.GetRepository <ICultureRepository>().NotNeutral().ToList())
            {
                SerializedForm serializedForm = this.requestHandler.Storage.GetRepository <ISerializedFormRepository>().WithKey(culture.Id, form.Id);

                if (serializedForm == null)
                {
                    this.requestHandler.Storage.GetRepository <ISerializedFormRepository>().Create(this.SerializeForm(culture, form));
                }

                else
                {
                    SerializedForm temp = this.SerializeForm(culture, form);

                    serializedForm.Code = temp.Code;
                    serializedForm.Name = temp.Name;
                    serializedForm.SubmitButtonTitle = temp.SubmitButtonTitle;
                    serializedForm.SerializedFields  = temp.SerializedFields;
                    this.requestHandler.Storage.GetRepository <ISerializedFormRepository>().Edit(serializedForm);
                }
            }

            this.requestHandler.Storage.Save();
        }
Exemple #5
0
 public void Unserialize(SerializedForm serializedForm)
 {
     foreach (Task.SerializedForm serializedTask in serializedForm.Tasks)
     {
         this.tasks.Add(new Task(serializedTask));
     }
 }
Exemple #6
0
		public Settings(SerializedForm serializedForm) {
			if (serializedForm == null) {
				this.initDefault();
				return;
			}
			this.Unserialize(serializedForm);
		}
Exemple #7
0
		public SerializedForm Serialize() {
			SerializedForm serializedForm = new SerializedForm() {
				Alarm = this.alarm,
				OnTop = this.onTop,
				Icon = this.icon
			};
			return serializedForm;
		}
Exemple #8
0
			public WorkTime(SerializedForm serializedForm) {
				this.StartedAt = DateTime.Parse(serializedForm.StartedAt);
				if (serializedForm.StoppedAt == null)
					this.StoppedAt = null;
				else
					this.StoppedAt = DateTime.Parse(serializedForm.StoppedAt);
					
			}
Exemple #9
0
 public Settings(SerializedForm serializedForm)
 {
     if (serializedForm == null)
     {
         this.initDefault();
         return;
     }
     this.Unserialize(serializedForm);
 }
Exemple #10
0
 public TaskList(SerializedForm serializedForm)
 {
     if (serializedForm == null)
     {
         return;
     }
     this.Unserialize(serializedForm);
     this.generateProjects();
     this.currentProjectFinishedTime = this.calcCurrentProjectFinishedTime();
 }
Exemple #11
0
        public SerializedForm Serialize()
        {
            SerializedForm serializedForm = new SerializedForm()
            {
                Alarm = this.alarm,
                OnTop = this.onTop,
                Icon  = this.icon
            };

            return(serializedForm);
        }
Exemple #12
0
 public WorkTime(SerializedForm serializedForm)
 {
     this.StartedAt = DateTime.Parse(serializedForm.StartedAt);
     if (serializedForm.StoppedAt == null)
     {
         this.StoppedAt = null;
     }
     else
     {
         this.StoppedAt = DateTime.Parse(serializedForm.StoppedAt);
     }
 }
Exemple #13
0
        public SerializedForm Serialize()
        {
            SerializedForm             serializedForm = new SerializedForm();
            List <Task.SerializedForm> tasks          = new List <Task.SerializedForm>();

            foreach (Task task in this.tasks)
            {
                tasks.Add(task.Serialize());
            }
            serializedForm.Tasks = tasks.ToArray();
            return(serializedForm);
        }
Exemple #14
0
        private IViewComponentResult GetViewComponentResult(string code)
        {
            SerializedForm serializedForm = this.Storage.GetRepository <ISerializedFormRepository>().WithCultureIdAndCode(
                CultureManager.GetCurrentCulture(this.Storage).Id, code
                );

            if (serializedForm == null)
            {
                return(this.Content($"There is no form with code “{code}” defined."));
            }

            return(this.View(new FormViewModelFactory(this).Create(serializedForm)));
        }
        private IViewComponentResult GetViewComponentResult(string code, string partialViewName = null, string additionalCssClass = null)
        {
            SerializedForm serializedForm = this.Storage.GetRepository <ISerializedFormRepository>().WithCultureIdAndCode(
                this.GetService <ICultureManager>().GetCurrentCulture().Id, code
                );

            if (serializedForm == null)
            {
                return(this.Content($"There is no form with code “{code}” defined."));
            }

            return(this.View(new FormViewModelFactory(this).Create(serializedForm, partialViewName, additionalCssClass)));
        }
Exemple #16
0
 public void Unserialize(SerializedForm serializedForm)
 {
     this.Project      = serializedForm.Project;
     this.Description  = serializedForm.Description;
     this.state        = States.STOPPED;
     this.SoundedAlarm = serializedForm.SoundedAlarm;
     string[] parts = serializedForm.ExpectedTime.Split(':');
     this.expectedTime = new TimeSpan(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]));
     foreach (WorkTime.SerializedForm serializedWork in serializedForm.WorkTimes)
     {
         this.workTimes.Add(new WorkTime(serializedWork));
     }
     this.updateFinishedDuration();
 }
        public async Task <IViewComponentResult> InvokeAsync(string code, string partialViewName = null, string additionalCssClass = null)
        {
            SerializedForm serializedForm = this.Storage.GetRepository <ISerializedFormRepository>().WithCultureIdAndCode(
                this.GetService <ICultureManager>().GetCurrentCulture().Id, code
                );

            if (serializedForm == null)
            {
                return(this.Content($"There is no form with code “{code}” defined."));
            }

            return(this.GetService <ICache>().GetFormViewComponentResultWithDefaultValue(
                       code, additionalCssClass, () => this.GetViewComponentResult(code, partialViewName, additionalCssClass)
                       ));
        }
        public FormViewModel Create(SerializedForm serializedForm)
        {
            IEnumerable <SerializedField> serializedFields = new SerializedField[] { };

            if (!string.IsNullOrEmpty(serializedForm.SerializedFields))
            {
                serializedFields = JsonConvert.DeserializeObject <IEnumerable <SerializedField> >(serializedForm.SerializedFields);
            }

            return(new FormViewModel()
            {
                Id = serializedForm.FormId,
                Name = serializedForm.Name,
                Fields = serializedFields.Select(
                    sf => new FieldViewModelFactory(this.RequestHandler).Create(sf)
                    ).ToList()
            });
        }
        public async Task <IViewComponentResult> InvokeAsync(string code)
        {
            SerializedForm cachedForm = this.Storage.GetRepository <ISerializedFormRepository>().WithCultureIdAndCode(
                CultureManager.GetCurrentCulture(this.Storage).Id, code
                );

            if (cachedForm == null)
            {
                Form form = this.Storage.GetRepository <IFormRepository>().WithCode(code);

                if (form == null)
                {
                    return(null);
                }

                return(this.View(new FormViewModelFactory(this).Create(form)));
            }

            return(this.View(new FormViewModelFactory(this).Create(cachedForm)));
        }
        private IViewComponentResult GetViewComponentResult(string code)
        {
            SerializedForm serializedForm = this.Storage.GetRepository <ISerializedFormRepository>().WithCultureIdAndCode(
                CultureManager.GetCurrentCulture(this.Storage).Id, code
                );

            if (serializedForm == null)
            {
                Form form = this.Storage.GetRepository <IFormRepository>().WithCode(code);

                if (form == null)
                {
                    return(null);
                }

                return(this.View(new FormViewModelFactory(this).Create(form)));
            }

            return(this.View(new FormViewModelFactory(this).Create(serializedForm)));
        }
Exemple #21
0
        public FormViewModel Create(SerializedForm serializedForm, string partialViewName, string additionalCssClass)
        {
            IEnumerable <SerializedField> serializedFields = new SerializedField[] { };

            if (!string.IsNullOrEmpty(serializedForm.SerializedFields))
            {
                serializedFields = JsonConvert.DeserializeObject <IEnumerable <SerializedField> >(serializedForm.SerializedFields);
            }

            return(new FormViewModel()
            {
                Id = serializedForm.FormId,
                Name = serializedForm.Name,
                SubmitButtonTitle = serializedForm.SubmitButtonTitle,
                Fields = serializedFields.Select(
                    sf => new FieldViewModelFactory(this.RequestHandler).Create(sf)
                    ).ToList(),
                PartialViewName = partialViewName ?? "_Form",
                AdditionalCssClass = additionalCssClass
            });
        }
Exemple #22
0
        public SerializedForm Serialize()
        {
            SerializedForm serializedForm = new SerializedForm();

            serializedForm.Project      = this.Project;
            serializedForm.Description  = this.Description;
            serializedForm.ExpectedTime = this.expectedTime.ToString("hh':'mm':'ss");
            serializedForm.SoundedAlarm = this.SoundedAlarm;
            List <WorkTime.SerializedForm> workTimes = new List <WorkTime.SerializedForm>();

            foreach (WorkTime workTime in this.workTimes)
            {
                // If task is in progress, don't save it yet
                if (!workTime.StoppedAt.HasValue)
                {
                    continue;
                }
                workTimes.Add(workTime.Serialize());
            }
            serializedForm.WorkTimes = workTimes.ToArray();
            return(serializedForm);
        }
        private SerializedForm SerializeForm(Culture culture, Form form)
        {
            List <SerializedField> serializedFields = new List <SerializedField>();

            foreach (Field field in this.requestHandler.Storage.GetRepository <IFieldRepository>().FilteredByFormId(form.Id).ToList())
            {
                serializedFields.Add(this.SerializeField(culture, field));
            }

            SerializedForm serializedForm = new SerializedForm();

            serializedForm.FormId    = form.Id;
            serializedForm.CultureId = culture.Id;
            serializedForm.Code      = form.Code;
            serializedForm.Name      = this.requestHandler.GetLocalizationValue(form.NameId, culture.Id);

            if (serializedFields.Count != 0)
            {
                serializedForm.SerializedFields = this.SerializeObject(serializedFields);
            }

            return(serializedForm);
        }
Exemple #24
0
 public override void Add <TResult>(SerializedForm <TResult> result, string f, object entity, CacheParams cacheParams, params object[] parameters)
 {
     InMemoryCacheSet <TResult> .Add(f, entity, result, cacheParams, parameters);
 }
Exemple #25
0
		public Task(SerializedForm serializedForm) {
			this.Unserialize(serializedForm);
		}
Exemple #26
0
 public abstract void Add <TResult>(SerializedForm <TResult> result, string f, object entity, CacheParams cacheParams, params object[] parameters);
Exemple #27
0
		public void Unserialize(SerializedForm serializedForm) {
			foreach (Task.SerializedForm serializedTask in serializedForm.Tasks) {
				this.tasks.Add(new Task(serializedTask));
			}
		}
Exemple #28
0
		public SerializedForm Serialize() {
			SerializedForm serializedForm = new SerializedForm();
			serializedForm.Project = this.Project;
			serializedForm.Description = this.Description;
			serializedForm.ExpectedTime = this.expectedTime.ToString("hh':'mm':'ss");
			serializedForm.SoundedAlarm = this.SoundedAlarm;
			List<WorkTime.SerializedForm> workTimes = new List<WorkTime.SerializedForm>();
			foreach (WorkTime workTime in this.workTimes) {
                // If task is in progress, don't save it yet
                if (!workTime.StoppedAt.HasValue)
                    continue;
				workTimes.Add(workTime.Serialize());
			}
			serializedForm.WorkTimes = workTimes.ToArray();
			return serializedForm;
		}
Exemple #29
0
		public void Unserialize(SerializedForm serializedForm) {
			this.alarm = serializedForm.Alarm;
			this.onTop = serializedForm.OnTop;
			this.icon = serializedForm.Icon;
		}
Exemple #30
0
		public SerializedForm Serialize() {
			SerializedForm serializedForm = new SerializedForm();
			List<Task.SerializedForm> tasks = new List<Task.SerializedForm>();
			foreach (Task task in this.tasks) {
				tasks.Add(task.Serialize());
			}
			serializedForm.Tasks = tasks.ToArray();
			return serializedForm;
		}
Exemple #31
0
 public Task(SerializedForm serializedForm)
 {
     this.Unserialize(serializedForm);
 }
Exemple #32
0
 public void Unserialize(SerializedForm serializedForm)
 {
     this.alarm = serializedForm.Alarm;
     this.onTop = serializedForm.OnTop;
     this.icon  = serializedForm.Icon;
 }
Exemple #33
0
		public void Unserialize(SerializedForm serializedForm) {
			this.Project = serializedForm.Project;
			this.Description = serializedForm.Description;
			this.state = States.STOPPED;
			this.SoundedAlarm = serializedForm.SoundedAlarm;
			string[] parts = serializedForm.ExpectedTime.Split(':');
			this.expectedTime = new TimeSpan(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]));
			foreach (WorkTime.SerializedForm serializedWork in serializedForm.WorkTimes) {
				this.workTimes.Add(new WorkTime(serializedWork));
			}
			this.updateFinishedDuration();
		}