public async Task UpdateAsync(BrandingInfo branding)
        {
            if (branding == null)
            {
                return;
            }

            Name = branding.Name;

            if (!string.IsNullOrWhiteSpace(branding.PrimaryColor))
            {
                ThemeManager.CurrentTheme.PrimaryColor = Theme.ColorFromHex(branding.PrimaryColor);
                _settings.Values[primaryColorKey]      = branding.PrimaryColor;
                _settings.Values[secondaryColorKey]    = branding.PrimaryColor;
            }

            if (!string.IsNullOrWhiteSpace(branding.SecondaryColor))
            {
                ThemeManager.CurrentTheme.AccentColor = Theme.ColorFromHex(branding.SecondaryColor);
                _settings.Values[secondaryColorKey]   = branding.SecondaryColor;
            }

            if (branding.HeaderImage != null)
            {
                var image = await SaveFileAsync(headerImageName, branding.HeaderImage);

                HeaderImage = GetImage(image);
            }
            else
            {
                await DeleteFileAsync(headerImageName);
            }

            if (branding.LogoImage != null)
            {
                var image = await SaveFileAsync(logoImageName, branding.LogoImage);

                LogoImage = GetImage(image);
            }
            else
            {
                await DeleteFileAsync(logoImageName);
            }
        }
示例#2
0
        private void ApplyBranding(BrandingInfo brandingInfo)
        {
            try
            {
                ProductName = "Remotely";

                if (!string.IsNullOrWhiteSpace(brandingInfo?.Product))
                {
                    ProductName = brandingInfo.Product;
                }

                TitleBackgroundColor = new SolidColorBrush(Color.FromRgb(
                                                               brandingInfo?.TitleBackgroundRed ?? 70,
                                                               brandingInfo?.TitleBackgroundGreen ?? 70,
                                                               brandingInfo?.TitleBackgroundBlue ?? 70));

                TitleForegroundColor = new SolidColorBrush(Color.FromRgb(
                                                               brandingInfo?.TitleForegroundRed ?? 29,
                                                               brandingInfo?.TitleForegroundGreen ?? 144,
                                                               brandingInfo?.TitleForegroundBlue ?? 241));

                TitleButtonForegroundColor = new SolidColorBrush(Color.FromRgb(
                                                                     brandingInfo?.ButtonForegroundRed ?? 255,
                                                                     brandingInfo?.ButtonForegroundGreen ?? 255,
                                                                     brandingInfo?.ButtonForegroundBlue ?? 255));

                TitleBackgroundColor.Freeze();
                TitleForegroundColor.Freeze();
                TitleButtonForegroundColor.Freeze();

                Icon = GetBitmapImageIcon(brandingInfo);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
            }
        }
示例#3
0
        private BitmapImage GetBitmapImageIcon(BrandingInfo bi)
        {
            Stream imageStream;

            if (bi.Icon?.Any() == true)
            {
                imageStream = new MemoryStream(bi.Icon);
            }
            else
            {
                imageStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Remotely.Desktop.Win.Assets.Remotely_Icon.png");
            }

            var bitmap = new BitmapImage();

            bitmap.BeginInit();
            bitmap.StreamSource = imageStream;
            bitmap.CacheOption  = BitmapCacheOption.OnLoad;
            bitmap.EndInit();
            bitmap.Freeze();
            imageStream.Close();

            return(bitmap);
        }
示例#4
0
        private BitmapImage GetBitmapImageIcon(BrandingInfo bi)
        {
            Stream imageStream;

            if (!string.IsNullOrWhiteSpace(bi?.Icon))
            {
                imageStream = new MemoryStream(Convert.FromBase64String(bi.Icon));
            }
            else
            {
                imageStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Remotely.Agent.Installer.Win.Assets.Remotely_Icon.png");
            }

            var bitmap = new BitmapImage();

            bitmap.BeginInit();
            bitmap.StreamSource = imageStream;
            bitmap.CacheOption  = BitmapCacheOption.OnLoad;
            bitmap.EndInit();
            bitmap.Freeze();
            imageStream.Close();

            return(bitmap);
        }
示例#5
0
        private async Task ExtractDeviceInitInfo()
        {
            try
            {
                var fileName   = Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().Location);
                var codeLength = AppConstants.RelayCodeLength + 2;

                for (var i = 0; i < fileName.Length; i++)
                {
                    var guid = string.Join("", fileName.Skip(i).Take(36));
                    if (Guid.TryParse(guid, out _))
                    {
                        OrganizationID = guid;
                        return;
                    }


                    var codeSection = string.Join("", fileName.Skip(i).Take(codeLength));

                    if (codeSection.StartsWith("[") &&
                        codeSection.EndsWith("]") &&
                        !string.IsNullOrWhiteSpace(ServerUrl))
                    {
                        var relayCode = codeSection.Substring(1, 4);
                        using (var httpClient = new HttpClient())
                        {
                            var response = await httpClient.GetAsync($"{ServerUrl}/api/relay/{relayCode}").ConfigureAwait(false);

                            if (response.IsSuccessStatusCode)
                            {
                                var serializer     = new JavaScriptSerializer();
                                var organizationId = await response.Content.ReadAsStringAsync();

                                OrganizationID = organizationId;
                                break;
                            }
                        }
                    }
                }

                if (!string.IsNullOrWhiteSpace(OrganizationID) &&
                    !string.IsNullOrWhiteSpace(ServerUrl))
                {
                    using (var httpClient = new HttpClient())
                    {
                        var serializer  = new JavaScriptSerializer();
                        var brandingUrl = $"{ServerUrl.TrimEnd('/')}/api/branding/{OrganizationID}";
                        using (var response = await httpClient.GetAsync(brandingUrl).ConfigureAwait(false))
                        {
                            var responseString = await response.Content.ReadAsStringAsync();

                            _brandingInfo = serializer.Deserialize <BrandingInfo>(responseString);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
            }
            finally
            {
                ApplyBranding(_brandingInfo);
            }
        }