コード例 #1
0
        public static async Task <bool> Check(ExternalResource externalResource)
        {
            var password = await KeyvaultHelper.Get(externalResource.Keyvault);

            ConnectionInfo ConnNfo = new ConnectionInfo(externalResource.Host, externalResource.Port, externalResource.Username,
                                                        new AuthenticationMethod[] {
                // Pasword based Authentication
                new PasswordAuthenticationMethod(externalResource.Username, password)
            }
                                                        );

            bool isSuccess = false;

            using (var sshclient = new SshClient(ConnNfo))
            {
                sshclient.Connect();
                if (sshclient.IsConnected)
                {
                    isSuccess = true;
                }
                sshclient.Disconnect();
            }

            return(isSuccess);
        }
コード例 #2
0
        public List <ObjectRelation> GetExternalRelations(Guid objectXId, byte DestinationObjectType)
        {
            List <ObjectRelation> objectRelations = new List <ObjectRelation>();

            var relations = GetRelations(objectXId, ConstObjectType.ExternalResource);

            foreach (var item in relations)
            {
                if (DestinationObjectType == 0)
                {
                    objectRelations.Add(item);
                }
                else
                {
                    if (item.RouteDestinationType == DestinationObjectType)
                    {
                        objectRelations.Add(item);
                    }
                    else
                    {
                        ExternalResource resource = SiteDb.ExternalResource.Get(item.objectYId);
                        if (resource != null && resource.DestinationObjectType == DestinationObjectType)
                        {
                            objectRelations.Add(item);
                        }
                    }
                }
            }

            return(objectRelations);
        }
コード例 #3
0
        public ExternalResource GetFileContent(List <ExternalColumnComparer <String, Int32> > columns, dtoCsvSettings settings, dtoCSVfile file)
        {
            CsvFile          csvFile = ContentOf.LoadCsvFile(file.RealName, settings);
            ExternalResource result  = new ExternalResource(columns, csvFile);

            return(result);
        }
コード例 #4
0
        public static async Task <bool> Check(ExternalResource externalResource)
        {
            bool isSuccess  = false;
            var  uriBuilder = new UriBuilder($"{externalResource.Host}:{externalResource.Port}{externalResource.Path}");
            var  uri        = uriBuilder.Uri;

            using (var client = new HttpClient(new HttpClientHandler()
            {
                AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip
            }))
            {
                var request = new HttpRequestMessage()
                {
                    RequestUri = uri,
                    Method     = HttpMethod.Post
                };

                request.Content = new StringContent(externalResource.Payload, Encoding.UTF8, "text/xml");

                request.Headers.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/xml"));
                request.Content.Headers.ContentType = new MediaTypeHeaderValue("text/xml");
                request.Headers.Add("SOAPAction", "");

                HttpResponseMessage response = client.SendAsync(request).Result;

                isSuccess = true;
            }

            return(isSuccess);
        }
コード例 #5
0
        private void DoCheck(RenderContext context, ExternalResource resource)
        {
            var fullUrl = resource.FullUrl;

            string header  = Hardcoded.GetValue("Missing link", context);
            var    message = String.Format("<a href=\"{0}\" target=\"_blank\">{0}</a>", fullUrl);

            try
            {
                HttpWebResponse response = DownloadHelper.RequestHeader(new Uri(fullUrl));

                if (!IsEnableStatusCode(response.StatusCode))
                {
                    session.AddMessage(header, message, MessageType.Critical);
                }
            }
            catch (Exception ex)
            {
                try
                {
                    HttpWebResponse response = DownloadHelper.RequestGet(fullUrl);
                    if (!IsEnableStatusCode(response.StatusCode))
                    {
                        session.AddMessage(header, message, MessageType.Critical);
                    }
                }
                catch (Exception)
                {
                    session.AddMessage(header, message, MessageType.Critical);
                }
            }
        }
コード例 #6
0
        public async Task <IActionResult> PutExternalResource([FromRoute] int id, [FromBody] ExternalResource externalResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != externalResource.Id)
            {
                return(BadRequest());
            }

            _context.Entry(externalResource).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ExternalResourceExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #7
0
        private async Task <bool> checkResourceHealth(ExternalResource externalResource)
        {
            if (string.IsNullOrEmpty(externalResource.Type))
            {
                throw new ArgumentNullException("Resource type is required");
            }

            var type = externalResource.Type.ToLower();

            switch (type)
            {
            case "ftp":
            case "ftps":
                return(await FtpConnectHandler.Check(externalResource));

            case "sftp":
                return(await SFtpConnectHandler.Check(externalResource));

            case "api":
                return(await ApiConnectHandler.Check(externalResource));

            case "soap":
                return(await SoapConnectHandler.Check(externalResource));

            default:
                throw new NotImplementedException();
            }
        }
コード例 #8
0
        /// <summary>
        /// Loads the specified resource
        /// </summary>
        /// <param name="resource">The external resource to load</param>
        /// <param name="client">The WebClient object used to fetch the XAP</param>
        private void FetchXap(ExternalResource resource, WebClient client)
        {
            _assemblies.Add(client, Path.GetFileNameWithoutExtension(resource.Path));
            _typeNames.Add(client, resource.Assembly);

            client.OpenReadAsync(new Uri(resource.Path, UriKind.RelativeOrAbsolute));
        }
コード例 #9
0
        public bool SaveReference(SaveExternalResourceInputDto inputDTO)
        {
            ExternalResource er = null;

            if (inputDTO.ID > 0)
            {
                er = this.externalResourceRepository.FindBy(x => x.ID == inputDTO.ID).FirstOrDefault();
            }

            if (er == null)
            {
                er    = new ExternalResource();
                er.ID = 0;
            }

            er.TopicID     = inputDTO.TopicID;
            er.Title       = inputDTO.Title;
            er.URL         = inputDTO.URL;
            er.Type        = inputDTO.Type;
            er.Description = inputDTO.Description;

            if (inputDTO.ID == 0)
            {
                this.externalResourceRepository.Add(er);
            }
            else
            {
                this.externalResourceRepository.Update(er);
            }

            this.unitOfWork.Commit();

            return(true);
        }
コード例 #10
0
 private string GetFormatedSkipReason(ExternalResource resource, string detail)
 {
     return("Disabled due to CI failure." +
            "This test required access " + resource.ToString() + " in runner agent machine." +
            Environment.NewLine +
            "Skip Detail:" +
            detail);
 }
コード例 #11
0
        /// <summary>
        /// Asyncronously loads the XAP file at the specified URI
        /// </summary>
        /// <param name="resource">URI to the XAP file for which to load</param>
        /// <param name="typeName">Specifies the type name to load</param>
        public void BeginLoadXap(ExternalResource resource)
        {
            WebClient client = new WebClient();

            // Wire up the OpenReadCompleted event handler
            client.OpenReadCompleted += OpenReadCompletedRaiseEvent;

            FetchXap(resource, client);
        }
コード例 #12
0
        public bool DeleteReference(int ID)
        {
            ExternalResource er = this.externalResourceRepository.FindBy(x => x.ID == ID).FirstOrDefault();

            if (er != null)
            {
                this.externalResourceRepository.Delete(er);
                this.unitOfWork.Commit();
                return(true);
            }
            return(false);
        }
コード例 #13
0
        public async Task <IActionResult> PostExternalResource([FromBody] ExternalResource externalResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.ExternalResources.Add(externalResource);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetExternalResource", new { id = externalResource.Id }, externalResource));
        }
コード例 #14
0
 public void AnalyzeItems(ExternalResource source, List <ExternalColumnComparer <String, Int32> > noDBfields, List <Int32> notEmptyColumns, List <Int32> notDuplicatedColumns)
 {
     if (noDBfields.Count > 0)
     {
         foreach (ExternalColumnComparer <String, Int32> field in noDBfields)
         {
             List <ExternalCell> invalidItems = View.ValidateDBItems(field.DestinationColumn, source.GetColumnCells(field.DestinationColumn.InputType, field.Number));
             invalidItems.ForEach(i => i.isDBduplicate = true);
         }
     }
     source.ValidateSourceData(notEmptyColumns, notDuplicatedColumns);
 }
コード例 #15
0
        public void ValidateSourceData(ExternalResource source, List <ExternalColumnComparer <String, Int32> > notEmptyColumns, List <ExternalColumnComparer <String, Int32> > notDuplicatedColumns)
        {
            List <Int32> notEmptyCol = notEmptyColumns.Where(f => !f.DestinationColumn.HasAlternative).Select(f => f.Number).ToList();

            source.ColumHeader.Where(c => notEmptyCol.Contains(c.Number)).ToList().ForEach(c => c.AllowEmpty = false);


            //source.ColumHeader.Where(c => notDuplicatedColumns.Where(f => f.DestinationColumn.Mandatory && !f.DestinationColumn.HasAlternative).Select(f => f.Number).ToList().Contains(c.Number)).ToList().ForEach(c => c.AllowEmpty = false);
            List <Int32> notDupCol = notDuplicatedColumns.Where(f => f.DestinationColumn.Mandatory && !f.DestinationColumn.HasAlternative).Select(f => f.Number).ToList();

            source.ColumHeader.Where(c => notDupCol.Contains(c.Number)).ToList().ForEach(c => c.AllowDuplicate = false);
            foreach (ExternalColumn col in source.ColumHeader.Where(c => notEmptyCol.Contains(c.Number) || notDupCol.Contains(c.Number)).ToList())
            {
                List <ExternalCell> cells = source.GetDuplicatedCells(col.InputType, col.Number);
                if (cells != null && cells.Count > 0)
                {
                    cells.ForEach(c => c.SetDuplicatedRows(cells.Where(cc => cc != c).Select(cr => cr.Row.Number).ToList()));
                }
            }
            source.Rows.ForEach(r => r.AllowImport = r.isValid());

            // verifica alternative !

            List <ExternalColumn> colEmpty = source.ColumHeader.Where(c => notEmptyColumns.Where(f => f.DestinationColumn.Mandatory && f.DestinationColumn.HasAlternative).Select(f => f.Number).ToList().Contains(c.Number)).ToList();

            //  List<ExternalColumn> colDuplicate = source.ColumHeader.Where(c => notDuplicatedColumns.Where(f => f.DestinationColumn.Mandatory && f.DestinationColumn.HasAlternative).Select(f => f.Number).ToList().Contains(c.Number)).ToList();


            foreach (ExternalColumn col in source.ColumHeader.Where(c => notEmptyColumns.Where(f => f.DestinationColumn.Mandatory && f.DestinationColumn.HasAlternative).Select(f => f.Number).ToList().Contains(c.Number)).ToList())
            {
                List <ExternalCell> cells = source.GetDuplicatedCells(col.InputType, col.Number);
                if (cells != null && cells.Count > 0)
                {
                    cells.ForEach(c => c.SetDuplicatedRows(cells.Where(cc => cc != c).Select(cr => cr.Row.Number).ToList()));
                }
            }
            source.Rows.ForEach(r => r.AllowImport = r.isValid());
            if (colEmpty.Any())
            {
                foreach (ExternalRow row in source.Rows)
                {
                    List <ExternalCell> cells = row.Cells.Where(c => colEmpty.Where(ce => ce.Number == c.Column.Number).Any()).ToList();
                    row.AllowImport = row.AllowImport && cells.Where(c => !c.isEmpty).Any();
                }
            }


            //foreach (ExternalRow row in Rows)
            //{
            //    row.AllowImport = row.isValid();
            //}
        }
コード例 #16
0
        public static async Task <bool> Check(ExternalResource externalResource)
        {
            var authType = externalResource.AuthenType?.ToLower();

            switch (authType)
            {
            case "oauth2":
                return(await oauth2Connect(externalResource));

            case "basic":
                return(await basicAuthConnect(externalResource));

            default:
                return(await connect(externalResource));
            }
        }
コード例 #17
0
        public void InitView(ExternalResource source, List <ExternalColumnComparer <String, Int32> > noDBfields, List <Int32> notEmptyColumns, List <Int32> notDuplicatedColumns)
        {
            if (UserContext.isAnonymous)
            {
                View.DisplaySessionTimeout();
            }
            else
            {
                View.Columns = source.ColumHeader;
                AnalyzeItems(source, noDBfields, notEmptyColumns, notDuplicatedColumns);
                List <ExternalResource> items = new List <ExternalResource>();
                items.Add(source);

                View.LoadItems(items, GetInvalidItems(source));
            }
        }
コード例 #18
0
        private static async Task <bool> oauth2Connect(ExternalResource rs)
        {
            string clientSecrect = await KeyvaultHelper.Get(rs.Keyvault);

            string accessTokenKey = (rs.CustAccessTokenField != null) ? rs.CustAccessTokenField : "access_token";

            var pairs = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("grant_type", "client_credentials"),
                new KeyValuePair <string, string>("client_id", rs.Username),
                new KeyValuePair <string, string> ("client_secret", clientSecrect),
                new KeyValuePair <string, string> ("scope", rs.Scope)
            };
            var    content = new FormUrlEncodedContent(pairs);
            string token   = string.Empty;

            using (var client = new HttpClient())
            {
                var response = await client.PostAsync(rs.IdentityEndpoint, content);

                var resContent = await response.Content.ReadAsStringAsync();

                JObject jobj = JObject.Parse(resContent);
                token = (string)jobj[accessTokenKey];
            }

            if (string.IsNullOrEmpty(token))
            {
                throw new Exception("Cannot get a token");
            }

            var uriBuilder = new UriBuilder($"{rs.Host}:{rs.Port}{rs.Path}");
            var uri        = uriBuilder.Uri;

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
                var result = await client.GetAsync(uri);

                if (result.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #19
0
        private List <InvalidImport> GetInvalidItems(ExternalResource source)
        {
            List <InvalidImport> invalidItems = new List <InvalidImport>();

            if (source.Rows.Where(r => r.isValid() == false).Any())
            {
                invalidItems.Add(InvalidImport.InvalidData);
            }
            if (source.Rows.Where(r => r.HasDuplicatedValues).Any())
            {
                invalidItems.Add(InvalidImport.SourceDuplicatedData);
            }
            if (source.Rows.Where(r => r.HasDBDuplicatedValues).Any())
            {
                invalidItems.Add(InvalidImport.AlreadyExist);
            }
            return(invalidItems);
        }
コード例 #20
0
        private static async Task <bool> connect(ExternalResource rs)
        {
            var isSuccess = false;

            var uriBuilder = new UriBuilder($"{rs.Host}:{rs.Port}{rs.Path}");
            var uri        = uriBuilder.Uri;

            using (var client = new HttpClient())
            {
                var result = await client.GetAsync(uri);

                if (result.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    return(true);
                }
            }

            return(isSuccess);
        }
コード例 #21
0
        private static ExternalResource GetGoogleResources(string accessToken, HttpClient client)
        {
            client.BaseAddress = new Uri("https://www.googleapis.com");

            // New code:
            HttpResponseMessage response = client.GetAsync("oauth2/v2/userinfo?access_token=" + accessToken).Result;

            if (response.IsSuccessStatusCode)
            {
                Stream stream = response.Content.ReadAsStreamAsync().Result;
                DataContractJsonSerializer ser     = new DataContractJsonSerializer(typeof(GoogleResource));
                GoogleResource             profile = (GoogleResource)ser.ReadObject(stream);
                var res = new ExternalResource {
                    email = profile.email, first_name = profile.given_name, last_name = profile.family_name, picture = profile.picture, name = profile.name, id = profile.id, link = profile.link
                };
                return(res);
            }
            return(null);
        }
コード例 #22
0
 public void AnalyzeItems(ExternalResource source, List <ExternalColumnComparer <String, Int32> > DBvalidateFields, List <ExternalColumnComparer <String, Int32> > notEmptyColumns, List <ExternalColumnComparer <String, Int32> > notDuplicatedColumns)
 {
     if (DBvalidateFields.Count > 0)
     {
         List <Int32> validatedItems = new List <Int32>();
         foreach (ExternalColumnComparer <String, Int32> dbValidate in DBvalidateFields)
         {
             List <ExternalCell> invalidItems = null;
             //if (fields.Where(f=> dbValidate.DestinationColumn.Id == f.Id && f.HasAlternative))
             if (dbValidate.DestinationColumn.HasAlternative && !validatedItems.Contains(dbValidate.DestinationColumn.Id))
             {
                 List <DestinationItemCells <Int32> > items = new List <DestinationItemCells <Int32> >();
                 items.Add(new DestinationItemCells <Int32>(dbValidate.DestinationColumn)
                 {
                     Cells = source.GetColumnCells(dbValidate.DestinationColumn.InputType, dbValidate.Number)
                 });
                 foreach (Int32 index in dbValidate.DestinationColumn.AlternativeAttributes)
                 {
                     if (DBvalidateFields.Where(f => f.DestinationColumn.Id == index).Any())
                     {
                         items.Add(new DestinationItemCells <Int32>(DBvalidateFields.Where(f => f.DestinationColumn.Id == index).Select(f => f.DestinationColumn).FirstOrDefault())
                         {
                             Cells = source.GetColumnCells(DBvalidateFields.Where(f => f.DestinationColumn.Id == index).Select(f => f.DestinationColumn).FirstOrDefault().InputType, DBvalidateFields.Where(f => f.DestinationColumn.Id == index).Select(f => f.Number).FirstOrDefault())
                         });
                     }
                 }
                 validatedItems.Add(dbValidate.DestinationColumn.Id);
                 validatedItems.AddRange(dbValidate.DestinationColumn.AlternativeAttributes);
                 invalidItems = View.ValidateAlternateDBItems(items);
                 invalidItems.ForEach(i => i.isDBduplicate = true);
             }
             else if (!validatedItems.Contains(dbValidate.DestinationColumn.Id))
             {
                 invalidItems = View.ValidateDBItems(dbValidate.DestinationColumn, source.GetColumnCells(dbValidate.DestinationColumn.InputType, dbValidate.Number));
                 validatedItems.Add(dbValidate.DestinationColumn.Id);
                 invalidItems.ForEach(i => i.isDBduplicate = true);
             }
         }
     }
     ValidateSourceData(source, notEmptyColumns, notDuplicatedColumns);
 }
コード例 #23
0
        private static ExternalResource GetFacebookResources(string accessToken, HttpClient client)
        {
            client.BaseAddress = new Uri("https://graph.facebook.com");

            HttpResponseMessage response = client.GetAsync("me?fields=email,link,location,first_name,last_name,name&access_token=" + accessToken).Result;

            if (response.IsSuccessStatusCode)
            {
                Stream stream = response.Content.ReadAsStreamAsync().Result;
                DataContractJsonSerializer ser     = new DataContractJsonSerializer(typeof(ExternalResource));
                ExternalResource           profile = (ExternalResource)ser.ReadObject(stream);
                profile.local = profile.location.name;
                HttpResponseMessage response2 = client.GetAsync("me/picture?access_token=" + accessToken).Result;
                if (response2.IsSuccessStatusCode)
                {
                    profile.picture = response2.RequestMessage.RequestUri.AbsoluteUri;
                }
                return(profile);
            }
            return(null);
        }
コード例 #24
0
        public static async Task <bool> Check(ExternalResource externalResource)
        {
            var password = await KeyvaultHelper.Get(externalResource.Keyvault);

            FtpClient ftpClient = (externalResource.Type.Equals("ftps", StringComparison.OrdinalIgnoreCase) || externalResource.Port.Equals(990)) ?
                                  new FtpClient(externalResource.Host)
            {               //FTPS explicitly or Port = 990 => automatically create FTPS
                Credentials = new NetworkCredential(externalResource.Username, password),
                Port        = externalResource.Port,
                EnableThreadSafeDataConnections = true,
                //DataConnectionType = config.Ftp.DataConnectionType.Equals(Constants.FtpActiveMode, StringComparison.InvariantCultureIgnoreCase) ? FtpDataConnectionType.AutoActive : FtpDataConnectionType.AutoPassive,
                EncryptionMode = externalResource.Port.Equals(990) ? FtpEncryptionMode.Implicit : FtpEncryptionMode.Explicit
            }
                        :
            new FtpClient(externalResource.Host)
            {
                Credentials = new NetworkCredential(externalResource.Username, password),
                Port        = externalResource.Port,
                EnableThreadSafeDataConnections = true
            };

            ftpClient.ValidateCertificate += (control, e) =>
            {
                e.Accept = true;
            };

            await ftpClient.ConnectAsync();

            bool isSuccess = false;

            if (ftpClient.IsConnected)
            {
                isSuccess = true;
                await ftpClient.DisconnectAsync();
            }

            return(isSuccess);
        }
コード例 #25
0
        private static async Task <bool> basicAuthConnect(ExternalResource rs)
        {
            var    isSuccess = false;
            string passwd    = await KeyvaultHelper.Get(rs.Keyvault);

            var uriBuilder = new UriBuilder($"{rs.Host}:{rs.Port}{rs.Path}");
            var uri        = uriBuilder.Uri;

            using (var client = new HttpClient())
            {
                var byteArray = Encoding.ASCII.GetBytes($"{rs.Username}:{passwd}");
                client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));

                var result = await client.GetAsync(uri);

                if (result.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    return(true);
                }
            }

            return(isSuccess);
        }
コード例 #26
0
        public void ImportAgencies(ExternalResource selectedItems)
        {
            View.PreviousStep = AgencyImportStep.None;
            View.SetupProgressInfo(selectedItems.Rows.Count);

            // Create profiles
            List <String>             notAddedItems = new List <String>();
            Dictionary <long, String> createdItems  = CreateAgencies(View.AvailableForAll, View.SelectedOrganizations, selectedItems, notAddedItems);

            View.UpdateSourceItems();
            Int32 itemsToSelect = View.ItemsToSelect;

            View.PreviousStep = (itemsToSelect > 0) ? AgencyImportStep.ItemsSelctor : AgencyImportStep.None;

            if (notAddedItems.Count == 0)
            {
                View.isCompleted = (itemsToSelect == 0);
                View.DisplayImportedAgencies(createdItems.Count, itemsToSelect);
            }
            else
            {
                View.DisplayImportError(createdItems.Count, notAddedItems);
            }
        }
コード例 #27
0
 /// <summary>
 /// Creates an external redirect.
 /// </summary>
 /// <param name="resource">The external resource. Do not pass null.</param>
 /// <param name="isPermanent">Pass true to use HTTP 308 (Permanent Redirect) instead of HTTP 307 (Temporary Redirect).</param>
 public ExternalRedirect(ExternalResource resource, bool isPermanent)
 {
     Resource    = resource;
     IsPermanent = isPermanent;
 }
コード例 #28
0
        private Dictionary <long, String> CreateAgencies(Boolean assignToAll, Dictionary <Int32, String> organizations, ExternalResource selectedItems, List <String> notAddedItems)
        {
            Dictionary <long, String> agencies = new Dictionary <long, String>();

            if (assignToAll == true || organizations.Count > 1)
            {
                long  idAgency = 0;
                Int32 index    = 1;
                List <ExternalColumnComparer <String, Int32> > columns = View.Fields;
                foreach (ExternalRow row in selectedItems.Rows)
                {
                    dtoAgency dto = new  dtoAgency();
                    dto.AlwaysAvailable = assignToAll;
                    dto.Name            = row.GetCellValue(columns.Where(c => c.DestinationColumn.Id == (int)ImportedAgencyColumn.name).Select(c => c.Number).FirstOrDefault());
                    dto.NationalCode    = row.GetCellValue(columns.Where(c => c.DestinationColumn.Id == (int)ImportedAgencyColumn.nationalCode).Select(c => c.Number).FirstOrDefault());
                    dto.TaxCode         = row.GetCellValue(columns.Where(c => c.DestinationColumn.Id == (int)ImportedAgencyColumn.taxCode).Select(c => c.Number).FirstOrDefault());
                    dto.ExternalCode    = row.GetCellValue(columns.Where(c => c.DestinationColumn.Id == (int)ImportedAgencyColumn.externalCode).Select(c => c.Number).FirstOrDefault());
                    dto.IsDefault       = false;
                    dto.IsEditable      = true;
                    if (!assignToAll)
                    {
                        dto.Organizations = (from o in organizations select new dtoOrganizationAffiliation()
                        {
                            Id = o.Key
                        }).ToList();
                    }
                    Agency agency = Service.SaveAgency(dto);

                    if (agency == null)
                    {
                        notAddedItems.Add(dto.Name);
                    }
                    else
                    {
                        agencies.Add(agency.Id, agency.Name);
                    }
                    View.UpdateAgencyCreation(selectedItems.Rows.Count, index, (agency != null), " // ");
                    index++;
                }
            }
            return(agencies);
        }
コード例 #29
0
 public IActionResult Create(ExternalResource externalResource)
 {
     _externalResourcesRepository.AddExternalResource(externalResource);
     return(RedirectToAction(nameof(Index)));
 }
        /// <summary>
        /// Инициализация таблицы "Внешние ресурсы"
        /// </summary>
        /// <param name="serviceProvider"></param>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public static async Task CreateExternalResources(IServiceProvider serviceProvider, IConfiguration configuration)
        {
            using (var serviceScope = serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                AppIdentityDBContext context = serviceScope.ServiceProvider.GetService <AppIdentityDBContext>();

                #region Инициализация таблицы "Внешние ресурсы"
                if (!await context.ExternalResources.AnyAsync())
                {
                    var row01 = new ExternalResource
                    {
                        ExternalResourceId     = (int)ExternalResourceEnum.SocialNetworks_VKontakte,
                        ExternalResourceTypeId = (int)ExternalResourceTypeEnum.SocialNetworks,
                        ExternalResourceName   = "ВКонтакте"
                    };

                    var row02 = new ExternalResource
                    {
                        ExternalResourceId     = (int)ExternalResourceEnum.SocialNetworks_ORCID,
                        ExternalResourceTypeId = (int)ExternalResourceTypeEnum.ScienceNetworks,
                        ExternalResourceName   = "ORCID"
                    };

                    var row03 = new ExternalResource
                    {
                        ExternalResourceId     = (int)ExternalResourceEnum.SocialNetworks_Mendeley,
                        ExternalResourceTypeId = (int)ExternalResourceTypeEnum.ScienceNetworks,
                        ExternalResourceName   = "Mendeley"
                    };

                    var row04 = new ExternalResource
                    {
                        ExternalResourceId     = (int)ExternalResourceEnum.Messengers_Skype,
                        ExternalResourceTypeId = (int)ExternalResourceTypeEnum.Messengers,
                        ExternalResourceName   = "Skype"
                    };

                    var row05 = new ExternalResource
                    {
                        ExternalResourceId     = (int)ExternalResourceEnum.CitationBases_Elibrary,
                        ExternalResourceTypeId = (int)ExternalResourceTypeEnum.CitationBases,
                        ExternalResourceName   = "РИНЦ"
                    };

                    var row06 = new ExternalResource
                    {
                        ExternalResourceId     = (int)ExternalResourceEnum.CitationBases_Scopus,
                        ExternalResourceTypeId = (int)ExternalResourceTypeEnum.CitationBases,
                        ExternalResourceName   = "Scopus"
                    };


                    await context.ExternalResources.AddRangeAsync(
                        row01,
                        row02,
                        row03,
                        row04,
                        row05,
                        row06
                        );

                    await context.SaveChangesAsync();
                }
                #endregion
            }
        }