Beispiel #1
0
        /// <summary>
        /// Поиск веб-ресурсов по именам.
        /// </summary>
        /// <param name="extension"></param>
        /// <param name="names"></param>
        /// <returns></returns>
        public Dictionary <string, WebResource> FindMultiple(string extension, string[] names, ColumnSet columnSet = null)
        {
            extension = extension.ToLower();

            if (!Types.ContainsKey(extension))
            {
                throw new Exception("File Extension " + extension + " is not allowed");
            }

            var type = Types[extension];

            var list = new List <string>();

            foreach (var item in names)
            {
                list.AddRange(WebResourceRepository.GetSplitedNames(item, extension));
            }

            var webResourceCollection = SearchByName(type, list.ToArray(), columnSet);

            Dictionary <string, WebResource> result = new Dictionary <string, WebResource>(StringComparer.InvariantCultureIgnoreCase);

            foreach (var ent in webResourceCollection)
            {
                result.Add(ent.Name.ToLower(), ent);
            }

            return(result);
        }
        public static string GetWebResourceFileName(WebResource webResource)
        {
            string extension = WebResourceRepository.GetTypeMainExtension(webResource.WebResourceType.Value);

            var allExtensions = WebResourceRepository.GetTypeAllExtensions(webResource.WebResourceType.Value);

            string webResourceFileName = Path.GetFileName(webResource.Name);

            webResourceFileName = FileOperations.RemoveWrongSymbols(webResourceFileName);

            webResourceFileName = CheckExtension(webResourceFileName, extension, allExtensions);

            return(webResourceFileName);
        }
        private Guid CreateNewWebResource(string name, string displayName, string description, string extension, string solutionUniqueName)
        {
            WebResource webResource = new WebResource()
            {
                LogicalName = WebResource.EntityLogicalName,
                Attributes  =
                {
                    { WebResource.Schema.Attributes.displayname,     displayName                                                             },
                    { WebResource.Schema.Attributes.name,            name                                                                    },
                    { WebResource.Schema.Attributes.webresourcetype, new OptionSetValue(WebResourceRepository.GetTypeByExtension(extension)) }
                }
            };

            if (!string.IsNullOrEmpty(description))
            {
                webResource.Attributes.Add(WebResource.Schema.Attributes.description, description);
            }


            CreateRequest request = new CreateRequest()
            {
                Target = webResource
            };

            request.Parameters.Add("SolutionUniqueName", solutionUniqueName);
            CreateResponse response = (CreateResponse)_service.Execute(request);

            return(response.id);
        }
Beispiel #4
0
        private async Task StartGettingWebResources()
        {
            try
            {
                var service = await GetServiceAsync();

                if (service == null)
                {
                    return;
                }

                {
                    var repository = new WebResourceRepository(service);

                    {
                        var listWebResources = await repository.GetListByTypesAsync(
                            new[] { (int)WebResource.Schema.OptionSets.webresourcetype.Webpage_HTML_1 }
                            , new ColumnSet
                            (
                                WebResource.Schema.Attributes.displayname
                                , WebResource.Schema.Attributes.name
                                , WebResource.Schema.Attributes.description
                            )
                            );

                        _WebResourceIntellisenseData.LoadWebResources(listWebResources, _WebResourceIntellisenseData.WebResourcesHtml);

                        _WebResourceIntellisenseData.NextLoadFileDate = DateTime.Now.AddMinutes(_loadPeriodInMinutes);
                    }

                    {
                        var listWebResources = await repository.GetListByTypesAsync(
                            new[] { (int)WebResource.Schema.OptionSets.webresourcetype.Script_JScript_3 }
                            , new ColumnSet
                            (
                                WebResource.Schema.Attributes.displayname
                                , WebResource.Schema.Attributes.name
                                , WebResource.Schema.Attributes.description
                            )
                            );

                        _WebResourceIntellisenseData.LoadWebResources(listWebResources, _WebResourceIntellisenseData.WebResourcesJavaScript);

                        _WebResourceIntellisenseData.NextLoadFileDate = DateTime.Now.AddMinutes(_loadPeriodInMinutes);
                    }

                    {
                        var listWebResources = await repository.GetListByTypesAsync(
                            new[]
                        {
                            (int)WebResource.Schema.OptionSets.webresourcetype.PNG_format_5
                            , (int)WebResource.Schema.OptionSets.webresourcetype.JPG_format_6
                            , (int)WebResource.Schema.OptionSets.webresourcetype.GIF_format_7
                            , (int)WebResource.Schema.OptionSets.webresourcetype.ICO_format_10
                            , (int)WebResource.Schema.OptionSets.webresourcetype.Vector_format_SVG_11
                        }
                            , new ColumnSet
                            (
                                WebResource.Schema.Attributes.displayname
                                , WebResource.Schema.Attributes.name
                                , WebResource.Schema.Attributes.webresourcetype
                                , WebResource.Schema.Attributes.content
                                , WebResource.Schema.Attributes.description
                            )
                            );

                        _WebResourceIntellisenseData.LoadWebResources(listWebResources, _WebResourceIntellisenseData.WebResourcesIcon);

                        _WebResourceIntellisenseData.NextLoadFileDate = DateTime.Now.AddMinutes(_loadPeriodInMinutes);
                    }
                }
            }
            catch (Exception ex)
            {
                DTEHelper.WriteExceptionToLog(ex);
            }
            finally
            {
                lock (_syncObjectTaskGettingWebResources)
                {
                    _taskGettingWebResources = null;
                }
            }
        }
Beispiel #5
0
        private async Task StartGettingWebResources()
        {
            try
            {
                var service = await GetServiceAsync();

                if (service == null)
                {
                    return;
                }

                var repository = new WebResourceRepository(service);

                {
                    var listWebResources = await repository.GetListAllAsync(
                        null
                        , new ColumnSet
                        (
                            WebResource.Schema.Attributes.name
                            , WebResource.Schema.Attributes.displayname
                            , WebResource.Schema.Attributes.description
                            , WebResource.Schema.Attributes.webresourcetype
                            , WebResource.Schema.Attributes.languagecode
                        )
                        );

                    LoadWebResources(listWebResources, _connectionData.WebResourceIntellisenseData.WebResourcesAll);
                }

                this._nextLoadFromCrmDate = DateTime.Now.AddSeconds(_loadPeriodInSeconds);

                _connectionData.WebResourceIntellisenseData.Save();

                {
                    var listWebResources = await repository.GetListByTypesAsync(
                        new[]
                    {
                        (int)WebResource.Schema.OptionSets.webresourcetype.PNG_format_5
                        , (int)WebResource.Schema.OptionSets.webresourcetype.JPG_format_6
                        , (int)WebResource.Schema.OptionSets.webresourcetype.GIF_format_7
                        , (int)WebResource.Schema.OptionSets.webresourcetype.ICO_format_10
                        , (int)WebResource.Schema.OptionSets.webresourcetype.Vector_format_SVG_11
                    }
                        , new ColumnSet
                        (
                            WebResource.Schema.Attributes.name
                            , WebResource.Schema.Attributes.displayname
                            , WebResource.Schema.Attributes.description
                            , WebResource.Schema.Attributes.webresourcetype
                            , WebResource.Schema.Attributes.languagecode
                            , WebResource.Schema.Attributes.content
                        )
                        );

                    LoadWebResources(listWebResources, _webResourcesIcon);
                }
            }
            catch (Exception ex)
            {
                DTEHelper.WriteExceptionToLog(ex);
            }
            finally
            {
                lock (_syncObjectTaskGettingWebResources)
                {
                    _taskGettingWebResources = null;
                }
            }
        }