Example #1
0
        /// <summary>
        /// Updates a customer record in the database.
        /// </summary>
        /// <param name="customer">The customer with updated values.</param>
        /// <returns>Number of rows affected.</returns>
        public int UpdateCustomer(Customer customer)
        {
            using (ActionDataContext db = DataContextFactory.CreateContext())
            {
                try
                {
                    CustomerEntity entity = Mapper.ToEntity(customer);
                    db.CustomerEntities.Attach(entity, true);
                    db.SubmitChanges();

                    // Update business object with new version
                    customer.Version = VersionConverter.ToString(entity.Version);

                    return(1);
                }
                catch (ChangeConflictException)
                {
                    throw new Exception("A change to customer record was made before your changes.");
                }
                catch
                {
                    return(0);
                }
            }
        }
Example #2
0
        public static void Main(string[] args)
        {
            var versionNumber = "1.0.1";
            var versionCode   = VersionConverter.VersionNumberToVersionCode(versionNumber);

            Console.WriteLine($"{versionNumber} >> {versionCode}");
        }
Example #3
0
 public static string ToViewString(Project project)
 {
     return(project.AssemblyVersion
            .Match(x =>
                   $"{project.Name} - {VersionConverter.ToString(project.Version)} - {VersionConverter.ToString(x)}",
                   $"{project.Name} - {VersionConverter.ToString(project.Version)}"));
 }
Example #4
0
        public static Project Save(Project project)
        {
            NodeModifier.Set(project.Path, VersionNode.Version, VersionConverter.ToString(project.Version));
            project.AssemblyVersion.IfSome(x =>
                                           NodeModifier.Set(project.Path, VersionNode.AssemblyVersion, VersionConverter.ToString(x)));

            return(project);
        }
        public void Should_not_convert()
        {
            var registry = new LocalizationRegistry(new Cache());

            var converter = new VersionConverter(registry);
            var version   = converter.Convert("en", "test");

            version.Should().BeNull();
        }
        public void Should_convert()
        {
            var registry = new LocalizationRegistry(new Cache());

            var converter = new VersionConverter(registry);
            var version   = converter.Convert("en", "1.0");

            version.Equals(new Version(1, 0)).Should().BeTrue();
        }
Example #7
0
 /// <summary>
 /// Maps product category entity to category business object.
 /// </summary>
 /// <param name="entity">A category entity.</param>
 /// <returns>A category business object.</returns>
 internal static Category Map(CategoryEntity entity)
 {
     return(new Category
     {
         CategoryId = entity.CategoryId,
         Description = entity.Description,
         Name = entity.CategoryName,
         Version = VersionConverter.ToString(entity.Version)
     });
 }
        public void ConvertToVersion()
        {
            var src = new V1beta1APIService().Initialize();

            src.ApiVersion.Should().Be("apiregistration.k8s.io/v1beta1");
            var sut = (V1APIService)VersionConverter.ConvertToVersion(src, "v1");

            sut.Should().NotBeNull();
            sut.ApiVersion.Should().Be("apiregistration.k8s.io/v1");
        }
Example #9
0
 /// <summary>
 /// Maps product category entity to category business object.
 /// </summary>
 /// <param name="c">A category entity.</param>
 /// <returns>A category business object.</returns>
 internal static Category ToBusinessObject(CategoryEntity c)
 {
     return(new Category
     {
         CategoryId = c.CategoryId,
         Description = c.Description,
         Name = c.CategoryName,
         Version = VersionConverter.ToString(c.Version)
     });
 }
Example #10
0
 static Converters()
 {
     IPAddress = new IPAddressConverter ();
     Regex = new RegexConverter ();
     ZeroOneBoolean = new ZeroOneBooleanConverter ();
     TextualZeroOneBoolean = new ZeroOneBooleanConverter (true);
     Uri = new UriConverter ();
     Version = new VersionConverter ();
     XmlNode = new XmlNodeConverter ();
 }
Example #11
0
 /// <summary>
 /// Maps customer entity to customer business object.
 /// </summary>
 /// <param name="entity">A customer entity to be transformed.</param>
 /// <returns>A customer business object.</returns>
 internal static Customer Map(CustomerEntity entity)
 {
     return(new Customer
     {
         CustomerId = entity.CustomerId,
         Company = entity.CompanyName,
         City = entity.City,
         Country = entity.Country,
         Version = VersionConverter.ToString(entity.Version)
     });
 }
Example #12
0
 /// <summary>
 /// Maps order detail entity to order detail business object.
 /// </summary>
 /// <param name="entity">An order detail entity.</param>
 /// <returns>An order detail business object.</returns>
 internal static OrderDetail Map(OrderDetailEntity entity)
 {
     return(new OrderDetail
     {
         ProductName = entity.ProductEntity.ProductName,
         Discount = (float)entity.Discount,
         Quantity = entity.Quantity,
         UnitPrice = (float)entity.UnitPrice,
         Version = VersionConverter.ToString(entity.Version)
     });
 }
Example #13
0
 /// <summary>
 /// Maps order detail entity to order detail business object.
 /// </summary>
 /// <param name="od">An order detail entity.</param>
 /// <returns>An order detail business object.</returns>
 internal static OrderDetail ToBusinessObject(OrderDetailEntity od)
 {
     return(new OrderDetail
     {
         ProductName = od.ProductEntity.ProductName,
         Discount = (float)od.Discount,
         Quantity = od.Quantity,
         UnitPrice = (float)od.UnitPrice,
         Version = VersionConverter.ToString(od.Version)
     });
 }
Example #14
0
 /// <summary>
 /// Maps order entity to order business object.
 /// </summary>
 /// <param name="o">An order entity.</param>
 /// <returns>An order business object.</returns>
 internal static Order ToBusinessObject(OrderEntity o)
 {
     return(new Order
     {
         OrderId = o.OrderId,
         Freight = o.Freight.HasValue ? (float)o.Freight : default(float),
         OrderDate = o.OrderDate,
         RequiredDate = o.RequiredDate.HasValue ? (DateTime)o.RequiredDate : default(DateTime),
         Version = VersionConverter.ToString(o.Version)
     });
 }
Example #15
0
 /// <summary>
 /// Maps customer entity to customer business object.
 /// </summary>
 /// <param name="c">A customer entity to be transformed.</param>
 /// <returns>A customer business object.</returns>
 internal static Customer ToBusinessObject(CustomerEntity c)
 {
     return(new Customer
     {
         CustomerId = c.CustomerId,
         Company = c.CompanyName,
         City = c.City,
         Country = c.Country,
         Version = VersionConverter.ToString(c.Version)
     });
 }
Example #16
0
 /// <summary>
 /// Maps order entity to order business object.
 /// </summary>
 /// <param name="entity">An order entity.</param>
 /// <returns>An order business object.</returns>
 internal static Order Map(OrderEntity entity)
 {
     return(new Order
     {
         OrderId = entity.OrderId,
         Freight = entity.Freight.HasValue ? (float)entity.Freight : default(float),
         OrderDate = entity.OrderDate,
         RequiredDate = entity.RequiredDate.HasValue ? (DateTime)entity.RequiredDate : default(DateTime),
         Version = VersionConverter.ToString(entity.Version)
     });
 }
        public void Should_not_be_able_to_convert()
        {
            var registry = new LocalizationRegistry(new Cache());

            registry.RegisterTranslation("en", LocalizationResources.FilterCommands.Version, "en-ach");
            registry.RegisterTranslation("fr", LocalizationResources.FilterCommands.Version, "fr-ach");

            var converter = new VersionConverter(registry);

            converter.CanConvert("en", "en-fake").Result.Should().BeFalse();
        }
Example #18
0
 /// <summary>
 /// Maps customer business object to customer entity.
 /// </summary>
 /// <param name="customer">A customer business object.</param>
 /// <returns>A customer entity.</returns>
 internal static CustomerEntity Map(Customer customer)
 {
     return(new CustomerEntity
     {
         CustomerId = customer.CustomerId,
         CompanyName = customer.Company,
         City = customer.City,
         Country = customer.Country,
         Version = VersionConverter.ToBinary(customer.Version),
     });
 }
Example #19
0
 static Converters()
 {
     IPAddress             = new IPAddressConverter();
     Regex                 = new RegexConverter();
     TextualZeroOneBoolean = new ZeroOneBooleanConverter(true);
     Type           = new ReflectedTypeConverter();
     Uri            = new UriConverter();
     Version        = new VersionConverter();
     XmlNode        = new XmlNodeConverter();
     ZeroOneBoolean = new ZeroOneBooleanConverter();
 }
Example #20
0
        public void WriteJsonNull()
        {
            StringWriter   sw         = new StringWriter();
            JsonTextWriter jsonWriter = new JsonTextWriter(sw);

            VersionConverter converter = new VersionConverter();

            converter.WriteJson(jsonWriter, null, null);

            StringAssert.AreEqual(@"null", sw.ToString());
        }
Example #21
0
 /// <summary>
 /// Maps product entity to product business object.
 /// </summary>
 /// <param name="p">A product entity.</param>
 /// <returns>A product business object.</returns>
 internal static Product ToBusinessObject(ProductEntity p)
 {
     return(new Product
     {
         ProductId = p.ProductId,
         ProductName = p.ProductName,
         UnitPrice = (double)p.UnitPrice,
         UnitsInStock = p.UnitsInStock,
         Weight = p.Weight,
         Version = VersionConverter.ToString(p.Version)
     });
 }
Example #22
0
 /// <summary>
 /// Maps product entity to product business object.
 /// </summary>
 /// <param name="entity">A product entity.</param>
 /// <returns>A product business object.</returns>
 internal static Product Map(ProductEntity entity)
 {
     return(new Product
     {
         ProductId = entity.ProductId,
         ProductName = entity.ProductName,
         UnitPrice = (double)entity.UnitPrice,
         UnitsInStock = entity.UnitsInStock,
         Weight = entity.Weight,
         Version = VersionConverter.ToString(entity.Version)
     });
 }
        public void Should_be_able_to_convert()
        {
            var registry = new LocalizationRegistry(new Cache());

            registry.RegisterTranslation("en", LocalizationResources.FilterCommands.Version, "en-ach");
            registry.RegisterTranslation("fr", LocalizationResources.FilterCommands.Version, "fr-ach");

            var converter = new VersionConverter(registry);

            converter.CanConvert("en", "en-ach").Result.Should().BeTrue();
            converter.CanConvert("en", "en-ach").MappedStaticField.Should().Be(Fields.Version);
            converter.CanConvert("en", "fr-ach").Result.Should().BeTrue();
        }
Example #24
0
        /// <summary>
        /// Updates a customer record in the database.
        /// </summary>
        /// <param name="customer">The customer with updated values.</param>
        /// <returns>Number of rows affected.</returns>
        public void UpdateCustomer(Customer customer)
        {
            var entity = Mapper.Map(customer);

            using (var context = DataContextFactory.CreateContext())
            {
                context.CustomerEntities.Attach(entity, true);
                context.SubmitChanges();

                // Update business object with new version
                customer.Version = VersionConverter.ToString(entity.Version);
            }
        }
Example #25
0
        /// <summary>
        /// Inserts a new customer record to the database.
        /// </summary>
        /// <param name="customer">The customer to be inserted.</param>
        public void InsertCustomer(Customer customer)
        {
            var entity = Mapper.Map(customer);

            using (var context = DataContextFactory.CreateContext())
            {
                context.CustomerEntities.InsertOnSubmit(entity);
                context.SubmitChanges();

                // update business object with new version and id
                customer.CustomerId = entity.CustomerId;
                customer.Version    = VersionConverter.ToString(entity.Version);
            }
        }
        public int Update(BusinessObjects.BizMsg model)
        {
            // Validate the BO
            var errorInfo = Validator.Check(model);

            if (errorInfo.Count() > 0)
            {
                throw new Exception("Validation error(s) occurred! Please make sure all validation rules are met.");
            }

            NiCris.DataAccess.SQL.LinqToSQL.BizMsg entity = BizMsgMapper.ToEntity(model);

            using (Database db = DataContextFactory.CreateContext())
            {
                try
                {
                    db.BizMsgs.Attach(entity, true);
                    db.SubmitChanges();

                    model.Id         = entity.Id;
                    model.RowVersion = VersionConverter.ToString(entity.rowversion);
                    return(entity.Id);
                }
                catch (ChangeConflictException)
                {
                    foreach (ObjectChangeConflict conflict in db.ChangeConflicts)
                    {
                        conflict.Resolve(RefreshMode.KeepCurrentValues);
                    }

                    try
                    {
                        db.SubmitChanges();
                    }
                    catch (ChangeConflictException)
                    {
                        throw new Exception("A concurrency error occurred!");
                    }

                    return(entity.Id);
                }
                catch (Exception ex)
                {
                    throw new Exception("There was an error updating the record! " + ex.Message);
                }
            }
        }
Example #27
0
        public SystemInformation(byte[] Data)
        {
            UnitFwInfo = new List <UnitInformation>();

            using (MemoryStream stream = new MemoryStream(Data))
            {
                using (BinaryReader reader = new BinaryReader(stream))
                {
                    this.MaxUnit         = (int)reader.ReadByte();
                    this.FirmwareVersion = VersionConverter.FromByteArray(reader.ReadBytes(4));
                    for (int i = 0; i < MaxUnit; i++)
                    {
                        UnitFwInfo.Add(new UnitInformation(reader.ReadBytes(4)));
                    }
                }
            }
        }
        private static async Task <TermDescriptorValue> GetTermDescriptorValueFromV3Session(
            IUpstreamEdFiApiInvoker invoker,
            HttpRequestHeaders headers,
            TermDescriptorKey key,
            short schoolYearFromRoute)
        {
            // Get the referenced section by natural key
            var response = await invoker.Get(
                typeof(V3Session),
                headers,
                new[]
            {
                new KeyValuePair <string, string>("schoolId", key.SchoolId.ToString()),
                new KeyValuePair <string, string>("schoolYear", key.SchoolYear.ToString()),
                new KeyValuePair <string, string>("sessionName", key.SessionName),
            },
                schoolYearFromRoute)
                           .ConfigureAwait(false);

            StreamReader sr = new StreamReader(response.ResponseStream);
            string       responseContent = await sr.ReadToEndAsync().ConfigureAwait(false);

            if (response.Status == HttpStatusCode.OK)
            {
                // Get the Session-derived members
                var v3Session = JsonConvert.DeserializeObject <V3Session[]>(responseContent, _serializerSettings)
                                .SingleOrDefault();

                if (v3Session == null)
                {
                    throw new Exception(
                              $"Session with schoolId '{key.SchoolId}', schoolYear '{key.SchoolYear}' and sessionName '{key.SessionName}' was not found in host. Unable to support termDescriptor conversion for v2.5 API client.");
                }

                return(new TermDescriptorValue(
                           VersionConverter.DescriptorV3ToV2("TermDescriptor", v3Session.TermDescriptor),
                           DateTime.Now));
            }

            throw new Exception(
                      $"Error obtaining V3 Session resource during mapping of TermDescriptor: {response.Status} - {responseContent}");
        }
Example #29
0
        /// <summary>
        /// Inserts a new customer record to the database.
        /// </summary>
        /// <param name="customer">The customer to be inserted.</param>
        public void InsertCustomer(Customer customer)
        {
            using (ActionDataContext db = DataContextFactory.CreateContext())
            {
                try
                {
                    CustomerEntity entity = Mapper.ToEntity(customer);
                    db.CustomerEntities.InsertOnSubmit(entity);
                    db.SubmitChanges();

                    // update business object with new version and id
                    customer.CustomerId = entity.CustomerId;
                    customer.Version    = VersionConverter.ToString(entity.Version);
                }
                catch (ChangeConflictException)
                {
                    throw new Exception("A change to customer record was made before your changes.");
                }
            }
        }
Example #30
0
        private static async Task <string> GetSessionName(
            IUpstreamEdFiApiInvoker invoker,
            HttpRequestHeaders headers,
            V2SectionReference source,
            short schoolYear)
        {
            // Get the referenced session by example
            var response = await invoker.Get(
                typeof(V3Session),
                headers, new[]
            {
                new KeyValuePair <string, string>("schoolId", source.SchoolId.ToString()),
                new KeyValuePair <string, string>("schoolYear", source.SchoolYear.ToString()),
                new KeyValuePair <string, string>("termDescriptor",
                                                  VersionConverter.DescriptorV2ToV3("TermDescriptor", source.TermDescriptor))
            },
                schoolYear)
                           .ConfigureAwait(false);

            StreamReader sr = new StreamReader(response.ResponseStream);
            string       responseContent = sr.ReadToEnd();

            if (response.Status == HttpStatusCode.OK)
            {
                var v3Sessions = JsonConvert.DeserializeObject <V3Session[]>(responseContent, _serializerSettings);

                var distinctSessionNames = v3Sessions.Select(x => x.SessionName).Distinct().ToList();

                if (distinctSessionNames.Count() > 1)
                {
                    throw new Exception($"Error obtaining SessionName from remote API due to multiple values matching in the Sessions for the supplied TermDescriptor.");
                }

                return(distinctSessionNames.FirstOrDefault());
            }

            throw new Exception(
                      $"Error obtaining V3 Session resource during mapping of SessionName: {response.Status} - {responseContent}");
        }
        public static NiCris.BusinessObjects.BizMsg ToBusinessObject(NiCris.DataAccess.SQL.LinqToSQL.BizMsg entity)
        {
            if (entity == null)
            {
                return(null);
            }

            return(new NiCris.BusinessObjects.BizMsg()
            {
                Id = entity.Id,
                Name = entity.Name,
                Date = entity.Date,
                User = entity.User,

                Description = entity.Description,
                AppId = entity.AppId,
                ServiceId = entity.ServiceId,
                StyleId = entity.StyleId,
                Roles = entity.Roles,

                RowVersion = VersionConverter.ToString(entity.rowversion)
            });
        }