Example #1
0
        /// <summary>
        /// Обновить запись
        /// </summary>
        /// <param name="id">Идентификатор записи в CRM</param>
        /// <param name="name">Наименование веб-ресурса</param>
        /// <param name="filePath">Путь до файла</param>
        /// <param name="type">Тип веб-ресурса</param>
        public void Update(Guid id, string name, string filePath, WebResourceType type = WebResourceType.Auto)
        {
            var record = CreateRecord(name, filePath, type);

            record.Id = id;
            OrganizationService.Update(record);
        }
Example #2
0
 public WebResourceDescriptor(WebResourceGroup group, WebResourceType type)
 {
     Name = group.Name;
     Version = String.IsNullOrEmpty(group.Version) ? "none" : group.Version;
     Compressed = group.Compressed;
     ResourceType = type;
 }
Example #3
0
        private Entity CreateRecord(string name, string filePath, WebResourceType type)
        {
            Map extMap = null;

            if (type == WebResourceType.Auto)
            {
                var extension = Path.GetExtension(filePath);

                extMap = WebresourceMapper.Instance.Items.FirstOrDefault(i => i.Extension == extension?.Remove(0, 1).ToLower());
                if (extMap != null)
                {
                    type = extMap.Type;
                }
            }

            var record = new Entity("webresource")
            {
                ["name"]            = name,
                ["webresourcetype"] = new OptionSetValue((int)type),
            };

            if (filePath != null && File.Exists(filePath))
            {
                record["content"] = Convert.ToBase64String(File.ReadAllBytes(filePath));
            }

            var map = extMap ?? WebresourceMapper.Instance.Items.FirstOrDefault(i => i.CrmValue == (int)type);

            if (map != null)
            {
                record.FormattedValues["webresourcetype"] = map.Label;
            }
            return(record);
        }
Example #4
0
 public Map(string extension, WebResourceType type, int crmValue, string label)
 {
     Extension = extension;
     Type      = type;
     CrmValue  = crmValue;
     Label     = label;
 }
 public PerformanceResourceKey(WebResourceType resourceType, string resourceName)
 {
     if (string.IsNullOrEmpty(resourceName))
     {
         throw new ArgumentNullException(nameof(resourceName));
     }
     this.ResourceType = resourceType;
     this.ResourceName = resourceName;
 }
Example #6
0
        private void EnsureWebResourceRegistration(string path, WebResourceType wrType)
        {
            var wrUrl             = this.Page.ClientScript.GetWebResourceUrl(this.GetType(), path);
            var alreadyRegistered = this.Page.Header.Controls.OfType <HtmlGenericControl>().Any(x => x.InnerText == "apo-demand-commons.js");

            if (!alreadyRegistered && wrType == WebResourceType.ScriptJavascript)
            {
                HtmlGenericControl include = new HtmlGenericControl("script");
                include.Attributes.Add("src", wrUrl);
                include.InnerText = "apo-demand-commons.js";
                include.Attributes.Add("type", "text/javascript");
                this.Page.Header.Controls.Add(include);
            }
        }
Example #7
0
        /// <summary>
        /// Get specified resource type.
        /// </summary>
        /// <param name="resourceTypeIdentifier">Resource type identifier.</param>
        /// <param name="localeId">Locale id.</param>
        /// <returns>Resource type.</returns>
        public static WebResourceType GetResourceType(ResourceTypeIdentifier resourceTypeIdentifier,
                                                      Int32 localeId)
        {
            WebResourceType resourceType;

            resourceType            = new WebResourceType();
            resourceType.Id         = (Int32)(resourceTypeIdentifier);
            resourceType.Identifier = resourceTypeIdentifier.ToString();
            switch (localeId)
            {
            case ((Int32)LocaleId.sv_SE):
                switch (resourceTypeIdentifier)
                {
                case ResourceTypeIdentifier.Database:
                    resourceType.Name = Settings.Default.ResourceTypeDatabaseSwedishName;
                    break;

                case ResourceTypeIdentifier.WebService:
                    resourceType.Name = Settings.Default.ResourceTypeWebServiceSwedishName;
                    break;

                default:
                    throw new ArgumentException("Not supported resource type = " + resourceTypeIdentifier);
                }
                break;

            default:
                // English is default and also returned if not
                // supported language is requested.
                switch (resourceTypeIdentifier)
                {
                case ResourceTypeIdentifier.Database:
                    resourceType.Name = Settings.Default.ResourceTypeDatabaseEnglishName;
                    break;

                case ResourceTypeIdentifier.WebService:
                    resourceType.Name = Settings.Default.ResourceTypeWebServiceEnglishName;
                    break;

                default:
                    throw new ArgumentException("Not supported resource type = " + resourceTypeIdentifier);
                }
                break;
            }

            return(resourceType);
        }
Example #8
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            //No bound file - nothing to compare to
            if (string.IsNullOrEmpty(values[0]?.ToString()))
            {
                return(false);
            }

            bool hasType = Int32.TryParse(values[1].ToString(), out int type);

            if (!hasType)
            {
                return(false);
            }

            WebResourceType webResourceType = WebResourceTypes.Types.FirstOrDefault(t => t.Type == type);

            return(webResourceType != null && webResourceType.AllowCompare);
        }
Example #9
0
        private void EnsureWebResourceRegistration(string path, WebResourceType wrType, string resourceName)
        {
            var wrUrl = this.Page.ClientScript.GetWebResourceUrl(this.GetType().BaseType, path);
            // Check if it script is already registered
            var alreadyRegistered = this.Page.Header.Controls.OfType <HtmlGenericControl>().Any(x => x.InnerText == resourceName);

            if (!alreadyRegistered)
            {
                switch (wrType)
                {
                case WebResourceType.ScriptJavascript:
                    EnsureJavascriptRegistration(wrUrl, resourceName);
                    break;

                case WebResourceType.ScriptTextTemplate:
                    EnsureHtmlTextTemplateRegistration(path);
                    break;
                }
            }
        }
Example #10
0
        /// <summary>
        /// Обновить или создать запись
        /// </summary>
        /// <param name="name">Наименование веб-ресурса</param>
        /// <param name="filePath">Путь до файла</param>
        /// <param name="type">Тип веб-ресурса</param>
        public Entity CreateOrUpdate(string name, string filePath, WebResourceType type = WebResourceType.Auto)
        {
            var idRecord = RetrieveWebresource(name);
            var record   = CreateRecord(name, filePath, type);

            if (idRecord?.Id != null)
            {
                record.Id = idRecord.Id;
            }

            var upsertReq = new UpsertRequest
            {
                Target = record
            };

            var ret = OrganizationService.Execute(upsertReq) as UpsertResponse;

            record.Id = ret?.Target.Id ?? Guid.Empty;
            return(record);
        }
Example #11
0
        /// <summary>
        /// Initializes a new instance of class WebResourcePicker
        /// </summary>
        /// <param name="type">Type of web resource to select</param>
        public WebResourcePicker(WebResourceType type, List<Entity> webResourcesImageCache, List<Entity> webResourcesHtmlCache, IOrganizationService service)
        {
            InitializeComponent();

            this.webResourcesImageCache = webResourcesImageCache;
            this.webResourcesHtmlCache = webResourcesHtmlCache;
            this.service = service;

            requestedType = (int)type;

            // Disables controls
            ListViewDelegates.SetEnableState(lstWebResources, false);
            CommonDelegates.SetEnableState(btnWebResourcePickerCancel, false);
            CommonDelegates.SetEnableState(btnWebResourcePickerValidate, false);
            CommonDelegates.SetEnableState(btnNewResource, false);

            // Run work
            var worker = new BackgroundWorker();
            worker.DoWork += worker_DoWork;
            worker.RunWorkerCompleted += worker_RunWorkerCompleted;
            worker.RunWorkerAsync();
        }
Example #12
0
        /// <summary>
        /// Initializes a new instance of class WebResourcePicker
        /// </summary>
        /// <param name="type">Type of web resource to select</param>
        public WebResourcePicker(WebResourceType type, List <Entity> webResourcesImageCache, List <Entity> webResourcesHtmlCache, IOrganizationService service)
        {
            InitializeComponent();

            this.webResourcesImageCache = webResourcesImageCache;
            this.webResourcesHtmlCache  = webResourcesHtmlCache;
            this.service = service;

            requestedType = (int)type;

            // Disables controls
            ListViewDelegates.SetEnableState(lstWebResources, false);
            CommonDelegates.SetEnableState(btnWebResourcePickerCancel, false);
            CommonDelegates.SetEnableState(btnWebResourcePickerValidate, false);
            CommonDelegates.SetEnableState(btnNewResource, false);

            // Run work
            var worker = new BackgroundWorker();

            worker.DoWork             += worker_DoWork;
            worker.RunWorkerCompleted += worker_RunWorkerCompleted;
            worker.RunWorkerAsync();
        }
 public CreateWebResourceDialog(WebResourceType type, IOrganizationService service)
 {
     InitializeComponent();
     this.service = service;
     requiredType = (int)type;
 }
 public CreateWebResourceDialog(WebResourceType type, IOrganizationService service)
 {
     InitializeComponent();
     this.service = service;
     requiredType = (int)type;
 }