예제 #1
0
        bool TrySubmit()
        {
            var trimmedInterfaceName = InterfaceName.Trim();
            var trimmedFileName      = FileName.Trim();

            if (!IncludedMembers.Any())
            {
                return(false);
            }
            if (conflictingTypeNames.Contains(trimmedInterfaceName))
            {
                return(false);
            }
            if (!syntaxFactsService.IsValidIdentifier(trimmedInterfaceName))
            {
                return(false);
            }
            if (trimmedFileName.IndexOfAny(System.IO.Path.GetInvalidFileNameChars()) >= 0)
            {
                return(false);
            }

            if (!System.IO.Path.GetExtension(trimmedFileName).Equals(fileExtension, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }
            return(true);
        }
예제 #2
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Name.Length != 0)
            {
                hash ^= Name.GetHashCode();
            }
            if (DeviceName.Length != 0)
            {
                hash ^= DeviceName.GetHashCode();
            }
            if (InterfaceName.Length != 0)
            {
                hash ^= InterfaceName.GetHashCode();
            }
            if (Address.Length != 0)
            {
                hash ^= Address.GetHashCode();
            }
            if (DeviceDetails.Length != 0)
            {
                hash ^= DeviceDetails.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
예제 #3
0
        private void ValidateNewName()
        {
            var tokenValues = typeof(Tokens).GetFields().Select(item => item.GetValue(null)).Cast <string>().Select(item => item);

            OkButton.Enabled = !ComponentNames.Contains(InterfaceName) &&
                               InterfaceName.Length > 1 &&
                               char.IsLetter(InterfaceName.FirstOrDefault()) &&
                               !tokenValues.Contains(InterfaceName, StringComparer.InvariantCultureIgnoreCase) &&
                               !InterfaceName.Any(c => !char.IsLetterOrDigit(c) && c != '_');

            InvalidNameValidationIcon.Visible = !OkButton.Enabled;
        }
예제 #4
0
 public void BindClassEntityList()
 {
     if (InterfaceName.IsNotEmpty())
     {
         var entity = TypeManager.Data.First(p => p.InterfaceType == Type.GetType(InterfaceName));
         ClassEntityList = entity.ClassEntityList.Copy();
         ClassEntityList.ForEach(p => p.Title = p.Title + " (" + p.Provider + ")");
         txtProvider.DisplayMember            = "Title";
         txtProvider.ValueMember   = "Provider";
         txtProvider.DataSource    = ClassEntityList;
         txtProvider.SelectedIndex = -1;
     }
 }
예제 #5
0
 public override int ComputeKey()
 {
     unchecked {
         var hashCode = BindingFlags.GetHashCode();
         hashCode = (hashCode * 397) ^ (Name != null ? Name.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ IsField.GetHashCode();
         hashCode = (hashCode * 397) ^ (FallbackAction != null ? FallbackAction.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (GetterFallbackAction != null ? GetterFallbackAction.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (SetterFallbackAction != null ? SetterFallbackAction.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (InterfaceName != null ? InterfaceName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (FallbackMode != null ? FallbackMode.GetHashCode() : 0);
         return(hashCode);
     }
 }
        internal bool TrySubmit()
        {
            var trimmedInterfaceName = InterfaceName.Trim();
            var trimmedFileName      = FileName.Trim();

            if (!MemberContainers.Any(c => c.IsChecked))
            {
                SendFailureNotification(ServicesVSResources.You_must_select_at_least_one_member);
                return(false);
            }

            if (_conflictingTypeNames.Contains(trimmedInterfaceName))
            {
                SendFailureNotification(ServicesVSResources.Interface_name_conflicts_with_an_existing_type_name);
                return(false);
            }

            if (!_syntaxFactsService.IsValidIdentifier(trimmedInterfaceName))
            {
                SendFailureNotification(string.Format(ServicesVSResources.Interface_name_is_not_a_valid_0_identifier, _languageName));
                return(false);
            }

            if (trimmedFileName.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
            {
                SendFailureNotification(ServicesVSResources.Illegal_characters_in_path);
                return(false);
            }

            if (!System.IO.Path.GetExtension(trimmedFileName).Equals(_fileExtension, StringComparison.OrdinalIgnoreCase))
            {
                SendFailureNotification(string.Format(ServicesVSResources.File_name_must_have_the_0_extension, _fileExtension));
                return(false);
            }

            // TODO: Deal with filename already existing

            return(true);
        }
예제 #7
0
        internal bool TrySubmit()
        {
            var trimmedInterfaceName = InterfaceName.Trim();
            var trimmedFileName      = FileName.Trim();

            if (!MemberContainers.Any(c => c.IsChecked))
            {
                SendFailureNotification(ServicesVSResources.YouMustSelectAtLeastOneMember);
                return(false);
            }

            if (_conflictingTypeNames.Contains(trimmedInterfaceName))
            {
                SendFailureNotification(ServicesVSResources.InterfaceNameConflictsWithTypeName);
                return(false);
            }

            if (!_syntaxFactsService.IsValidIdentifier(trimmedInterfaceName))
            {
                SendFailureNotification(string.Format(ServicesVSResources.InterfaceNameIsNotAValidIdentifier, _languageName));
                return(false);
            }

            if (trimmedFileName.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
            {
                SendFailureNotification(ServicesVSResources.IllegalCharactersInPath);
                return(false);
            }

            if (!System.IO.Path.GetExtension(trimmedFileName).Equals(_fileExtension, StringComparison.OrdinalIgnoreCase))
            {
                SendFailureNotification(string.Format(ServicesVSResources.FileNameMustHaveTheExtension, _fileExtension));
                return(false);
            }

            // TODO: Deal with filename already existing

            return(true);
        }
예제 #8
0
        internal bool TrySubmit()
        {
            var trimmedInterfaceName = InterfaceName.Trim();
            var trimmedFileName      = FileName.Trim();

            if (!MemberContainers.Any(c => c.IsChecked))
            {
                SendFailureNotification("YouMustSelectAtLeastOneMember");
                return(false);
            }

            if (_conflictingTypeNames.Contains(trimmedInterfaceName))
            {
                SendFailureNotification("InterfaceNameConflictsWithTypeName");
                return(false);
            }

            //if (!_syntaxFactsService.IsValidIdentifier(trimmedInterfaceName))
            //{
            //    SendFailureNotification($"InterfaceNameIsNotAValidIdentifier {_languageName}");
            //    return false;
            //}

            if (trimmedFileName.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
            {
                SendFailureNotification("IllegalCharactersInPath");
                return(false);
            }

            if (!Path.GetExtension(trimmedFileName).Equals(_fileExtension, StringComparison.OrdinalIgnoreCase))
            {
                SendFailureNotification($"FileNameMustHaveTheExtension {_fileExtension}");
                return(false);
            }

            // TODO: Deal with filename already existing

            return(true);
        }
예제 #9
0
        public async Task <IActionResult> PostRange(
            [FromServices] PnPServerContext dbContext,
            Guid networkDeviceTypeId,
            [FromBody] PostNetworkInterfaceRangeViewModel range
            )
        {
            // TODO : Additional verification on range validity
            if (networkDeviceTypeId == Guid.Empty ||
                range == null ||
                string.IsNullOrEmpty(range.Name)
                )
            {
                return(BadRequest());
            }

            var interfaceName = InterfaceName.tryParse(range.Name);

            if (interfaceName == null)
            {
                System.Diagnostics.Debug.WriteLine("Invalid format for interface name : " + range.Name);
                return(BadRequest());
            }

            var networkDeviceType = await dbContext.NetworkDeviceTypes.Include("Interfaces").FirstOrDefaultAsync(x => x.Id == networkDeviceTypeId);

            if (networkDeviceType == null)
            {
                System.Diagnostics.Debug.WriteLine("Network device type " + networkDeviceTypeId.ToString() + " does not exist");
                return(BadRequest());
            }

            var interfaceList = new List <string>();
            var networkInterfaceRecordList = new List <NetworkInterface>();

            for (var i = 0; i < range.Count; i++)
            {
                var newInterfaceName = interfaceName.subsequent(i).ToString();
                interfaceList.Add(newInterfaceName);
                networkInterfaceRecordList.Add(new NetworkInterface
                {
                    Name           = newInterfaceName,
                    InterfaceIndex = range.FirstIndex + i
                });
            }

            var conflictingRecords = await dbContext.NetworkInterfaces
                                     .Where(x =>
                                            interfaceList.Contains(x.Name, StringComparer.OrdinalIgnoreCase) &&
                                            x.DeviceType.Id == networkDeviceTypeId
                                            )
                                     .ToListAsync();

            if (conflictingRecords.Count() != 0)
            {
                System.Diagnostics.Debug.WriteLine("Conflicting network interface names found");
                return(BadRequest());
            }

            networkDeviceType.Interfaces.AddRange(networkInterfaceRecordList);
            dbContext.Update(networkDeviceType);

            await dbContext.SaveChangesAsync();

            foreach (var networkInterface in networkInterfaceRecordList)
            {
                networkInterface.DeviceType.Interfaces = null;
            }

            return(new CreatedAtRouteResult("GetNetworkInterfaces", networkInterfaceRecordList));
        }