Ejemplo n.º 1
0
        public (string statement, CommandParameterValues parameterValues) CreateDelete(IId document)
        {
            var mapping = mappings.Get(document.GetType());
            var id      = (string)mapping.IdColumn.ReaderWriter.Read(document);

            return(CreateDeleteById(mapping, id));
        }
Ejemplo n.º 2
0
        public void SelectNodeById(IId iId)
        {
            if (iId == null)
            {
                return;
            }
            int nodeType = 0;
            var r        = FindNode(iId.Id, iId.GetType());

            if (r != null)
            {
                //TreeView1.SelectedItem = r;
                r.IsSelected = true;
                ExpandParent(r);
            }
        }
Ejemplo n.º 3
0
        public (DocumentMap, string, CommandParameterValues) CreateUpdate(IId document, string tableHint)
        {
            var mapping = mappings.Get(document.GetType());

            var updates   = string.Join(", ", mapping.IndexedColumns.Select(c => "[" + c.ColumnName + "] = @" + c.ColumnName).Union(new[] { $"[JSON] = @{JsonVariableName}" }));
            var statement = $"UPDATE dbo.[{mapping.TableName}] {tableHint ?? ""} SET {updates} WHERE [{mapping.IdColumn.ColumnName}] = @{IdVariableName}";

            var parameters = GetDocumentParameters(
                m => throw new Exception("Cannot update a document if it does not have an ID"),
                document,
                mapping,
                null
                );

            statement = AppendRelatedDocumentStatementsForUpdate(statement, parameters, mapping, document);

            return(mapping, statement, parameters);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Inserts object into database if it doesn't already exist
        /// </summary>
        /// <returns>True if the object was inserted, otherwise false</returns>
        public static async Task <bool> Upload(
            IId obj,
            IDataApiClient dataApiClient,
            bool overwriteIfExists = false)
        {
            if (overwriteIfExists)
            {
                await dataApiClient.ReplaceAsync(obj, obj.Id);

                return(true);
            }
            var exists = await dataApiClient.ExistsAsync(obj.GetType().Name, obj.Id);

            if (!exists)
            {
                await dataApiClient.InsertAsync(obj, obj.Id);
            }
            return(!exists);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 获取可视信息
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static string GetText(this IId entity, Func <IId, string> textFactory = null)
        {
            if (textFactory != null)
            {
                return(textFactory(entity));
            }

            if (entity is IText)
            {
                return(((IText)entity).Text);
            }

            var pi = entity.GetType().GetPropertyAny(typeof(string), "DisplayName", "Name", "Description");

            if (pi != null)
            {
                return(pi.GetValue(entity) as string);
            }


            return(entity.ToString());
        }
Ejemplo n.º 6
0
 public static ShortId FromIId(string shortId, IId iid)
 {
     return(new ShortId(shortId, iid.GetType().Name, iid.Id));
 }
Ejemplo n.º 7
0
        public bool Equals(IId other)
        {
            if (other == null)
            {
                return(false);
            }

            if (object.ReferenceEquals(this, other))
            {
                return(true);
            }

            if (!(other is DMTId))
            {
                logger.Error("Comparing incompatible IId implementations. {0} and {1}", typeof(DMTId), other.GetType());
                return(false);
            }

            DMTId other2 = (DMTId)other;

            return(this.value.Equals(other2.value));
        }
Ejemplo n.º 8
0
 public static DataReference FromIId(IId obj)
 {
     return(new DataReference(obj.GetType().Name, obj.Id));
 }