Ejemplo n.º 1
0
        /// <summary>
        /// Deletes the specified data.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="data">The data.</param>
        /// <returns>a task</returns>
        public async Task Delete <T>(T data) where T : BaseModel
        {
            try
            {
                // Change local
                await DataHandler.Delete(data);

                AssassinCache.Remove(data);

                // send data to server
                if (QuantWebClient != null && observingTypes.Any(p => p.TypeDescritor == typeof(T).AssemblyQualifiedName))
                {
                    await CheckConnection();

                    if (IsConnected)
                    {
                        await QuantWebClient?.Delete(data);
                    }
                }

                // delete image
                CheckForImage(data, true);
            }
            catch (Exception ex)
            {
                OnNotify?.Invoke(this, ex.ToText("Error updating data."), LogLevel.Error);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds, updates or deletes the specific data from the server
        /// </summary>
        /// <param name="data">The data.</param>
        /// <returns>true if successful</returns>
        private bool AddUpdateDelete(BaseModel data, BaseModel currentData)
        {
            bool okay = true;

            try
            {
                data.Synced = true;
                var newObject = data.CastAs(Type.GetType(data.TypeDiscriptor));
                if (newObject != null && currentData == null)
                {
                    DataHandler.Insert(newObject);
                    AssassinCache.AddOrUpdate(data);
                }
                else if (newObject != null && currentData != null && currentData.ModifiedDT < newObject.ModifiedDT)
                {
                    if ((newObject as BaseModel).Archived)
                    {
                        DataHandler.Delete(newObject);
                        AssassinCache.Remove(data);
                    }
                    else
                    {
                        DataHandler.Update(newObject);
                        AssassinCache.AddOrUpdate(data);
                    }
                }
            }
            catch (Exception ex)
            {
                OnNotify?.Invoke(this, ex.ToText("Error updating data received from server."), LogLevel.Error);
                okay = false;
            }

            return(okay);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates the specified data.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="data">The data.</param>
        /// <param name="updateImage">if set to <c>true</c> the image entity will also be updated.</param>
        /// <returns>a task</returns>
        public async Task Update <T>(T data, bool updateImage = false) where T : BaseModel
        {
            try
            {
                data.ModifiedDT = DateTime.UtcNow;
                data.Synced     = false;

                // change local data
                await DataHandler.Update(data);

                AssassinCache.AddOrUpdate(data);

                // send to server if observed
                if (QuantWebClient != null && observingTypes.Any(p => p.TypeDescritor == typeof(T).AssemblyQualifiedName))
                {
                    await CheckConnection();

                    if (IsConnected)
                    {
                        await QuantWebClient?.Update(data);
                    }
                }

                // update image
                if (updateImage)
                {
                    CheckForImage(data);
                }
            }
            catch (Exception ex)
            {
                OnNotify?.Invoke(this, ex.ToText("Error updating data."), LogLevel.Error);
            }
        }