Beispiel #1
0
    void OnFinishRequest(HTTPRequest request, HTTPResponse response)
    {
        if (response != null)
        {
            string info = response.DataAsText;
            if (!string.IsNullOrEmpty(info))
            {
                //string info = System.IO.File.ReadAllText(Application.dataPath + "/_VerInfo/VerInfo.txt",System.Text.Encoding.UTF8);
                VerInfoList verInfo = JsonUtility.FromJson <VerInfoList>(response.DataAsText);
                foreach (var item in verInfo.list)
                {
                    VerInfo infoNew = new VerInfo(item.SocketIp, item.Port, item.Ver);
                    if (_dicVerInfo.ContainsKey(infoNew.Ver))
                    {
                        _dicVerInfo[infoNew.Ver] = infoNew;
                    }
                    else
                    {
                        _dicVerInfo.Add(infoNew.Ver, infoNew);
                    }
                }

                if (OnCallBack != null)
                {
                    OnCallBack(true);
                }

                return;
            }
        }


        Debug.LogError("网络连接出错,配置信息无法获取");

        if (OnCallBack != null)
        {
            OnCallBack(false);
        }

//		System.IO.StringReader sr = new System.IO.StringReader(response.DataAsText);
//		if(sr != null)
//		{
//			string lineTxt = sr.ReadLine();
//			while(!string.IsNullOrEmpty(lineTxt))
//			{
//				Debug.Log("line:" + lineTxt);
//
//				lineTxt = sr.ReadLine();
//			}
//
//			sr.Close();
//		}
//
//		string info = System.IO.File.ReadAllText(Application.dataPath + "/_VerInfo/VerInfo.txt",System.Text.Encoding.UTF8);
//		VerInfoList verInfo = JsonUtility.FromJson<VerInfoList>(info);
//		foreach(var item in verInfo.list)
//		{
//			Debug.Log(item.SocketIp + "," + item.Ver);
//		}
    }
Beispiel #2
0
    public VerInfo BuildFileTxt(List <AssetBundleBuild> list)
    {
        //string filePath = outPath + "/"+m_BuildResInfo.ResName+".txt";
        VerInfo infos = new VerInfo();

        infos.ver = ProjectBuild.version;
        foreach (AssetBundleBuild ab in list)
        {
            for (int i = infos.files.Count - 1; i >= 0; i--)
            {
                if (infos.files[i].fileName == ab.assetBundleName)
                {
                    infos.files.RemoveAt(i);
                }
            }
            ABInfo info = new ABInfo();
            info.fileName = ab.assetBundleName;
            info.sha1     = BuildAB.GenHashOne(outPath + "/" + ab.assetBundleName, ref info.length);
            infos.files.Add(info);
            foreach (string str in ab.assetNames)
            {
                info.assets.Add(Path.GetFileName(str));
            }
        }
        return(infos);
        //File.WriteAllText(filePath , JsonUtility.ToJson(infos, true));
    }
Beispiel #3
0
    public static void BuildCollectionsResByInfo(BuildCollectionResInfo info)
    {
        string              fileName = Application.streamingAssetsPath + "/" + info.CollectionID + "ver.txt";
        List <VerInfo>      allList  = new List <VerInfo>();
        List <BuildResInfo> list     = new List <BuildResInfo>(info.builds);

        for (int i = list.Count - 1; i >= 0; i--)
        {
            BuildInfoAB    build = new BuildInfoAB(list[i]);
            List <VerInfo> infos = build.BuildAb(2);
            foreach (VerInfo _v in infos)
            {
                if (_v != null)
                {
                    allList.Add(_v);
                }
            }
        }
        VerInfo buildinfo = new VerInfo();

        foreach (VerInfo ver in allList)
        {
            buildinfo.ver = ver.ver;
            buildinfo.files.AddRange(ver.files);
        }
        string txtStr = JsonUtility.ToJson(buildinfo, true);

        File.WriteAllText(fileName, txtStr);
        AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
    }
    public void RefreshLocalVerInfo(Action callBack)
    {
        string loaclFileName = AppConst.AppExternalDataPath + "/" + GameCfgMgr.Instance.localGameCfg.CollectionIDVerFileName;

        if (File.Exists(loaclFileName))
        {
            string content = File.ReadAllText(loaclFileName);
            try
            {
                verInfo = JsonUtility.FromJson <VerInfo>(content);
                Debug.LogWarning("本地有配置信息 版本为:" + verInfo.ver);
                verInfo.verName = Path.GetFileNameWithoutExtension(GameCfgMgr.Instance.localGameCfg.CollectionIDVerFileName);
                callBack();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        else
        {
            verInfo         = new VerInfo();
            verInfo.ver     = "0.0.0";
            verInfo.verName = Path.GetFileNameWithoutExtension(GameCfgMgr.Instance.localGameCfg.CollectionIDVerFileName);
            if (callBack != null)
            {
                callBack();
            }
        }
    }
    /// <summary>
    /// 获取要解压的文件
    /// </summary>
    /// <param name="verTextName"></param>
    /// <param name="callBack"></param>
    public void GetDecompressionTaskList(VerInfo localVer, Action <DecompressionOrDownInfo> callBack)
    {
        string  sourceUrl = AppConst.SourceResPathUrl + "/" + localVer.verName + ".txt";
        VerInfo remoteVer = null;

        Action <WWW> loadlocaled = www =>
        {
            if (www != null && string.IsNullOrEmpty(www.error))
            {
                try
                {
                    remoteVer = JsonUtility.FromJson <VerInfo>(www.text);
                }
                catch (Exception)
                {
                    Debug.LogError("本地没有这个文件:" + sourceUrl);
                }
            }
            else
            {
                Debug.LogError("本地没有这个文件:" + sourceUrl);
            }
            ComparisonInfo          info = VerInfo.ComparisonVer(localVer, remoteVer);
            DecompressionOrDownInfo dord = new DecompressionOrDownInfo();
            dord.remoteVer      = remoteVer;
            dord.localVer       = localVer;
            dord.comparisonInfo = info;
            if (callBack != null)
            {
                callBack(dord);
            }
        };

        ComUtil.WWWLoad(sourceUrl, loadlocaled);
    }
    public void GetDownList(VerInfo localVer, Action <DecompressionOrDownInfo> callBack)
    {
        if (downLoadInfo == null)
        {
            DecompressionOrDownInfo downInfo = new DecompressionOrDownInfo();
            downInfo.localVer       = localVer;
            downInfo.remoteVer      = null;
            downInfo.comparisonInfo = VerInfo.ComparisonVer(localVer, downInfo.remoteVer);
            if (callBack != null)
            {
                callBack(downInfo);
            }
            return;
        }
        string  remoturl  = downLoadInfo.ResUrl + "/" + localVer.verName + ".txt";
        VerInfo remoteVer = null;

        Debug.LogWarning("准备校验远程文件:" + remoturl);
        Action <WWW> wwwed = www =>
        {
            if (www != null && string.IsNullOrEmpty(www.error))
            {
                try
                {
                    remoteVer = JsonUtility.FromJson <VerInfo>(www.text);
                }
                catch (System.Exception ex)
                {
                    Debug.LogError("远程文件解析失败:text=" + www.text);
                }
            }
            else
            {
                Debug.LogError("从远程下载文件失败:url=" + remoturl);
            }

            ComparisonInfo info = VerInfo.ComparisonVer(localVer, remoteVer);
            if (localVer != null)
            {
                Debug.LogWarning("检查完成 本地版本:" + localVer.ver);
            }
            if (remoteVer != null)
            {
                Debug.LogWarning("检查完成 远程版本:" + remoteVer.ver);
            }
            DecompressionOrDownInfo dord = new DecompressionOrDownInfo();
            dord.remoteVer      = remoteVer;
            dord.localVer       = localVer;
            dord.comparisonInfo = info;
            if (callBack != null)
            {
                callBack(dord);
            }
            www.Dispose();
        };

        Debug.LogWarning("从远程下载文件" + remoturl);
        ComUtil.WWWLoad(remoturl, wwwed);
    }
Beispiel #7
0
    public VerInfo GetVerInfo(string ver)
    {
        VerInfo info = null;

        _dicVerInfo.TryGetValue(ver, out info);

        return(info);
    }
Beispiel #8
0
    /// <summary>
    /// 发送连接请求
    /// </summary>
    public void SendConnect()
    {
        VerInfo info = MyHttp.Instance.GetVerInfo(VerInfo.CurrentVer);

        if (info != null)
        {
            ConnectServer(info.SocketIp, info.Port);
        }
    }
Beispiel #9
0
    public void SendReConnect()
    {
//      ReConnectServer(AppConst.SocketAddress, AppConst.SocketPort);
        VerInfo info = MyHttp.Instance.GetVerInfo(VerInfo.CurrentVer);

        if (info != null)
        {
            ReConnectServer(info.SocketIp, info.Port);
        }
    }
Beispiel #10
0
        private static string getDetailedInfo(VerInfo infoNum, System.Diagnostics.FileVersionInfo fileVerInfo)
        {
            string ret = "";

            switch (infoNum)
            {
                case VerInfo.COMMENTS:
                    ret = fileVerInfo.Comments;
                    break;
                case VerInfo.COMPANYNAME:
                    ret = fileVerInfo.CompanyName;
                    break;
                case VerInfo.FILEDESCRIPSTION:
                    ret = fileVerInfo.FileDescription;
                    break;
                case VerInfo.FILEVERSION:
                    ret = fileVerInfo.FileVersion;
                    break;
                case VerInfo.INTERNALNAME:
                    ret = fileVerInfo.InternalName;
                    break;
                case VerInfo.LEAGALCOPYRIGHT:
                    ret = fileVerInfo.LegalCopyright;
                    break;
                case VerInfo.LEAGALTRADEMARKS:
                    ret = fileVerInfo.LegalTrademarks;
                    break;
                case VerInfo.ORIGINALFILENAME:
                    ret = fileVerInfo.OriginalFilename;
                    break;
                case VerInfo.PRIVATEBUILD:
                    ret = fileVerInfo.PrivateBuild;
                    break;
                case VerInfo.PRODUCTNAME:
                    ret = fileVerInfo.ProductName;
                    break;
                case VerInfo.PRODUCTVERSION:
                    ret = fileVerInfo.ProductVersion;
                    break;
                case VerInfo.SPECIALBUILD:
                    ret = fileVerInfo.SpecialBuild;
                    break;
                default:
                    ret = null;
                    break;
            }

            // If information does not exit.
            if (ret == null)
            {
                throw new System.IO.FileNotFoundException();
            }

            return ret;
        }
Beispiel #11
0
        public static VerInfo GetVer()
        {
            VerInfo verInfo = (VerInfo)CacheUtils.Get("JsonLeeCMS_CacheForVER");

            if (verInfo == null)
            {
                verInfo = Ver.GetData();
                CacheUtils.Insert("JsonLeeCMS_CacheForVER", verInfo, 60, 1);
            }
            return(verInfo);
        }
Beispiel #12
0
    /// <summary>
    /// 生成某个配置文件的AB
    /// </summary>
    /// <param name="info"></param>
    public static void BuildResByInfo(BuildResInfo info, int flag)
    {
        string  fileName = Application.streamingAssetsPath + "/0ver.txt";
        VerInfo oldVer   = null;

        if (File.Exists(fileName))
        {
            oldVer = JsonUtility.FromJson <VerInfo>(File.ReadAllText(fileName));
        }
        BuildInfoAB    build   = new BuildInfoAB(info);
        List <VerInfo> newInfo = build.BuildAb(flag);

        if (oldVer != null)
        {
            foreach (VerInfo verinfo in newInfo)
            {
                foreach (ABInfo ver in verinfo.files)
                {
                    bool has = false;
                    foreach (ABInfo _ver in oldVer.files)
                    {
                        if (ver.fileName == _ver.fileName)
                        {
                            _ver.length = ver.length;
                            _ver.assets = ver.assets;
                            _ver.sha1   = ver.sha1;
                            has         = true;
                        }
                    }
                    if (!has)
                    {
                        oldVer.files.Add(ver);
                    }
                }
            }
        }
        else
        {
            VerInfo buildinfo = new VerInfo();
            foreach (VerInfo ver in newInfo)
            {
                buildinfo.ver = ver.ver;
                buildinfo.files.AddRange(ver.files);
            }
            oldVer = buildinfo;
        }
        string txtStr = JsonUtility.ToJson(oldVer, true);

        File.WriteAllText(fileName, txtStr);
    }
Beispiel #13
0
        public static int Add(VerInfo entity)
        {
            int result;

            if (entity == null)
            {
                result = 0;
            }
            else
            {
                result = BizBase.dbo.InsertModel <VerInfo>(entity);
            }
            return(result);
        }
Beispiel #14
0
        /// <summary>
        /// Get file version information.
        /// </summary>
        /// <param name="infoNum"></param>
        /// <returns></returns>
        public static string GetVersionInfo(VerInfo infoNum)
        {
            string ret = "";

            // Get my assembly.
            System.Reflection.Assembly asm =
                System.Reflection.Assembly.GetExecutingAssembly();
            // Get file version information.
            System.Diagnostics.FileVersionInfo fileVerInfo =
                System.Diagnostics.FileVersionInfo.GetVersionInfo(asm.Location);
            // Get requested information.
            ret = getDetailedInfo(infoNum, fileVerInfo);

            return ret;
        }
Beispiel #15
0
    public List <VerInfo> BuildAb(int all)
    {
        List <VerInfo> list = new List <VerInfo>();

        EditorUtility.ClearProgressBar();
        outPath = Application.streamingAssetsPath;

        if (!Directory.Exists(outPath))
        {
            Directory.CreateDirectory(outPath);
            AssetDatabase.SaveAssets();
        }

        string resPath = FileUtil.GetProjectRelativePath(outPath);

        BuildAssetBundleOptions options = BuildAssetBundleOptions.UncompressedAssetBundle
                                          | BuildAssetBundleOptions.DeterministicAssetBundle
                                          | BuildAssetBundleOptions.ForceRebuildAssetBundle;

        BuildTarget traget = EditorUserBuildSettings.activeBuildTarget;

        if (all == 0)
        {
            VerInfo info = BuildLua(resPath, traget, options);
            list.Add(info);
        }
        else if (all == 1)
        {
            VerInfo info = BuildRes(resPath, traget, options);
            list.Add(info);
        }
        else
        {
            VerInfo resinfo = BuildRes(resPath, traget, options);
            VerInfo luainfo = BuildLua(resPath, traget, options);
            if (luainfo != null)
            {
                list.Add(luainfo);
            }
            if (resinfo != null)
            {
                list.Add(resinfo);
            }
        }
        return(list);
    }
Beispiel #16
0
 void InitGroups(string txt)
 {
     string[] lines = txt.Split(new string[] { "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries);
     foreach (var l in lines)
     {
         if (l.IndexOf("Ver:") == 0)
         {
             ver = int.Parse(l.Substring(4));
         }
         else
         {
             //Debug.Log(l);
             var sp = l.Split('|');
             groups[sp[0]] = new VerInfo(sp[0], sp[1], int.Parse(sp[2]));
         }
     }
 }
Beispiel #17
0
    public List <VerInfo> BuildAb(int all)
    {
        List <VerInfo> list = new List <VerInfo>();

        EditorUtility.ClearProgressBar();
        outPath = Application.streamingAssetsPath;

        if (!Directory.Exists(outPath))
        {
            Directory.CreateDirectory(outPath);
            AssetDatabase.SaveAssets();
        }

        string resPath = FileUtil.GetProjectRelativePath(outPath);

        BuildAssetBundleOptions options = BuildAssetBundleOptions.UncompressedAssetBundle
                                          | BuildAssetBundleOptions.DeterministicAssetBundle
                                          | BuildAssetBundleOptions.ForceRebuildAssetBundle;

        BuildTarget traget = BuildTarget.StandaloneWindows;

#if UNITY_ANDROID
        traget = BuildTarget.Android;
#elif UNITY_IOS
        traget = BuildTarget.iOS;
#else
        traget = BuildTarget.StandaloneWindows;
#endif
        if (all == 0)
        {
            VerInfo info = BuildLua(resPath, traget, options);
            list.Add(info);
        }
        else if (all == 1)
        {
            VerInfo info = BuildRes(resPath, traget, options);
            list.Add(info);
        }
        else
        {
            list.Add(BuildLua(resPath, traget, options));
            list.Add(BuildRes(resPath, traget, options));
        }
        return(list);
    }
Beispiel #18
0
        public static VerInfo GetVersion()
        {
            try
            {
                Assembly     assembly     = Assembly.GetExecutingAssembly();
                AssemblyName assemblyName = assembly.GetName();
                Version      version      = assemblyName.Version;

                VerInfo v = new VerInfo();
                v.Name    = assemblyName.Name;
                v.Version = version.Major.ToString() + "." + version.Minor.ToString() + "." + version.Build.ToString() + "." + version.Revision.ToString();
                return(v);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Beispiel #19
0
    public static ComparisonInfo ComparisonVer(VerInfo local, VerInfo remoteVer)
    {
        ComparisonInfo comparisonInfo = new ComparisonInfo();

        if (remoteVer == null)
        {
            comparisonInfo.flag = 0;
            return(comparisonInfo);
        }
        if (local == null || local.ver == "0.0.0")
        {
            comparisonInfo.flag = -1;
        }
        else
        {
            comparisonInfo.flag = local.CompareTo(remoteVer.ver);
        }
        if (comparisonInfo.flag != 0)
        {
            foreach (ABInfo info in remoteVer.files)
            {
                bool need = false;
                if (comparisonInfo.flag == -1)
                {
                    need = true;
                }
                else
                {
                    var localInfo = local.GetABDownLoadInfo(info.fileName);
                    if (localInfo == null || !localInfo.IsSame(info))
                    {
                        need = true;
                    }
                }

                if (need)
                {
                    comparisonInfo.Size += (info.length / 1024.0f / 1024.0f);
                    comparisonInfo.needDecompressionList.Add(info);
                }
            }
        }
        return(comparisonInfo);
    }
Beispiel #20
0
        /// <summary>
        /// 通过路径,读取版本文件数据
        /// </summary>
        /// <param name="path"></param>
        public static VerManager Read(string path)
        {
            string p = Path.Combine(path, "allver.ver.txt");

            if (!File.Exists(p))
            {
                return(null);
            }

            //有文本数据
            string txt = File.ReadAllText(p, Encoding.UTF8);

            string[]   lines = txt.Split(new string[] { "\n", "\r" }, System.StringSplitOptions.RemoveEmptyEntries);
            VerManager ver   = new VerManager();

            foreach (string l in lines)
            {
                if (l.IndexOf("Ver:") == 0)
                {
                    //取得文件版本号
                    ver.Ver = int.Parse(l.Substring(4));
                }
                else
                {
                    //解析获得文件内容信息    组信息,hash,文件个数
                    string[] sp   = l.Split('|');
                    VerInfo  info = new VerInfo(sp[0]);
                    info.Read(ver.Ver, sp[1], int.Parse(sp[2]), path);

                    if (ver.Groups.ContainsKey(sp[0]))
                    {
                        ver.Groups[sp[0]] = info;
                    }
                    else
                    {
                        ver.Groups.Add(sp[0], info);
                    }
                }
            }

            return(ver);
        }
Beispiel #21
0
    public static void BulidAssetCorrespondABFileName()
    {
        VerInfo infos = new VerInfo();

        infos.ver = ProjectBuild.version;
        foreach (AssetBundleBuild ab in maps)
        {
            ABInfo info = new ABInfo();
            info.fileName = ab.assetBundleName;
            info.sha1     = GenHashOne(Application.streamingAssetsPath + "/" + ab.assetBundleName, ref info.length);
            infos.files.Add(info);
            foreach (string str in ab.assetNames)
            {
                if (ab.assetBundleName != "lua")
                {
                    info.assets.Add(Path.GetFileName(str));
                }
            }
        }

        File.WriteAllText(Application.streamingAssetsPath + "/file.txt", JsonUtility.ToJson(infos, true));
    }
Beispiel #22
0
    private static void CreateInfo()
    {
        VerInfoList listInfo = new VerInfoList();

        VerInfo info = new VerInfo("116.228.88.149", 5555, "1.0");

        listInfo.list.Add(info);

        info = new VerInfo("192.168.10.28", 5555, "1.1");
        listInfo.list.Add(info);

        info = new VerInfo("games.emagroup.cn", 5555, "99");
        listInfo.list.Add(info);

        string jsonInfo = JsonUtility.ToJson(listInfo);

        System.IO.File.WriteAllText(Application.dataPath + "/_VerInfo/VerInfo.txt", jsonInfo);
        Debug.Log("生成配置文件成功");
        AssetDatabase.Refresh();

//		PlayerSettings.bundleVersion
    }
Beispiel #23
0
        /// <summary>
        /// 初始化版本号和文件路径信息
        /// </summary>
        static void InitVerAndPath()
        {
            //读取文件分组版本信息
            ver = VerManager.Read(root);
            if (ver == null)
            {
                //如果当前路径下面没有此版本文件组信息
                //初始化一个版本文件组信息

                ver = new VerManager();
                //获得根目录下面的文件夹名称
                string[] groups = Directory.GetDirectories(root);
                foreach (string g in groups)
                {
                    //移除根目录
                    string path = g.Replace(root, "").ToLower();
                    if (path.IndexOf("path") == 0 || path.Contains(".svn"))
                    {
                        continue;
                    }

                    VerInfo info = new VerInfo(path);
                    if (ver.Groups.ContainsKey(path))
                    {
                        ver.Groups[path] = info;
                    }
                    else
                    {
                        ver.Groups.Add(path, info);
                    }
                }

                //设置文件版本号
                ver.Ver = 0;
            }
        }
 bool ReadLocalVer(string path, string filename, IEnumerable<string> groups)
 {
     string txt = null;
     using (var s = System.IO.File.OpenRead(filename))
     {
         byte[] bs = new byte[s.Length];
         s.Read(bs, 0, bs.Length);
         txt = System.Text.Encoding.UTF8.GetString(bs, 0, bs.Length);
     }
     string[] lines = txt.Split(new string[] { "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries);
     int mver = 0;
     string mgroup = null;
     string mhash = null;
     int mfilecount = 0;
     foreach (var l in lines)
     {
         if (l.IndexOf("Ver:") == 0)
         {
             mver = int.Parse(l.Substring(4));
             if (mver < this.ver)
             {
                 Debug.Log("(ver)储存版本旧了,使用嵌入");
                 return false;
             }
             if (mver > this.ver)
             {
                 Debug.Log("(ver)储存版本新,覆盖嵌入");
             }
         }
         else
         {
             //Debug.Log(l);
             var sp = l.Split('|');
             mgroup = sp[0];
             mhash = sp[1];
             mfilecount = int.Parse(sp[2]);
             if (this.groups.ContainsKey(mgroup))
             {
                 if (this.groups[mgroup].grouphash == mhash && this.groups[mgroup].groupfilecount == mfilecount)
                 {
                     Debug.Log("group未改变:" + mgroup);
                     continue;
                 }
             }
             var g = new VerInfo(mgroup, mhash, mfilecount);
             bool b = g.ReadLocal(System.IO.Path.Combine(path, mgroup + ".ver.txt"));
             if(b)
             {
                 this.groups[mgroup] = g;
                 Debug.Log("(ver)覆盖Group:" + mgroup);
             }
             else
             {
                  Debug.Log("Group读取失败:" + mgroup);
             }
         }
     }
     return true;
 }
 void InitGroups(string txt)
 {
     string[] lines = txt.Split(new string[] { "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries);
     foreach (var l in lines)
     {
         if (l.IndexOf("Ver:") == 0)
         {
             ver = int.Parse(l.Substring(4));
         }
         else
         {
             //Debug.Log(l);
             var sp = l.Split('|');
             groups[sp[0]] = new VerInfo(sp[0], sp[1], int.Parse(sp[2]));
         }
     }
 }
Beispiel #26
0
 public static bool Update(VerInfo entity)
 {
     return(entity != null && BizBase.dbo.UpdateModel <VerInfo>(entity));
 }
        /// <summary>
        /// STA文件解析
        /// </summary>
        /// <param name="row"></param>
        void STAAnalysis(string[] row)
        {
            #region 读取STA信息
            //
            string[] verInfo1 = row[0].Split(new string[] { "," }, StringSplitOptions.None);    // 版本信息
            string[] verInfo2 = row[1].Split(new string[] { "," }, StringSplitOptions.None);    // 版本信息
            //
            string[] DataR  = row.Skip(2).Take(32).ToArray();                                   //
            string[] DataR2 = row.Skip(34).Take(12).ToArray();
            //
            string[] DataR3 = row.Skip(46).Take(3).ToArray();
            string[] DataR4 = row.Skip(49).Take(1).ToArray();

            string CoolingValve     = "CoolingValve";
            string MoldTemperature  = "MoldTemperature";
            string PressurePoint    = "PressurePoint";
            string PressurePointEnd = "PressurePointEnd";

            #endregion

            #region 冷却阀
            string[] code = { "",
                              "ControlSelection",
                              "ControlTemperatureCh",
                              "TemperatureControlRangeSelection",
                              "FBOneTargetTemperature",
                              "FBOneCoolingWait",
                              "FBOneCoolingTime",
                              "FBTwoTargetTemperature",
                              "FBTwoCoolingWait",
                              "FBTwoCoolingTime",
                              "FBThreeTargetTemperature",
                              "FBThreeCoolingWait",
                              "FBThreeCoolingTime",
                              "SEQOneCoolingWait",
                              "SEQOneCoolingTime",
                              "SEQTwoCoolingWait",
                              "SEQTwoCoolingTime",
                              "SEQThreeCoolingWait",
                              "SEQThreeCoolingTime" };
            Dictionary <string, Dictionary <int, Dictionary <string, string> > > dic = new Dictionary <string, Dictionary <int, Dictionary <string, string> > >();
            Dictionary <int, Dictionary <string, string> > dicList = new Dictionary <int, Dictionary <string, string> >();
            Dictionary <string, string> pairs = null;
            string[] tmpList = null;
            foreach (var tmp in DataR)
            {
                tmpList = tmp.Split(new string[] { "," }, StringSplitOptions.None);
                pairs   = new Dictionary <string, string>();
                int i = 0;
                foreach (var item in tmpList)
                {
                    i++;
                    pairs.Add(code[i], item);
                }
                dicList.Add(dicList.Count + 1, pairs);
            }
            dic.Add(CoolingValve, dicList);
            #endregion

            #region 模具温度
            string[] code2 = { "",
                               "MonitoringWhetherOrNot",
                               "UpperMonitoringLimit",
                               "MonitoringLowerLimit",
                               "TwoMonitoringWhetherOrNot",
                               "TwoUpperMonitoringLimit",
                               "TwoMonitoringLowerLimit" };
            dicList = new Dictionary <int, Dictionary <string, string> >();
            foreach (var tmp in DataR2)
            {
                tmpList = tmp.Split(new string[] { "," }, StringSplitOptions.None);
                pairs   = new Dictionary <string, string>();
                int i = 0;
                foreach (var item in tmpList)
                {
                    i++;
                    pairs.Add(code2[i], item);
                }
                dicList.Add(dicList.Count + 1, pairs);
            }
            dic.Add(MoldTemperature, dicList);
            #endregion

            #region 加压点
            string[] Colcode  = { "", "P1", "P2", "P3" };
            string[] Colcode2 = { "", "End" };
            string[] code3    = { "", "TargetForce", "AddingTime" };
            dicList = new Dictionary <int, Dictionary <string, string> >();
            foreach (var tmp in DataR3)
            {
                tmpList = tmp.Split(new string[] { "," }, StringSplitOptions.None);
                pairs   = new Dictionary <string, string>();
                int i = 0;
                foreach (var item in tmpList)
                {
                    i++;
                    pairs.Add(code3[i], item);
                }
                dicList.Add(dicList.Count + 1, pairs);
            }
            dic.Add(PressurePoint, dicList);


            //
            string[] code4 = { "", "AddingTime" };
            dicList = new Dictionary <int, Dictionary <string, string> >();
            foreach (var tmp in DataR4)
            {
                tmpList = tmp.Split(new string[] { "," }, StringSplitOptions.None);
                pairs   = new Dictionary <string, string>();
                int i = 0;
                foreach (var item in tmpList)
                {
                    i++;
                    pairs.Add(code4[i], item);
                }
                dicList.Add(dicList.Count + 1, pairs);
            }
            dic.Add(PressurePointEnd, dicList);
            #endregion

            #region 开始形成Class
            var compares = new Dictionary <string, CompareEnum>();
            compares.Add("QR", CompareEnum.Equal);
            var vi = verInfoRepository.GetSingle(new { QR = verInfo1[1] }, compares);
            if (vi == null)
            {
                vi = new VerInfo()
                {
                    FID = Guid.NewGuid().ToString()
                };
                vi.DSType = "STA";
            }
            else if (vi.DSType != "STA")
            {
                vi.DSType = "true";
            }
            else if (vi.DSType == "true")
            {
                return;
            }
            else
            {
                return;
            }

            vi.DeviceNum      = DeviceNum;
            vi.MachineName    = verInfo1[5];
            vi.CZRNO          = verInfo1[6];
            vi.QR             = verInfo1[1];
            vi.CollectionTime = verInfo1[7];
            vi.StressTime     = verInfo1[11];
            vi.ProductsNo     = verInfo1[2];
            // 数据保存  年月日
            vi.YMD = verInfo1[3];
            // 数据保存  时分秒
            vi.HMS = verInfo1[4];
            // 注汤前时间
            vi.TTime = verInfo1[8];
            // 预备
            vi.Prepare = verInfo1[9];
            // 溶汤温度
            vi.DissolvingTemperature = verInfo1[10];
            // 铸造机加压时间
            vi.HHStressTime = verInfo1[11];
            // 铸造机冷却时间
            vi.HHCoolingTime = verInfo1[12];
            // 铸造机抽芯时间
            vi.HHLooseCoreTime = verInfo1[13];
            // 最终加压未使用
            vi.EndStressNotUsed = verInfo1[14];
            // S阀用下限值
            vi.SValvesLower = verInfo2[0];
            // S阀用上限值
            vi.SValvesUpper = verInfo2[1];
            // M阀用下限值
            vi.MValvesLower = verInfo2[2];
            // M阀用上限值
            vi.MValvesUpper = verInfo2[3];
            // 加压开始
            vi.StressStart = verInfo2[4];
            // 加压中
            vi.Stressing = verInfo2[5];
            // 据点以及应用程序版本NO
            vi.AppVerNo = verInfo1[0];

            //
            List <TEMPerA> temperaList = new List <TEMPerA>();
            TEMPerA        tempera     = null;

            // 1
            Dictionary <string, string[]> keyValuePairs = new Dictionary <string, string[]>();

            foreach (var tmp in dic[CoolingValve])
            {
                foreach (var item in tmp.Value)
                {
                    if (keyValuePairs.ContainsKey(item.Key))
                    {
                        List <string> ls = keyValuePairs[item.Key].ToList();
                        ls.Add(item.Value);
                        keyValuePairs[item.Key] = ls.ToArray();
                    }
                    else
                    {
                        keyValuePairs.Add(item.Key, new string[] { item.Value });
                    }
                }
            }
            foreach (var tmp in keyValuePairs)
            {
                tempera = new TEMPerA()
                {
                    FID       = Guid.NewGuid().ToString(),
                    VerInfoID = vi.FID,
                    DicCode   = CoolingValve,
                    DicCode2  = tmp.Key,
                    DicCode3  = "",
                    CH1M      = tmp.Value[0],
                    CH1S      = tmp.Value[1],
                    CH2M      = tmp.Value[2],
                    CH2S      = tmp.Value[3],
                    CH3M      = tmp.Value[4],
                    CH3S      = tmp.Value[5],
                    CH4M      = tmp.Value[6],
                    CH4S      = tmp.Value[7],
                    CH5M      = tmp.Value[8],
                    CH5S      = tmp.Value[9],
                    CH6M      = tmp.Value[10],
                    CH6S      = tmp.Value[11],
                    CH7M      = tmp.Value[12],
                    CH7S      = tmp.Value[13],
                    CH8M      = tmp.Value[14],
                    CH8S      = tmp.Value[15],
                    CH9M      = tmp.Value[16],
                    CH9S      = tmp.Value[17],
                    CH10M     = tmp.Value[18],
                    CH10S     = tmp.Value[19],
                    CH11M     = tmp.Value[20],
                    CH11S     = tmp.Value[21],
                    CH12M     = tmp.Value[22],
                    CH12S     = tmp.Value[23],
                    CH13M     = tmp.Value[24],
                    CH13S     = tmp.Value[25],
                    CH14M     = tmp.Value[26],
                    CH14S     = tmp.Value[27],
                    CH15M     = tmp.Value[28],
                    CH15S     = tmp.Value[29],
                    CH16M     = tmp.Value[30],
                    CH16S     = tmp.Value[31]
                };
                temperaList.Add(tempera);
            }

            // 2
            Dictionary <string, string[]> keyValuePairs2 = new Dictionary <string, string[]>();
            foreach (var tmp in dic[MoldTemperature])
            {
                foreach (var item in tmp.Value)
                {
                    if (keyValuePairs2.ContainsKey(item.Key))
                    {
                        List <string> ls = keyValuePairs2[item.Key].ToList();
                        ls.Add(item.Value);
                        keyValuePairs2[item.Key] = ls.ToArray();
                    }
                    else
                    {
                        keyValuePairs2.Add(item.Key, new string[] { item.Value });
                    }
                }
            }
            foreach (var tmp in keyValuePairs2)
            {
                tempera = new TEMPerA()
                {
                    FID       = Guid.NewGuid().ToString(),
                    VerInfoID = vi.FID,
                    DicCode   = MoldTemperature,
                    DicCode2  = tmp.Key,
                    DicCode3  = "",
                    CH1M      = tmp.Value[0],
                    CH1S      = tmp.Value[1],
                    CH2M      = tmp.Value[2],
                    CH2S      = tmp.Value[3],
                    CH3M      = tmp.Value[4],
                    CH3S      = tmp.Value[5],
                    CH4M      = tmp.Value[6],
                    CH4S      = tmp.Value[7],
                    CH5M      = tmp.Value[8],
                    CH5S      = tmp.Value[9],
                    CH6M      = tmp.Value[10],
                    CH6S      = tmp.Value[11],
                    CH7M      = "",
                    CH7S      = "",
                    CH8M      = "",
                    CH8S      = "",
                    CH9M      = "",
                    CH9S      = "",
                    CH10M     = "",
                    CH10S     = "",
                    CH11M     = "",
                    CH11S     = "",
                    CH12M     = "",
                    CH12S     = "",
                    CH13M     = "",
                    CH13S     = "",
                    CH14M     = "",
                    CH14S     = "",
                    CH15M     = "",
                    CH15S     = "",
                    CH16M     = "",
                    CH16S     = ""
                };
                temperaList.Add(tempera);
            }

            // 3
            List <PressureRecord> pressureRecords = new List <PressureRecord>();
            PressureRecord        record          = new PressureRecord();
            int dic3 = 0;
            foreach (var tmp in dic[PressurePoint])
            {
                dic3++;
                foreach (var item in tmp.Value)
                {
                    record = new PressureRecord()
                    {
                        FID        = Guid.NewGuid().ToString(),
                        VerInfoID  = vi.FID,
                        DicCode    = PressurePoint,
                        DicCode2   = item.Key,
                        DicCode3   = Colcode[dic3],
                        RecordTime = "",
                        RecordVal  = item.Value,
                    };
                    pressureRecords.Add(record);
                }
            }

            // 4
            int dic4 = 0;
            foreach (var tmp in dic[PressurePointEnd])
            {
                dic4++;
                foreach (var item in tmp.Value)
                {
                    record = new PressureRecord()
                    {
                        FID        = Guid.NewGuid().ToString(),
                        VerInfoID  = vi.FID,
                        DicCode    = PressurePoint,
                        DicCode2   = item.Key,
                        DicCode3   = Colcode2[dic4],
                        RecordTime = "",
                        RecordVal  = item.Value,
                    };
                    pressureRecords.Add(record);
                }
            }
            #endregion

            // 需要保存的对象以及集合 vi,temperaList,pressureRecords

            #region 保存到数据库
            // 开始插入数据库
            SaveData(vi, temperaList, pressureRecords);
            #endregion
        }
        /// <summary>
        /// 保存数据
        /// </summary>
        /// <param name="vi">表头</param>
        /// <param name="temperaList">明细数据</param>
        /// <param name="pressureRecords">加压记录</param>
        void SaveData(VerInfo vi, List <TEMPerA> temperaList, List <PressureRecord> pressureRecords)
        {
            #region 查询是否有该条记录
            var viwhere = new VerInfo()
            {
                QR        = vi.QR,
                DeviceNum = vi.DeviceNum,
                DSType    = "true"
            };
            var dic = new Dictionary <string, CompareEnum>();
            dic.Add("QR", CompareEnum.Equal);
            dic.Add("DeviceNum", CompareEnum.Equal);
            dic.Add("DSTYPE", CompareEnum.Equal);
            var count = verInfoRepository.Select(viwhere, dic).Count();

            if (count > 0)
            {
                return;
            }
            #endregion

            var startTime = DateTime.Now;

            #region 组装数据
            var targetList  = pressureRecords.Where(p => p.DicCode == "TargetPressureForPressurization").AsParallel();
            var pressauList = pressureRecords.Where(p => p.DicCode == "PressureOfPressurizedState").AsParallel();
            var outputList  = pressureRecords.Where(p => p.DicCode == "LevelOutputValueForPressurization").AsParallel();

            foreach (var record in pressauList)
            {
                var targetRow = targetList.FirstOrDefault(p => p.VerInfoID == record.VerInfoID && p.RecordTime == record.RecordTime);
                var outputRow = outputList.FirstOrDefault(p => p.VerInfoID == record.VerInfoID && p.RecordTime == record.RecordTime);

                record.OutputVal = outputRow is null ? null : outputRow.RecordVal;
                record.TargetVal = targetRow is null ? null : targetRow.RecordVal;
            }

            pressureRecords = pressauList.ToList();
            #endregion

            // 开始事务
            using (var conn = DBConnectionFactory.GetConnection(DBTypeEnums.MYSQL))
            {
                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }

                var tran = conn.BeginTransaction();

                if (vi.DSType == "true")
                {
                    verInfoRepository.Update(vi, new { QR = vi.QR }, tran);
                }
                else
                {
                    verInfoRepository.Insert(vi, tran);
                }

                temPerARepository.InsertBulk(temperaList, tran);
                pressureRepository.InsertBulk(pressureRecords, tran);

                //for (int i = 0; i < (int)Math.Ceiling((decimal)temperaList.Count / tCount); i++)
                //{
                //    temPerARepository.InsertBulk(temperaList.Skip(i * tCount).Take(tCount).ToList());
                //}

                //for (int i = 0; i < (int)Math.Ceiling((decimal)pressureRecords.Count / tCount); i++)
                //{
                //    pressureRepository.InsertBulk(pressureRecords.Skip(i * tCount).Take(tCount).ToList());
                //}


                tran.Commit();
            }
            //
            var timespan = DateTime.Now - startTime;
            try
            {
                MySqlHelper.ExecuteNonQueryStoredProcedure($"ver_qr", new MySql.Data.MySqlClient.MySqlParameter[] { new MySql.Data.MySqlClient.MySqlParameter("str", vi.QR) });
                LogHelper.Info($"【{vi.QR}】数据保存成功,数据写入耗时【{timespan.TotalSeconds}】秒");
            }
            catch (Exception ex)
            {
                LogHelper.Info($"【{vi.QR}】数据call ver_qr('{vi.QR}')异常【{ex.Message}】");
            }
        }
        /// <summary>
        /// DAT文件解析
        /// </summary>
        /// <param name="row"></param>
        void DATAnalysis(string[] row)
        {
            #region 读取DAT信息
            string   verInfo    = row[0]; // 版本信息
            string[] tmpInfo    = verInfo.Split(new string[] { "," }, StringSplitOptions.None);
            int      rowNum     = Convert.ToInt32(tmpInfo[tmpInfo.Length - 1]) + 1;
            bool     IsOne      = true;  // 去除第一条
            bool     IsNewTable = false; // 是否需要插入到新表
            int      intAdd     = 0;     // 判断出现两次可以转回为Int的就插入新的表
            int      vsNum      = 0;     // 判断int作用
            int      i          = 1;     //
            // 第一个表的数据
            Dictionary <int, Dictionary <string, string> > dic = new Dictionary <int, Dictionary <string, string> >();
            Dictionary <string, string> dicRow = new Dictionary <string, string>();
            //string[] code = { "", "実態金型温度", "FB控制用模具温度", "FB控制用目标温度", "冷却阀ON.・OFF状态", "吸管温度" };
            string[] code = { "", "HotMetalTemperature", "MoldTemperatureForFBControl", "TargetTemperatureForFBControl", "CoolingValveOn.Off", "PipetteTemperature" };
            // 其余表的数据
            Dictionary <string, Dictionary <string, string> > TowdicRow = new Dictionary <string, Dictionary <string, string> >();
            //string[] DataType = { "", "加圧用実態圧力", "加圧用目標圧力", "加圧用レギュレーター出力値" };
            string[] DataType    = { "", "PressureOfPressurizedState", "TargetPressureForPressurization", "LevelOutputValueForPressurization" };
            int      intDataType = 1;
            // 开始循环解析数据
            foreach (var tmp in row)
            {
                // 去除第一条
                if (IsOne)
                {
                    IsOne = false; continue;
                }
                // 判断是否需要插入到新的表,判断出现两次可以转回为Int的就插入新的表
                intAdd     = Int32.TryParse(tmp, out vsNum) ? intAdd + 1 : 0;
                IsNewTable = (intAdd == 2) || IsNewTable;
                // 是否新表
                if (!IsNewTable)
                {
                    if (i == 1)
                    {
                        dicRow = new Dictionary <string, string>();
                    }
                    dicRow.Add(code[i], tmp);
                    if (i == 5)
                    {
                        dic.Add(dic.Count + 1, dicRow);
                        i = 0;
                    }
                    i++;
                }
                // 下面每个表的
                else
                {
                    if (i == 1)
                    {
                        dicRow = new Dictionary <string, string>();
                    }
                    dicRow.Add((i * 0.1).ToString("0.0"), tmp);
                    i++;
                    if (i % rowNum == 0)
                    {
                        TowdicRow.Add(DataType[intDataType], dicRow);
                        i = 1;
                        intDataType++;
                    }
                }
            }
            #endregion

            var compares = new Dictionary <string, CompareEnum>();
            compares.Add("QR", CompareEnum.Equal);
            var vi = verInfoRepository.GetSingle(new { QR = tmpInfo[1] }, compares);

            if (vi == null)
            {
                vi = new VerInfo {
                    FID = Guid.NewGuid().ToString(), DSType = "DAT"
                };
            }
            else if (vi.DSType != "DAT")
            {
                vi.DSType = "true";
            }
            else if (vi.DSType == "true")
            {
                return;
            }
            else
            {
                return;
            }

            vi.AppVerNo         = tmpInfo[0];
            vi.QR               = tmpInfo[1];
            vi.CollectionTime   = tmpInfo[2];
            vi.PressureDuration = tmpInfo[3];
            vi.DeviceNum        = DeviceNum;
            #region 开始形成Class

            List <TEMPerA> temperaList   = new List <TEMPerA>();
            TEMPerA        tempera       = null;
            List <string>  tmpStringList = new List <string>();
            string[]       tmpList       = null;

            foreach (var item in dic)
            {
                foreach (var tmp in item.Value)
                {
                    tmpList = tmp.Value.Split(new string[] { "," }, StringSplitOptions.None);
                    tmpStringList.AddRange(tmpList);
                    for (int k = 0; k < 32 - tmpList.Length; k++)
                    {
                        tmpStringList.Add("");
                    }
                    tmpList = tmpStringList.ToArray();
                    //
                    tempera = new TEMPerA()
                    {
                        FID       = Guid.NewGuid().ToString(),
                        VerInfoID = vi.FID,
                        DicCode   = tmp.Key,
                        CH1M      = tmpList[0],
                        CH1S      = tmpList[1],
                        CH2M      = tmpList[2],
                        CH2S      = tmpList[3],
                        CH3M      = tmpList[4],
                        CH3S      = tmpList[5],
                        CH4M      = tmpList[6],
                        CH4S      = tmpList[7],
                        CH5M      = tmpList[8],
                        CH5S      = tmpList[9],
                        CH6M      = tmpList[10],
                        CH6S      = tmpList[11],
                        CH7M      = tmpList[12],
                        CH7S      = tmpList[13],
                        CH8M      = tmpList[14],
                        CH8S      = tmpList[15],
                        CH9M      = tmpList[16],
                        CH9S      = tmpList[17],
                        CH10M     = tmpList[18],
                        CH10S     = tmpList[19],
                        CH11M     = tmpList[20],
                        CH11S     = tmpList[21],
                        CH12M     = tmpList[22],
                        CH12S     = tmpList[23],
                        CH13M     = tmpList[24],
                        CH13S     = tmpList[25],
                        CH14M     = tmpList[26],
                        CH14S     = tmpList[27],
                        CH15M     = tmpList[28],
                        CH15S     = tmpList[29],
                        CH16M     = tmpList[30],
                        CH16S     = tmpList[31]
                    };
                    temperaList.Add(tempera);
                }
            }
            //
            List <PressureRecord> pressureRecords = new List <PressureRecord>();
            PressureRecord        record          = new PressureRecord();
            foreach (var item in TowdicRow)
            {
                foreach (var tmp in item.Value)
                {
                    record = new PressureRecord()
                    {
                        FID        = Guid.NewGuid().ToString(),
                        VerInfoID  = vi.FID,
                        DicCode    = item.Key,
                        DicCode2   = "",
                        DicCode3   = "",
                        RecordTime = tmp.Key,
                        RecordVal  = tmp.Value
                    };
                    pressureRecords.Add(record);
                }
            }


            #endregion

            #region 保存到数据库

            #endregion
            // 需要保存的对象以及集合 vi,temperaList,pressureRecords

            SaveData(vi, temperaList, pressureRecords);
        }
Beispiel #30
0
    bool ReadLocalVer(string path, string filename, IEnumerable <string> groups)
    {
        string txt = null;

        using (var s = File.OpenRead(filename))
        {
            byte[] bs = new byte[s.Length];
            s.Read(bs, 0, bs.Length);
            txt = Encoding.UTF8.GetString(bs, 0, bs.Length);
        }
        string[] lines      = txt.Split(new string[] { "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries);
        int      mver       = 0;
        string   mgroup     = null;
        string   mhash      = null;
        int      mfilecount = 0;

        foreach (var l in lines)
        {
            if (l.IndexOf("Ver:") == 0)
            {
                mver = int.Parse(l.Substring(4));
                if (mver < this.ver)
                {
                    Debug.Log("(ver)储存版本旧了,使用嵌入");
                    return(false);
                }
                if (mver > this.ver)
                {
                    Debug.Log("(ver)储存版本新,覆盖嵌入");
                }
            }
            else
            {
                //Debug.Log(l);
                var sp = l.Split('|');
                mgroup     = sp[0];
                mhash      = sp[1];
                mfilecount = int.Parse(sp[2]);
                if (this.groups.ContainsKey(mgroup))
                {
                    if (this.groups[mgroup].grouphash == mhash && this.groups[mgroup].groupfilecount == mfilecount)
                    {
                        Debug.Log("group未改变:" + mgroup);
                        continue;
                    }
                }
                var  g = new VerInfo(mgroup, mhash, mfilecount);
                bool b = g.ReadLocal(System.IO.Path.Combine(path, mgroup + ".ver.txt"));
                if (b)
                {
                    this.groups[mgroup] = g;
                    Debug.Log("(ver)覆盖Group:" + mgroup);
                }
                else
                {
                    Debug.Log("Group读取失败:" + mgroup);
                }
            }
        }
        return(true);
    }