示例#1
0
        /// <summary>
        /// Generate new client ID.
        /// </summary>
        /// <returns></returns>
        /// <remarks> If remote DB isn't connected an exception will be thrown. </remarks>
        public int GenerateClientId()
        {
            SystemDetails details = new SystemDetails();

            string url = string.Format(
                "{0}/GenerateClientId.php?Cpu={1}&Ram={2}&FreeSpace={3}&DiskSize={4}&OS={5}&ServicePack={6}&is64Bit={7}&HostName={8}&UserName={9}&Version={10}", WEBSITE_ADDRESS,
                details.CPU, details.RamMemorySIze, details.PartitionFreeSpace, details.PartitionSize, details.OS, details.SP, details.Is64Bit ? "1" : "0", details.HostName, details.UserName,
                typeof(DAL).Assembly.GetName().Version);

            Debug.Write(url);
            string response = CommonFuncs.SendHttpGetRequest(url);

            Debug.Write(response);
            foreach (var part in response.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
            {
                if (part.StartsWith("ID="))
                {
                    Id = int.Parse(part.Replace("ID=", ""));
                    _keepAliveTimer = new Timer((x) => UpdateKeepAlive(), null, 0, KEEPALIVE_PERIOD);
                    SubscriseCurrentVersion(Id);
                    break;
                }
                else if (part.StartsWith("ERROR=") && !part.StartsWith("ERROR=Duplicate entry"))
                {
                    break;
                }
            }
            return(Id);
        }
        private void CreateSelfDeleteBatch(string localFilename, string appFilename)
        {
            string baseFolder = Path.GetDirectoryName(localFilename);
            bool   is64       = SystemDetails.IsOs64Bit();

            using (StreamWriter writer = new StreamWriter(localFilename))
            {
                writer.WriteLine("@echo off");
                writer.WriteLine(":CHECK");
                writer.WriteLine("tasklist /fi \"PID eq " + Process.GetCurrentProcess().Id + "\" | find \"" + Process.GetCurrentProcess().Id + "\">NUL");
                writer.WriteLine("if \"%ERRORLEVEL%\"==\"0\" goto WasteTime");
                writer.WriteLine("goto Delete");
                writer.WriteLine(":WasteTime");
                writer.WriteLine("timeout /t 1");
                writer.WriteLine("goto CHECK");
                writer.WriteLine(":Delete");

                //string bitsVersion = is64 ? "64" : "";
                writer.WriteLine(@"%SystemRoot%\Microsoft.NET\Framework{0}\v2.0.50727\installutil.exe -u {1}", "", appFilename);
                writer.WriteLine("cd \"" + baseFolder + "\"");

                writer.WriteLine("del Conf.xml");
                writer.WriteLine("del Conf.bak.xml");
                writer.WriteLine("del log4net.dll");
                writer.WriteLine("del log4net.xml");
                writer.WriteLine("del mylogfile*");
                writer.WriteLine("del TezaExperiment.dll");
                writer.WriteLine("del TezaExperiment.dll.config");
                writer.WriteLine("del TezaExperiment.pdb");
                //writer.WriteLine("del InstallUtil.InstallLog");
                writer.WriteLine("del \"" + appFilename + "\"");
                //writer.WriteLine("del \"" + appFilename.Replace(".exe", ".InstallLog") + "\"");
                //writer.WriteLine("del \"" + appFilename.Replace(".exe", ".InstallState") + "\"");
                writer.WriteLine("del \"" + appFilename.Replace(".exe", ".pdb") + "\"");
                writer.WriteLine("del \"" + appFilename + ".config" + "\"");

                // Bat deletes itself

                if (!string.IsNullOrEmpty(_tempFolder) && localFilename.Contains(_tempFolder))
                {
                    writer.WriteLine("rmdir /Q /S \"" + _tempFolder + "\"");
                }
                else
                {
                    writer.WriteLine("del /F \"" + localFilename + "\"");
                }
            }
        }