Beispiel #1
0
        public void TestDerivedFileName()
        {
            string path;

            using (DisposingList l = new DisposingList())
            {
                TempFile ftarget = new TempFile();
                ftarget.Delete();

                l.Add(ftarget);
                TempFile fbigone = TempFile.Attach(String.Format("{0}.~{1:x4}", ftarget.TempPath, 0x10008 - 25));
                fbigone.Create().Dispose();
                Assert.IsTrue(fbigone.Exists);
                l.Add(fbigone);
                path = ftarget.TempPath;

                string tmpName;
                Dictionary <string, object> names = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);

                for (int i = 0; i < 25; i++)
                {
                    Stream s = ReplaceFile.CreateDerivedFile(ftarget.TempPath, out tmpName);
                    l.Add(TempFile.Attach(tmpName));
                    l.Add(s);
                    names.Add(tmpName, null);
                }

                fbigone.Delete();
                Assert.AreEqual(25, Directory.GetFiles(Path.GetDirectoryName(path), Path.GetFileName(path) + "*").Length);
            }
            Assert.AreEqual(0, Directory.GetFiles(Path.GetDirectoryName(path), Path.GetFileName(path) + "*").Length);
        }
Beispiel #2
0
        public void TestReplaceRollback()
        {
            string testdata = Guid.NewGuid().ToString();

            using (TempFile replace = new TempFile())
                using (ReplaceFile temp = new ReplaceFile(replace.TempPath))
                {
                    temp.WriteAllText(testdata);
                    Assert.IsTrue(temp.Exists);
                    temp.Rollback();
                    Assert.IsFalse(temp.Exists);
                }
        }
        public DataTable GetDataTable(ReplaceFile.ServerDatabaseEntityCRF dse, string sql, SqlParameter[] sp)
        {
            DataTable dt;
            switch (dse.ServerType)
            {
                case SrnprCommon.EnumCommon.DataServerType.MsSql:
                    dt = DataHelper.SqlHelperCDH.ExecuteDataTable(dse.ConnString, sql, sp);
                    break;

                default:
                    dt = new DataTable();
                    break;
            }
            return dt;
        }
Beispiel #4
0
 public override void OnInspectorGUI()
 {
     serializedObject.Update();
     RF = (ReplaceFile)target;
     if (GUILayout.Button(" Change Model"))
     {
         RF.GetInfo();
     }
     if (GUILayout.Button("ChangeMaterial"))
     {
         RF.SetMats();
     }
     if (GUILayout.Button("Delete"))
     {
         RF.DeleteObj();
     }
 }
Beispiel #5
0
        public void TestIsFullPath()
        {
            string tmpname = Guid.NewGuid().ToString();

            Assert.IsFalse(File.Exists(tmpname));
            using (ReplaceFile f = new ReplaceFile(tmpname))
            {
                Assert.IsTrue(Path.IsPathRooted(f.TargetFile));
                Assert.AreEqual(Environment.CurrentDirectory, Path.GetDirectoryName(f.TargetFile));
            }
            Assert.IsFalse(File.Exists(tmpname));
            using (TransactFile f = new TransactFile(tmpname))
            {
                Assert.IsTrue(Path.IsPathRooted(f.TargetFile));
                Assert.AreEqual(Environment.CurrentDirectory, Path.GetDirectoryName(f.TargetFile));
            }
            Assert.IsFalse(File.Exists(tmpname));
        }
Beispiel #6
0
        private ITransactable WriteBytes(ContentRecord.Builder builder, byte[] content)
        {
            AssertModify();
            if (!builder.HasContentStoreId)
            {
                ulong  fid;
                string name;
                do
                {
                    fid  = Guid.NewGuid().ToUInt64();
                    name = FileName(fid);
                }while(File.Exists(name));

                builder.SetContentStoreId(fid);
            }

            ReplaceFile f = new ReplaceFile(FileName(builder.ContentStoreId));

            f.WriteAllBytes(content);
            return(f);
        }
Beispiel #7
0
        public void TestReplaceFiles()
        {
            string testdata = Guid.NewGuid().ToString();
            string tmpPath;

            TempFile replace = new TempFile();

            using (ReplaceFile temp = new ReplaceFile(replace.TempPath))
            {
                Assert.AreEqual(temp.TargetFile, replace.TempPath);
                tmpPath = temp.TempPath;
                Assert.IsTrue(temp.Exists);
                temp.WriteAllText(testdata);
                //missing commit:
                //temp.Commit();
            }
            Assert.AreEqual(0, replace.Length);
            Assert.IsFalse(File.Exists(tmpPath));

            string backupfile = Path.ChangeExtension(replace.TempPath, ".bak");

            File.Delete(Path.ChangeExtension(replace.TempPath, ".bak"));
            Assert.IsFalse(File.Exists(backupfile));
            replace.WriteAllText("backup");

            //now for real
            using (ReplaceFile temp = new ReplaceFile(replace.TempPath, ".bak"))
            {
                tmpPath = temp.TempPath;
                Assert.IsTrue(temp.Exists);
                temp.WriteAllText(testdata);
                temp.Commit();
            }
            Assert.IsFalse(File.Exists(tmpPath));
            Assert.AreEqual(testdata, replace.ReadAllText());

            Assert.IsTrue(File.Exists(backupfile));
            using (TempFile fbackup = TempFile.Attach(backupfile))
                Assert.AreEqual("backup", fbackup.ReadAllText());
        }
Beispiel #8
0
        /// <summary>
        /// 
        /// Description: 发送邮件
        /// Author:Liudpc
        /// Create Date: 2010-6-30 11:06:50
        /// </summary>
        /// <param name="emailInfo"></param>
        /// <param name="emailServer"></param>
        /// <returns></returns>
        public static bool Send(ReplaceFile.DoSendEmailEntityCRF emailInfo,ReplaceFile.ServerEmailEntityCRF emailServer)
        {
            try
            {

                MailAddress from = new MailAddress(emailServer.SendMailName, emailServer.SendMailDisplayName);
                MailAddress to = new MailAddress(emailInfo.ToEmail);
                System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(from, to);

                mail.Subject = emailInfo.Title;
                mail.Body = emailInfo.Content;
                mail.BodyEncoding = Encoding.UTF8; ;
                mail.SubjectEncoding = Encoding.UTF8;

                mail.IsBodyHtml = emailServer.IsBodyHtml;

                SmtpClient client = new SmtpClient(emailServer.SmtpHost);

                NetworkCredential smtpuserinfo = new System.Net.NetworkCredential(emailServer.UserName, emailServer.Password);
                client.Credentials = smtpuserinfo;

                client.EnableSsl = emailServer.EnableSsl;

                if (!string.IsNullOrEmpty(emailServer.Port))
                {
                    client.Port = int.Parse(emailServer.Port);
                }

                client.Send(mail);

                emailInfo.SendSuccessFlag = true;
            }
            catch
            {
                emailInfo.SendSuccessFlag = false;
            }

            return emailInfo.SendSuccessFlag;
        }