ningshuxia
2025-03-26 6171f94b5ca6c804ac2892d214943ff0ac400d26
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System.Runtime.Serialization.Formatters.Binary;
 
namespace HydroUI
    [Serializable]
    public static class HelperC
    {
        public static Type GetObjType(this MapObjectType type)
        {
            switch (type)
            {
                case MapObjectType.全部: return null;
                case MapObjectType.节点: return typeof(JunctionViewModel);
                case MapObjectType.水表: return typeof(MeterViewModel);
                case MapObjectType.水库: return typeof(ReservoirViewModel);
                case MapObjectType.水池: return typeof(TankViewModel);
                case MapObjectType.喷头: return typeof(NozzleViewModel);
                case MapObjectType.管线: return typeof(PipeViewModel);
                case MapObjectType.阀门: return typeof(ValveViewModel);
                case MapObjectType.重复器: return typeof(RepeaterViewModel);
                case MapObjectType.水泵: return typeof(PumpViewModel);
                case MapObjectType.阀门点: return typeof(ValveNodeViewModel);
                case MapObjectType.水泵点: return typeof(PumpNodeViewModel);
                default: return null;
            }
 
        }
 
 
        public static T DeepCopy<T>(this T obj)
        {
            dynamic retval;
            using (MemoryStream ms = new MemoryStream())
            {
                BinaryFormatter bf = new BinaryFormatter();
                //序列化成流
                bf.Serialize(ms, obj);
                ms.Seek(0, SeekOrigin.Begin);
                //反序列化成对象
                retval = bf.Deserialize(ms);
                ms.Close();
            }
            return (T)retval;
        }
 
 
        public static void ClearFileReadOnly(string filePath)
        {
            if (File.Exists(filePath))
            {
                // 获取当前文件属性
                FileAttributes attributes = File.GetAttributes(filePath);
 
                // 如果文件被设置为只读,则移除只读属性
                if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                {
                    attributes &= ~FileAttributes.ReadOnly; // 移除只读标志
 
                    // 设置新的文件属性
                    File.SetAttributes(filePath, attributes);
 
                }
 
            }
        }
 
        public static void Copy(string source, string destination, bool isOverWrite = true)
        {
            //判断源文件是否存在
            if (!System.IO.File.Exists(source))
            {
                return;
            }
            //判断源文件是否为只读,如果是则更改为非只读
            System.IO.FileInfo file = new System.IO.FileInfo(source);
            if (file.IsReadOnly)
            {
                file.IsReadOnly = false;
            }
            //判断目标文件夹是否存在,不存在则创建
            string dir = System.IO.Path.GetDirectoryName(destination);
            try
            {
                System.IO.File.Copy(source, destination, isOverWrite);
            }
            catch (Exception)
            {
 
            }
 
        }
    }
}