示例#1
0
        public async Task <StudentDisciplineVO> AddTaskAsync(StudentVO student)
        {
            StudentModel studentEntity = _studentConverter.Parse(student);

            if (!(GuidFormat.TryParseList(studentEntity.Disciplines, ';', out List <Guid> result)))
            {
                return(null);
            }

            //checando se não existe nenhuma disciplina repetida.
            foreach (Guid disc in result)
            {
                if (result.Count(x => x.Equals(disc)) > 1)
                {
                    return(null);
                }
            }

            if (!(await _disciplineBusiness.FindAllByDisciplineIdsTaskAsync(result) is List <DisciplineVO> disciplines))
            {
                return(null);
            }

            if (!(await _studentRepository.AddTaskAsync(studentEntity) is StudentModel addedStudent))
            {
                return(null);
            }

            //await _emailSender.SendEmailTaskAsync(addedStudent.Email);

            return(_studentDisciplineConverter.Parse((addedStudent, _disciplineConverter.ParseList(disciplines))));
        }
示例#2
0
        public async Task <List <StudentDisciplineVO> > FindAllByCourseIdTaskAsync(Guid courseId)
        {
            if (!(await _studentRepository.FindAllByCourseIdTaskAsync(courseId) is List <StudentModel> students))
            {
                return(null);
            }

            var studentDisciplines = new List <(StudentModel student, List <DisciplineModel> discipline)>();

            foreach (StudentModel student in students)
            {
                if (!GuidFormat.TryParseList(student.Disciplines, ';', out List <Guid> result))
                {
                    return(null);
                }

                if (!(await _disciplineBusiness.FindAllByDisciplineIdsTaskAsync(result) is List <DisciplineVO> disciplines))
                {
                    return(null);
                }

                studentDisciplines.Add((student, _disciplineConverter.ParseList(disciplines)));
            }

            return(_studentDisciplineConverter.ParseList(studentDisciplines));
        }
        public Options()
        {
            // Fields
            this.guidFormat = GuidFormatStringConverter.DefaultFormat;

            // Displayed options
            // Note: Features that add to VS capabilities I've turned on by default.
            // However, features that remove/suppress VS behaviors (e.g., IsMouseWheelZoomEnabled)
            // are initialized where VS's standard behavior is retained.  I'll manually change those option
            // values in environments where I want to suppress the standard behavior.
            this.SaveAllBeforeExecuteFile    = true;
            this.PredefinedRegions           = DefaultPredefinedRegions;
            this.UseByteSpaceSeparators      = true;
            this.UseGroupDelimiterForDecimal = true;
            this.UppercaseGuids                    = true;
            this.IsMouseWheelZoomEnabled           = true;
            this.HighlightTrailingWhiteSpace       = true;
            this.HighlightInvalidLeadingWhiteSpace = true;
            this.HighlightExcessLineLength         = DefaultExcessLineLength;
            this.HighlightOutputText               = true;
            this.OutputHighlights                  = CreateDefaultOutputHighlights();
            this.HighlightFindResultsDetails       = true;
            this.HighlightFindResultsFileNames     = true;
            this.HighlightFindResultsMatches       = true;
            this.HighlightAllCodeFiles             = true;
            this.HighlightFileExtensions           = DefaultHighlightFileExtensions;
            this.EnableCommentScans                = true;
            this.ExcludeFromCommentScans           = DefaultExcludePatterns;

            // Other dialog state settings
            this.TrimEnd                 = true;
            this.SortAscending           = true;
            this.SortIgnoreWhitespace    = true;
            this.BaseConverterNumberType = NumberType.Int32;
        }
        public static GuidFormat ToFormat(string text)
        {
            // Callers depend on this returning the default GuidFormat if the text is null or unrecognized.
            GuidFormat result = Associations.Where(a => a.Item1 == text).Select(a => a.Item2).FirstOrDefault();

            return(result);
        }
示例#5
0
 private void CopyIID(ListView view, GuidFormat type)
 {
     if (view != null && view.SelectedIndices.Count > 0)
     {
         ListViewItem item = view.SelectedItems[0];
         Tuple <COMInterfaceInstance, COMInterfaceEntry> intf = item.Tag as Tuple <COMInterfaceInstance, COMInterfaceEntry>;
         COMUtilities.CopyGuidToClipboard(intf.Item1.Iid, type);
     }
 }
示例#6
0
        /// <summary>
        /// Returns a string representation of the GUID instance, 
        /// according to the provided format.
        /// </summary>
        /// <param name="format">
        /// Format that indicates how to represent the value of the GUID.
        /// If format is null, D-format is used.</param>
        /// <param name="uppercase"> 
        /// true — convert the returned string to uppercase, 
        /// false — convert the returned string to lowercase.</param>
        /// <returns> The value of the GUID instance, 
        /// represented as a string of hexadecimal digits in the specified format.</returns>
        public static String Build(GuidFormat format, Boolean uppercase)
        {
            var guid = Guid.NewGuid();

            // If format is null,
            // String.Format returns an empty string,
            // it amounts that format specifier "D" is used.
            var guidString = guid.ToString(String.Format("{0}", format));

            return uppercase ? guidString.ToUpper() : guidString.ToLower();
        }
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = Pattern.GetHashCode();
         hashCode = (hashCode * 397) ^ DateTimeFormat.GetHashCode();
         hashCode = (hashCode * 397) ^ GuidFormat.GetHashCode();
         hashCode = (hashCode * 397) ^ SupportFormats.GetHashCode();
         return(hashCode);
     }
 }
        public static string ToString(GuidFormat format)
        {
            string result = Associations.Where(a => a.Item2 == format).Select(a => a.Item1).FirstOrDefault();

            if (string.IsNullOrEmpty(result))
            {
                result = ToString(DefaultFormat);
            }

            return(result);
        }
示例#9
0
        /// <summary>
        /// Creates a new <see cref="PropVariant"/> and initialises it with a <see cref="Guid"/>
        /// </summary>
        /// <param name="guid">The initial value of the new PropVariant</param>
        /// <param name="format">The <see cref="GuidFormat"/> that defines how the PropVariant should save the Guid</param>
        public PropVariant(Guid guid, GuidFormat format = GuidFormat.Native)
        {
            IntPtr nativeGuid = IntPtr.Zero;

            try {
                HRESULT hr;
                _ppv = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(PROPVARIANT)));
                switch (format)
                {
                case GuidFormat.Native:
                    nativeGuid = Marshal.AllocCoTaskMem(16);
                    Marshal.Copy(guid.ToByteArray(), 0, nativeGuid, 16);
                    if ((hr = InitPropVariantFromCLSID(nativeGuid, _ppv)).Failed)
                    {
                        throw (Exception)hr;
                    }
                    break;

                case GuidFormat.String:
                    nativeGuid = Marshal.AllocCoTaskMem(16);
                    Marshal.Copy(guid.ToByteArray(), 0, nativeGuid, 16);
                    if ((hr = InitPropVariantFromGUIDAsString(nativeGuid, _ppv)).Failed)
                    {
                        throw (Exception)hr;
                    }
                    break;

                case GuidFormat.Buffer:
                    if ((hr = InitPropVariantFromBuffer(guid.ToByteArray(), 16, _ppv)).Failed)
                    {
                        throw (Exception)hr;
                    }
                    break;

                default:
                    throw new ArgumentException();
                }
            }
            catch {
                if (_ppv != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(_ppv);
                    _ppv = IntPtr.Zero;
                }
                throw;
            }
            finally {
                if (nativeGuid != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(nativeGuid);
                }
            }
            MarshalPointerToValue();
        }
        private void CopyGuid(object sender, GuidFormat copy_type)
        {
            ListView list = sender as ListView;

            if (list != null && list.SelectedItems.Count > 0)
            {
                ListViewItemWithGuid item = list.SelectedItems[0] as ListViewItemWithGuid;
                if (item != null)
                {
                    COMUtilities.CopyGuidToClipboard(item.Guid, copy_type);
                }
            }
        }
示例#11
0
文件: Options.cs 项目: menees/VsTools
        public Options()
        {
            // Fields
            this.guidFormat = GuidFormatStringConverter.DefaultFormat;

            // Displayed options
            // Note: Features that add to VS capabilities I've turned on by default.
            // However, features that remove/suppress VS behaviors (e.g., IsMouseWheelZoomEnabled)
            // are initialized where VS's standard behavior is retained.  I'll manually change those option
            // values in environments where I want to suppress the standard behavior.
            this.SaveAllBeforeExecuteFile = true;
            this.UppercaseGuids           = true;
            this.IsMouseWheelZoomEnabled  = true;

            // Other dialog state settings
            this.TrimEnd = true;
        }
示例#12
0
 /// <summary>
 /// Returns the GUID formatter for the specified guid format.
 /// </summary>
 public static string GetFormat(GuidFormat format)
 {
     switch (format)
     {
         case GuidFormat.JustDigits:
             return @"N";
         case GuidFormat.JustDigitsWithHyphens:
             return @"D";
         case GuidFormat.DigitsHyphensCurlyBraces:
             return @"B";
         case GuidFormat.DigitsHyphensRoundBraces:
             return @"P";
         case GuidFormat.Hexadecimal:
             return @"X";
         default:
             throw new InvalidOperationException();
     }
 }
示例#13
0
        /// <summary>
        /// Converts the string representation of a Guid to its Guid
        /// equivalent. A return value indicates whether the operation
        /// succeeded.
        /// </summary>
        /// <param name="s">A string containing a Guid to convert.</param>
        /// <param name="result">
        /// When this method returns, contains the Guid value equivalent to
        /// the Guid contained in <paramref name="s"/>, if the conversion
        /// succeeded, or <see cref="Guid.Empty"/> if the conversion failed.
        /// The conversion fails if the <paramref name="s"/> parameter is a
        /// <see langword="null" /> reference (<see langword="Nothing" /> in
        /// Visual Basic), or is not of the correct format.
        /// </param>
        /// <value>
        /// <see langword="true" /> if <paramref name="s"/> was converted
        /// successfully; otherwise, <see langword="false" />.
        /// </value>
        /// <exception cref="ArgumentNullException">
        ///        Thrown if <pararef name="s"/> is <see langword="null"/>.
        /// </exception>
        public static bool GuidTryParse(string s, out Guid result)
        {
            if (s == null)
            {
                throw new ArgumentNullException("s");
            }
            Match match = GuidFormat.Match(s);

            if (match.Success)
            {
                result = new Guid(s);
                return(true);
            }
            else
            {
                result = Guid.Empty;
                return(false);
            }
        }
示例#14
0
        public async Task <StudentDisciplineVO> FindByStudentIdTaskAsync(Guid studentId)
        {
            if (!(await _studentRepository.FindByStudentIdTaskAsync(studentId) is StudentModel studentModel))
            {
                return(null);
            }

            if (!GuidFormat.TryParseList(studentModel.Disciplines, ';', out List <Guid> result))
            {
                return(null);
            }

            if (!(await _disciplineBusiness.FindAllByDisciplineIdsTaskAsync(result) is List <DisciplineVO> disciplines))
            {
                return(null);
            }

            return(_studentDisciplineConverter.Parse((studentModel, _disciplineConverter.ParseList(disciplines))));
        }
示例#15
0
        /// <summary>
        /// Returns the GUID formatter for the specified guid format.
        /// </summary>
        public static string GetFormat(GuidFormat format)
        {
            switch (format)
            {
            case GuidFormat.JustDigits:
                return(@"N");

            case GuidFormat.JustDigitsWithHyphens:
                return(@"D");

            case GuidFormat.DigitsHyphensCurlyBraces:
                return(@"B");

            case GuidFormat.DigitsHyphensRoundBraces:
                return(@"P");

            case GuidFormat.Hexadecimal:
                return(@"X");

            default:
                throw new InvalidOperationException();
            }
        }
示例#16
0
        public async Task <StudentDisciplineVO> UpdateTaskAsync(StudentVO newStudent)
        {
            if (!(await _studentRepository.FindByStudentIdTaskAsync(newStudent.StudentId) is StudentModel studentModel))
            {
                return(null);
            }

            if (!(await _studentRepository.UpdateTaskAsync(studentModel, _studentConverter.Parse(newStudent)) is StudentModel newStudentModel))
            {
                return(null);
            }

            if (!GuidFormat.TryParseList(newStudentModel.Disciplines, ';', out List <Guid> disciplineIDs))
            {
                return(null);
            }

            if (!(await _disciplineBusiness.FindAllByDisciplineIdsTaskAsync(disciplineIDs) is List <DisciplineVO> disciplines))
            {
                return(null);
            }

            return(_studentDisciplineConverter.Parse((newStudentModel, _disciplineConverter.ParseList(disciplines))));
        }
示例#17
0
 public static IMaybe <Guid> GuidExact(string input, GuidFormat format) =>
 System.Guid.TryParseExact(input, char.ToString((char)format), out var guid)
         ? Maybe.Value(guid)
         : Maybe.None <Guid>();
示例#18
0
 public static IResult <Guid, string> GuidExact(string input, GuidFormat format) =>
 System.Guid.TryParseExact(input, char.ToString((char)format), out var guid)
         ? Result.Value <Guid, string>(guid)
         : Result.Error <Guid, string>(FormatStringParserMessage <Guid>(input));
示例#19
0
 /// <summary>
 /// Generates a new <see cref="System.Guid" /> using the specified format.
 /// </summary>
 /// <param name="format">The <see cref="GuidFormat" /> to be used for <see cref="string" /> formatting.</param>
 /// <returns>
 /// A new <see cref="System.Guid" />.
 /// </returns>
 public static string Guid(GuidFormat format)
 {
     return(System.Guid.NewGuid().ToString(format));
 }
示例#20
0
 /// <summary>
 /// Returns a <see cref="string" /> representation of the value of this <see cref="Guid" /> instance, according to the provided format specifier.
 /// </summary>
 /// <param name="guid">The unique identifier.</param>
 /// <param name="format">The <see cref="GuidFormat" /> that is used as a format specifier.</param>
 /// <returns>
 /// The value of this <see cref="Guid" /> represented as a <see cref="string" /> in the specified format.
 /// </returns>
 public static string ToString(this Guid guid, GuidFormat format)
 {
     return(guid.ToString(((char)format).ToString(), CultureInfo.InvariantCulture));
 }