Exemple #1
0
        public static string UUIDAsName(string fileName)
        {
            AssertUtils.AssertNotNull(fileName);

            int dotIdx = fileName.LastIndexOf('.');

            AssertUtils.AssertTrue(dotIdx >= 0, "fileName is invalid.");

            return($"{UUIDUtils.randomUUID()}{fileName.Substring(dotIdx)}");
        }
Exemple #2
0
        public static string UUIDAppendToName(string fileName)
        {
            AssertUtils.AssertNotNull(fileName);

            int dotIdx = fileName.LastIndexOf('.');

            AssertUtils.AssertTrue(dotIdx >= 0, "fileName is invalid.");

            string name = StringUtils.TrimToEmpty(fileName.Substring(0, dotIdx));

            if (name.Length == 0)
            {
                return($"{UUIDUtils.randomUUID()}{fileName.Substring(dotIdx)}");
            }
            return($"{name}-{UUIDUtils.randomUUID()}{fileName.Substring(dotIdx)}");
        }
        public static void SetProperties(object to, object from, Func <string, bool> forProperties)
        {
            AssertUtils.AssertNotNull(to);
            AssertUtils.AssertNotNull(from);
            AssertUtils.AssertNotNull(forProperties);

            PropertyInfo[] fromProperties = from.GetType().GetProperties();
            foreach (PropertyInfo fromProp in fromProperties)
            {
                if (!forProperties(fromProp.Name))
                {
                    continue;
                }
                AssertUtils.AssertTrue(fromProp.CanRead);

                PropertyInfo toProp = to.GetType().GetProperty(fromProp.Name);
                AssertUtils.AssertNotNull(toProp);
                AssertUtils.AssertTrue(toProp.CanWrite);

                toProp.SetValue(to, fromProp.GetValue(from));
            }
        }
 public static bool IsPastTime(long timeMillis, int leewayMs)
 {
     AssertUtils.AssertTrue(leewayMs >= 0);
     return(CurrentTimeMillis + leewayMs >= timeMillis);
 }
 public static bool IsFutureTime(long timeMillis, int leewayMs)
 {
     AssertUtils.AssertTrue(leewayMs >= 0);
     return(CurrentTimeMillis - leewayMs < timeMillis);
 }