public ArchiveModuleSelectFieldsDialog()
        {
            InitializeComponent();

            _availableModules = RestAPIWrapper.GetModules();
            this.AddStandardModules();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add the standard modules to the list view.
        /// </summary>
        private void AddStandardModules()
        {
            AvailableModules allModules = RestAPIWrapper.GetModules();

            foreach (string moduleKey in this.standardModules.OrderBy(x => x))
            {
                var module = allModules.items.FirstOrDefault(x => x.module_key == moduleKey);
                if (module != null)
                {
                    this.lstViewSearchModules.Items.Add(new ListViewItem
                    {
                        Tag  = module.module_key,
                        Text = module.module_label
                    });
                }
                else
                {
                    Log.Warn($"Standard modules '{moduleKey}' was not found on the CRM system");
                }
            }
        }
Exemplo n.º 3
0
        protected void PopulateCustomModulesListView(ListView view, List <string> ignoreModules)
        {
            foreach (AvailableModule module in RestAPIWrapper.GetModules().items.OrderBy(i => i.module_key))
            {
                string moduleKey = module.module_key;
                if (!ignoreModules.Contains(moduleKey) && Properties.Settings.Default.CustomModules != null)
                {
                    ListViewItem item = new ListViewItem
                    {
                        Checked  = Properties.Settings.Default.CustomModules.Select(i => i == moduleKey).Count() > 0,
                        Text     = moduleKey,
                        Tag      = moduleKey,
                        SubItems = { module.module_label }
                    };

                    if (view.Items.Cast <ListViewItem>().Select(i => i.Text == moduleKey).Count() > 0)
                    {
                        view.Items.Add(item);
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Cache permissions for all modules, and return the value for the specified parameters.
        /// </summary>
        /// <remarks>
        /// We deliberately cache permissions for all named modules whether we're interested in them or not -
        /// it's quicker than filtering them.
        /// </remarks>
        /// <param name="moduleKey">The key of the module we're actually seeking.</param>
        /// <param name="permission">The permission we're actually seeking.</param>
        /// <returns>true if we have the access specified by permission for the module specified by this module key.</returns>
        private bool CacheAllAndCheckAccess(string moduleKey, string permission)
        {
            bool?cached;
            bool result;

            try
            {
                this.Log.Debug("Note: ");

                foreach (AvailableModule item in RestAPIWrapper.GetModules().items)
                {
                    CachePermissionsForModule(item);
                }

                cached = HasCachedAccess(moduleKey, permission);

                if (cached == null)
                {
                    /* really shouldn't happen - we've just set it! */
                    Log.Warn($"Cannot detect access {moduleKey}/{permission} despite having just set it");
                    /* not really satisfactory, but unlikely to happen */
                    result = false;
                }
                else
                {
                    result = (bool)cached;
                }
            }
            catch (Exception fetchFailed)
            {
                Log.Error($"Cannot detect access {moduleKey}/{permission} because {fetchFailed.GetType().Name}: {fetchFailed.Message}", fetchFailed);
                throw;
            }

            return(result);
        }
        /// <summary>
        /// Check whether my synchroniser is allowed access to the specified CRM module, with the specified permission.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Note that, surprisingly, although CRM will report what permissions we have, it will not
        /// enforce them, so we have to do the honourable thing and not cheat.
        /// </para>
        /// <para>
        /// Note also that the cache is locked here, not in lower level functions. The only other
        /// place the cache is locked is in PerformIteration, where the cache is flushed.
        /// </para>
        /// </remarks>
        /// <param name="moduleName">The name of the CRM module being queried.</param>
        /// <param name="permission">The permission sought.</param>
        /// <returns>true if my synchroniser is allowed access to the specified CRM module, with the specified permission.</returns>
        /// <see cref="CRMPermissionsCache{OutlookItemType}.PerformIteration"/>
        public bool HasAccess(string moduleName, string permission)
        {
            bool result = false;

            try
            {
                lock (CRMPermissionsCache.cacheLock)
                {
                    bool?cached = HasCachedAccess(moduleName, permission);

                    if (cached != null)
                    {
                        result = (bool)cached;
                        this.Log.Debug($"Permissions cache hit for {moduleName}/{permission}");
                    }
                    else
                    {
                        this.Log.Debug($"Permissions cache miss for {moduleName}/{permission}");
                        try
                        {
                            this.Log.Debug("Note: we deliberately cache permissions for all named modules whether we're interested in them or not - it's quicker than filtering them");

                            foreach (AvailableModule item in RestAPIWrapper.GetModules().items)
                            {
                                if (!string.IsNullOrWhiteSpace(item.module_key))
                                {
                                    CacheAccessPermission(
                                        item.module_key,
                                        ImportPermissionToken,
                                        item.module_acls1.FirstOrDefault(b => b.action == ImportPermissionToken)?.access ?? false);
                                    CacheAccessPermission(
                                        item.module_key,
                                        ExportPermissionToken,
                                        item.module_acls1.FirstOrDefault(b => b.action == ExportPermissionToken)?.access ?? false);

                                    try
                                    {
                                        Log.Debug($"Cached {CRMPermissionsCache.cache[item.module_key]} permission for {item.module_key}");
                                    }
                                    catch (KeyNotFoundException)
                                    {
                                        // ignore for now.
                                    }
                                }
                            }

                            cached = HasCachedAccess(moduleName, permission);

                            if (cached == null)
                            {
                                /* really shouldn't happen - we've just set it! */
                                Log.Warn($"Cannot detect access {moduleName}/{permission} despite having just set it");
                                /* not really satisfactory, but unlikely to happen */
                                result = false;
                            }
                            else
                            {
                                result = (bool)cached;
                            }
                        }
                        catch (Exception fetchFailed)
                        {
                            Log.Error($"Cannot detect access {moduleName}/{permission} because {fetchFailed.GetType().Name}: {fetchFailed.Message}", fetchFailed);
                            throw;
                        }
                    }
                }

                return(result);
            }
            catch (KeyNotFoundException knf)
            {
                // OK, this is impossible. But it IS happening... why?
                Log.Error($"Key not found exception while seeking '{moduleName}'", knf);
                return(result);
            }
        }