コード例 #1
0
 public static MySingleton <T> GetInstance()
 {
     if (instance == null)
     {
         instance = new MySingleton <T>();
     }
     return(instance);
 }
コード例 #2
0
ファイル: MySingleton.cs プロジェクト: Chen5454/Hw_2
 public static MySingleton GetSingleton()
 {
     if (_instance == null)
     {
         _instance = new MySingleton();
     }
     return(_instance);
 }
コード例 #3
0
 public static GetInstance()
 {
     if (instance_ == null)
     {
         instance_ = new MySingleton();
     }
     return(instance_);
 }
コード例 #4
0
 public static MySingleton GetMySingleton(DependencyThing thing)
 {
     if (instance == null)
     {
         instance = new MySingleton(thing);
     }
     return(instance);
 }
コード例 #5
0
    static void Main(string[] args)
    {
        MySingleton.Init();
        Thread.Sleep(7000);
        Console.WriteLine("Getting instance...");
        var mySingleton = MySingleton.Instance;

        Console.WriteLine("Got instance.");
    }
コード例 #6
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            MySingleton.GetSingleton().score++;

            Debug.Log("**DING** You Gain An Extra Coin! Total Of Coins is : " + MySingleton.GetSingleton().score);
        }
    }
コード例 #7
0
 // chiama la stored procedure InsertStudentGrade
 public int InsertStudentGrade(VotoStudente vs)
 {
     using (var context = new SchoolEntities()) {
         var sg = MySingleton.GetAutoMapperInstance().Map <StudentGrade>(vs);
         context.StudentGrades.Add(sg);
         context.SaveChanges();
         return(sg.EnrollmentID);
     }
 }
コード例 #8
0
        static void Main(string[] args)
        {
            MySingleton obj  = MySingleton.ABC;
            MySingleton obj1 = MySingleton.World;

            obj.DoSomething();
            obj1.text();
            Console.ReadLine();
        }
コード例 #9
0
    public static void Create(params object[] parameters)
    {
        if (_instance != null)
        {
            return;
        }

        _instance = new MySingleton(parameters);
    }
コード例 #10
0
 void Awake()
 {
     if (m_instance)
     {
         Destroy(gameObject);
     }
     else
     {
         m_instance = this;
     }
 }
コード例 #11
0
ファイル: Program.cs プロジェクト: reyou/Ggg.Autofac
        /// <summary>
        /// Rather than tying those components directly to the singleton,
        /// it can be registered with the container as an instance:
        /// </summary>
        private static void RegisteringSingleton()
        {
            Console.WriteLine("\nRegisteringSingleton:\n");
            ContainerBuilder builder = new ContainerBuilder();

            builder.RegisterInstance(MySingleton.Instance).ExternallyOwned();
            IContainer  container   = builder.Build();
            MySingleton mySingleton = container.Resolve <MySingleton>();

            Console.WriteLine("MySingleton resolved.");
        }
コード例 #12
0
        public ActionResult Modifica(int id)
        {
            var repo = new StudentGradeRepository();
            var vs   = new VotoStudente();

            vs = repo.GetVotoStudenteForEdit(id);
            var vmedit = new EditGradeViewModel();

            vmedit = MySingleton.GetAutoMapperInstance().Map <EditGradeViewModel>(vs);
            return(View(vmedit));
        }
コード例 #13
0
ファイル: MySingleton.cs プロジェクト: polymetal0/FlyPortTest
 public virtual void Awake()
 {
     if (instance == null)
     {
         instance = this as MySingleton;
         DontDestroyOnLoad(this.gameObject);
     }
     else
     {
         Destroy(gameObject);
     }
 }
コード例 #14
0
 public static MySingleton GetInstance()
 {
     if (I == null)
     {
         I = new MySingleton();
         return(I);
     }
     else
     {
         return(I);
     }
 }
コード例 #15
0
    void Start()
    {
        MySingleton Data1 = MySingleton.GetInstance();
        MySingleton Data2 = MySingleton.GetInstance();

        Data1.PlusData();
        Data1.PlusData();
        Data1.PlusData();
        Data1.PlusData();
        Data1.PlusData();
        Data1.PlusData();
        Debug.Log(Data2.Data);
    }
コード例 #16
0
 public static MySingleton GetInstance()
 {
     if (Instance == null)
     {
         lock (initLock)
         {
             if (Instance == null)
             {
                 Instance = new MySingleton();
             }
         }
     }
     return(Instance);
 }
コード例 #17
0
 // chiama la stored procedure DeleteStudentGrade
 public void DeleteStudentGrade(VotoStudente vs)
 {
     using (var context = new SchoolEntities()) {
         StudentGrade studentGrade = new StudentGrade();
         var          sg           = MySingleton.GetAutoMapperInstance().Map <StudentGrade>(vs);
         // per cancellare un'entità dobbiamo prima "materializzarla" nel contesto EF
         var studentGradeToDelete = context.StudentGrades.Where(x => x.CourseID == sg.CourseID && x.StudentID == sg.StudentID).FirstOrDefault();
         if (studentGradeToDelete != null)
         {
             context.StudentGrades.Remove(studentGradeToDelete);
         }
         context.SaveChanges();
     }
 }
コード例 #18
0
        public void test_singleton_create_destroy()
        {
            MySingleton.createInstance();

            Assert.That(MySingleton.Instance, Is.Not.Null);

            MySingleton.destroyInstance();

#if DEBUG
            Assert.That(MySingleton.Instance, Is.Not.Null);
#else
            Assert.That(MySingleton.Instance, Is.Null);
#endif
        }
コード例 #19
0
    protected void btnOK_Click(object sender, EventArgs e)
    {
        string emp_id = "";
        string path   = Server.MapPath("~/UpFiles");

        foreach (GridViewRow gvr in GridView1.Rows)
        {
            if ((gvr.FindControl("CheckBox1") as CheckBox).Checked == true)
            {
                emp_id += string.Format("{0},", GridView1.DataKeys[gvr.RowIndex].Value.ToString());
            }
        }

        if (emp_id.EndsWith(","))
        {
            emp_id = emp_id.Substring(0, emp_id.Length - 1);
        }

        MySingleton.AlterRegistResult MyResult = MySingleton.AlterRegistResult.CancelRegistSucess;
        if (!string.IsNullOrEmpty(emp_id))
        {
            // MySingleton.AlterRegistResult MyResult = MySingleton.GetMySingleton().AlterRegist(null, null, MySingleton.AlterRegistType.CancelRegist, new Guid(activity_id), emp_id, regist_deadline, cancelregist_deadline, ((Button)sender).Page.Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.IndexOf('/', 7)) + "/ACMS/WebForm/RegistActivity/RegistedActivityQuery.aspx",path);
            string aa = string.Format("{0}://{1}{2}", HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Authority, HttpContext.Current.Request.ApplicationPath).TrimEnd('/');
            MyResult = MySingleton.GetMySingleton().AlterRegist(null, null, MySingleton.AlterRegistType.CancelRegist, new Guid(activity_id), emp_id, regist_deadline, cancelregist_deadline, aa + "/Default.aspx", path, "", aa + "/Default.aspx");


            GridView1.DataBind();
        }


        if (CancelPersonRegistClick != null)
        {
            this.Visible = false;
            CancelPersonRegistClick(this, e);
        }

        if (MyResult == MySingleton.AlterRegistResult.CancelRegistSucess)
        {
            clsMyObj.ShowMessage("取消報名完成。");
        }
        else if (MyResult == MySingleton.AlterRegistResult.CancelRegistFail_DayOver)
        {
            clsMyObj.ShowMessage("取消報名截止日之後無法取消報名!。");
        }
        else if (MyResult == MySingleton.AlterRegistResult.CancelRegistFail)
        {
            clsMyObj.ShowMessage("取消報名失敗!。");
        }
    }
コード例 #20
0
        public void TestMethod()
        {
            var instanceA = MySingleton.GetInstance();
            var instanceB = MySingleton.GetInstance();
            var random    = new Random();


            Assert.AreSame(instanceA, instanceB);

            instanceA.Value = random.Next(1, 100);
            Assert.AreEqual(instanceA.Value, instanceB.Value);

            instanceA.Value = random.Next(1, 100);
            Assert.AreEqual(instanceA.Value, instanceB.Value);
        }
コード例 #21
0
 public VotoStudente GetVotoStudenteForEdit(int idToEdit)
 {
     using (var context = new SchoolEntities()) {
         // per aggiornare un'entità dobbiamo prima "materializzarla" nel contesto EF
         var studentGradeToUpdate = context.StudentGrades.Where(x => x.EnrollmentID == idToEdit).FirstOrDefault();
         if (studentGradeToUpdate != null)
         {
             var vs = MySingleton.GetAutoMapperInstance().Map <VotoStudente>(studentGradeToUpdate);
             return(vs);
         }
         else
         {
             return(null);
         }
     }
 }
コード例 #22
0
            public static MySingleton GetInstance()
            {
                if (mySingleton == null)    // check
                {
                    lock (myLock)
                    {
                        if (mySingleton == null)    // double check
                        {
                            MySingleton newSingleton = new MySingleton();
                            System.Threading.Thread.MemoryBarrier();
                            mySingleton = newSingleton;
                        }
                    }
                }

                return(mySingleton);
            }
コード例 #23
0
        public ActionResult Visualizza(int id = 1)
        {
            var repo = new StudentGradeRepository();
            //var gradeList = repo.GetStudentGrades(id);
            var gradeList = repo.GetStudentGradesExt(id);

            var gradeVM = new GradeViewModel();

            gradeVM.StudentId = id;
            gradeVM.ListaVoti = new List <GradeDtoVM>();
            foreach (var grade in gradeList)
            {
                var dto = MySingleton.GetAutoMapperInstance().Map <GradeDtoVM>(grade);
                gradeVM.ListaVoti.Add(dto);
            }
            return(View(gradeVM));
        }
コード例 #24
0
            public static MySingleton GetInstance()
            {
                // Den yttre if-satsen gör så man inte behöver låsa i onödan
                if (_instance == null)
                {
                    // Låset förhindrar att i en multitrådmiljö att flera instanser skapas
                    lock (syncLock)
                    {
                        if (_instance == null)
                        {
                            _instance = new MySingleton();
                        }
                    }
                }

                return(_instance);
            }
コード例 #25
0
        private static void TestMySingleton()
        {
            Console.WriteLine("--- MySingleton ---");

            // Avkommentera koden nedan. Alla tre tärningskast ska ge samma resultat.

            var x = MySingleton.GetInstance();

            Console.WriteLine($"Diceroll x: {x.DiceRoll}");

            var y = MySingleton.GetInstance();

            Console.WriteLine($"Diceroll y: {y.DiceRoll}");

            var z = MySingleton.GetInstance();

            Console.WriteLine($"Diceroll z: {z.DiceRoll}");

            Console.WriteLine("");
        }
コード例 #26
0
        static void Main()
        {
            RemotingConfiguration.Configure("SponsorClient.exe.config", false);

            String idClient = "id" + Math.Abs(DateTime.Now.GetHashCode() / 1000000);

            Console.WriteLine("Client started, {0}", idClient);

            MyClientActivatedObject myClientActivated;

            try {
                myClientActivated = new MyClientActivatedObject();
            }
            catch (WebException) {
                Console.WriteLine("Ошибка при подключении к серверу.");
                Console.ReadLine();
                return;
            }

            myClientActivated.SetId(idClient);

            myClientActivated.MyRegistration(new CaoClientSponsor("CAO " + idClient));
            myClientActivated.Run();

            MySingleton mySingleton;

            try {
                mySingleton = new MySingleton();
            }
            catch (WebException) {
                Console.WriteLine("Ошибка при подключении к серверу.");
                Console.ReadLine();
                return;
            }

            mySingleton.MyRegistration(new SingletonClientSponsor("Singleton"));
            mySingleton.Run();

            Console.WriteLine("Press Enter to end ...");
            Console.ReadLine();
        }
コード例 #27
0
 public static MySingleton GetInstance()
 {
     if (mySingleton == null)       // 1st check
     {
         lock (myLock) {
             if (mySingleton == null)       // 2nd (double) check
             {
                 mySingleton = new MySingleton();
                 // Write-release semantics are implicitly handled by marking mySingleton with
                 // 'volatile', which inserts the necessary memory barriers between the constructor call
                 // and the write to mySingleton. The barriers created by the lock are not sufficient
                 // because the object is made visible before the lock is released.
             }
         }
     }
     // The barriers created by the lock are not sufficient because not all threads will
     // acquire the lock. A fence for read-acquire semantics is needed between the test of mySingleton
     // (above) and the use of its contents.This fence is automatically inserted because mySingleton is
     // marked as 'volatile'.
     return(mySingleton);
 }
コード例 #28
0
        // chiama la stored procedure GetStudentGrades passando il parametro di input e mappando il risultato su di una lista di domain entities utilizzando l'automapper
        public IEnumerable <VotoStudente> GetStudentGrades(int studentId)
        {
            var listaVoti = new List <VotoStudente>();

            using (var context = new SchoolEntities()) {
                var studentGrades = context.GetStudentGrades(studentId);
                foreach (var sg in studentGrades)
                {
                    var vs = MySingleton.GetAutoMapperInstance().Map <VotoStudente>(sg);
                    // l'automapper sostituisce il codice sottostante

                    /*
                     * var vs = new VotoStudente();
                     * vs.IdStudente = studentId;
                     * vs.IdCorso = sg.CourseID;
                     * vs.Voto = (decimal)sg.Grade;
                     */
                    listaVoti.Add(vs);
                }
                return(listaVoti);
            }
        }
コード例 #29
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            // automapper - creazione istanza mapper, configurazione e salvataggio istanza mapper nel singleton
            var config = new MapperConfiguration(cfg => {
                cfg.CreateMap <VotoStudente, GradeDtoVM>();
                cfg.CreateMap <VotoStudente, EditGradeViewModel>();
                cfg.CreateMap <StudentGrade, VotoStudente>()
                .ForMember(dest => dest.IdCorso, opt => opt.MapFrom(src => src.CourseID))
                .ForMember(dest => dest.Voto, opt => opt.MapFrom(src => src.Grade))
                .ForMember(dest => dest.IdStudente, opt => opt.MapFrom(src => src.StudentID))
                //.ForMember(dest => dest.CognomeStudente, opt => opt.Ignore())
                //.ForMember(dest => dest.NomeStudente, opt => opt.Ignore())
                ;
                cfg.CreateMap <GetStudentGrades2_Result, VotoStudente>()
                .ForMember(dest => dest.IdCorso, opt => opt.MapFrom(src => src.CourseID))
                .ForMember(dest => dest.Voto, opt => opt.MapFrom(src => src.Grade))
                .ForMember(dest => dest.IdStudente, opt => opt.MapFrom(src => src.StudentID))
                .ForMember(dest => dest.CognomeStudente, opt => opt.Ignore())
                .ForMember(dest => dest.NomeStudente, opt => opt.Ignore())
                ;

                cfg.CreateMap <VotoStudente, StudentGrade>()
                .ForMember(dest => dest.CourseID, opt => opt.MapFrom(src => src.IdCorso))
                .ForMember(dest => dest.Grade, opt => opt.MapFrom(src => src.Voto))
                .ForMember(dest => dest.StudentID, opt => opt.MapFrom(src => src.IdStudente))
                ;
            });
            IMapper mapper = new Mapper(config);

            MySingleton.AssignMapper(mapper);
        }
コード例 #30
0
    protected void btnOK_Click(object sender, EventArgs e)
    {
        string emp_id1 = "";
        string emp_id2 = "";
        string path    = Server.MapPath("~/UpFiles");

        //  先檢查是否低於下限

        int membersInt = 0;

        foreach (GridViewRow gvr in GridView1.Rows)
        {
            if ((gvr.FindControl("CheckBox1") as CheckBox).Checked == false)
            {
                membersInt += 1;
            }
        }

        ACMS.BO.ActivatyBO aBO = new ACMS.BO.ActivatyBO();
        ACMS.VO.ActivatyVO aVO = aBO.SelectActivatyByActivatyID(new Guid(activity_id));

        if (membersInt < aVO.team_member_min)
        {
            // string sdoPostScript = "  __doPostBack('" + btnCancelAll1.ClientID + "','1');   ";
            // string ScriptAll = " if (confirm('取消報名則團隊人數將低於下限,是否要全隊取消報名?')==true) { alert ('1232456'); window.open('http://www.google.com.tw');" + sdoPostScript + "} ";
            //  string ScriptAll = " if (confirm('取消報名則團隊人數將低於下限,是否要全隊取消報名?')==true) { alert ('1232456')} ";

            //BasePage.RunClientScript (this.Page , ScriptAll);

            //clsMyObj.ShowMessage("若您取消報名則團隊人數將低於下限,因此系統將取消整個團隊的報名資格,若確定要取消報名,請點選「確定」按鈕後於下個視窗點選「確定取消報名」按鈕!");
            btnOK.Visible        = false;
            btnCancelAll.Visible = false;
            btnOK0.Visible       = true;
            lblMessage.Visible   = true;
            GridView1.Visible    = false;
            mpSearch.Show();
            return;
        }



        //已換隊長

        if (newBoss != "")
        {
            foreach (GridViewRow gvr in GridView1.Rows)
            {
                if ((gvr.FindControl("CheckBox1") as CheckBox).Checked == true)
                {
                    if (GridView1.DataKeys[gvr.RowIndex].Value.ToString() == newBoss)
                    {
                        clsMyObj.ShowMessage("您為此隊隊長,請更換隊長,再進行取消!");
                        this.mpSearch.Show();
                        return;
                    }
                }
            }
            ACMS.DAO.ActivityTeamMemberDAO myActivityTeamMemberDAO = new ACMS.DAO.ActivityTeamMemberDAO();
            myActivityTeamMemberDAO.ChangeBoss(new Guid(activity_id), newBoss, emp_id);
        }

        foreach (GridViewRow gvr in GridView1.Rows)
        {
            if ((gvr.FindControl("CheckBox1") as CheckBox).Checked == true && (gvr.FindControl("RadioButton1") as RadioButton).Checked == true)
            {
                clsMyObj.ShowMessage("您為此隊隊長,請更換隊長,再進行取消!");
                this.mpSearch.Show();
                return;
            }
        }



        foreach (GridViewRow gvr in GridView1.Rows)
        {
            if ((gvr.FindControl("CheckBox1") as CheckBox).Checked == true)
            {
                emp_id1 += string.Format("{0},", GridView1.DataKeys[gvr.RowIndex].Value.ToString());
            }
            emp_id2 += string.Format("{0},", GridView1.DataKeys[gvr.RowIndex].Value.ToString());
        }

        if (emp_id1.EndsWith(","))
        {
            emp_id1 = emp_id1.Substring(0, emp_id1.Length - 1);
        }

        if (emp_id1 == "" && newBoss == "")
        {
            clsMyObj.ShowMessage("您未取消報名也未更換隊長,程式沒有修改任資料!");

            return;
        }

        MySingleton.AlterRegistResult MyResult = MySingleton.AlterRegistResult.CancelRegistSucess;
        if (!string.IsNullOrEmpty(emp_id1))
        {
            string aa = string.Format("{0}://{1}{2}", HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Authority, HttpContext.Current.Request.ApplicationPath).TrimEnd('/');

            //MySingleton.AlterRegistResult MyResult = MySingleton.GetMySingleton().AlterRegist_Team(null, null, null, MySingleton.AlterRegistType.CancelRegist, new Guid(activity_id), emp_id1, regist_deadline, cancelregist_deadline, ((Button)sender).Page.Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.IndexOf('/', 7)) + "/ACMS/WebForm/RegistActivity/RegistedActivityQuery.aspx", path);
            MyResult = MySingleton.GetMySingleton().AlterRegist_Team(null, null, null, MySingleton.AlterRegistType.CancelRegist, new Guid(activity_id), emp_id1, regist_deadline, cancelregist_deadline, aa + "/Default.aspx", path, "", aa + "/Default.aspx");
            //.ResolveUrl("~/WebForm/RegistActivity/RegistedActivityQuery.aspx"));

            GridView1.DataBind();
        }

        if (CancelTeamRegistClick != null)
        {
            this.Visible = false;
            CancelTeamRegistClick(this, e);
        }

        ACMS.DAO.ActivityRegistDAO regDao = new ACMS.DAO.ActivityRegistDAO();
        emp_id2 = emp_id2.TrimEnd(',');
        string members = regDao.AllTeamMemberByMembers(new Guid(activity_id), emp_id2);

        if (members == "")
        {
            clsMyObj.ShowMessage("已達人數下限,目前已取消該隊的報名資格");
            return;
        }
        if (MyResult == MySingleton.AlterRegistResult.CancelRegistSucess)
        {
            if (newBoss == "" && emp_id1 != "")
            {
                clsMyObj.ShowMessage("取消報名完成。");
            }
            if (newBoss != "" && emp_id1 != "")
            {
                clsMyObj.ShowMessage("更換隊長及取消報名完成。");
            }
            if (newBoss != "" && emp_id1 == "")
            {
                clsMyObj.ShowMessage("更換隊長完成。");
            }
        }
        else if (MyResult == MySingleton.AlterRegistResult.CancelRegistFail_DayOver)
        {
            clsMyObj.ShowMessage("取消報名截止日之後無法取消報名!。");
        }
        else if (MyResult == MySingleton.AlterRegistResult.CancelRegistFail)
        {
            clsMyObj.ShowMessage("取消報名失敗!。");
        }
    }
コード例 #31
0
ファイル: clsMyObj.cs プロジェクト: puentepr/creasys-acms
    public static MySingleton GetMySingleton()
    {
        lock (typeof(MySingleton))
        {
            if (_singleton == null)
            {
                _singleton = new MySingleton();
            }
        }

        return _singleton;
    }