Ejemplo n.º 1
0
        private static void SaveConnection(Settings settings)
        {
            SaveLatestConnectionString(settings.ConnectionString);

            var baseFileName = BuildBaseFileName();

            var file             = $@"{baseFileName}-Connection.dat";
            var connectionString = settings.ConnectionString;

            if (!File.Exists(file) && connectionString.IsFilled())
            {
                File.Create(file).Dispose();
                Status.Update("[Settings] Created a new connection file.");
            }

            if (!File.Exists(file))
            {
                return;
            }

            Status.Update("[Settings] Writing to file ...");

            var encodedString = Convert.ToBase64String(Encoding.UTF8.GetBytes(connectionString));

            File.WriteAllText(file, encodedString);

            Status.Update($"[Settings] Connection string: {ConnectionHelpers.SecureConnectionString(connectionString)}");
        }
Ejemplo n.º 2
0
        private static void ProcessSettings(Settings settings)
        {
            settings.AppId ??= Constants.AppId;
            settings.AppVersion ??= Constants.AppVersion;
            settings.SettingsVersion = Constants.SettingsVersion;
            settings.BaseFileName    = FileName;

            LoadConnection(settings);
            SetTemplateInfo(settings);

            Status.Update("[Settings] [DONE] Loading settings.");
        }
Ejemplo n.º 3
0
        public static Settings CreateNewSettings()
        {
            Status.Update("[Settings] Creating new settings ...");

            var newSettings = new Settings();

            ProcessSettings(newSettings);

            Status.Update("[Settings] [DONE] Creating new settings.");

            return(newSettings);
        }
Ejemplo n.º 4
0
        private void ButtonNewSettings_Click(object sender, RoutedEventArgs e)
        {
            var isMigrate = DteHelper.IsConfirmed("Current settings will be deleted and new settings will be created.\r\n\r\n"
                                                  + "Would you like to proceed?",
                                                  ">> WARNING << Settings Reset");

            if (isMigrate)
            {
                settings = Configuration.CreateNewSettings();
                Initialise();
                DteHelper.ShowInfo("Settings has been reset.",
                                   "Settings Reset");
            }
        }
Ejemplo n.º 5
0
 private static void MigrateOldSettings(Settings settings, Model.OldSettings.Settings oldSettings)
 {
     MigrateOldSettings2(settings,
                         new Model.OldSettings2.Settings
     {
         EntityProfilesHeaderSelector =
             new EntityProfilesHeaderSelector_old2
         {
             SelectedFilterIndex   = oldSettings.EntityDataFilterArray.SelectedFilterIndex,
             EntityProfilesHeaders = new ObservableCollection <EntityProfilesHeader_old2>(oldSettings
                                                                                          .EntityDataFilterArray.EntityFilters
                                                                                          .Select(ef =>
                                                                                                  new EntityProfilesHeader_old2
             {
                 Prefix         = ef.Prefix,
                 Suffix         = ef.Suffix,
                 EntityProfiles = ef
                                  .EntityFilterList?
                                  .Select(efl =>
                                          new EntityProfile_old2(efl.LogicalName)
                 {
                     IsApplyToCrm       = ef.IsDefault,
                     Attributes         = efl.Attributes,
                     AttributeLanguages = efl.AttributeLanguages,
                     AttributeRenames   = efl.AttributeRenames,
                     ClearFlag          = efl.ClearFlag,
                     EnglishLabelField  = efl.EnglishLabelField,
                     EntityRename       = efl.EntityRename,
                     IsExcluded         = efl.IsExcluded,
                     IsGenerateMeta     = efl.IsGenerateMeta,
                     IsLookupLabels     = efl.IsLookupLabels,
                     IsOptionsetLabels  = efl.IsOptionsetLabels,
                     LogicalName        = efl.LogicalName,
                     NToN           = efl.NToN,
                     NToNReadOnly   = efl.NToNReadOnly,
                     NToNRenames    = efl.NToNRenames,
                     NToOne         = efl.NToOne,
                     NToOneFlatten  = efl.NToOneFlatten,
                     NToOneReadOnly = efl.NToOneReadOnly,
                     NToOneRenames  = efl.NToOneRenames,
                     OneToN         = efl.OneToN,
                     OneToNReadOnly = efl.OneToNReadOnly,
                     OneToNRenames  = efl.OneToNRenames,
                     ReadOnly       = efl.ReadOnly,
                     ValueClearMode = (ClearModeEnum_old2?)efl.ValueClearMode
                 }).ToList()
             }))
         }
     });
 }
Ejemplo n.º 6
0
        public Login(DTE2 dte)
        {
            Assembly.Load("Xceed.Wpf.Toolkit");

            InitializeComponent();

            var main = dte.GetMainWindow();

            Owner = main;

            settings = Configuration.LoadSettings();

            connectionManager = CacheHelpers.GetFromMemCacheAdd(Constants.ConnCacheMemKey,
                                                                () => new ConnectionManager(settings.Threads));

            ////EventManager.RegisterClassHandler(typeof(TextBox), MouseDoubleClickEvent, new RoutedEventHandler(SelectAddress));
            ////EventManager.RegisterClassHandler(typeof(TextBox), GotKeyboardFocusEvent, new RoutedEventHandler(SelectAddress));
            ////EventManager.RegisterClassHandler(typeof(TextBox), PreviewMouseLeftButtonDownEvent,
            ////	new MouseButtonEventHandler(SelectivelyIgnoreMouseButton));
        }
Ejemplo n.º 7
0
        private static string LoadConnection(Settings settings)
        {
            var baseFileName = BuildBaseFileName();

            var file = $@"{baseFileName}-Connection.dat";

            string connectionString = null;

            if (File.Exists(file))
            {
                Status.Update($"[Settings] Found connection file: {file}.");
                Status.Update($"[Settings] Reading content ...");

                var fileContent = File.ReadAllText(file);
                connectionString = Encoding.UTF8.GetString(Convert.FromBase64String(fileContent));

                Status.Update($"[Settings] Connection string: {ConnectionHelpers.SecureConnectionString(connectionString)}");
            }

            if (connectionString.IsFilled())
            {
                settings.ConnectionString = connectionString;
            }
            else
            {
                var latest = LoadLatestConnectionString();

                if (latest.IsNotEmpty())
                {
                    connectionString = settings.ConnectionString = latest;
                    Status.Update($"[Settings] Connection string: {ConnectionHelpers.SecureConnectionString(connectionString)}");
                }
            }

            return(connectionString);
        }
Ejemplo n.º 8
0
        private static void CleanSettings(Settings settings)
        {
            // clean redundant profiles
            foreach (var header in settings.EntityProfilesHeaderSelector.EntityProfilesHeaders)
            {
                var groups = header.EntityProfiles.GroupBy(e => e.LogicalName);

                foreach (var group in groups.Where(e => e.Count() > 1))
                {
                    foreach (var profile in group.Skip(1))
                    {
                        header.EntityProfiles.Remove(profile);
                    }
                }
            }

            // clean redundant profiles
            var crmProfileGroups = settings.CrmEntityProfiles.GroupBy(e => e.LogicalName);

            foreach (var group in crmProfileGroups.Where(e => e.Count() > 1))
            {
                foreach (var profile in group.Skip(1))
                {
                    settings.CrmEntityProfiles.Remove(profile);
                }
            }

            // set empty collections as null to save JSON
            var profiles = settings.EntityProfilesHeaderSelector.EntityProfilesHeaders
                           .SelectMany(e => e.EntityProfiles)
                           .Union(settings.CrmEntityProfiles);

            var mainCollections =
                new[]
            {
                nameof(EntityProfile.Attributes),
                nameof(EntityProfile.OneToN),
                nameof(EntityProfile.NToOne),
                nameof(EntityProfile.NToN)
            };

            foreach (var profile in profiles)
            {
                profile.Attributes?.RemoveEmpty();
                profile.AttributeRenames?.RemoveEmpty();
                profile.AttributeLanguages?.RemoveEmpty();
                profile.AttributeAnnotations?.RemoveEmpty();
                profile.ReadOnly?.RemoveEmpty();
                profile.ClearFlag?.RemoveEmpty();
                profile.OneToN?.RemoveEmpty();
                profile.OneToNRenames?.RemoveEmpty();
                profile.OneToNReadOnly?.RemoveEmpty();
                profile.NToOne?.RemoveEmpty();
                profile.NToOneRenames?.RemoveEmpty();
                profile.NToOneFlatten?.RemoveEmpty();
                profile.NToOneReadOnly?.RemoveEmpty();
                profile.NToN?.RemoveEmpty();
                profile.NToNRenames?.RemoveEmpty();
                profile.NToNReadOnly?.RemoveEmpty();

                var collectionsToNull =
                    profile.GetType().GetProperties()
                    .Where(p => !mainCollections.Contains(p.Name) && typeof(IEnumerable).IsAssignableFrom(p.PropertyType));

                foreach (var info in collectionsToNull)
                {
                    if (info.GetValue(profile) is IEnumerable e && e.IsEmpty())
                    {
                        info.SetValue(profile, null);
                    }
                }
            }

            var isCleanProfiles = settings.IsRemoveUnselectedProfiles;

            foreach (var filter in settings.EntityProfilesHeaderSelector.EntityProfilesHeaders)
            {
                CleanProfiles(filter.EntityProfiles, isCleanProfiles);
            }
        }
Ejemplo n.º 9
0
        public static void SaveSettings(Settings settings)
        {
            Status.Update("[Settings] Writing settings ... ");

            var baseFileName = BuildBaseFileName();

            SaveConnection(settings);

            var file = $@"{baseFileName}-Config.json";

            if (!File.Exists(file))
            {
                File.Create(file).Dispose();
                var project = GetProjectObject();
                project.ProjectItems.AddFromFile(file);
                project.Save();
                Status.Update("[Settings] Created a new settings file.");
            }

            // check out file if in TFS
            try
            {
                CheckoutTfs(file);
            }
            catch (Exception)
            {
                // ignored
            }

            Status.Update("[Settings] Ordering profiles ...");

            settings.EntitiesSelected  = new ObservableCollection <string>(settings.EntitiesSelected.OrderBy(e => e));
            settings.CrmEntityProfiles = new List <EntityProfile>(settings.CrmEntityProfiles
                                                                  .OrderBy(e => e.LogicalName));

            settings.EntityProfilesHeaderSelector.EntityProfilesHeaders = new ObservableCollection <EntityProfilesHeader>(settings
                                                                                                                          .EntityProfilesHeaderSelector.EntityProfilesHeaders.OrderBy(e => e.DisplayName));

            foreach (var header in settings.EntityProfilesHeaderSelector.EntityProfilesHeaders)
            {
                header.EntityProfiles = new List <EntityProfile>(header.EntityProfiles
                                                                 .OrderBy(e => e.LogicalName));
            }

            Status.Update("[Settings] Cleaning redundant settings ...");

            if (settings.IsCleanSave)
            {
                CleanSettings(settings);
            }

            Status.Update("[Settings] Serialising settings ...");
            var serialisedSettings = JsonConvert.SerializeObject(settings, Formatting.Indented,
                                                                 new JsonSerializerSettings
            {
                DefaultValueHandling = DefaultValueHandling.Ignore,
                NullValueHandling    = NullValueHandling.Ignore
            });

            Status.Update("[Settings] Writing to file ...");
            File.WriteAllText(file, serialisedSettings);

            Status.Update("[Settings] [DONE] Writing settings.");
        }
Ejemplo n.º 10
0
        private static void MigrateOldSettings2(Settings settings, Model.OldSettings2.Settings oldSettings)
        {
            settings.CrmEntityProfiles =
                oldSettings
                .EntityProfilesHeaderSelector.EntityProfilesHeaders
                .SelectMany(ef => ef.EntityProfiles.Where(ep => ep.IsApplyToCrm)
                            .Select(ep =>
                                    new EntityProfile(ep.LogicalName)
            {
                Attributes         = ep.Attributes,
                AttributeLanguages = ep.AttributeLanguages,
                AttributeRenames   = ep.AttributeRenames,
                ClearFlag          = ep.ClearFlag,
                EnglishLabelField  = ep.EnglishLabelField,
                EntityRename       = ep.EntityRename,
                IsIncluded         = !ep.IsExcluded,
                IsGenerateMeta     = ep.IsGenerateMeta,
                IsLookupLabels     = ep.IsLookupLabels,
                IsOptionsetLabels  = ep.IsOptionsetLabels,
                LogicalName        = ep.LogicalName,
                NToN           = ep.NToN,
                NToNReadOnly   = ep.NToNReadOnly,
                NToNRenames    = ep.NToNRenames,
                NToOne         = ep.NToOne,
                NToOneFlatten  = ep.NToOneFlatten,
                NToOneReadOnly = ep.NToOneReadOnly,
                NToOneRenames  = ep.NToOneRenames,
                OneToN         = ep.OneToN,
                OneToNReadOnly = ep.OneToNReadOnly,
                OneToNRenames  = ep.OneToNRenames,
                ReadOnly       = ep.ReadOnly,
                ValueClearMode = (ClearModeEnum?)ep.ValueClearMode
            })).ToList();

            settings.EntityProfilesHeaderSelector =
                new EntityProfilesHeaderSelector
            {
                SelectedFilterIndex   = oldSettings.EntityProfilesHeaderSelector.SelectedFilterIndex,
                EntityProfilesHeaders = new ObservableCollection <EntityProfilesHeader>(oldSettings
                                                                                        .EntityProfilesHeaderSelector.EntityProfilesHeaders
                                                                                        .Select(ef =>
                                                                                                new EntityProfilesHeader
                {
                    Prefix         = ef.Prefix,
                    Suffix         = ef.Suffix,
                    EntityProfiles = ef
                                     .EntityProfiles?
                                     .Select(efl =>
                                             new EntityProfile(efl.LogicalName)
                    {
                        Attributes         = efl.Attributes,
                        AttributeLanguages = efl.AttributeLanguages,
                        AttributeRenames   = efl.AttributeRenames,
                        ClearFlag          = efl.ClearFlag,
                        EnglishLabelField  = efl.EnglishLabelField,
                        EntityRename       = efl.EntityRename,
                        IsIncluded         = !efl.IsExcluded,
                        IsGenerateMeta     = efl.IsGenerateMeta,
                        IsLookupLabels     = efl.IsLookupLabels,
                        IsOptionsetLabels  = efl.IsOptionsetLabels,
                        LogicalName        = efl.LogicalName,
                        NToN           = efl.NToN,
                        NToNReadOnly   = efl.NToNReadOnly,
                        NToNRenames    = efl.NToNRenames,
                        NToOne         = efl.NToOne,
                        NToOneFlatten  = efl.NToOneFlatten,
                        NToOneReadOnly = efl.NToOneReadOnly,
                        NToOneRenames  = efl.NToOneRenames,
                        OneToN         = efl.OneToN,
                        OneToNReadOnly = efl.OneToNReadOnly,
                        OneToNRenames  = efl.OneToNRenames,
                        ReadOnly       = efl.ReadOnly,
                        ValueClearMode = (ClearModeEnum?)efl.ValueClearMode
                    }).ToList()
                }))
            };
        }
Ejemplo n.º 11
0
        private static void SetTemplateInfo(Settings settings, bool isRetry = false)
        {
            var baseFileName = BuildBaseFileName();

            if (baseFileName.IsEmpty())
            {
                return;
            }

            try
            {
                var file = $"{baseFileName}.tt";

                if (!File.Exists(file))
                {
                    if (!isRetry)
                    {
                        Thread.Sleep(500);
                        SetTemplateInfo(settings, true);
                        return;
                    }

                    Status.Update("!! [Template] ![ERROR]! Could not find template file.");
                    return;
                }

                Status.Update($"[Template] Found template file: {file}.");
                Status.Update($"[Template] Reading content ...");

                var bytes = new byte[2000];

                using (var reader = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    reader.Seek(500, SeekOrigin.Begin);
                    reader.Read(bytes, 0, bytes.Length);
                }

                var templateInfo = TemplateHelpers.ParseTemplateInfo(Encoding.UTF8.GetString(bytes));

                if (templateInfo?.DetectedTemplateVersion.IsFilled() == true)
                {
                    settings.DetectedTemplateVersion = templateInfo.DetectedTemplateVersion;
                    Status.Update($"[Template] Template version: {settings.DetectedTemplateVersion}.");
                }
                else
                {
                    Status.Update($"!! [Template] ![ERROR]! Could not detect template version.");
                }

                if (templateInfo?.DetectedMinAppVersion.IsFilled() == true)
                {
                    settings.DetectedMinAppVersion = templateInfo.DetectedMinAppVersion;
                    Status.Update($"[Template] Minimum app version: {settings.DetectedMinAppVersion}.");
                }
                else
                {
                    Status.Update($"!! [Template] ![ERROR]! Could not detect minimum app version.");
                }
            }
            catch
            {
                Status.Update("!! [Template] ![ERROR]! Failed to detect template version.");
            }
        }