Beispiel #1
0
        public static IEvent NewEvent(this IEntitySession session, EventData data)
        {
            var ev = session.NewEntity <IEvent>();

            ev.Id          = data.Id;
            ev.EventType   = data.EventType;
            ev.StartedOn   = data.StartedOn ?? session.Context.App.TimeService.UtcNow;
            ev.Duration    = data.Duration;
            ev.Location    = data.Location;
            ev.UserId      = data.UserId;
            ev.SessionId   = data.SessionId;
            ev.TenantId    = data.TenantId;
            ev.Value       = data.Value;
            ev.StringValue = data.StringValue ?? data.Value + string.Empty;
            if (data.Parameters != null && data.Parameters.Count > 0)
            {
                foreach (var de in data.Parameters)
                {
                    var prm = session.NewEntity <IEventParameter>();
                    prm.Event = ev;
                    prm.Name  = de.Key;
                    prm.Value = de.Value;
                }
            }
            return(ev);
        } //method
Beispiel #2
0
        public static IPublisher NewPublisher(this IEntitySession session, string name)
        {
            var pub = session.NewEntity <IPublisher>();

            pub.Name = name;
            return(pub);
        }
 public static IEncryptedData NewEncryptedData(IEntitySession session, byte[] data, string channelName = null)
 {
     var encrService = GetService(session);
       var ent = session.NewEntity<IEncryptedData>();
       ent.Data = encrService.Encrypt(data, ent.Id.ToString(), channelName);
       return ent;
 }
        public static IUser NewUser(this IEntitySession session, string name)
        {
            var user = session.NewEntity <IUser>();

            user.Name = name;
            return(user);
        }
        // Use it to import from resource - look at ImportDefaultSecretQuestions
        public static int ImportSecretQuestions(IEntitySession session, Stream stream)
        {
            var reader = new StreamReader(stream);
            var text   = reader.ReadToEnd(); // File.ReadAllLines(filePath);
            var lines  = text.Split(new [] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            // Postgres blows up here, trying with LINQ
            //var oldList = session.GetEntities<ISecretQuestion>();
            var oldList = session.EntitySet <ISecretQuestion>().ToList();
            var count   = 0;

            foreach (var line in lines)
            {
                if (string.IsNullOrWhiteSpace(line) || line.StartsWith("//"))
                {
                    continue;
                }
                //check if there's existing
                var trimLine = line.Trim();
                var oldLine  = oldList.FirstOrDefault(l => l.Question == trimLine);
                if (oldLine != null)
                {
                    continue;
                }
                var q = session.NewEntity <ISecretQuestion>();
                q.Question = trimLine;
                q.Number   = count++;
                q.Flags    = SecretQuestionFlags.None;
            }
            return(count);
        }
Beispiel #6
0
        private IMsSqlDataTypesEntity CreateSpecialDataTypesEntity(IEntitySession session, string varCharProp)
        {
            var ent = session.NewEntity <IMsSqlDataTypesEntity>();

            ent.Id = Guid.NewGuid();
            // Test bug fix
            ent.CharNProp          = "12345678";
            ent.NCharNProp         = "234567";
            ent.VarCharProp        = varCharProp;
            ent.TimeProp           = DateTime.Now.TimeOfDay;
            ent.DateProp           = DateTime.Now.Date;
            ent.DateTimeProp       = DateTime.Now;
            ent.SmallDateTimeProp  = DateTime.Now;
            ent.DateTimeOffsetProp = new DateTimeOffset(2015, 3, 14, 9, 26, 53, TimeSpan.FromHours(-7)); //PI day/time in Seattle DateTimeOffset.Now;
            // ent.TimeStampProp is set automatically by database

            /*
             *    // Have no idea how to properly assign these properties; assigning random data does not work, so made columns nullable and skip assignment
             *    ent.GeographyProp = new byte[] { 1, 2, 3, 4 };
             *    ent.GeometryProp = new byte[] { 5, 6, 7, 8 };
             *    ent.HierarchyIdProp = new byte[] { 11, 12, 13, 14 };
             */
            ent.ImageProp      = new byte[] { 21, 22, 23, 24 };
            ent.NTextProp      = "abcd";
            ent.TextProp       = "defg";
            ent.XmlProp        = "<foo/>";
            ent.SmallMoneyProp = 1.23m;
            ent.SqlVariantProp = "xx"; // 1234;

            return(ent);
        }
Beispiel #7
0
        public static IDbUpgradeBatch NewDbModelChangeBatch(this IEntitySession session,
                                                            string fromVersion, string toVersion, DateTime startedOn, DateTime?completedOn,
                                                            DbUpgradeMethod method, string machineName, string userName,
                                                            Exception exception = null)
        {
            var ent = session.NewEntity <IDbUpgradeBatch>();

            ent.FromVersion = fromVersion;
            ent.ToVersion   = toVersion;
            ent.StartedOn   = startedOn;
            ent.CompletedOn = completedOn;
            ent.Method      = method;
            ent.MachineName = machineName ?? Environment.MachineName;
            ent.UserName    = userName ?? Environment.UserName;
            if (exception == null)
            {
                ent.Success = true;
            }
            else
            {
                ent.Success = false;
                ent.Errors  = exception.ToLogString();
            }
            return(ent);
        }
Beispiel #8
0
        public static IBookOrder NewOrder(this IEntitySession session, IUser user)
        {
            var order = session.NewEntity <IBookOrder>();

            order.User   = user;
            order.Status = OrderStatus.Open;
            return(order);
        }
Beispiel #9
0
        public static ITreeNode NewNode(this IEntitySession session, string name, ITreeNode parent = null)
        {
            var node = session.NewEntity <ITreeNode>();

            node.Name   = name;
            node.Parent = parent;
            return(node);
        }
Beispiel #10
0
        public static IAuthor NewAuthor(this IEntitySession session, string firstName, string lastName)
        {
            var author = session.NewEntity <IAuthor>();

            author.FirstName = firstName;
            author.LastName  = lastName;
            return(author);
        }
Beispiel #11
0
        public static IEncryptedData NewEncryptedData(this IEntitySession session, byte[] data, string channelName = null)
        {
            var encrService = GetService(session);
            var ent         = session.NewEntity <IEncryptedData>();

            ent.Data = encrService.Encrypt(data, ent.Id.ToString(), channelName);
            return(ent);
        }
Beispiel #12
0
        public static IDepartment NewDepartment(this IEntitySession session, string name, IEmployee manager)
        {
            var dep = session.NewEntity <IDepartment>();

            dep.Name    = name;
            dep.Manager = manager;
            return(dep);
        }
Beispiel #13
0
        public static IAuthor NewAuthor(this IEntitySession session, string firstName, string lastName, string bio = null)
        {
            var auth = session.NewEntity <IAuthor>();

            auth.FirstName = firstName;
            auth.LastName  = lastName;
            auth.Bio       = bio;// ?? string.Empty; //experiment/behavior check
            return(auth);
        }
Beispiel #14
0
        public static ICoupon NewCoupon(this IEntitySession session, string promoCode, double discountPerc, DateTime expires)
        {
            var coupon = session.NewEntity <ICoupon>();

            coupon.PromoCode    = promoCode;
            coupon.DiscountPerc = discountPerc;
            coupon.ExpiresOn    = expires;
            return(coupon);
        }
Beispiel #15
0
        public static IDriver NewDriver(this IEntitySession session, string licenseNumber, string firstName, string lastName)
        {
            var driver = session.NewEntity <IDriver>();

            driver.LicenseNumber = licenseNumber;
            driver.FirstName     = firstName;
            driver.LastName      = lastName;
            return(driver);
        }
Beispiel #16
0
        public static IImage NewImage(this IEntitySession session, string name, ImageType type, string mediaType, byte[] data)
        {
            var img = session.NewEntity <IImage>();

            img.Name      = name;
            img.Type      = type;
            img.MediaType = mediaType;
            img.Data      = data;
            return(img);
        }
Beispiel #17
0
        public static IUser NewUser(this IEntitySession session, string userName, UserType type, string displayName = null)
        {
            var user = session.NewEntity <IUser>();

            user.UserName    = userName;
            user.DisplayName = string.IsNullOrWhiteSpace(displayName) ? userName : displayName;
            user.Type        = type;
            user.IsActive    = true;
            return(user);
        }
Beispiel #18
0
        public static IEmployee NewEmployee(this IEntitySession session, string name, string jobTitle, IEmployee reportsTo = null, IDepartment department = null)
        {
            var emp = session.NewEntity <IEmployee>();

            emp.Name       = name;
            emp.JobTitle   = jobTitle;
            emp.ReportsTo  = reportsTo;
            emp.Department = department;
            return(emp);
        }
Beispiel #19
0
        public static IVehicle NewVehicle(this IEntitySession session, string model, int year, IDriver owner, IDriver driver = null)
        {
            var veh = session.NewEntity <IVehicle>();

            veh.Model  = model;
            veh.Year   = year;
            veh.Owner  = owner;
            veh.Driver = driver;
            return(veh);
        }
Beispiel #20
0
        public static IBookReview NewReview(this IEntitySession session, IUser user, IBook book, int rating, string caption, string text)
        {
            var review = session.NewEntity <IBookReview>();

            review.User    = user;
            review.Book    = book;
            review.Rating  = rating;
            review.Caption = caption;
            review.Review  = text;
            return(review);
        }
Beispiel #21
0
        // Providing Id explicitly allows to sync ID values with external entities - like loginId, userId, etc
        public static IParty NewParty(this IEntitySession session, PartyKind kind, string name, Guid?id = null)
        {
            var party = session.NewEntity <IParty>();

            party.Kind = kind;
            party.Name = name;
            if (id != null)
            {
                party.Id = id.Value;
            }
            return(party);
        }
Beispiel #22
0
 void IObjectSaveHandler.SaveObjects(IEntitySession session, IList<object> items)
 {
     foreach (LoginLogEntry e in items) {
     var entry = session.NewEntity<ILoginLog>();
     entry.CreatedOn = e.CreatedOn;
     entry.UserName = e.UserName;
     entry.LoginId = e.LoginId;
     entry.EventType = e.EventType;
     entry.Notes = e.Notes;
     entry.WebCallId = e.WebCallId;
       }
 }
Beispiel #23
0
        public static ITextTemplate NewTextTemplate(this IEntitySession session, string name, string template, TemplateFormat format,
                                                    string culture = "EN-US", string engine = "Simple", Guid?ownerId = null)
        {
            var templ = session.NewEntity <ITextTemplate>();

            templ.Name     = name;
            templ.Template = template;
            templ.Format   = format;
            templ.Culture  = culture;
            templ.Engine   = engine;
            templ.OwnerId  = ownerId;
            return(templ);
        }
        private IJob NewJob(IEntitySession session, string name, JobStartInfo startInfo, RetryPolicy retryPolicy)
        {
            var job = session.NewEntity <IJob>();

            job.Name                 = name;
            job.ThreadType           = startInfo.ThreadType;
            job.DeclaringType        = startInfo.DeclaringType.Namespace + "." + startInfo.DeclaringType.Name;
            job.MethodName           = startInfo.Method.Name;
            job.MethodParameterCount = startInfo.Arguments.Length;
            job.Arguments            = SerializeArguments(startInfo.Arguments);
            job.RetryIntervals       = retryPolicy.AsString;
            return(job);
        }
Beispiel #25
0
 void IObjectSaveHandler.SaveObjects(IEntitySession session, IList <object> items)
 {
     foreach (LoginLogEntry e in items)
     {
         var entry = session.NewEntity <ILoginLog>();
         entry.CreatedOn = e.CreatedOn;
         entry.UserName  = e.UserName;
         entry.LoginId   = e.LoginId;
         entry.EventType = e.EventType;
         entry.Notes     = e.Notes;
         entry.WebCallId = e.WebCallId;
     }
 }
 public void AddBookToOrder(IEntitySession session, Guid orderId, Guid bookId, int quantity)
 {
     var order = session.GetEntity<IBookOrder>(orderId, LockOptions.ForUpdate);
       var book = session.GetEntity<IBook>(bookId);
       var orderLine = session.NewEntity<IBookOrderLine>();
       orderLine.Order = order;
       orderLine.Book = book;
       orderLine.Quantity = quantity;
       orderLine.Price = book.Price;
       order.Lines.Add(orderLine);
       order.Total = order.Lines.Sum(ol => ol.Price * ol.Quantity);
       session.SaveChanges();
 }
Beispiel #27
0
        // called by background process to save the info in provided session
        public void SaveObjects(IEntitySession session, IList<object> items)
        {
            foreach (WebCallContext webCtx in items) {
            var ent = session.NewEntity<IWebCallLog>();
            ent.Id = webCtx.Id;
            ent.WebCallId = webCtx.Id;
            ent.CreatedOn = webCtx.CreatedOn;
            ent.Duration = (int)(webCtx.TickCountEnd - webCtx.TickCountStart);
            ent.Url = webCtx.RequestUrl;
            ent.UrlTemplate = webCtx.RequestUrlTemplate;
            ent.UrlReferrer = webCtx.Referrer;
            ent.IPAddress = webCtx.IPAddress;
            var ctx = webCtx.OperationContext;
            if (ctx != null) {
              if (ctx.User != null)
            ent.UserName = ctx.User.UserName;
              if (ctx.LogLevel == LogLevel.Details)
            ent.LocalLog = ctx.GetLogContents();
              if (ctx.UserSession != null)
            ent.UserSessionId = ctx.UserSession.SessionId;
            }
            ent.ControllerName = webCtx.ControllerName;
            ent.MethodName = webCtx.MethodName;
            if (webCtx.Exception != null) {
              ent.Error = webCtx.Exception.Message;
              ent.ErrorDetails = webCtx.Exception.ToLogString();
            }
            ent.ErrorLogId = webCtx.ErrorLogId;
            ent.HttpMethod = webCtx.HttpMethod + string.Empty;
            ent.HttpStatus = webCtx.HttpStatus;
            ent.RequestSize = webCtx.RequestSize;
            ent.RequestHeaders = webCtx.RequestHeaders;
            ent.Flags = webCtx.Flags;
            if (webCtx.CustomTags.Count > 0)
              ent.CustomTags = string.Join(",", webCtx.CustomTags);
            if (webCtx.Flags.IsSet(WebCallFlags.HideRequestBody))
              ent.RequestBody = "(Omitted)";
            else
              ent.RequestBody = webCtx.RequestBody;

            ent.ResponseSize = webCtx.ResponseSize;
            ent.ResponseHeaders = webCtx.ResponseHeaders;
            if (webCtx.Flags.IsSet(WebCallFlags.HideResponseBody))
              ent.ResponseBody = "(Omitted)";
            else
              ent.ResponseBody = webCtx.ResponseBody;
            ent.RequestObjectCount = webCtx.RequestObjectCount;
            ent.ResponseObjectCount = webCtx.ResponseObjectCount;
              }
        }
        public void AddBookToOrder(IEntitySession session, Guid orderId, Guid bookId, byte quantity)
        {
            var order     = session.GetEntity <IBookOrder>(orderId, LockOptions.ForUpdate);
            var book      = session.GetEntity <IBook>(bookId);
            var orderLine = session.NewEntity <IBookOrderLine>();

            orderLine.Order    = order;
            orderLine.Book     = book;
            orderLine.Quantity = quantity;
            orderLine.Price    = book.Price;
            order.Lines.Add(orderLine);
            order.Total = order.Lines.Sum(ol => ol.Price * ol.Quantity);
            session.SaveChanges();
        }
Beispiel #29
0
        public static IBook NewBook(this IEntitySession session, BookEdition editions, BookCategory category, string title, string description,
                                    IPublisher publisher, DateTime?publishedOn, decimal price, IImage coverImage = null)
        {
            var book = session.NewEntity <IBook>();

            book.Editions    = editions;
            book.Category    = category;
            book.Title       = title;
            book.Description = description;
            book.Publisher   = publisher;
            book.PublishedOn = publishedOn;
            book.Price       = price;
            book.CoverImage  = coverImage;
            return(book);
        }
Beispiel #30
0
        public static IOrganization NewOrg(this IEntitySession session, OrgType orgType, string legalName,
                                           string extendedName = null, string legalId = null, string dba = null)
        {
            Util.Check(!string.IsNullOrWhiteSpace(legalName), "LegalName may not be empty");
            var party = session.NewParty(PartyKind.Org, legalName);
            var org   = session.NewEntity <IOrganization>();

            org.Party        = party;
            org.OrgType      = orgType;
            org.LegalName    = legalName;
            org.ExtendedName = extendedName ?? legalName;
            org.DbaAlias     = dba ?? legalName;
            org.LegalId      = legalId;
            return(org);
        }
Beispiel #31
0
        public static TAddress NewAddress <TAddress>(this IEntitySession session, string street1, string street2, string aptNo,
                                                     string city, string stateProvince, string postalCode, string country = null)
            where TAddress : class, IAddress
        {
            var addr = session.NewEntity <TAddress>();

            addr.Street1       = street1;
            addr.Street2       = street2;
            addr.SuiteNo       = aptNo;
            addr.City          = city;
            addr.StateProvince = stateProvince;
            addr.PostalCode    = postalCode;
            addr.Country       = country;
            return(addr);
        }
Beispiel #32
0
        public static TEntity NewLogEntity <TEntity>(this IEntitySession session, LogEntry entry)
            where TEntity : class, ILogEntityBase
        {
            var ent = session.NewEntity <TEntity>();

            if (entry.Id != null)
            {
                ent.Id = entry.Id.Value;
            }
            ent.CreatedOn     = entry.CreatedOn;
            ent.UserName      = entry.UserName;
            ent.UserSessionId = entry.UserSessionId;
            ent.WebCallId     = entry.WebCallId;
            return(ent);
        }
Beispiel #33
0
 public void SaveObjects(IEntitySession session, IList <object> items)
 {
     foreach (ClientLogEntry entry in items)
     {
         var ent = session.NewEntity <IWebClientLog>();
         ent.ClientName         = entry.ClientName;
         ent.CreatedOn          = entry.CreatedOn;
         ent.UserName           = entry.UserName;
         ent.UserSessionId      = entry.UserSessionId;
         ent.WebCallId          = entry.WebCallId;
         ent.Duration           = entry.Duration;
         ent.HttpMethod         = entry.HttpMethod;
         ent.ResponseHttpStatus = entry.HttpStatus;
         if (entry.RequestUri != null)
         {
             ent.Server    = entry.RequestUri.Scheme + "://" + entry.RequestUri.Authority;
             ent.PathQuery = entry.RequestUri.PathAndQuery;
         }
         else
         {
             ent.Server = "(unknown)"; //just in case
         }
         ent.CallTemplate = entry.CallTemplate;
         try {
             ent.RequestHeaders  = entry.RequestHeaders;
             ent.RequestBody     = entry.RequestBody;
             ent.ResponseHeaders = entry.ResponseHeaders;
             ent.ResponseBody    = entry.ResponseBody;
             if (ent.RequestBody != null)
             {
                 ent.RequestSize = ent.RequestBody.Length;
             }
             if (ent.ResponseBody != null)
             {
                 ent.ResponseSize = ent.ResponseBody.Length;
             }
             if (entry.Exception != null)
             {
                 ent.Error = entry.Exception.ToLogString();
             }
             ent.ErrorLogId = entry.ErrorLogId;
         } catch (Exception ex) {
             ent.Error = "ERROR saving client log: " + ex.ToLogString();
         }
     } //foreach
 }     //method
Beispiel #34
0
        private void SaveModulesInfo(IEntitySession session, DbVersionInfo dbVersion)
        {
            // important - should use EntitySet here; otherwise MySql fails
            var moduleRecs = session.EntitySet <IDbModuleInfo>().ToList();

            foreach (var mi in dbVersion.Modules)
            {
                var mrec = moduleRecs.FirstOrDefault(r => r.ModuleName == mi.ModuleName && r.Schema == mi.Schema);
                if (mrec == null)
                {
                    mrec            = session.NewEntity <IDbModuleInfo>();
                    mrec.ModuleName = mi.ModuleName;
                    mrec.Schema     = mi.Schema;
                }
                mrec.Version = mi.Version.ToString();
            }
        }
Beispiel #35
0
 public static IOAuthRemoteServer CreateOrUpdateServer(IEntitySession session,  string name, OAuthServerOptions options, 
     string siteUrl, string authorizationUrl, string tokenRequestUrl, string tokenRefreshUrl, string scopes,
     string documentationUrl, string basicProfileUrl, string profileUserIdTag)
 {
     IOAuthRemoteServer srv = session.EntitySet<IOAuthRemoteServer>().Where(s => s.Name == name).FirstOrDefault();
       if(srv == null)
     srv = session.NewEntity<IOAuthRemoteServer>();
       srv.Name = name;
       srv.Options = options;
       srv.SiteUrl = siteUrl;
       srv.AuthorizationUrl = authorizationUrl;
       srv.TokenRequestUrl = tokenRequestUrl;
       srv.TokenRefreshUrl = tokenRefreshUrl;
       srv.Scopes = scopes;
       srv.DocumentationUrl = documentationUrl;
       srv.BasicProfileUrl = basicProfileUrl;
       srv.ProfileUserIdTag = profileUserIdTag;
       return srv;
 }
 // Use it to import from resource - look at ImportDefaultSecretQuestions
 public static int ImportSecretQuestions(IEntitySession session, Stream stream)
 {
     var reader = new StreamReader(stream);
       var text = reader.ReadToEnd(); // File.ReadAllLines(filePath);
       var lines = text.Split(new [] {'\r', '\n'}, StringSplitOptions.RemoveEmptyEntries);
       var oldList = session.GetEntities<ISecretQuestion>();
       var count = 0;
       foreach(var line in lines) {
     if(string.IsNullOrWhiteSpace(line) || line.StartsWith("//"))
       continue;
     //check if there's existing
     var trimLine = line.Trim();
     var oldLine = oldList.FirstOrDefault(l => l.Question == trimLine);
     if(oldLine != null)
       continue;
     var q = session.NewEntity<ISecretQuestion>();
     q.Question = trimLine;
     q.Number = count++;
     q.Flags = SecretQuestionFlags.None;
       }
       return count;
 }
Beispiel #37
0
        private IMsSqlDataTypesEntity CreateSpecialDataTypesEntity(IEntitySession session, string varCharProp)
        {
            var ent = session.NewEntity<IMsSqlDataTypesEntity>();
              ent.Id = Guid.NewGuid();
              ent.CharNProp = "12345678";
              ent.NCharNProp = "234567";
              ent.VarCharProp = varCharProp;
              ent.TimeProp = DateTime.Now.TimeOfDay;
              ent.DateProp = DateTime.Now.Date;
              ent.DateTimeProp = DateTime.Now;
              ent.SmallDateTimeProp = DateTime.Now;
              ent.DateTimeOffsetProp = new DateTimeOffset(2015, 3, 14, 9, 26, 53, TimeSpan.FromHours(-7)); //PI day/time in Seattle DateTimeOffset.Now;
              // ent.TimeStampProp is set automatically by database
              /*
            // Have no idea how to properly assign these properties; assigning random data does not work, so made columns nullable and skip assignment
            ent.GeographyProp = new byte[] { 1, 2, 3, 4 };
            ent.GeometryProp = new byte[] { 5, 6, 7, 8 };
            ent.HierarchyIdProp = new byte[] { 11, 12, 13, 14 };
               */
              ent.ImageProp = new byte[] { 21, 22, 23, 24 };
              ent.NTextProp = "abcd";
              ent.TextProp = "defg";
              ent.XmlProp = "<foo/>";
              ent.SmallMoneyProp = 1.23m;
              ent.SqlVariantProp = "xx"; // 1234;

              return ent;
        }
Beispiel #38
0
        private IDataTypesEntity CreateDataTypesEntity(IEntitySession session, string strProp, string memoProp)
        {
            var ent = session.NewEntity<IDataTypesEntity>();
              var id = ent.Id = Guid.NewGuid();
              ent.StringProp = strProp;
              ent.MemoProp = memoProp;
              ent.ByteProp = 250;
              ent.BoolProp = true;
              ent.Int16Prop = -234;
              ent.Int32Prop = -345;
              ent.Int64Prop = Int64.MinValue; // (long)Int32.MaxValue + 100;
              ent.Int32NullProp = 222;
              ent.CharProp = 'X';

              ent.DoubleProp = 3.456;
              ent.DoublePropNull = 1.2345;
              ent.SingleProp = 4.567f;
              ent.DecProp = 2.34m;
              ent.MoneyProp = 3.45m;
              ent.DateTimeProp = DateTime.Now;
              ent.TimeProp = DateTime.Now.TimeOfDay;

              ent.EnumProp = SimpleEnum.Two;
              ent.EnumNullProp = SimpleEnum.Three;
              ent.BitsProp = BitEnum.Bit1 | BitEnum.Bit2;
              ent.BitsNullProp = BitEnum.Bit0;

              ent.ByteArrayProp = new byte[] { 1, 2, 3 };
              ent.BinaryProp = new Binary(new byte[] { 4, 5, 6 });
              ent.BigBinaryProp = new Binary(new byte[] { 11, 12, 13, 14 });

              ent.SByteProp = 12;
              ent.UInt16Prop = 456;
              ent.UInt32Prop = 567;
              ent.UInt64Prop = 678;

              return ent;
        }
 public ILogin NewLogin(IEntitySession session, string userName, string password,
     DateTime? expires = null, LoginFlags flags = LoginFlags.None, Guid? loginId = null,
     Guid? userId = null, Int64? altUserId = null, Guid? tenantId = null)
 {
     userName = CheckUserName(session.Context, userName);
       CheckPasswordStrength(session.Context, password);
       var login = session.NewEntity<ILogin>();
       if(loginId != null)
     login.Id = loginId.Value;
       login.UserName = userName;
       login.UserNameHash = Util.StableHash(userName);
       login.PasswordHash = HashPassword(password, login.Id);
       login.TenantId = (tenantId == null) ? Guid.Empty : tenantId.Value;
       login.Flags = flags;
       login.HashWorkFactor = _settings.PasswordHasher.WorkFactor;
       login.WeakPasswordHash = GetWeakPasswordHash(password);
       login.PasswordResetFactors = _settings.DefaultPasswordResetFactors;
       login.MultiFactorLoginFactors = ExtraFactorTypes.Email; //default, but multi-factor is not enabled yet
       login.IncompleteFactors = login.PasswordResetFactors;
       if (userId != null)
     login.UserId = userId.Value;
       if(altUserId != null)
     login.AltUserId = altUserId.Value;
       var utcNow = App.TimeService.UtcNow;
       if(expires != null)
     login.Expires = expires;
       else
     SetPasswordExpiration(login);
       login.PasswordResetOn = utcNow;
       login.CreatePasswordHistoryEntry();
       OnLoginEvent(session.Context, LoginEventType.LoginCreated, login);
       return login;
 }
Beispiel #40
0
 private void SaveModulesInfo(IEntitySession session, DbVersionInfo dbVersion)
 {
     var moduleRecs = session.GetEntities<IDbModuleInfo>(take: 1000);
       foreach (var mi in dbVersion.Modules) {
     var mrec = moduleRecs.FirstOrDefault(r => r.ModuleName == mi.ModuleName && r.Schema == mi.Schema);
     if (mrec == null) {
       mrec = session.NewEntity<IDbModuleInfo>();
       mrec.ModuleName = mi.ModuleName;
       mrec.Schema = mi.Schema;
     }
     mrec.Version = mi.Version.ToString();
       }
 }