コード例 #1
0
        public void Setup()
        {
            exampleServiceWrapper = RMock <IExampleService> .Builder()
                                    .DefineReturn("GetMessage", "Hello World")
                                    .DefineReturn("GetPerson", new Person("Rich"))
                                    .DefineReturn("GetValue", 13)
                                    .Compile();

            dependant = new DependantType(exampleServiceWrapper.Instance);
        }
コード例 #2
0
        protected void Save(object sender, EventArgs e)
        {
            dependants = GetExistingData();
            DateTime dob;

            DateTime.TryParse(tbDDateOfBirth.Text, out dob);
            int              idGender        = int.Parse(lbDGenders.SelectedValue);
            Gender           gender          = entity.Genders.Where(p => p.IdGender == idGender).FirstOrDefault();
            int              idDependantType = int.Parse(lbDependantTypes.SelectedValue);
            DependantType    dType           = entity.DependantTypes.Where(p => p.IdDependantType == idDependantType).FirstOrDefault();
            Student          student         = entity.Students.Where(p => p.ReferenceNumber == hfReference.Value).FirstOrDefault();
            StudentDependant newDep          = new StudentDependant
            {
                DateOfBirth     = dob,
                IdDependantType = idDependantType,
                Gender          = gender,
                Name            = tbDName.Text,
                Surname         = tbDSurname.Text,
                IdGender        = idGender,
                DependantType   = dType,
                IdStudent       = student.IdStudent
            };

            dependants.Add(newDep);
            entity.AddToStudentDependants(newDep);
            entity.SaveChanges();
            //DataSet ds = gv.DataSource as DataSet;
            //DataRow dr = ds.Tables[0].NewRow();
            //dr[0] = txtempID.Text;
            //dr[1] = txtName.Text;
            //dr[2] = txtCity.Text;
            //dr[3] = txtSalary.Text;
            //ds.Tables[0].Rows.Add(dr);
            //ds.AcceptChanges();
            //ds.WriteXml(Server.MapPath("empdata.xml"));
            Cache["Dependants"] = dependants;
            BindData(dependants);
            tbDName.Text        = string.Empty;
            tbDSurname.Text     = string.Empty;
            tbDDateOfBirth.Text = string.Empty;
        }
コード例 #3
0
        private void CompletePage1AndSend(Student student)
        {
            string fileNameExisting = ConfigurationManager.AppSettings.Get("ApplicationFormFilePath") + "TemplatePage1.pdf";
            string fileNameNew      = ConfigurationManager.AppSettings.Get("ApplicationFormFilePath") + "App_" + student.ReferenceNumber + ".pdf";

            // open the reader
            PdfReader reader   = new PdfReader(fileNameExisting);
            Rectangle size     = reader.GetPageSizeWithRotation(1);
            Document  document = new Document(size);

            // open the writer
            FileStream fs     = new FileStream(fileNameNew, FileMode.Create, FileAccess.Write);
            PdfWriter  writer = PdfWriter.GetInstance(document, fs);

            document.Open();

            // the pdf content
            PdfContentByte cb = writer.DirectContent;

            // select the font properties
            BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

            cb.SetColorFill(BaseColor.DARK_GRAY);
            cb.SetFontAndSize(bf, 8);

            // write the text in the pdf content
            cb.BeginText();
            //line1
            cb.ShowTextAligned(3, student.CommencementDate.Value.ToShortDateString(), 140, 670, 0);
            cb.ShowTextAligned(3, student.EndDate.Value.ToShortDateString(), 450, 670, 0);
            //line2
            cb.ShowTextAligned(3, student.MembershipNumber, 140, 650, 0);
            cb.ShowTextAligned(3, student.ReferenceNumber, 450, 650, 0);
            //line3
            cb.ShowTextAligned(3, student.Surname, 140, 610, 0);
            cb.ShowTextAligned(3, student.Contribution.ToString(), 450, 610, 0);
            //line4
            cb.ShowTextAligned(3, student.FirstNames, 140, 590, 0);
            Gender gender = entity.Genders.Where(p => p.IdGender == student.IdGender).FirstOrDefault();

            cb.ShowTextAligned(3, gender.GenderDescription, 450, 590, 0);
            //line5
            Title title = entity.Titles.Where(p => p.IdTitle == student.IdTitle).FirstOrDefault();

            cb.ShowTextAligned(3, title.TitleAbbreviation, 110, 570, 0);
            MaritalStatuss status = entity.MaritalStatusses.Where(p => p.IdMaritalStatus == student.IdMaritalStatus).FirstOrDefault();

            cb.ShowTextAligned(3, status.Description, 200, 570, 0);
            Country country = entity.Countries.Where(p => p.IdCountry == student.CountryOfIssue).FirstOrDefault();

            cb.ShowTextAligned(3, country.Name, 450, 570, 0);
            //line6
            cb.ShowTextAligned(3, student.DateOfBirth.Value.ToShortDateString(), 140, 550, 0);
            cb.ShowTextAligned(3, student.IDPassport, 450, 550, 0);
            //line7
            StudentAddress postal     = entity.StudentAddresses.Where(p => p.IdStudent == student.IdStudent && p.IsPostalAddress.Value).FirstOrDefault();
            string         postalAddy = postal != null ? postal.Address1 + ", " + postal.Address2 + ", " + postal.Address3 + ", " + postal.Address4 + ", " + entity.Provinces.Where(p => p.IdProvince == postal.IdProvince).FirstOrDefault().Name + " ," + postal.PostalCode : "Not provided.";

            cb.ShowTextAligned(3, postalAddy, 140, 530, 0);
            //line8
            StudentAddress physical = entity.StudentAddresses.Where(p => p.IdStudent == student.IdStudent && !p.IsPostalAddress.Value).FirstOrDefault();
            string         physAddy = physical != null ? physical.Address1 + ", " + physical.Address2 + ", " + physical.Address3 + ", " + physical.Address4 + ", " + entity.Provinces.Where(p => p.IdProvince == physical.IdProvince).FirstOrDefault().Name + " ," + physical.PostalCode : "Not provided.";

            cb.ShowTextAligned(3, physAddy, 140, 500, 0);
            //line9
            cb.ShowTextAligned(3, student.Email, 140, 480, 0);
            //line10
            cb.ShowTextAligned(3, student.BusinessTelephone, 140, 460, 0);
            cb.ShowTextAligned(3, student.HomeTelephone, 450, 460, 0);
            //line11
            cb.ShowTextAligned(3, student.Facsimile, 140, 440, 0);
            cb.ShowTextAligned(3, student.Cellular, 450, 440, 0);
            //line12
            Institution ins = entity.Institutions.Where(p => p.IdInstitution == student.StudyInstitution).FirstOrDefault();

            cb.ShowTextAligned(3, ins.InstitutionName, 140, 420, 0);
            cb.ShowTextAligned(3, student.StudentNumber, 450, 420, 0);
            //line13
            cb.ShowTextAligned(3, student.IncomeAmount != null ? student.IncomeAmount.Value.ToString() : "n/a", 140, 375, 0);
            //group 14
            List <StudentDependant> deps = entity.StudentDependants.Where(p => p.IdStudent == student.IdStudent).ToList();

            if (deps != null)
            {
                int y = 350;

                foreach (var item in deps)
                {
                    cb.ShowTextAligned(3, item.Name, 140, y, 0);
                    cb.ShowTextAligned(3, item.Surname, 200, y, 0);
                    DependantType type = entity.DependantTypes.Where(p => p.IdDependantType == item.IdDependantType).FirstOrDefault();
                    cb.ShowTextAligned(3, type != null ? type.DependantTypeDescription : "n/a", 260, y, 0);
                    Gender gen = entity.Genders.Where(p => p.IdGender == item.IdGender).FirstOrDefault();
                    cb.ShowTextAligned(3, gen != null ? gen.GenderDescription : "n/a", 310, y, 0);
                    cb.ShowTextAligned(3, item.DateOfBirth != null ? item.DateOfBirth.Value.ToShortDateString() : "n/a", 370, y, 0);
                    y = y - 20;
                }
            }
            //group 15
            cb.ShowTextAligned(3, student.MedicalQ1 != null ? "yes" : "no", 450, 205, 0);
            cb.ShowTextAligned(3, student.MedicalQ1 != null ? "yes" : "no", 450, 195, 0);
            cb.ShowTextAligned(3, student.MedicalQ1 != null ? "yes" : "no", 450, 185, 0);
            List <TreatmentDetail> meds = entity.TreatmentDetails.Where(p => p.IdStudent == student.IdStudent).ToList();

            if (meds != null)
            {
                int y = 120;

                foreach (var item in meds)
                {
                    cb.ShowTextAligned(3, item.Name, 80, y, 0);
                    cb.ShowTextAligned(3, item.DetailsOfCondition, 160, y, 0);
                    cb.ShowTextAligned(3, item.TreatmentDate != null ? item.TreatmentDate.Value.ToShortDateString() : "n/a", 300, y, 0);
                    cb.ShowTextAligned(3, item.DegreeOfRecovery, 470, y, 0);
                    y = y - 20;
                }
            }
            //line 16
            Supplier sup = entity.Suppliers.Where(p => p.IdSupplier == student.PreferredSupplier).FirstOrDefault();

            cb.ShowTextAligned(3, sup != null ? sup.SupplierBHFNumber : "Not Selected", 140, 30, 0);
            cb.EndText();
            //add template to content
            PdfImportedPage page = writer.GetImportedPage(reader, 1);

            cb.AddTemplate(page, 0, 0);
            // close the streams and voilá the file should be changed :)
            document.Close();
            fs.Close();
            writer.Close();
            reader.Close();
            SendEmail("*****@*****.**", "StudentPlan Application Form", "See Attached", fileNameNew);
        }
コード例 #4
0
        private DirectedSparseGraph <DependantType> BuildTypeDependencyGraph()
        {
            var graph = new DirectedSparseGraph <DependantType>();

            var processedTypes = new List <DependantType>();

            foreach (var syntaxTree in _context.Compilation.SyntaxTrees)
            {
                var root          = syntaxTree.GetRoot();
                var semanticModel = _context.Compilation.GetSemanticModel(syntaxTree);

                var classNodes = root.DescendantNodes().OfType <ClassDeclarationSyntax>().ToList();

                foreach (var classNode in classNodes)
                {
                    DependantType type = null;

                    var classSymbol = semanticModel.GetDeclaredSymbol(classNode) as INamedTypeSymbol;

                    var processedType = processedTypes.FirstOrDefault(t => t.Name == classSymbol.Name);

                    if (processedType != null)
                    {
                        // we already added this to the graph as a dependency earlier
                        type = processedType;

                        type.SemanticModel   = semanticModel;
                        type.NamedTypeSymbol = classSymbol;
                    }
                    else
                    {
                        type = new DependantType()
                        {
                            Name               = classSymbol.Name,
                            Namespace          = classSymbol.ContainingNamespace.ToString(),
                            ContainingAssembly = classSymbol.ContainingAssembly.Name,
                            IsExternal         = false,
                            SemanticModel      = semanticModel,
                            NamedTypeSymbol    = classSymbol,
                            TypeKind           = classSymbol.TypeKind
                        };

                        processedTypes.Add(type);
                        graph.AddVertex(type);
                    }

                    if (_context.Solution != null)
                    {
                        var referencesToClass = SymbolFinder.FindReferencesAsync(classSymbol, _context.Solution).Result;
                    }

                    var classDependencies = classNode.DescendantNodes()
                                            .Select(n => semanticModel.GetTypeInfo(n).Type)
                                            .Where(n => n != null)
                                            .Distinct()
                                            .ToList();

                    foreach (var dependency in classDependencies)
                    {
                        DependantType dep = null;

                        var processedDep = processedTypes.FirstOrDefault(t => t.Name == dependency.Name);

                        if (processedDep != null)
                        {
                            dep = processedDep;
                        }
                        else
                        {
                            dep = new DependantType()
                            {
                                Name               = dependency.Name,
                                Namespace          = dependency.ContainingNamespace.ToString(),
                                ContainingAssembly = dependency.ContainingAssembly.Name,
                                NamedTypeSymbol    = dependency as INamedTypeSymbol,
                                TypeKind           = dependency.TypeKind,
                                IsExternal         = dependency.ContainingAssembly.Name == "mscorlib"
                            };

                            processedTypes.Add(dep);
                        }

                        if (!graph.HasVertex(dep))
                        {
                            graph.AddVertex(dep);
                        }

                        graph.AddEdge(type, dep);
                    }
                }


                var enumNodes = root.DescendantNodes().OfType <EnumDeclarationSyntax>().ToList();

                foreach (var enumNode in enumNodes)
                {
                    DependantType type = null;

                    var enumSymbol = semanticModel.GetDeclaredSymbol(enumNode) as INamedTypeSymbol;

                    var processedType = processedTypes.FirstOrDefault(t => t.Name == enumSymbol.Name);

                    if (processedType != null)
                    {
                        // we already added this to the graph as a dependency earlier
                        type = processedType;

                        type.SemanticModel   = semanticModel;
                        type.NamedTypeSymbol = enumSymbol;
                    }
                    else
                    {
                        type = new DependantType()
                        {
                            Name               = enumSymbol.Name,
                            Namespace          = enumSymbol.ContainingNamespace.ToString(),
                            ContainingAssembly = enumSymbol.ContainingAssembly.Name,
                            IsExternal         = false,
                            SemanticModel      = semanticModel,
                            NamedTypeSymbol    = enumSymbol,
                            TypeKind           = enumSymbol.TypeKind
                        };

                        processedTypes.Add(type);
                        graph.AddVertex(type);
                    }
                }
            }

            return(graph);
        }