Exemple #1
0
 /// <summary>
 /// Called from native code from any thread. minimize any memory allocations
 /// We'll queue the objs on any random thread, then dequeue to HashSet when needed
 /// </summary>
 public void AddObjectToTrack(object obj, ObjSource objSource, string description = null)
 {
     if (obj != null)
     {
         _queue.Enqueue(new ObjWeakRefData(obj, objSource, description));
     }
 }
Exemple #2
0
        public ServiceResult Add(ObjSource objSource)
        {
            var source = Map(objSource);

            _sourceRepository.Insert(source);
            _sourceRepository.SaveChanges();
            return(ServiceResult.SuccessResult());
        }
Exemple #3
0
 public Source Map(ObjSource model)
 {
     return(new Source()
     {
         Id = model.Id,
         Name = model.Name,
         Description = model.Description,
         Position = model.Position,
     });
 }
Exemple #4
0
 public ObjWeakRefData(object obj, ObjSource objSource, string description)
 {
     _dtCreated      = DateTime.Now;
     _objSource      = objSource;
     _wr             = new WeakReference <object>(obj);
     _serialNo       = g_baseSerialNo;
     _hashCodeTarget = obj.GetHashCode();
     Interlocked.Increment(ref g_baseSerialNo);
     Descriptor = $"{obj.GetType().FullName} {description}".Trim();
 }
Exemple #5
0
        public ServiceResult Edit(ObjSource objSource)
        {
            var source = _sourceRepository.Get(objSource.Id);

            if (source.Name == objSource.Name)
            {
                return(ServiceResult.ErrorResult("Источник с таким имеенм уже существует"));
            }
            source.Name        = objSource.Name;
            source.Description = objSource.Description;
            source.Position    = objSource.Position;
            _sourceRepository.Update(source);
            _sourceRepository.SaveChanges();

            return(ServiceResult.SuccessResult());
        }
 public IActionResult EditSource(ObjSource objSource)
 {
     if (objSource.Id == -1)
     {
         objSource.Id = 0;
         var result = _sourceService.Add(objSource);
         if (result.Success)
         {
             return(RedirectToActionOk("Sources", "Источник сохранен"));
         }
         return(RedirectToActionError("Sources", result.ErrorMessage));
     }
     else
     {
         var result = _sourceService.Edit(objSource);
         if (result.Success)
         {
             return(RedirectToActionOk("Sources", "Источник сохранен"));
         }
         return(RedirectToActionError("Sources", result.ErrorMessage));
     }
 }