Ejemplo n.º 1
0
        private static void CreateXml(string fileName, WebResource webResource, Action <string> trace)
        {
            try
            {
                var dir = Path.GetDirectoryName(fileName);
                if (string.IsNullOrWhiteSpace(dir))
                {
                    trace($"Не указана папка для файла : {fileName}");
                    return;
                }
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }

                var xns = new XmlSerializerNamespaces();
                xns.Add(string.Empty, string.Empty);

                var formatter = new XmlSerializer(typeof(WebResource));

                using (var fs = new StreamWriter(fileName, false, new UTF8Encoding()))
                {
                    formatter.Serialize(fs, webResource, xns);
                }
            }
            catch (Exception e)
            {
                trace($"CreateXml error : {e}");
            }
        }
Ejemplo n.º 2
0
        private static async Task CreateFileIfNotFound(string filePath, string webResInCrmSolFolder,
                                                       string filePathInCrmSolFolder, string webResourceType, Action <string> trace)
        {
            var isExistInRepo = IsExist(filePathInCrmSolFolder, trace);

            if (isExistInRepo == null)
            {
                trace($"Не удалось проверить наличие файла {filePathInCrmSolFolder}.");
                return;
            }

            if (isExistInRepo.Value)
            {
                trace($"Файл уже существует {filePathInCrmSolFolder}.");
                return;
            }

            var isExistInCrm = await IsExistInCrm(filePath, trace);

            if (isExistInCrm == null)
            {
                trace("Не удалось подключиться к CRM.");
                return;
            }

            WebResource resource;

            if (isExistInCrm.Value)
            {
                resource = await GetWebResource(filePath, trace);

                if (resource == null)
                {
                    trace($"Не удалось получить файл из CRM {filePath}.");
                    return;
                }

                var id = resource.WebResourceId;
                resource.FileName      = $"/WebResources/{resource.Name.Replace("/", "").Replace(".", "")}{id.ToUpper()}";
                resource.WebResourceId = $"{{{id}}}";
            }
            else
            {
                var id    = Guid.NewGuid();
                var strId = id.ToString();
                var name  = filePath;

                resource = new WebResource
                {
                    WebResourceId               = $"{{{strId}}}",
                    Name                        = name,
                    FileName                    = $"/WebResources/{name.Replace("/", "").Replace(".", "")}{strId.ToUpper()}",
                    WebResourceType             = webResourceType,
                    IntroducedVersion           = "1.0",
                    IsEnabledForMobileClient    = 0,
                    IsAvailableForMobileOffline = 0,
                    IsCustomizable              = 1,
                    CanBeDeleted                = 1,
                    IsHidden                    = 0,
                };
            }

            CreateXml(filePathInCrmSolFolder, resource, trace);
            AddToSolution($"{webResInCrmSolFolder}/Other/Solution.xml", filePath, trace);
        }