Beispiel #1
0
        public string EncodeCompressData(string args, string username, string tablename, string dbname, bool compressdata)
        {
            try
            {
                string ap = "";



                // ZipFile z = new ZipFile();
                Maintenance_Backup back = new Maintenance_Backup();



                if ((args != null) && (username != null) && (tablename != null) &&
                    (dbname != null))
                {
                    string path = Path.Combine(MultyUser.GetUsersMainFolder("system"), "WhiteTiger", MultyUser.tmpFolder);


                    if (Directory.Exists(path) != true)
                    {
                        back.CreateFolder(path);
                    }

                    string rndfile = tablename + Guid.NewGuid().ToString() + ".hbt";
                    string file    = Path.Combine(path, rndfile);
                    string zipdir  = path; // Path.Combine(MultyUser.GetUsersMainFolder("system"), "WhiteTiger", MultyUser.tmpFolder, "zip");
                    string zipfile = Path.Combine(zipdir, rndfile + ".zip");

                    if (Directory.Exists(file) != true)
                    {
                        back.CreateFolder(file);
                    }
                    StreamWriter wr = File.CreateText(Path.Combine(file, rndfile));
                    wr.WriteLine(args);
                    wr.Flush();
                    wr.Close();
                    wr.Dispose();
                    if (compressdata)
                    {
                        FastZip zip = new FastZip();
                        zip.CreateZip(zipfile, file, false, null);


                        ap = zipfile;
                    }
                    else
                    {
                        ap = file;
                    }
                }

                return(ap);
            }
            catch (Exception ex)
            {
                program.errorreport(ex);

                return(null);
            }
        }
        public MainWindow()
        {
            try
            {
                InitializeComponent();
                Program.CreateTempPath();
                multyuser.initialiseMultyUserInterface(false);

                MultyUser.CreateHydrobaseFileSystem(Environment.UserName);
                HydrobaseSDK.SDKBase.UserMainPath = MultyUser.GetUsersMainFolder(Environment.UserName);
                Maintenance_Backup mnt = new Maintenance_Backup();
                mnt.CreateFolder(Path.Combine(MultyUser.GetUsersMainFolder(Environment.UserName), BaseClass.tmpFolder));

                discoveryclient = new DiscoveryClient(new UdpDiscoveryEndpoint());
                FindResponse    discoveryResponse = discoveryclient.Find(new FindCriteria(typeof(White_Tiger.IWhiteTigerService)));
                EndpointAddress address;
                if (discoveryResponse.Endpoints.Count > 0)
                {
                    address        = discoveryResponse.Endpoints[0].Address;
                    Program.client = new White_TigerServiceReference.WhiteTigerServiceClient(new BasicHttpBinding(), address);
                }
                else
                {
                    Program.client = new White_TigerServiceReference.WhiteTigerServiceClient();
                }

                ;

                // MessageBox.Show(address.Uri.ToString() );


                BasicHttpBinding httpBinding = new BasicHttpBinding();
                httpBinding.MaxReceivedMessageSize = 2147483647;
                httpBinding.MaxBufferSize          = 2147483647;
                BindingParameterCollection par = new BindingParameterCollection();
                par.Add(httpBinding);

                Program.client.Endpoint.Behaviors[0].AddBindingParameters(Program.client.Endpoint, par);



                Program.client.Open();
                // this.Text += "";

                //Program.client.Open();
                lblStatus.Text               = Program.client.State.ToString();
                lblServerAddress.Text        = Program.client.Endpoint.Address.ToString();
                lblServerVer.Text            = Program.client.GetVersion();
                this.Text                    = Application.ProductName;
                aboutToolStripMenuItem.Text += "  " + Application.ProductName;
            }
            catch (Exception ex)
            {
                System.Net.WebException webex = new System.Net.WebException();
                if (ex.GetType() != webex.GetType())
                {
                    Program.errorreport(ex);
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
        private string EncodeAndCompressData(string args, string username, string tablename)
        {
            try
            {
                string ap = "";



                // ZipFile z = new ZipFile();
                Maintenance_Backup back = new Maintenance_Backup();

                if (WhiteTigerService.pref.UseCompressition)
                {
                    if ((args != null) && (username != null) && (tablename != null))
                    {
                        string path = Path.Combine(MultyUser.GetUsersMainFolder("system"), "WhiteTiger", MultyUser.tmpFolder);

                        if (Directory.Exists(path) != true)
                        {
                            back.CreateFolder(path);
                        }

                        string   rndfile = tablename + Guid.NewGuid().ToString() + ".hbt";
                        string   file    = Path.Combine(path, rndfile);
                        FileInfo fi      = new FileInfo(file);

                        /*  StreamWriter f = File.CreateText(file);
                         * f.Write(args);
                         * f.Close();
                         * f.Flush();*/
                        FileStream      fsOut           = File.Create(file + ".zip");
                        ZipOutputStream zipOutputStream = new ZipOutputStream(fsOut);
                        zipOutputStream.SetLevel(9);
                        //FileStream fs = File.OpenRead(file);
                        ZipEntry entry = new ZipEntry(ZipEntry.CleanName(file));
                        entry.Size     = fi.Length;
                        entry.DateTime = fi.LastWriteTime;
                        byte[] buffer = new byte[4096];
                        using (FileStream streamReader = File.OpenRead(file))
                        {
                            StreamUtils.Copy(streamReader, zipOutputStream, buffer);
                        }
                        zipOutputStream.PutNextEntry(entry);



                        zipOutputStream.Close();



                        ap = this.GetServiceUrl() + "GetFile/" + Path.GetFileName(file) + ".zip";
                    }
                }
                else
                {
                    if ((args != null) && (username != null) && (tablename != null))
                    {
                        string path = Path.Combine(MultyUser.GetUsersMainFolder("System"),
                                                   "WhiteTiger", MultyUser.tmpFolder);

                        if (Directory.Exists(path) != true)
                        {
                            back.CreateFolder(path);
                        }

                        string       rndfile = tablename + Guid.NewGuid().ToString() + ".hbt";
                        string       file    = Path.Combine(path, rndfile);
                        StreamWriter wr      = File.CreateText(file);
                        wr.WriteLine(args);
                        wr.Flush();
                        wr.Close();
                        wr.Dispose();



                        ap = this.GetServiceUrl() + "GetFile/" + Path.GetFileName(file);
                    }
                }
                return(ap);
            }
            catch (Exception ex)
            {
                program.errorreport(ex);

                return(null);
            }
        }