Exemplo n.º 1
0
 public bool checkUniqueID(RecordInfo ri, FileStream fs)
 {
     bool result = true;
     if (!ri.FreeSlot)
     {
         try
         {
             _uniqueCheckList.Add(ri.ID, ri.ID);
         }
         catch
         {
             //patch free
             fs.Position = ri.Offset + sizeof(long);
             fs.WriteByte(0);
             fs.Position = ri.Offset + ri.Length;
             result = false;
         }
     }
     return result;
 }
Exemplo n.º 2
0
        void FormatMonitor(StringBuilder code, RecordInfo info)
        {
            var lines = info.Message.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

            if (lines.Length <= 0)
            {
                return;
            }
            code.AppendLine("<table><tr style='border-bottom: silver 1px solid;padding: 4px'>");
            var line  = lines[0];
            var words = line.Split(new char[] { '|', '│' }, 5);

            for (var index = 0; index < words.Length && index < 4; index++)
            {
                var word = words[index];
                code.AppendLine($"<td>{word.Trim()}</td>");
            }

            for (var index = 1; index < lines.Length; index++)
            {
                line  = lines[index].Substring(1);//.TrimStart(new char[] { '|', '│', '┌', '└', '├' });
                words = line.Split(new char[] { '|', '│' });
                code.AppendLine("<tr style='border-bottom: silver 1px solid;padding: 4px'>");
                var word = words[0];
                code.Append("<td");
                if (words.Length == 1)
                {
                    code.AppendLine(" colspan='4'>");
                }
                else
                {
                    code.Append('>');
                }
                foreach (var ch in word)
                {
                    switch (ch)
                    {
                    default:
                        code.Append(ch);
                        break;

                    case '┌':
                    case '│':
                    case '└':
                    case '├':
                    case '┴':
                    case '─':
                        code.Append(" ");
                        break;
                    }
                }
                code.AppendLine("</td>");
                for (var i = 1; i < words.Length; i++)
                {
                    word = words[i];
                    code.AppendLine($"<td>{word.Trim()}</td>");
                }

                code.AppendLine("</tr>");
            }

            code.AppendLine("</table>");
        }
Exemplo n.º 3
0
 public void Lock(ref RecordInfo recordInfo, ref Key key, ref Value value, LockType lockType, ref long lockContext)
 {
 }
Exemplo n.º 4
0
 /// <summary>Creates an instance of this class.</summary>
 protected DataStorage(Type recordClass)
 {
     mRecordType = recordClass;
     mRecordInfo = new RecordInfo(recordClass);
 }
Exemplo n.º 5
0
        private void PlayRecord(string fileName, List <string> listRelativeNames)
        {
            try
            {
                if (RecordInfoItem == null)
                {
                    return;
                }
                RecordInfo recordInfo = RecordInfoItem.RecordInfo;
                if (recordInfo == null)
                {
                    return;
                }
                int mediaType = recordInfo.MediaType;


                #region 自定义参数设置

                bool noPlayScreen = false;
                if (ListUserSettingInfos != null)
                {
                    var setting =
                        ListUserSettingInfos.FirstOrDefault(
                            c => c.ParamID == S3102Consts.USER_PARAM_PLAYSCREEN_NOPLAY);
                    if (setting != null && setting.StringValue == "1")
                    {
                        noPlayScreen = true;
                    }
                }
                bool autoRelative = true;
                if (ListUserSettingInfos != null)
                {
                    var setting =
                        ListUserSettingInfos.FirstOrDefault(
                            c => c.ParamID == S3102Consts.USER_PARAM_AUTORELATIVEPLAY);
                    if (setting != null && setting.StringValue == "0")
                    {
                        autoRelative = false;
                    }
                }

                #endregion


                if (string.IsNullOrEmpty(fileName))
                {
                    CurrentApp.WriteLog("PlayRecord", string.Format("FileName is empty"));
                    return;
                }
                if (listRelativeNames.Count <= 0)
                {
                    CurrentApp.WriteLog("PlayRecord", string.Format("RelativeName is empty"));
                    autoRelative = false;
                }
                VoicePlayer.Session = CurrentApp.Session;
                if (mediaType == 3)
                {
                    #region 艺赛旗录屏播放

                    //艺赛旗录屏播放,需要设置服务器地址和艺赛旗流水号
                    if (noPlayScreen)
                    {
                        return;
                    }
                    CurrentApp.WriteLog("PlayRecord", string.Format("VedioPath:{0}(IsaVedio)", fileName));
                    VoicePlayer.MediaType   = 2;
                    VoicePlayer.IsIsaScreen = true;
                    VoicePlayer.IsaServer   = recordInfo.VoiceIP;
                    VoicePlayer.IsaRefID    = fileName;
                    VoicePlayer.Play();

                    #endregion

                    return;
                }
                string audioUrl = string.Format("{0}://{1}:{2}/{3}/{4}",
                                                CurrentApp.Session.AppServerInfo.SupportHttps ? "https" : "http",
                                                CurrentApp.Session.AppServerInfo.Address,
                                                CurrentApp.Session.AppServerInfo.Port,
                                                ConstValue.TEMP_DIR_MEDIADATA,
                                                fileName);
                string videoPath;
                string relativeName = string.Empty;
                switch (mediaType)
                {
                case 0:
                    if (noPlayScreen)
                    {
                        VoicePlayer.MediaType = 1;
                        VoicePlayer.AudioUrl  = audioUrl;
                        CurrentApp.WriteLog("PlayRecord", string.Format("AudioUrl:{0}", audioUrl));
                        VoicePlayer.Play();
                    }
                    else
                    {
                        #region VCLog 录屏播放

                        VoicePlayer.ListVideoUrls.Clear();
                        VoicePlayer.MediaType = 3;
                        VoicePlayer.AudioUrl  = audioUrl;
                        CurrentApp.WriteLog("PlayRecord", string.Format("AudioUrl:{0}", audioUrl));
                        videoPath = string.Empty;
                        RecordOperator recordOperator = new RecordOperator();
                        recordOperator.Debug  += (cat, msg) => CurrentApp.WriteLog(cat, msg);
                        recordOperator.Session = CurrentApp.Session;
                        OperationReturn optReturn = recordOperator.DownloadFileToLocal(fileName);
                        if (!optReturn.Result)
                        {
                            ShowRecordOperatorMessage(optReturn);
                            CurrentApp.WriteLog("DownloadToLocal",
                                                string.Format("Fail.\t{0}\t{1}", optReturn.Code, optReturn.Message));
                        }
                        else
                        {
                            videoPath = optReturn.Data.ToString();
                        }
                        VoicePlayer.IsIsaScreen = false;
                        VoicePlayer.ListVideoUrls.Add(videoPath);
                        CurrentApp.WriteLog("PlayRecord", string.Format("VideoPath:{0}", videoPath));
                        VoicePlayer.Play();

                        #endregion
                    }
                    break;

                case 1:
                    if (noPlayScreen ||
                        !autoRelative)
                    {
                        VoicePlayer.MediaType = 1;
                        VoicePlayer.AudioUrl  = audioUrl;
                        CurrentApp.WriteLog("PlayRecord", string.Format("AudioUrl:{0}", audioUrl));
                        VoicePlayer.Play();
                    }
                    else
                    {
                        VoicePlayer.ListVideoUrls.Clear();
                        VoicePlayer.MediaType = 3;
                        VoicePlayer.AudioUrl  = audioUrl;
                        CurrentApp.WriteLog("PlayRecord", string.Format("AudioUrl:{0}", audioUrl));
                        videoPath = string.Empty;

                        var relativeRecords = RecordInfoItem.ListRelativeInfos;
                        for (int i = 0; i < relativeRecords.Count; i++)
                        {
                            var relativeRecord = relativeRecords[i];

                            if (relativeRecord.MediaType == 3)
                            {
                                #region 艺赛旗录屏播放

                                if (listRelativeNames.Count > i)
                                {
                                    relativeName = listRelativeNames[i];
                                }
                                CurrentApp.WriteLog("PlayRecord",
                                                    string.Format("VedioPath:{0}(IsaVedio)", relativeName));
                                VoicePlayer.IsIsaScreen = true;
                                VoicePlayer.IsaServer   = relativeRecord.VoiceIP;
                                VoicePlayer.IsaRefID    = relativeName;

                                #endregion
                            }
                            else
                            {
                                #region VCLog 录屏播发

                                if (listRelativeNames.Count > i)
                                {
                                    relativeName = listRelativeNames[i];
                                }
                                if (!string.IsNullOrEmpty(relativeName))
                                {
                                    RecordOperator recordOperator = new RecordOperator();
                                    recordOperator.Debug  += (cat, msg) => CurrentApp.WriteLog(cat, msg);
                                    recordOperator.Session = CurrentApp.Session;
                                    OperationReturn optReturn = recordOperator.DownloadFileToLocal(relativeName);
                                    if (!optReturn.Result)
                                    {
                                        ShowRecordOperatorMessage(optReturn);
                                        CurrentApp.WriteLog("DownloadToLocal",
                                                            string.Format("Fail.\t{0}\t{1}", optReturn.Code, optReturn.Message));
                                    }
                                    else
                                    {
                                        videoPath = optReturn.Data.ToString();
                                    }
                                    VoicePlayer.IsIsaScreen = false;
                                    VoicePlayer.ListVideoUrls.Add(videoPath);
                                    CurrentApp.WriteLog("PlayRecord", string.Format("VideoPath:{0}", videoPath));
                                }

                                #endregion
                            }
                        }
                        VoicePlayer.Play();
                    }
                    break;

                case 2:
                    if (!noPlayScreen)
                    {
                        #region VCLog 录屏播放

                        VoicePlayer.MediaType = 2;
                        videoPath             = string.Empty;
                        RecordOperator recordOperator = new RecordOperator();
                        recordOperator.Debug  += (cat, msg) => CurrentApp.WriteLog(cat, msg);
                        recordOperator.Session = CurrentApp.Session;
                        OperationReturn optReturn = recordOperator.DownloadFileToLocal(fileName);
                        if (!optReturn.Result)
                        {
                            ShowRecordOperatorMessage(optReturn);
                            CurrentApp.WriteLog("DownloadToLocal",
                                                string.Format("Fail.\t{0}\t{1}", optReturn.Code, optReturn.Message));
                        }
                        else
                        {
                            videoPath = optReturn.Data.ToString();
                        }
                        VoicePlayer.IsIsaScreen = false;
                        VoicePlayer.ListVideoUrls.Add(videoPath);
                        CurrentApp.WriteLog("PlayRecord", string.Format("VideoPath:{0}", videoPath));
                        VoicePlayer.Play();

                        #endregion
                    }
                    break;

                default:
                    CurrentApp.WriteLog("PlayRecord", string.Format("MediaType invalid.\t{0}", mediaType));
                    break;
                }
            }
            catch (Exception ex)
            {
                CurrentApp.WriteLog("PlayRecord", string.Format("Fail.\t{0}", ex.Message));
            }
        }
Exemplo n.º 6
0
        public override bool LoadWaypoints(List<Framework.Data.Waypoint> wps, List<Framework.Data.UserWaypoint> usrwps)
        {
            bool result = true;
            int index = 0;
            int procStep = 0;

            if (File.Exists(_fileCollection.DatabaseInfoFilename))
            {

                int lsize = sizeof(long);
                byte[] memBuffer = new byte[5 * 1024];
                using (MemoryStream ms = new MemoryStream(memBuffer))
                using (BinaryReader br = new BinaryReader(ms))
                {

                    int wptCount = 0;

                    XmlDocument doc = new XmlDocument();
                    doc.Load(_fileCollection.DatabaseInfoFilename);
                    XmlElement root = doc.DocumentElement;
                    wptCount = int.Parse(root.SelectSingleNode("WaypointCount").InnerText);

                    using (FileStream fs = File.Open(_fileCollection.WaypointsFilename, FileMode.OpenOrCreate, FileAccess.Read))
                    {
                        fs.Position = 0;
                        long eof = fs.Length;
                        while (fs.Position < eof)
                        {
                            RecordInfo ri = new RecordInfo();
                            ri.Offset = fs.Position;
                            fs.Read(memBuffer, 0, lsize + 1);
                            ms.Position = 0;
                            ri.Length = br.ReadInt64();
                            if (memBuffer[lsize] == 0)
                            {
                                //free
                                ri.FreeSlot = true;
                                ri.ID = string.Concat("_", ri.Offset.ToString());
                                fs.Position = ri.Offset + ri.Length;
                            }
                            else
                            {
                                //read
                                ri.FreeSlot = false;
                                Framework.Data.Waypoint wp = new Framework.Data.Waypoint();

                                fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                ms.Position = 0;
                                wp.Code = br.ReadString();
                                ri.ID = wp.Code;

                                wp.Comment = br.ReadString();
                                wp.DataFromDate = DateTime.Parse(br.ReadString());
                                wp.Description = br.ReadString();
                                wp.GeocacheCode = br.ReadString();
                                wp.ID = br.ReadString();
                                if (br.ReadBoolean())
                                {
                                    wp.Lat = br.ReadDouble();
                                    wp.Lon = br.ReadDouble();
                                }
                                wp.Name = br.ReadString();
                                wp.Time = DateTime.Parse(br.ReadString());
                                wp.Url = br.ReadString();
                                wp.UrlName = br.ReadString();
                                wp.WPType = Utils.DataAccess.GetWaypointType(Core.WaypointTypes, br.ReadInt32());

                                wp.Saved = true;
                                wp.IsDataChanged = false;
                                wps.Add(wp);

                                index++;
                                procStep++;
                                if (procStep >= 20000)
                                {
                                    UpdateLoadingInBackgroundProgress(STR_LOADING_WAYPOINTS_BG, wptCount, index);
                                    procStep = 0;
                                }
                            }
                            _fileCollection._wptsInDB.Add(ri.ID, ri);
                        }
                    }

                    using (FileStream fs = File.Open(_fileCollection.UserWaypointsFilename, FileMode.OpenOrCreate, FileAccess.Read))
                    {
                        fs.Position = 0;
                        long eof = fs.Length;
                        while (fs.Position < eof)
                        {
                            RecordInfo ri = new RecordInfo();
                            ri.Offset = fs.Position;
                            fs.Read(memBuffer, 0, lsize + 1);
                            ms.Position = 0;
                            ri.Length = br.ReadInt64();
                            if (memBuffer[lsize] == 0)
                            {
                                //free
                                ri.FreeSlot = true;
                                ri.ID = string.Concat("_", ri.Offset.ToString());
                                fs.Position = ri.Offset + ri.Length;
                            }
                            else
                            {
                                //read
                                ri.FreeSlot = false;
                                Framework.Data.UserWaypoint wp = new Framework.Data.UserWaypoint();

                                fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                ms.Position = 0;
                                ri.ID = br.ReadString();
                                wp.ID = int.Parse(ri.ID);

                                wp.Description = br.ReadString();
                                wp.GeocacheCode = br.ReadString();
                                wp.Lat = br.ReadDouble();
                                wp.Lon = br.ReadDouble();
                                wp.Date = DateTime.Parse(br.ReadString());

                                wp.Saved = true;
                                wp.IsDataChanged = false;
                                usrwps.Add(wp);
                            }
                            _fileCollection._usrwptsInDB.Add(ri.ID, ri);
                        }
                    }

                }
            }

            return result;
        }
Exemplo n.º 7
0
    /// <summary>
    ///   Loads the master list.
    /// </summary>
    public void LoadList()
    {
      m_dicMasterList = new Dictionary<string, RecordInfo>();
      if (!File.Exists(LoadOrderTemplatePath))
      {
        return;
      }
      var fileLines = File.ReadAllLines(LoadOrderTemplatePath);

      if (!int.TryParse(fileLines[0], out fileVersion))
      {
        fileVersion = 0;
      }
      var upto = 0;
      var requires = new List<string>();
      var conflicts = new List<string>();
      var comments = new List<string>();
      for (var i = 0; i < fileLines.Length; i++)
      {
        var comment = fileLines[i].IndexOf('\\');
        if (comment != -1)
        {
          fileLines[i] = fileLines[i].Remove(comment);
        }
        fileLines[i] = fileLines[i].Trim();
        if (fileLines[i] != string.Empty)
        {
          var ri = new RecordInfo(upto++);
          var skiplines = 0;
          for (var j = i + 1; j < fileLines.Length; j++)
          {
            fileLines[j] = fileLines[j].Trim();
            if (fileLines[j].Length > 0)
            {
              switch (fileLines[j][0])
              {
                case ':':
                  requires.Add(fileLines[j].Substring(1).ToLowerInvariant().Trim());
                  skiplines++;
                  continue;
                case '"':
                  conflicts.Add(fileLines[j].Substring(1).ToLowerInvariant().Trim());
                  skiplines++;
                  continue;
                case '*':
                case '?':
                  comments.Add(fileLines[j].Substring(1).Trim());
                  skiplines++;
                  continue;
              }
              break;
            }
            skiplines++;
          }
          if (requires.Count > 0)
          {
            ri.requires = requires.ToArray();
            requires.Clear();
          }
          if (conflicts.Count > 0)
          {
            ri.conflicts = conflicts.ToArray();
            conflicts.Clear();
          }
          if (comments.Count > 0)
          {
            ri.comments = comments.ToArray();
            comments.Clear();
          }
          fileLines[i] = fileLines[i].ToLowerInvariant();
          if (m_dicMasterList.ContainsKey(fileLines[i]))
          {
            duplicateCount++;
          }
          m_dicMasterList[fileLines[i]] = ri;
          i += skiplines;
        }
      }
    }
Exemplo n.º 8
0
        private bool insertFromDatabase(bool overwrite)
        {
            bool result = false;

            try
            {
                int lsize = sizeof(long);
                byte[] memBuffer = new byte[10 * 1024 * 1024];
                using (MemoryStream ms = new MemoryStream(memBuffer))
                using (BinaryReader br = new BinaryReader(ms))
                using (FileCollection fc = new FileCollection(_selectedInsertFromFilename))
                {

                    int gcCount = 0;
                    int logCount = 0;
                    int logimgCount = 0;
                    int geocacheimgCount = 0;
                    int wptCount = 0;
                    int usrwptCount = 0;

                    Hashtable htInsertedGeocaches = new Hashtable();
                    Hashtable htInsertedLogs = new Hashtable();

                    XmlDocument doc = new XmlDocument();
                    doc.Load(fc.DatabaseInfoFilename);
                    XmlElement root = doc.DocumentElement;
                    gcCount = int.Parse(root.SelectSingleNode("GeocacheCount").InnerText);
                    logCount = int.Parse(root.SelectSingleNode("LogCount").InnerText);
                    logimgCount = int.Parse(root.SelectSingleNode("LogImagesCount").InnerText);
                    wptCount = int.Parse(root.SelectSingleNode("WaypointCount").InnerText);
                    usrwptCount = int.Parse(root.SelectSingleNode("UserWaypointCount").InnerText);
                    if (root.SelectSingleNode("GeocacheImagesCount") != null)
                    {
                        geocacheimgCount = int.Parse(root.SelectSingleNode("GeocacheImagesCount").InnerText);
                    }

                    DateTime nextUpdateTime = DateTime.MinValue;
                    RecordInfo ri = new RecordInfo();
                    using (Utils.ProgressBlock fixscr = new Utils.ProgressBlock(this, STR_LOADING, STR_LOADINGDATA, 1, 0))
                    {
                        using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_LOADING, STR_LOADINGGEOCACHES, gcCount, 0))
                        {
                            int index = 0;

                            FileStream fs = fc._fsGeocaches;
                            fs.Position = 0;
                            long eof = fs.Length;
                            while (fs.Position < eof)
                            {
                                ri.Offset = fs.Position;
                                fs.Read(memBuffer, 0, lsize + 1);
                                ms.Position = 0;
                                ri.Length = br.ReadInt64();
                                if (memBuffer[lsize] == 0)
                                {
                                    //free
                                    //ignore
                                    fs.Position = ri.Offset + ri.Length;
                                }
                                else if (memBuffer[lsize] == 2)
                                {
                                    //read
                                    fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                    ms.Position = 0;
                                    ri.ID = br.ReadString().Substring(2);
                                    bool newGeocache;
                                    Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, ri.ID);
                                    if (gc == null)
                                    {
                                        gc = new Framework.Data.Geocache();
                                        htInsertedGeocaches.Add(ri.ID, gc);
                                        newGeocache = true;
                                    }
                                    else
                                    {
                                        if (overwrite || htInsertedGeocaches[ri.ID] != null)
                                        {
                                            newGeocache = false;
                                        }
                                        else
                                        {
                                            continue;
                                        }
                                    }
                                    gc.BeginUpdate();
                                    try
                                    {
                                        gc.Code = ri.ID;
                                        gc.ShortDescription = br.ReadString();
                                        gc.ShortDescriptionInHtml = br.ReadBoolean();
                                        gc.LongDescription = br.ReadString();
                                        gc.LongDescriptionInHtml = br.ReadBoolean();
                                    }
                                    catch
                                    {
                                    }
                                    gc.EndUpdate();
                                    if (newGeocache)
                                    {
                                        Core.Geocaches.Add(gc);
                                    }
                                }
                                else
                                {
                                    //read

                                    fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                    ms.Position = 0;
                                    ri.ID = br.ReadString();

                                    bool newGeocache;
                                    Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, ri.ID);
                                    if (gc == null)
                                    {
                                        gc = new Framework.Data.Geocache();
                                        htInsertedGeocaches.Add(ri.ID, gc);
                                        newGeocache = true;
                                    }
                                    else
                                    {
                                        if (overwrite || htInsertedGeocaches[ri.ID] != null)
                                        {
                                            newGeocache = false;
                                        }
                                        else
                                        {
                                            continue;
                                        }
                                    }
                                    gc.BeginUpdate();
                                    try
                                    {
                                        gc.Code = ri.ID;
                                        gc.Archived = br.ReadBoolean();
                                        gc.AttributeIds = ReadIntegerArray(br);
                                        gc.Available = br.ReadBoolean();
                                        gc.City = br.ReadString();
                                        gc.Container = Utils.DataAccess.GetGeocacheContainer(Core.GeocacheContainers, br.ReadInt32());
                                        gc.CustomCoords = br.ReadBoolean();
                                        gc.Country = br.ReadString();
                                        if (br.ReadBoolean())
                                        {
                                            gc.CustomLat = br.ReadDouble();
                                            gc.CustomLon = br.ReadDouble();
                                        }
                                        gc.Difficulty = br.ReadDouble();
                                        gc.EncodedHints = br.ReadString();
                                        gc.Favorites = br.ReadInt32();
                                        gc.Flagged = br.ReadBoolean();
                                        gc.Found = br.ReadBoolean();
                                        gc.GeocacheType = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, br.ReadInt32());
                                        gc.ID = br.ReadString();
                                        gc.Lat = br.ReadDouble();
                                        gc.Lon = br.ReadDouble();
                                        gc.MemberOnly = br.ReadBoolean();
                                        gc.Municipality = br.ReadString();
                                        gc.Name = br.ReadString();
                                        gc.Notes = br.ReadString();
                                        gc.Owner = br.ReadString();
                                        gc.OwnerId = br.ReadString();
                                        gc.PersonaleNote = br.ReadString();
                                        gc.PlacedBy = br.ReadString();
                                        gc.PublishedTime = DateTime.Parse(br.ReadString());
                                        gc.State = br.ReadString();
                                        gc.Terrain = br.ReadDouble();
                                        gc.Title = br.ReadString();
                                        gc.Url = br.ReadString();
                                        gc.DataFromDate = DateTime.Parse(br.ReadString());
                                        gc.Locked = br.ReadBoolean();

                                        Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, Core.CenterLocation);
                                    }
                                    catch
                                    {
                                    }
                                    gc.EndUpdate();

                                    if (newGeocache)
                                    {
                                        Core.Geocaches.Add(gc);
                                    }

                                    index++;
                                    if (DateTime.Now >= nextUpdateTime)
                                    {
                                        progress.UpdateProgress(STR_LOADING, STR_LOADINGGEOCACHES, gcCount, index);
                                        nextUpdateTime = DateTime.Now.AddSeconds(1);
                                    }
                                }
                            }
                        }

                        using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGS, logCount, 0))
                        {
                            int index = 0;
                            nextUpdateTime = DateTime.MinValue;

                            FileStream fs = fc._fsLogs;
                            fs.Position = 0;
                            long eof = fs.Length;
                            while (fs.Position < eof)
                            {
                                ri.Offset = fs.Position;
                                fs.Read(memBuffer, 0, lsize + 1);
                                ms.Position = 0;
                                ri.Length = br.ReadInt64();
                                if (memBuffer[lsize] == 0)
                                {
                                    //free
                                    fs.Position = ri.Offset + ri.Length;
                                }
                                else if (memBuffer[lsize] == 2)
                                {
                                    //read
                                    fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                    ms.Position = 0;
                                    ri.ID = br.ReadString().Substring(2);
                                    fs.Position = ri.Offset + ri.Length;

                                    bool newLog;
                                    bool logComplete = true;
                                    Framework.Data.Log log = Utils.DataAccess.GetLog(Core.Logs, ri.ID);
                                    if (log == null)
                                    {
                                        newLog = true;
                                        log = htInsertedLogs[ri.ID] as Framework.Data.Log;
                                        if (log == null)
                                        {
                                            log = new Framework.Data.Log();
                                            htInsertedLogs.Add(ri.ID, log);
                                            logComplete = false;
                                        }
                                        else
                                        {
                                            logComplete = true;
                                        }
                                    }
                                    else
                                    {
                                        if (overwrite)
                                        {
                                            newLog = false;
                                        }
                                        else
                                        {
                                            continue;
                                        }
                                    }
                                    log.BeginUpdate();
                                    try
                                    {
                                        log.ID = ri.ID;
                                        log.TBCode = br.ReadString();
                                        log.FinderId = br.ReadString();
                                        log.Text = br.ReadString();
                                        log.Encoded = br.ReadBoolean();
                                    }
                                    catch
                                    {
                                    }
                                    log.EndUpdate();
                                    if (newLog && logComplete && htInsertedLogs[ri.ID] != null)
                                    {
                                        if (htInsertedGeocaches[log.GeocacheCode ?? ""] != null || Utils.DataAccess.GetGeocache(Core.Geocaches, log.GeocacheCode ?? "") != null)
                                        {
                                            Core.Logs.Add(log);
                                        }
                                        htInsertedLogs.Remove(ri.ID);
                                    }
                                }
                                else
                                {
                                    //read
                                    fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                    ms.Position = 0;
                                    ri.ID = br.ReadString();

                                    bool newLog;
                                    bool logComplete = true;
                                    Framework.Data.Log log = Utils.DataAccess.GetLog(Core.Logs, ri.ID);
                                    if (log == null)
                                    {
                                        newLog = true;
                                        log = htInsertedLogs[ri.ID] as Framework.Data.Log;
                                        if (log == null)
                                        {
                                            log = new Framework.Data.Log();
                                            htInsertedLogs.Add(ri.ID, log);
                                            logComplete = false;
                                        }
                                        else
                                        {
                                            logComplete = true;
                                        }
                                    }
                                    else
                                    {
                                        if (overwrite)
                                        {
                                            newLog = false;
                                        }
                                        else
                                        {
                                            continue;
                                        }
                                    }
                                    log.BeginUpdate();
                                    try
                                    {

                                        log.ID = ri.ID;
                                        log.DataFromDate = DateTime.Parse(br.ReadString());
                                        log.Date = DateTime.Parse(br.ReadString());
                                        log.Finder = br.ReadString();
                                        log.GeocacheCode = br.ReadString();
                                        log.ID = br.ReadString();
                                        log.LogType = Utils.DataAccess.GetLogType(Core.LogTypes, br.ReadInt32());
                                    }
                                    catch
                                    {
                                    }
                                    log.EndUpdate();

                                    if (newLog && logComplete && htInsertedLogs[ri.ID] != null)
                                    {
                                        //check if geocache is present
                                        if (htInsertedGeocaches[log.GeocacheCode ?? ""] != null || Utils.DataAccess.GetGeocache(Core.Geocaches, log.GeocacheCode ?? "") != null)
                                        {
                                            Core.Logs.Add(log);
                                        }
                                        htInsertedLogs.Remove(ri.ID);
                                    }

                                    index++;
                                    if (DateTime.Now >= nextUpdateTime)
                                    {
                                        progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGS, logCount, index);
                                        nextUpdateTime = DateTime.Now.AddSeconds(1);
                                    }
                                }
                            }
                        }


                        using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, 0))
                        {
                            int index = 0;
                            int procStep = 0;

                            using (FileStream fs = File.Open(fc.WaypointsFilename, FileMode.OpenOrCreate, FileAccess.Read))
                            {
                                fs.Position = 0;
                                long eof = fs.Length;
                                while (fs.Position < eof)
                                {
                                    ri.Offset = fs.Position;
                                    fs.Read(memBuffer, 0, lsize + 1);
                                    ms.Position = 0;
                                    ri.Length = br.ReadInt64();
                                    if (memBuffer[lsize] == 0)
                                    {
                                        //free
                                        fs.Position = ri.Offset + ri.Length;
                                    }
                                    else
                                    {
                                        //read
                                        fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                        ms.Position = 0;
                                        ri.ID = br.ReadString();

                                        bool newWp;
                                        Framework.Data.Waypoint wp = Utils.DataAccess.GetWaypoint(Core.Waypoints, ri.ID);
                                        if (wp == null)
                                        {
                                            newWp = true;
                                            wp = new Framework.Data.Waypoint();
                                        }
                                        else
                                        {
                                            if (overwrite)
                                            {
                                                newWp = false;
                                            }
                                            else
                                            {
                                                continue;
                                            }
                                        }

                                        wp.BeginUpdate();
                                        try
                                        {
                                            wp.Code = ri.ID;
                                            wp.Comment = br.ReadString();
                                            wp.DataFromDate = DateTime.Parse(br.ReadString());
                                            wp.Description = br.ReadString();
                                            wp.GeocacheCode = br.ReadString();
                                            wp.ID = br.ReadString();
                                            if (br.ReadBoolean())
                                            {
                                                wp.Lat = br.ReadDouble();
                                                wp.Lon = br.ReadDouble();
                                            }
                                            wp.Name = br.ReadString();
                                            wp.Time = DateTime.Parse(br.ReadString());
                                            wp.Url = br.ReadString();
                                            wp.UrlName = br.ReadString();
                                            wp.WPType = Utils.DataAccess.GetWaypointType(Core.WaypointTypes, br.ReadInt32());
                                        }
                                        catch
                                        {
                                        }
                                        wp.EndUpdate();
                                        if (newWp)
                                        {
                                            if (Utils.DataAccess.GetGeocache(Core.Geocaches, wp.GeocacheCode ?? "") != null)
                                            {
                                                Core.Waypoints.Add(wp);
                                            }
                                        }

                                        index++;
                                        procStep++;
                                        if (procStep >= 1000)
                                        {
                                            progress.UpdateProgress(STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, index);
                                            procStep = 0;
                                        }
                                    }
                                }
                            }
                        }

                        using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, 0))
                        {
                            int index = 0;
                            int procStep = 0;

                            using (FileStream fs = File.Open(fc.LogImagesFilename, FileMode.OpenOrCreate, FileAccess.Read))
                            {
                                fs.Position = 0;
                                long eof = fs.Length;
                                while (fs.Position < eof)
                                {
                                    ri.Offset = fs.Position;
                                    fs.Read(memBuffer, 0, lsize + 1);
                                    ms.Position = 0;
                                    ri.Length = br.ReadInt64();
                                    if (memBuffer[lsize] == 0)
                                    {
                                        //free
                                        fs.Position = ri.Offset + ri.Length;
                                    }
                                    else
                                    {
                                        //read
                                        fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                        ms.Position = 0;
                                        ri.ID = br.ReadString();

                                        bool newWp;
                                        Framework.Data.LogImage li = Utils.DataAccess.GetLogImage(Core.LogImages, ri.ID);
                                        if (li == null)
                                        {
                                            newWp = true;
                                            li = new Framework.Data.LogImage();
                                        }
                                        else
                                        {
                                            if (overwrite)
                                            {
                                                newWp = false;
                                            }
                                            else
                                            {
                                                continue;
                                            }
                                        }

                                        li.BeginUpdate();
                                        try
                                        {
                                            li.ID = ri.ID;
                                            li.DataFromDate = DateTime.Parse(br.ReadString());
                                            li.LogID = br.ReadString();
                                            li.Name = br.ReadString();
                                            li.Url = br.ReadString();
                                        }
                                        catch
                                        {
                                        }
                                        li.EndUpdate();

                                        if (newWp)
                                        {
                                            if (Utils.DataAccess.GetLog(Core.Logs, li.LogID ?? "") != null)
                                            {
                                                Core.LogImages.Add(li);
                                            }
                                        }

                                        index++;
                                        procStep++;
                                        if (procStep >= 1000)
                                        {
                                            progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, index);
                                            procStep = 0;
                                        }
                                    }
                                }
                            }
                        }

                        using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGGEOCACHEIMAGES, geocacheimgCount, 0))
                        {
                            int index = 0;
                            int procStep = 0;

                            using (FileStream fs = File.Open(fc.GeocacheImagesFilename, FileMode.OpenOrCreate, FileAccess.Read))
                            {
                                fs.Position = 0;
                                long eof = fs.Length;
                                while (fs.Position < eof)
                                {
                                    ri.Offset = fs.Position;
                                    fs.Read(memBuffer, 0, lsize + 1);
                                    ms.Position = 0;
                                    ri.Length = br.ReadInt64();
                                    if (memBuffer[lsize] == 0)
                                    {
                                        //free
                                        fs.Position = ri.Offset + ri.Length;
                                    }
                                    else
                                    {
                                        //read
                                        fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                        ms.Position = 0;
                                        ri.ID = br.ReadString();

                                        bool newWp;
                                        Framework.Data.GeocacheImage wp = Utils.DataAccess.GetGeocacheImage(Core.GeocacheImages, ri.ID);
                                        if (wp == null)
                                        {
                                            newWp = true;
                                            wp = new Framework.Data.GeocacheImage();
                                        }
                                        else
                                        {
                                            if (overwrite)
                                            {
                                                newWp = false;
                                            }
                                            else
                                            {
                                                continue;
                                            }
                                        }

                                        wp.BeginUpdate();
                                        try
                                        {
                                            wp.ID = ri.ID;
                                            wp.DataFromDate = DateTime.Parse(br.ReadString());
                                            wp.GeocacheCode = br.ReadString();
                                            wp.Description = br.ReadString();
                                            wp.Name = br.ReadString();
                                            wp.Url = br.ReadString();
                                            wp.MobileUrl = br.ReadString();
                                            wp.ThumbUrl = br.ReadString();
                                        }
                                        catch
                                        {
                                        }
                                        wp.EndUpdate();
                                        if (newWp)
                                        {
                                            if (Utils.DataAccess.GetGeocache(Core.Geocaches, wp.GeocacheCode ?? "") != null)
                                            {
                                                Core.GeocacheImages.Add(wp);
                                            }
                                        }

                                        index++;
                                        procStep++;
                                        if (procStep >= 1000)
                                        {
                                            progress.UpdateProgress(STR_LOADING, STR_LOADINGGEOCACHEIMAGES, geocacheimgCount, index);
                                            procStep = 0;
                                        }
                                    }
                                }
                            }
                        }

                        {
                            using (FileStream fs = File.Open(fc.UserWaypointsFilename, FileMode.OpenOrCreate, FileAccess.Read))
                            {
                                fs.Position = 0;
                                long eof = fs.Length;
                                while (fs.Position < eof)
                                {
                                    ri.Offset = fs.Position;
                                    fs.Read(memBuffer, 0, lsize + 1);
                                    ms.Position = 0;
                                    ri.Length = br.ReadInt64();
                                    if (memBuffer[lsize] == 0)
                                    {
                                        //free
                                        fs.Position = ri.Offset + ri.Length;
                                    }
                                    else
                                    {
                                        //read
                                        fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                        ms.Position = 0;
                                        ri.ID = br.ReadString();

                                        bool newWp;
                                        Framework.Data.UserWaypoint wp = Utils.DataAccess.GetUserWaypoint(Core.UserWaypoints, int.Parse(ri.ID));
                                        if (wp == null)
                                        {
                                            newWp = true;
                                            wp = new Framework.Data.UserWaypoint();
                                        }
                                        else
                                        {
                                            if (overwrite)
                                            {
                                                newWp = false;
                                            }
                                            else
                                            {
                                                continue;
                                            }
                                        }

                                        wp.BeginUpdate();
                                        try
                                        {
                                            wp.ID = int.Parse(ri.ID);
                                            wp.Description = br.ReadString();
                                            wp.GeocacheCode = br.ReadString();
                                            wp.Lat = br.ReadDouble();
                                            wp.Lon = br.ReadDouble();
                                            wp.Date = DateTime.Parse(br.ReadString());
                                        }
                                        catch
                                        {
                                        }
                                        if (newWp)
                                        {
                                            if (Utils.DataAccess.GetGeocache(Core.Geocaches, wp.GeocacheCode ?? "") != null)
                                            {
                                                Core.UserWaypoints.Add(wp);
                                            }
                                        }

                                        wp.EndUpdate();
                                    }
                                }
                            }
                        }
                    }
                }
                result = true;
            }
            catch
            {
            }
            return result;
        }
Exemplo n.º 9
0
 /// <summary>
 /// Create a new Mapping for the record Type 't'.
 /// </summary>
 /// <param name="recordType">The record class.</param>
 public DataMapper(Type recordType)
 {
     mRecordInfo = new RecordInfo(recordType);
 }
Exemplo n.º 10
0
 /// <include file='FileHelperEngine.docs.xml' path='doc/FileHelperEngineCtr/*'/>
 /// <param name="ri">Record information</param>
 internal VisynFileHelper(RecordInfo ri) : base(ri)
 {
 }
 private static string RecordInfoToName(RecordInfo recordInfo)
 {
     return(string.Join("|", recordInfo.id, recordInfo.time.ToUnixTimeSeconds(), recordInfo.title));
 }
Exemplo n.º 12
0
        public void Execute()
        {
            var window = new RecordInfo((VinylRecord)row.Item);

            window.Show();
        }
Exemplo n.º 13
0
 string Generate(RecordInfo record, string injectCode = "", string globalNamespace = "") => Generate(record.Yield(), injectCode, globalNamespace);
Exemplo n.º 14
0
        public void GenerateSimpleClass(string name, Visibility visibility, bool isClass, string expected)
        {
            RecordInfo record = new RecordInfo(name, isClass, visibility);

            Assert.Equal(expected, Generate(record));
        }
Exemplo n.º 15
0
 /// <summary>
 /// Create a new Mapping for the record Type 't'.
 /// </summary>
 /// <param name="t">The record class.</param>
 public DataMapper()
 {
     mRecordInfo = new RecordInfo(typeof(T));
 }
Exemplo n.º 16
0
        private static bool Import(Database database, string filename)
        {
            bool result = false;
            try
            {
                byte[] memBuffer = new byte[10 * 1024 * 1024];

                int gcCount = 0;
                int logCount = 0;
                int logimgCount = 0;
                int geocacheimgCount = 0;
                int wptCount = 0;
                int usrwptCount = 0;
                int index = 0;

                XmlDocument doc = new XmlDocument();
                doc.Load(filename);
                XmlElement root = doc.DocumentElement;
                gcCount = int.Parse(root.SelectSingleNode("GeocacheCount").InnerText);
                logCount = int.Parse(root.SelectSingleNode("LogCount").InnerText);
                logimgCount = int.Parse(root.SelectSingleNode("LogImagesCount").InnerText);
                wptCount = int.Parse(root.SelectSingleNode("WaypointCount").InnerText);
                usrwptCount = int.Parse(root.SelectSingleNode("UserWaypointCount").InnerText);
                if (root.SelectSingleNode("GeocacheImagesCount") != null)
                {
                    geocacheimgCount = int.Parse(root.SelectSingleNode("GeocacheImagesCount").InnerText);
                }

                DateTime nextUpdateTime = DateTime.Now.AddSeconds(1);

                using (Utils.ProgressBlock prog = new ProgressBlock("Importing database", "Importing...", 6, 0))
                {
                    List<RecordInfo> records = new List<RecordInfo>();
                    Hashtable f_records = new Hashtable();

                    using (Utils.ProgressBlock subProg = new ProgressBlock("Importing geocaches...", gcCount, 0))
                    {

                        //GEOCACHES
                        //first all record
                        using (FileStream fs = File.Open(Path.Combine(Path.GetDirectoryName(filename), string.Format("{0}.cch", Path.GetFileNameWithoutExtension(filename))), FileMode.OpenOrCreate, FileAccess.Read))
                        using (BinaryReader br = new BinaryReader(fs))
                        {
                            fs.Position = 0;
                            long eof = fs.Length;
                            while (fs.Position < eof)
                            {
                                RecordInfo ri = new RecordInfo();
                                ri.Offset = fs.Position;
                                ri.Length = br.ReadInt64();
                                byte slotType = br.ReadByte();
                                if (slotType == 0)
                                {
                                    //free
                                }
                                else
                                {
                                    //read
                                    ri.ID = br.ReadString();
                                    if (slotType == 1)
                                    {
                                        records.Add(ri);
                                    }
                                    else
                                    {
                                        f_records.Add(ri.ID, ri);
                                    }
                                }
                                fs.Position = ri.Offset + ri.Length;
                            }
                            foreach (RecordInfo ri in records)
                            {
                                GeocacheData gc = new GeocacheData();
                                gc.Code = ri.ID;

                                fs.Position = ri.Offset + 9;

                                string dummyString = br.ReadString(); //id
                                gc.Archived = br.ReadBoolean();
                                gc.AttributeIds = ReadIntegerArray(br);
                                gc.Available = br.ReadBoolean();
                                gc.City = br.ReadString();
                                gc.Container = Utils.DataAccess.GetGeocacheContainer(br.ReadInt32());
                                bool dummyBool = br.ReadBoolean();
                                gc.Country = br.ReadString();
                                if (br.ReadBoolean())
                                {
                                    gc.CustomLat = br.ReadDouble();
                                    gc.CustomLon = br.ReadDouble();
                                }
                                gc.Difficulty = br.ReadDouble();
                                gc.EncodedHints = br.ReadString();
                                gc.Favorites = br.ReadInt32();
                                gc.Flagged = br.ReadBoolean();
                                gc.Found = br.ReadBoolean();
                                gc.GeocacheType = Utils.DataAccess.GetGeocacheType(br.ReadInt32());
                                dummyString = br.ReadString();
                                gc.Lat = br.ReadDouble();
                                gc.Lon = br.ReadDouble();
                                gc.MemberOnly = br.ReadBoolean();
                                gc.Municipality = br.ReadString();
                                gc.Name = br.ReadString();
                                gc.Notes = br.ReadString();
                                gc.Owner = br.ReadString();
                                gc.OwnerId = br.ReadString();
                                gc.PersonalNote = br.ReadString();
                                gc.PlacedBy = br.ReadString();
                                gc.PublishedTime = DateTime.Parse(br.ReadString());
                                gc.State = br.ReadString();
                                gc.Terrain = br.ReadDouble();
                                gc.Name = br.ReadString();
                                gc.Url = br.ReadString();
                                gc.DataFromDate = DateTime.Parse(br.ReadString());
                                gc.Locked = br.ReadBoolean();

                                RecordInfo rf = f_records[string.Format("F_{0}", ri.ID)] as RecordInfo;
                                if (rf != null)
                                {
                                    fs.Position = rf.Offset + 9;

                                    br.ReadString(); //id
                                    gc.ShortDescription = br.ReadString();
                                    gc.ShortDescriptionInHtml = br.ReadBoolean();
                                    gc.LongDescription = br.ReadString();
                                    gc.LongDescriptionInHtml = br.ReadBoolean();
                                }
                                DataAccess.AddGeocache(database, gc);
                                index++;
                                if (DateTime.Now >= nextUpdateTime)
                                {
                                    subProg.Update("Importing geocaches...", gcCount, index);
                                    nextUpdateTime = DateTime.Now.AddSeconds(1);
                                }
                            }
                        }
                    }
                    prog.Update("Importing...", 6, 1);

                    records.Clear();
                    f_records.Clear();

                    using (Utils.ProgressBlock subProg = new ProgressBlock("Importing logs...", logCount, 0))
                    {
                        index = 0;
                        //LOGS
                        //first all record
                        using (FileStream fs = File.Open(Path.Combine(Path.GetDirectoryName(filename), string.Format("{0}.lgs", Path.GetFileNameWithoutExtension(filename))), FileMode.OpenOrCreate, FileAccess.Read))
                        using (BinaryReader br = new BinaryReader(fs))
                        {
                            fs.Position = 0;
                            long eof = fs.Length;
                            while (fs.Position < eof)
                            {
                                RecordInfo ri = new RecordInfo();
                                ri.Offset = fs.Position;
                                ri.Length = br.ReadInt64();
                                byte slotType = br.ReadByte();
                                if (slotType == 0)
                                {
                                    //free
                                }
                                else
                                {
                                    //read
                                    ri.ID = br.ReadString();
                                    if (slotType == 1)
                                    {
                                        records.Add(ri);
                                    }
                                    else
                                    {
                                        f_records.Add(ri.ID, ri);
                                    }
                                }
                                fs.Position = ri.Offset + ri.Length;
                            }
                            foreach (RecordInfo ri in records)
                            {
                                LogData gc = new LogData();
                                gc.ID = ri.ID;

                                fs.Position = ri.Offset + 9;
                                string dummyString = br.ReadString(); //id
                                gc.DataFromDate = DateTime.Parse(br.ReadString());
                                gc.Date = DateTime.Parse(br.ReadString());
                                gc.Finder = br.ReadString();
                                gc.GeocacheCode = br.ReadString();
                                gc.ID = br.ReadString();
                                gc.LogType = Utils.DataAccess.GetLogType(br.ReadInt32());

                                RecordInfo rf = f_records[string.Format("F_{0}", ri.ID)] as RecordInfo;
                                if (rf != null)
                                {
                                    fs.Position = rf.Offset + 9;

                                    br.ReadString(); //id
                                    gc.TBCode = br.ReadString();
                                    gc.FinderId = br.ReadString();
                                    gc.Text = br.ReadString();
                                    gc.Encoded = br.ReadBoolean();
                                }
                                DataAccess.AddLog(database, gc);
                                index++;
                                if (DateTime.Now >= nextUpdateTime)
                                {
                                    subProg.Update("Importing geocaches...", gcCount, index);
                                    nextUpdateTime = DateTime.Now.AddSeconds(1);
                                }
                            }
                        }
                    }
                    prog.Update("Importing...", 6, 2);

                    records.Clear();
                    f_records.Clear();

                    using (Utils.ProgressBlock subProg = new ProgressBlock("Importing waypoints...", logCount, 0))
                    {
                        index = 0;
                        //Waypoints
                        using (FileStream fs = File.Open(Path.Combine(Path.GetDirectoryName(filename), string.Format("{0}.wpt", Path.GetFileNameWithoutExtension(filename))), FileMode.OpenOrCreate, FileAccess.Read))
                        using (BinaryReader br = new BinaryReader(fs))
                        {
                            fs.Position = 0;
                            long eof = fs.Length;
                            RecordInfo ri = new RecordInfo();
                            while (fs.Position < eof)
                            {
                                ri.Offset = fs.Position;
                                ri.Length = br.ReadInt64();
                                byte slotType = br.ReadByte();
                                if (slotType == 0)
                                {
                                    //free
                                }
                                else
                                {
                                    //read
                                    Core.Data.WaypointData wp = new Core.Data.WaypointData();

                                    wp.Code = br.ReadString();
                                    wp.Comment = br.ReadString();
                                    wp.DataFromDate = DateTime.Parse(br.ReadString());
                                    wp.Description = br.ReadString();
                                    wp.GeocacheCode = br.ReadString();
                                    wp.ID = br.ReadString();
                                    if (br.ReadBoolean())
                                    {
                                        wp.Lat = br.ReadDouble();
                                        wp.Lon = br.ReadDouble();
                                    }
                                    wp.Name = br.ReadString();
                                    wp.Time = DateTime.Parse(br.ReadString());
                                    wp.Url = br.ReadString();
                                    wp.UrlName = br.ReadString();
                                    wp.WPType = Utils.DataAccess.GetWaypointType(br.ReadInt32());

                                    DataAccess.AddWaypoint(database, wp);
                                    index++;
                                    if (DateTime.Now >= nextUpdateTime)
                                    {
                                        subProg.Update("Importing waypoints...", gcCount, index);
                                        nextUpdateTime = DateTime.Now.AddSeconds(1);
                                    }

                                }
                                fs.Position = ri.Offset + ri.Length;
                            }
                        }
                    }
                    prog.Update("Importing...", 6, 3);

                    records.Clear();
                    f_records.Clear();

                    using (Utils.ProgressBlock subProg = new ProgressBlock("Importing log images...", logimgCount, 0))
                    {
                        index = 0;
                        using (FileStream fs = File.Open(Path.Combine(Path.GetDirectoryName(filename), string.Format("{0}.lmg", Path.GetFileNameWithoutExtension(filename))), FileMode.OpenOrCreate, FileAccess.Read))
                        using (BinaryReader br = new BinaryReader(fs))
                        {
                            fs.Position = 0;
                            long eof = fs.Length;
                            RecordInfo ri = new RecordInfo();
                            while (fs.Position < eof)
                            {
                                ri.Offset = fs.Position;
                                ri.Length = br.ReadInt64();
                                byte slotType = br.ReadByte();
                                if (slotType == 0)
                                {
                                    //free
                                }
                                else
                                {
                                    //read
                                    Core.Data.LogImageData li = new Core.Data.LogImageData();

                                    li.ID = br.ReadString();
                                    li.DataFromDate = DateTime.Parse(br.ReadString());
                                    li.LogId = br.ReadString();
                                    li.Name = br.ReadString();
                                    li.Url = br.ReadString();

                                    DataAccess.AddLogImage(database, li);
                                    index++;
                                    if (DateTime.Now >= nextUpdateTime)
                                    {
                                        subProg.Update("Importing log images...", logimgCount, index);
                                        nextUpdateTime = DateTime.Now.AddSeconds(1);
                                    }
                                }
                                fs.Position = ri.Offset + ri.Length;

                            }
                        }
                    }
                    prog.Update("Importing...", 6, 4);

                    records.Clear();
                    f_records.Clear();

                    using (Utils.ProgressBlock subProg = new ProgressBlock("Importing geocache images...", geocacheimgCount, 0))
                    {
                        index = 0;
                        using (FileStream fs = File.Open(Path.Combine(Path.GetDirectoryName(filename), string.Format("{0}.gmg", Path.GetFileNameWithoutExtension(filename))), FileMode.OpenOrCreate, FileAccess.Read))
                        using (BinaryReader br = new BinaryReader(fs))
                        {
                            fs.Position = 0;
                            long eof = fs.Length;
                            RecordInfo ri = new RecordInfo();
                            while (fs.Position < eof)
                            {
                                ri.Offset = fs.Position;
                                ri.Length = br.ReadInt64();
                                byte slotType = br.ReadByte();
                                if (slotType == 0)
                                {
                                    //free
                                }
                                else
                                {
                                    //read
                                    Core.Data.GeocacheImageData li = new Core.Data.GeocacheImageData();

                                    li.ID = br.ReadString();
                                    li.DataFromDate = DateTime.Parse(br.ReadString());
                                    li.GeocacheCode = br.ReadString();
                                    li.Description = br.ReadString();
                                    li.Name = br.ReadString();
                                    li.Url = br.ReadString();
                                    li.MobileUrl = br.ReadString();
                                    li.ThumbUrl = br.ReadString();

                                    DataAccess.AddGeocacheImage(database, li);
                                    index++;
                                    if (DateTime.Now >= nextUpdateTime)
                                    {
                                        subProg.Update("Importing geocache images...", geocacheimgCount, index);
                                        nextUpdateTime = DateTime.Now.AddSeconds(1);
                                    }

                                }
                                fs.Position = ri.Offset + ri.Length;
                            }
                        }
                    }
                    prog.Update("Importing...", 6, 5);

                    records.Clear();
                    f_records.Clear();

                    using (Utils.ProgressBlock subProg = new ProgressBlock("Importing user waypoints...", usrwptCount, 0))
                    {
                        index = 0;
                        using (FileStream fs = File.Open(Path.Combine(Path.GetDirectoryName(filename), string.Format("{0}.uwp", Path.GetFileNameWithoutExtension(filename))), FileMode.OpenOrCreate, FileAccess.Read))
                        using (BinaryReader br = new BinaryReader(fs))
                        {
                            fs.Position = 0;
                            long eof = fs.Length;
                            RecordInfo ri = new RecordInfo();
                            while (fs.Position < eof)
                            {
                                ri.Offset = fs.Position;
                                ri.Length = br.ReadInt64();
                                byte slotType = br.ReadByte();
                                if (slotType == 0)
                                {
                                    //free
                                }
                                else
                                {
                                    //read
                                    Core.Data.UserWaypointData wp = new Core.Data.UserWaypointData();

                                    wp.ID = br.ReadString();
                                    wp.Description = br.ReadString();
                                    wp.GeocacheCode = br.ReadString();
                                    wp.Lat = br.ReadDouble();
                                    wp.Lon = br.ReadDouble();
                                    wp.Date = DateTime.Parse(br.ReadString());

                                    DataAccess.AddUserWaypoint(database, wp);
                                    index++;
                                    if (DateTime.Now >= nextUpdateTime)
                                    {
                                        subProg.Update("Importing user waypoints...", usrwptCount, index);
                                        nextUpdateTime = DateTime.Now.AddSeconds(1);
                                    }

                                }
                                fs.Position = ri.Offset + ri.Length;
                            }
                        }
                    }
                    prog.Update("Importing...", 6, 6);

                    result = true;
                }
            }
            catch
            {
            }
            return result;
        }
Exemplo n.º 17
0
 /// <include file='MasterDetailEngine.docs.xml' path='doc/MasterDetailEngineCtr1/*' />
 public MasterDetailEngine(Type masterType, Type detailType, MasterDetailSelector recordSelector) : base(detailType)
 {
     mMasterType     = masterType;
     mMasterInfo     = new RecordInfo(masterType);
     mRecordSelector = recordSelector;
 }
Exemplo n.º 18
0
        // 根据册条码号或者记录路径,装入册记录
        // parameters:
        //      strBarcodeOrRecPath 册条码号或者记录路径。如果内容前缀为"@path:"则表示为路径
        //      strMatchLocation    附加的馆藏地点匹配条件。如果==null,表示没有这个附加条件(注意,""和null含义不同,""表示确实要匹配这个值)
        // return: 
        //      -2  册条码号或者记录路径已经在list中存在了(行没有加入listview中)
        //      -1  出错(注意表示出错的行已经加入listview中了)
        //      0   因为馆藏地点不匹配,没有加入list中
        //      1   成功
        int LoadOneItem(
            string strPubType,
            string strBarcodeOrRecPath,
            RecordInfo info,
            ListView list,
            string strMatchLocation,
            out string strOutputItemRecPath,
            ref ListViewItem item,
            out string strError)
        {
            strError = "";
            strOutputItemRecPath = "";
            long lRet = 0;

            // 判断是否有 @path: 前缀,便于后面分支处理
            bool bIsRecPath = StringUtil.HasHead(strBarcodeOrRecPath, "@path:");

            string strItemText = "";
            string strBiblioText = "";

            // string strItemRecPath = "";
            string strBiblioRecPath = "";
            XmlDocument item_dom = null;
            string strBiblioSummary = "";
            string strISBnISSN = "";

            if (info == null)
            {
                byte[] item_timestamp = null;

            REDO_GETITEMINFO:
                lRet = Channel.GetItemInfo(
                    stop,
                    strBarcodeOrRecPath,
                    "xml",
                    out strItemText,
                    out strOutputItemRecPath,
                    out item_timestamp,
                    "recpath",
                    out strBiblioText,
                    out strBiblioRecPath,
                    out strError);
                if (lRet == -1)
                {
                    DialogResult temp_result = MessageBox.Show(this,
    strError + "\r\n\r\n是否重试?",
    "AccountBookForm",
    MessageBoxButtons.RetryCancel,
    MessageBoxIcon.Question,
    MessageBoxDefaultButton.Button1);
                    if (temp_result == DialogResult.Retry)
                        goto REDO_GETITEMINFO;
                }
                if (lRet == -1 || lRet == 0)
                {
#if NO
                    if (item == null)
                    {
                        item = new ListViewItem(strBarcodeOrRecPath, 0);
                        list.Items.Add(item);
                    }
                    else
                    {
                        Debug.Assert(item.ListView == list, "");
                    }

                    // item.SubItems.Add(strError);
                    ListViewUtil.ChangeItemText(item, COLUMN_ERRORINFO, strError);

                    SetItemColor(item, TYPE_ERROR);

                    // 将新加入的事项滚入视野
                    list.EnsureVisible(list.Items.IndexOf(item));
#endif
                    SetError(list,
                        ref item,
                        strBarcodeOrRecPath,
                        strError);
                    goto ERROR1;
                }

                SummaryInfo summary = (SummaryInfo)this.m_summaryTable[strBiblioRecPath];
                if (summary != null)
                {
                    strBiblioSummary = summary.Summary;
                    strISBnISSN = summary.ISBnISSn;
                }

                if (strBiblioSummary == ""
                    && this.checkBox_load_fillBiblioSummary.Checked == true)
                {
                    string[] formats = new string[2];
                    formats[0] = "summary";
                    formats[1] = "@isbnissn";
                    string[] results = null;
                    byte[] timestamp = null;

                    stop.SetMessage("正在装入书目记录 '" + strBiblioRecPath + "' 的摘要 ...");

                    Debug.Assert(String.IsNullOrEmpty(strBiblioRecPath) == false, "strBiblioRecPath值不能为空");
                REDO_GETBIBLIOINFO:
                    lRet = Channel.GetBiblioInfos(
                        stop,
                        strBiblioRecPath,
                    "",
                        formats,
                        out results,
                        out timestamp,
                        out strError);
                    if (lRet == -1)
                    {
                        DialogResult temp_result = MessageBox.Show(this,
        strError + "\r\n\r\n是否重试?",
        "AccountBookForm",
        MessageBoxButtons.RetryCancel,
        MessageBoxIcon.Question,
        MessageBoxDefaultButton.Button1);
                        if (temp_result == DialogResult.Retry)
                            goto REDO_GETBIBLIOINFO;
                    }
                    if (lRet == -1 || lRet == 0)
                    {
                        if (lRet == 0 && String.IsNullOrEmpty(strError) == true)
                            strError = "书目记录 '" + strBiblioRecPath + "' 不存在";

                        strBiblioSummary = "获得书目摘要时发生错误: " + strError;
                    }
                    else
                    {
                        Debug.Assert(results != null && results.Length == 2, "results必须包含2个元素");
                        strBiblioSummary = results[0];
                        strISBnISSN = results[1];

                        // 避免cache占据的内存太多
                        if (this.m_summaryTable.Count > 1000)
                            this.m_summaryTable.Clear();

                        if (summary == null)
                        {
                            summary = new SummaryInfo();
                            summary.Summary = strBiblioSummary;
                            summary.ISBnISSn = strISBnISSN;
                            this.m_summaryTable[strBiblioRecPath] = summary;
                        }
                    }
                }

                // 剖析一个册的xml记录,取出有关信息放入listview中
                if (item_dom == null)
                {
                    item_dom = new XmlDocument();
                    try
                    {
                        item_dom.LoadXml(strItemText);
                    }
                    catch (Exception ex)
                    {
                        strError = "册记录的XML装入DOM时出错: " + ex.Message;
                        goto ERROR1;
                    }
                }

            }
            else
            {
                // record 不为空调用时,对调用时参数strBarcodeOrRecPath不作要求

                strBarcodeOrRecPath = "@path:" + info.Record.Path;
                bIsRecPath = true;

                if (info.Record.RecordBody.Result.ErrorCode != ErrorCodeValue.NoError)
                {
#if NO
                    if (item == null)
                        item = new ListViewItem(strBarcodeOrRecPath, 0);


                    item.SubItems.Add(info.Record.RecordBody.Result.ErrorString);

                    SetItemColor(item, TYPE_ERROR);
                    list.Items.Add(item);

                    // 将新加入的事项滚入视野
                    list.EnsureVisible(list.Items.Count - 1);
#endif
                    SetError(list,
    ref item,
    strBarcodeOrRecPath,
    info.Record.RecordBody.Result.ErrorString);
                    goto ERROR1;
                }

                strItemText = info.Record.RecordBody.Xml;
                strOutputItemRecPath = info.Record.Path;

                //
                item_dom = info.Dom;
                strBiblioRecPath = info.BiblioRecPath;
                if (info.SummaryInfo != null)
                {
                    strBiblioSummary = info.SummaryInfo.Summary;
                    strISBnISSN = info.SummaryInfo.ISBnISSn;
                }
            }


            // 附加的馆藏地点匹配
            if (strMatchLocation != null)
            {
                // TODO: #reservation, 情况如何处理?
                string strLocation = DomUtil.GetElementText(item_dom.DocumentElement,
                    "location");

                // 2013/3/26
                if (strLocation == null)
                    strLocation = "";

                if (strMatchLocation != strLocation)
                    return 0;
            }

            if (item == null)
            {
                item = AddToListView(list,
                    item_dom,
                    strOutputItemRecPath,
                    strBiblioSummary,
                    strISBnISSN,
                    strBiblioRecPath);

                // 图标
                // item.ImageIndex = TYPE_NORMAL;
                SetItemColor(item, TYPE_NORMAL);

                // 将新加入的事项滚入视野
                list.EnsureVisible(list.Items.Count - 1);

#if NO
                // 填充需要从订购库获得的栏目信息
                if (this.checkBox_load_fillOrderInfo.Checked == true)
                    FillOrderColumns(item, strPubType);
#endif
            }
            else
            {
                SetListViewItemText(item_dom,
    true,
    strOutputItemRecPath,
    strBiblioSummary,
    strISBnISSN,
    strBiblioRecPath,
    item);
                SetItemColor(item, TYPE_NORMAL);
            }

            return 1;
        ERROR1:
            return -1;
        }
Exemplo n.º 19
0
 internal IgnoreCommentInfo(RecordInfo ri)
 {
     mRecordInfo = ri;
 }
Exemplo n.º 20
0
		/// <summary>Must Return the records from the DataSource (DB, Excel, etc)</summary>
		/// <returns>The extracted records.</returns>
		public DataTable ExtractRecordsAsDT()
		{
			RecordInfo ri = new RecordInfo(RecordType);
			return ri.RecordsToDataTable(ExtractRecords());
		}
Exemplo n.º 21
0
 internal RecordOptions(RecordInfo info)
 {
     mRecordInfo          = info;
     mRecordConditionInfo = new RecordConditionInfo(info);
     mIgnoreCommentInfo   = new IgnoreCommentInfo(info);
 }
Exemplo n.º 22
0
        private void writeRecord(Hashtable ht, string id, MemoryStream ms, BinaryWriter bw, FileStream fs, byte[] memBuffer, byte[] extraBuffer, List<RecordInfo> freeRecords)
        {
            //look for record
            long recordLength = ms.Position;
            int lsize = sizeof(long);
            byte isFree = 0;
            bool findFreeSlot = false;
            RecordInfo ri = ht[id] as RecordInfo;
            if (ri == null)
            {
                //find free slot
                findFreeSlot = true;
            }
            else if (ri.Length >= recordLength)
            {
                //length stays the same
                fs.Position = ri.Offset + lsize;
                fs.Write(memBuffer, lsize, (int)recordLength - lsize);
            }
            else
            {
                //current is too small
                //mark current record als free (change id)
                ht.Remove(ri.ID);
                ri.ID = string.Concat("_", ri.ID);
                ri.FreeSlot = true;
                ht.Add(ri.ID, ri);

                //scratch file to mark it as free
                fs.Position = ri.Offset + lsize;
                fs.WriteByte(isFree);

                //find free slot
                findFreeSlot = true;
            }
            if (findFreeSlot)
            {
                //get list of free slots before saving (saves time, otherwise going through the list too often
                //ri = (from r in freeRecords where r.Length >= recordLength select r).FirstOrDefault();
                //assume sorted from large to small
                if (freeRecords.Count > 0 && freeRecords[0].Length >= recordLength)
                {
                    ri = freeRecords[0];
                }
                else
                {
                    ri = null;
                }
                if (ri != null)
                {
                    freeRecords.Remove(ri);

                    ht.Remove(ri.ID);
                    ri.ID = id;
                    ri.FreeSlot = false;
                    ht.Add(ri.ID, ri);

                    //insert new record
                    fs.Position = ri.Offset + lsize;
                    fs.Write(memBuffer, lsize, (int)recordLength - lsize);
                }
                else
                {
                    //add
                    bw.Write(extraBuffer);
                    recordLength = ms.Position;
                    ms.Seek(0, SeekOrigin.Begin);
                    bw.Write(recordLength); //overwrite afterwards

                    ri = new RecordInfo();
                    ri.FreeSlot = false;
                    ri.ID = id;
                    ri.Length = recordLength;
                    ri.Offset = fs.Length;
                    ht[id] = ri;

                    fs.Position = fs.Length;
                    fs.Write(memBuffer, 0, (int)recordLength);
                }
            }
        }
Exemplo n.º 23
0
 internal RecordConditionInfo(RecordInfo ri)
 {
     mRecordInfo = ri;
 }
Exemplo n.º 24
0
        /// <summary>Must Return the records from the DataSource (DB, Excel, etc)</summary>
        /// <returns>The extracted records.</returns>
        public DataTable ExtractRecordsAsDT()
        {
            var ri = new RecordInfo(RecordType);

            return(ri.RecordsToDataTable(ExtractRecords()));
        }
Exemplo n.º 25
0
 /// <summary>
 /// 录像查询消息处理
 /// </summary>
 /// <param name="localSIPEndPoint">本地终结点</param>
 /// <param name="remoteEndPoint">远程终结点</param>
 /// <param name="response">sip响应</param>
 /// <param name="record">录像xml结构体</param>
 private void RecordInfoHandle(SIPEndPoint localEP, SIPEndPoint remoteEP, SIPRequest request, RecordInfo record)
 {
     _nodeMonitorService[record.DeviceID].RecordQueryTotal(record.SumNum);
     if (OnRecordInfoReceived != null && record.RecordItems != null)
     {
         OnRecordInfoReceived(record);
     }
 }
Exemplo n.º 26
0
 public RecordOperator(RecordInfo recordInfo)
     : this()
 {
     mRecordInfo = recordInfo;
 }
Exemplo n.º 27
0
        /// <summary>
        /// Message消息处理
        /// </summary>
        /// <param name="localEP">本地终结点</param>
        /// <param name="remoteEP">远程终结点</param>
        /// <param name="request">sip请求</param>
        private void MessageHandle(SIPEndPoint localEP, SIPEndPoint remoteEP, SIPRequest request)
        {
            SendResponse(localEP, remoteEP, request);

            //心跳消息
            KeepAlive keepAlive = KeepAlive.Instance.Read(request.Body);

            if (keepAlive != null && keepAlive.CmdType == CommandType.Keepalive)
            {
                KeepaliveHandle(localEP, remoteEP, request, keepAlive);
                return;
            }


            //设备目录
            Catalog catalog = Catalog.Instance.Read(request.Body);

            if (catalog != null && catalog.CmdType == CommandType.Catalog)
            {
                CatalogHandle(localEP, remoteEP, request, catalog);
                return;
            }

            //录像查询
            RecordInfo record = RecordInfo.Instance.Read(request.Body);

            if (record != null && record.CmdType == CommandType.RecordInfo)
            {
                RecordInfoHandle(localEP, remoteEP, request, record);
                return;
            }

            //媒体通知
            MediaStatus mediaStatus = MediaStatus.Instance.Read(request.Body);

            if (mediaStatus != null && mediaStatus.CmdType == CommandType.MediaStatus)
            {
                _nodeMonitorService[request.Header.From.FromURI.User].ByeVideoReq();
                //取值121表示历史媒体文件发送结束(回放结束/下载结束)
                //NotifyType未找到相关文档标明所有该类型值,暂时只处理121
                if (mediaStatus.NotifyType.Equals("121"))
                {
                    OnMediaStatusReceived?.Invoke(remoteEP, mediaStatus);
                }
                return;
            }

            //设备状态查询
            DeviceStatus deviceStatus = DeviceStatus.Instance.Read(request.Body);

            if (deviceStatus != null && deviceStatus.CmdType == CommandType.DeviceStatus)
            {
                OnDeviceStatusReceived?.Invoke(remoteEP, deviceStatus);
                return;
            }

            //设备信息查询
            DeviceInfo deviceInfo = DeviceInfo.Instance.Read(request.Body);

            if (deviceInfo != null && deviceInfo.CmdType == CommandType.DeviceInfo)
            {
                OnDeviceInfoReceived?.Invoke(remoteEP, deviceInfo);
                return;
            }

            //设备配置查询
            DeviceConfigDownload devDownload = DeviceConfigDownload.Instance.Read(request.Body);

            if (devDownload != null && devDownload.CmdType == CommandType.ConfigDownload)
            {
                OnDeviceConfigDownloadReceived?.Invoke(remoteEP, devDownload);
            }

            //预置位查询
            PresetInfo preset = PresetInfo.Instance.Read(request.Body);

            if (preset != null && preset.CmdType == CommandType.PresetQuery)
            {
                OnPresetQueryReceived?.Invoke(remoteEP, preset);
            }

            //报警通知
            Alarm alarm = Alarm.Instance.Read(request.Body);

            if (alarm != null && alarm.CmdType == CommandType.Alarm)//单兵上报经纬度
            {
                OnAlarmReceived?.Invoke(alarm);
            }
        }
Exemplo n.º 28
0
 public bool Unlock(ref RecordInfo recordInfo, ref Key key, ref Value value, LockType lockType, long lockContext) => true;
        void OnGUI()
        {
            if (_items == null)
            {
                Load();
            }

            if (string.IsNullOrEmpty(_newUrl))
            {
                _newUrl = UrlDefault;
            }
            if (string.IsNullOrEmpty(_newRes))
            {
                _newRes = ResDefault;
            }

            var needSave = false;

            if (_items.Count > 0)
            {
                EditorGUILayout.LabelField("List of csv resources", EditorStyles.boldLabel);
                _scrollPos = GUILayout.BeginScrollView(_scrollPos, false, true);
                for (var i = 0; i < _items.Count; i++)
                {
                    var item = _items[i];
                    GUILayout.BeginHorizontal(GUI.skin.box);
                    GUILayout.BeginVertical();

                    GUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField(
                        "External url path:", EditorStyles.label, GUILayout.Width(EditorGUIUtility.labelWidth));
                    EditorGUILayout.SelectableLabel(
                        item.Url, EditorStyles.textField, GUILayout.Height(EditorGUIUtility.singleLineHeight));
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField(
                        "Local resource path:", EditorStyles.label, GUILayout.Width(EditorGUIUtility.labelWidth));
                    EditorGUILayout.SelectableLabel(
                        item.Resource, EditorStyles.textField, GUILayout.Height(EditorGUIUtility.singleLineHeight));
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField(
                        "Convert to JSON:", EditorStyles.label, GUILayout.Width(EditorGUIUtility.labelWidth));
                    GUI.enabled = false;
                    EditorGUILayout.EnumPopup(item.JsonMode);
                    GUI.enabled = true;
                    GUILayout.EndHorizontal();

                    GUILayout.EndVertical();
                    if (GUILayout.Button("Remove", GUILayout.Width(80f), GUILayout.Height(52f)))
                    {
                        _items.Remove(item);
                        needSave = true;
                    }
                    GUILayout.EndHorizontal();
                }
                GUILayout.EndScrollView();
            }

            GUILayout.Space(4f);
            EditorGUILayout.LabelField("New external csv", EditorStyles.boldLabel);
            GUILayout.BeginHorizontal(GUI.skin.box);
            GUILayout.BeginVertical();
            _newUrl  = EditorGUILayout.TextField("External Url path:", _newUrl).Trim();
            _newRes  = EditorGUILayout.TextField("Resource file:", _newRes).Trim();
            _newJson = (JsonMode)EditorGUILayout.EnumPopup("Convert to JSON:", _newJson);
            GUILayout.EndVertical();
            if (GUILayout.Button("Add", GUILayout.Width(80f), GUILayout.Height(52f)))
            {
                var newItem = new RecordInfo();
                newItem.Url      = _newUrl;
                newItem.Resource = _newRes;
                newItem.JsonMode = _newJson;
                _items.Add(newItem);
                _newUrl  = UrlDefault;
                _newRes  = ResDefault;
                _newJson = JsonMode.None;
                needSave = true;
            }
            GUILayout.EndHorizontal();

            if (needSave)
            {
                Save();
            }

            GUILayout.Space(4f);

            GUI.enabled = _items.Count > 0;
            if (GUILayout.Button("Update data from external urls", GUILayout.Height(30f)))
            {
                var res = Process(_items);
                EditorUtility.DisplayDialog(titleContent.text, res ?? "Success", "Close");
            }
            GUI.enabled = true;
        }
Exemplo n.º 30
0
 // Track the recordInfo for its PreviousAddress.
 public override void ReadCompletionCallback(ref Key key, ref Value input, ref Value output, Context ctx, Status status, RecordInfo recordInfo)
 {
     if (ctx is not null)
     {
         ctx.output     = output;
         ctx.recordInfo = recordInfo;
         ctx.status     = status;
     }
 }
Exemplo n.º 31
0
        private bool GetRecordInfoByRef(string recordreference)//20140212... 2014年2月12号
        {
            bool ret = false;

            try
            {
                string tablename = ConstValue.TABLE_NAME_RECORD + "_" + CurrentApp.Session.RentInfo.Token;
                var    tableInfo =
                    CurrentApp.Session.ListPartitionTables.FirstOrDefault(
                        t => t.TableName == ConstValue.TABLE_NAME_RECORD && t.PartType == TablePartType.DatetimeRange);
                if (tableInfo != null)//有分表 当前仅按年月分表 ex:T_21_001_00000_1405
                {
                    tablename += "_" + recordreference.Substring(0, 4);
                }
                string     strSql     = string.Format("SELECT * FROM {0} WHERE C002={1}", tablename, recordreference);
                WebRequest webRequest = new WebRequest();
                webRequest.Session = CurrentApp.Session;
                webRequest.Code    = 13;
                webRequest.ListData.Add(strSql);
                webRequest.ListData.Add(tablename);
                webRequest.ListData.Add("mark");
                //Service31031Client client = new Service31031Client();
                Service31031Client client    = new Service31031Client(WebHelper.CreateBasicHttpBinding(CurrentApp.Session), WebHelper.CreateEndpointAddress(CurrentApp.Session.AppServerInfo, "Service31031"));
                WebReturn          webReturn = client.UMPTaskOperation(webRequest);
                client.Close();
                if (!webReturn.Result)
                {
                    if (webReturn.Message != "ERR_TABLE_NOT_EXIT")
                    {
                        ShowException(string.Format("Fail.\t{0}\t{1}", webReturn.Code, webReturn.Message));
                    }
                    return(false);
                }
                if (webReturn.ListData == null)
                {
                    ShowException(CurrentApp.GetLanguageInfo("3105T00101", string.Format("ListData is null")));
                    return(false);
                }
                if (webReturn.ListData.Count <= 0)
                {
                    return(false);
                }

                OperationReturn optReturn = XMLHelper.DeserializeObject <RecordInfo>(webReturn.ListData[0]);
                if (!optReturn.Result)
                {
                    ShowException(string.Format("Fail.\t{0}\t{1}", optReturn.Code, optReturn.Message));
                    return(false);
                }
                RecordInfo recordInfo = optReturn.Data as RecordInfo;
                if (recordInfo == null)
                {
                    ShowException(CurrentApp.GetLanguageInfo("3105T00101", string.Format("ListData is null")));
                    return(false);
                }
                RecordInfoItem = new RecordInfoItem(recordInfo);
                ret            = true;
            }
            catch
            {
                ret = false;
            }
            return(ret);
        }
Exemplo n.º 32
0
        public bool RepairV1()
        {
            bool result = true;

            if (File.Exists(_fileCollection.DatabaseInfoFilename))
            {
                int lsize = sizeof(long);
                byte[] memBuffer = new byte[10 * 1024 * 1024];
                using (MemoryStream ms = new MemoryStream(memBuffer))
                using (BinaryReader br = new BinaryReader(ms))
                {

                    int gcCount = 0;
                    int logCount = 0;
                    int logimgCount = 0;
                    int wptCount = 0;
                    int usrwptCount = 0;

                    XmlDocument doc = new XmlDocument();
                    doc.Load(_fileCollection.DatabaseInfoFilename);
                    XmlElement root = doc.DocumentElement;
                    gcCount = int.Parse(root.SelectSingleNode("GeocacheCount").InnerText);
                    logCount = int.Parse(root.SelectSingleNode("LogCount").InnerText);
                    logimgCount = int.Parse(root.SelectSingleNode("LogImagesCount").InnerText);
                    wptCount = int.Parse(root.SelectSingleNode("WaypointCount").InnerText);
                    usrwptCount = int.Parse(root.SelectSingleNode("UserWaypointCount").InnerText);

                    DateTime nextUpdateTime = DateTime.MinValue;
                    using (Utils.ProgressBlock fixscr = new Utils.ProgressBlock(this, STR_LOADING, STR_LOADINGDATA, 1, 0))
                    {
                        using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_LOADING, STR_LOADINGGEOCACHES, gcCount, 0))
                        {
                            int index = 0;

                            FileStream fs = _fileCollection._fsGeocaches;
                            fs.Position = 0;
                            long eof = fs.Length;
                            long lastOKPosition = 0;
                            RecordInfo ri = new RecordInfo();
                            try
                            {
                                while (fs.Position < eof)
                                {
                                    lastOKPosition = fs.Position;
                                    ri.Offset = fs.Position;
                                    fs.Read(memBuffer, 0, lsize + 1);
                                    ms.Position = 0;
                                    ri.Length = br.ReadInt64();
                                    if (memBuffer[lsize] == 0)
                                    {
                                        //free
                                        ri.FreeSlot = true;
                                        ri.ID = string.Concat("_", ri.Offset.ToString());
                                        fs.Position = ri.Offset + ri.Length;
                                    }
                                    else if (memBuffer[lsize] == 2)
                                    {
                                        ri.FreeSlot = false;
                                        fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                        ms.Position = 0;
                                        ri.ID = br.ReadString();
                                        br.ReadString();
                                        br.ReadBoolean();
                                        br.ReadString();
                                        br.ReadBoolean();
                                    }
                                    else
                                    {
                                        //read
                                        ri.FreeSlot = false;
                                        Framework.Data.Geocache gc = new Framework.Data.Geocache();

                                        fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                        ms.Position = 0;
                                        gc.Code = br.ReadString();
                                        ri.ID = gc.Code;

                                        gc.Archived = br.ReadBoolean();
                                        gc.AttributeIds = ReadIntegerArray(br);
                                        gc.Available = br.ReadBoolean();
                                        gc.City = br.ReadString();
                                        gc.Container = Utils.DataAccess.GetGeocacheContainer(Core.GeocacheContainers, br.ReadInt32());
                                        gc.CustomCoords = br.ReadBoolean();
                                        gc.Country = br.ReadString();
                                        if (br.ReadBoolean())
                                        {
                                            gc.CustomLat = br.ReadDouble();
                                            gc.CustomLon = br.ReadDouble();
                                        }
                                        gc.Difficulty = br.ReadDouble();
                                        gc.EncodedHints = br.ReadString();
                                        gc.Favorites = br.ReadInt32();
                                        gc.Flagged = br.ReadBoolean();
                                        gc.Found = br.ReadBoolean();
                                        gc.GeocacheType = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, br.ReadInt32());
                                        gc.ID = br.ReadString();
                                        gc.Lat = br.ReadDouble();
                                        gc.Lon = br.ReadDouble();
                                        gc.MemberOnly = br.ReadBoolean();
                                        gc.Municipality = br.ReadString();
                                        gc.Name = br.ReadString();
                                        gc.Notes = br.ReadString();
                                        gc.Owner = br.ReadString();
                                        gc.OwnerId = br.ReadString();
                                        gc.PersonaleNote = br.ReadString();
                                        gc.PlacedBy = br.ReadString();
                                        gc.PublishedTime = DateTime.Parse(br.ReadString());
                                        gc.State = br.ReadString();
                                        gc.Terrain = br.ReadDouble();
                                        gc.Title = br.ReadString();
                                        gc.Url = br.ReadString();
                                        gc.DataFromDate = DateTime.Parse(br.ReadString());
                                        gc.Locked = br.ReadBoolean();

                                        gc.Saved = true;
                                        gc.IsDataChanged = false;

                                        index++;
                                        if (DateTime.Now >= nextUpdateTime)
                                        {
                                            progress.UpdateProgress(STR_LOADING, STR_LOADINGGEOCACHES, gcCount, index);
                                            nextUpdateTime = DateTime.Now.AddSeconds(1);
                                        }
                                    }

                                    checkUniqueID(ri, fs);
                                }
                            }
                            catch
                            {
                                //error in file after lastOKPosition
                                fs.SetLength(lastOKPosition);
                            }
                        }

                        _uniqueCheckList.Clear();
                        using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGS, logCount, 0))
                        {
                            int index = 0;
                            nextUpdateTime = DateTime.MinValue;

                            FileStream fs = _fileCollection._fsLogs;
                            fs.Position = 0;
                            long lastOKPosition = 0;
                            long eof = fs.Length;
                            RecordInfo ri = new RecordInfo();
                            try
                            {
                                while (fs.Position < eof)
                                {
                                    lastOKPosition = fs.Position;
                                    ri.Offset = fs.Position;
                                    fs.Read(memBuffer, 0, lsize + 1);
                                    ms.Position = 0;
                                    ri.Length = br.ReadInt64();
                                    if (memBuffer[lsize] == 0)
                                    {
                                        //free
                                        ri.FreeSlot = true;
                                        ri.ID = string.Concat("_", ri.Offset.ToString());
                                        fs.Position = ri.Offset + ri.Length;
                                    }
                                    else if (memBuffer[lsize] == 2)
                                    {
                                        ri.FreeSlot = false;
                                        fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                        ms.Position = 0;
                                        ri.ID = br.ReadString();
                                        br.ReadString();
                                        br.ReadString();
                                        br.ReadString();
                                        br.ReadBoolean();
                                    }
                                    else
                                    {
                                        //read
                                        ri.FreeSlot = false;
                                        Framework.Data.Log log = new Framework.Data.Log();

                                        fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                        ms.Position = 0;
                                        log.ID = br.ReadString();
                                        ri.ID = log.ID;

                                        log.DataFromDate = DateTime.Parse(br.ReadString());
                                        log.Date = DateTime.Parse(br.ReadString());
                                        log.Finder = br.ReadString();
                                        log.GeocacheCode = br.ReadString();
                                        log.ID = br.ReadString();
                                        log.LogType = Utils.DataAccess.GetLogType(Core.LogTypes, br.ReadInt32());

                                        log.Saved = true;
                                        log.IsDataChanged = false;

                                        index++;
                                        if (DateTime.Now >= nextUpdateTime)
                                        {
                                            progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGS, logCount, index);
                                            nextUpdateTime = DateTime.Now.AddSeconds(1);
                                        }
                                    }
                                    checkUniqueID(ri, fs);
                                }
                            }
                            catch
                            {
                                //error in file after lastOKPosition
                                fs.SetLength(lastOKPosition);
                            }
                        }

                        _uniqueCheckList.Clear();
                        using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, 0))
                        {
                            int index = 0;
                            int procStep = 0;

                            using (FileStream fs = File.Open(_fileCollection.WaypointsFilename, FileMode.OpenOrCreate, FileAccess.ReadWrite))
                            {
                                fs.Position = 0;
                                long eof = fs.Length;
                                long lastOKPosition = 0;
                                RecordInfo ri = new RecordInfo();
                                try
                                {
                                    while (fs.Position < eof)
                                    {
                                        lastOKPosition = fs.Position;
                                        ri.Offset = fs.Position;
                                        fs.Read(memBuffer, 0, lsize + 1);
                                        ms.Position = 0;
                                        ri.Length = br.ReadInt64();
                                        if (memBuffer[lsize] == 0)
                                        {
                                            //free
                                            ri.FreeSlot = true;
                                            ri.ID = string.Concat("_", ri.Offset.ToString());
                                            fs.Position = ri.Offset + ri.Length;
                                        }
                                        else
                                        {
                                            //read
                                            ri.FreeSlot = false;
                                            Framework.Data.Waypoint wp = new Framework.Data.Waypoint();

                                            fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                            ms.Position = 0;
                                            wp.Code = br.ReadString();
                                            ri.ID = wp.Code;

                                            wp.Comment = br.ReadString();
                                            wp.DataFromDate = DateTime.Parse(br.ReadString());
                                            wp.Description = br.ReadString();
                                            wp.GeocacheCode = br.ReadString();
                                            wp.ID = br.ReadString();
                                            if (br.ReadBoolean())
                                            {
                                                wp.Lat = br.ReadDouble();
                                                wp.Lon = br.ReadDouble();
                                            }
                                            wp.Name = br.ReadString();
                                            wp.Time = DateTime.Parse(br.ReadString());
                                            wp.Url = br.ReadString();
                                            wp.UrlName = br.ReadString();
                                            wp.WPType = Utils.DataAccess.GetWaypointType(Core.WaypointTypes, br.ReadInt32());

                                            wp.Saved = true;
                                            wp.IsDataChanged = false;

                                            index++;
                                            procStep++;
                                            if (procStep >= 1000)
                                            {
                                                progress.UpdateProgress(STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, index);
                                                procStep = 0;
                                            }
                                        }
                                        checkUniqueID(ri, fs);
                                    }
                                }
                                catch
                                {
                                    //error in file after lastOKPosition
                                    fs.SetLength(lastOKPosition);
                                }
                            }
                        }

                        _uniqueCheckList.Clear();
                        using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, 0))
                        {
                            int index = 0;
                            int procStep = 0;

                            using (FileStream fs = File.Open(_fileCollection.LogImagesFilename, FileMode.OpenOrCreate, FileAccess.ReadWrite))
                            {
                                fs.Position = 0;
                                long eof = fs.Length;
                                long lastOKPosition = 0;
                                RecordInfo ri = new RecordInfo();
                                try
                                {
                                    while (fs.Position < eof)
                                    {
                                        lastOKPosition = fs.Position;
                                        ri.Offset = fs.Position;
                                        fs.Read(memBuffer, 0, lsize + 1);
                                        ms.Position = 0;
                                        ri.Length = br.ReadInt64();
                                        if (memBuffer[lsize] == 0)
                                        {
                                            //free
                                            ri.FreeSlot = true;
                                            ri.ID = string.Concat("_", ri.Offset.ToString());
                                            fs.Position = ri.Offset + ri.Length;
                                        }
                                        else
                                        {
                                            //read
                                            ri.FreeSlot = false;
                                            Framework.Data.LogImage li = new Framework.Data.LogImage();

                                            fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                            ms.Position = 0;
                                            li.ID = br.ReadString();
                                            ri.ID = li.ID;

                                            li.DataFromDate = DateTime.Parse(br.ReadString());
                                            li.LogID = br.ReadString();
                                            li.Name = br.ReadString();
                                            li.Url = br.ReadString();

                                            li.Saved = true;
                                            li.IsDataChanged = false;

                                            index++;
                                            procStep++;
                                            if (procStep >= 1000)
                                            {
                                                progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, index);
                                                procStep = 0;
                                            }
                                        }
                                        checkUniqueID(ri, fs);
                                    }
                                }
                                catch
                                {
                                    //error in file after lastOKPosition
                                    fs.SetLength(lastOKPosition);
                                }
                            }
                        }

                        {
                            int index = 0;
                            _uniqueCheckList.Clear();
                            using (FileStream fs = File.Open(_fileCollection.UserWaypointsFilename, FileMode.OpenOrCreate, FileAccess.ReadWrite))
                            {
                                fs.Position = 0;
                                long eof = fs.Length;
                                long lastOKPosition = 0;
                                RecordInfo ri = new RecordInfo();
                                try
                                {
                                    while (fs.Position < eof)
                                    {
                                        lastOKPosition = fs.Position;
                                        ri.Offset = fs.Position;
                                        fs.Read(memBuffer, 0, lsize + 1);
                                        ms.Position = 0;
                                        ri.Length = br.ReadInt64();
                                        if (memBuffer[lsize] == 0)
                                        {
                                            //free
                                            ri.FreeSlot = true;
                                            ri.ID = string.Concat("_", ri.Offset.ToString());
                                            fs.Position = ri.Offset + ri.Length;
                                        }
                                        else
                                        {
                                            //read
                                            ri.FreeSlot = false;
                                            Framework.Data.UserWaypoint wp = new Framework.Data.UserWaypoint();

                                            fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                            ms.Position = 0;
                                            ri.ID = br.ReadString();
                                            wp.ID = int.Parse(ri.ID);

                                            wp.Description = br.ReadString();
                                            wp.GeocacheCode = br.ReadString();
                                            wp.Lat = br.ReadDouble();
                                            wp.Lon = br.ReadDouble();
                                            wp.Date = DateTime.Parse(br.ReadString());

                                            wp.Saved = true;
                                            wp.IsDataChanged = false;

                                            index++;
                                        }
                                        checkUniqueID(ri, fs);
                                    }
                                }
                                catch
                                {
                                    //error in file after lastOKPosition
                                    fs.SetLength(lastOKPosition);
                                }
                            }
                        }
                    }
                }
            }

            return result;
        }
Exemplo n.º 33
0
 private void GetRealPassword(RecordEncryptInfo info)
 {
     try
     {
         if (RecordInfoItem == null)
         {
             return;
         }
         RecordInfo recordInfo = RecordInfoItem.RecordInfo;
         if (recordInfo == null)
         {
             return;
         }
         if (ParentPage3 != null)
         {
             ParentPage3.SetBusy(true, string.Empty);
         }
         if (ParentPage2 != null)
         {
             ParentPage2.SetBusy(true, string.Empty);
         }
         bool isSuccess = false;
         mWorker         = new BackgroundWorker();
         mWorker.DoWork += (s, de) =>
         {
             try
             {
                 OperationReturn optReturn;
                 RecordOperator  recordOperator = new RecordOperator(recordInfo);
                 recordOperator.Debug             += (cat, msg) => CurrentApp.WriteLog(cat, msg);
                 recordOperator.Session            = CurrentApp.Session;
                 recordOperator.ListSftpServers    = ListSftpServers;
                 recordOperator.ListDownloadParams = ListDownloadParams;
                 recordOperator.ListEncryptInfo    = ListEncryptInfo;
                 recordOperator.Service03Helper    = Service03Helper;
                 optReturn = recordOperator.GetRealPassword(info);
                 if (!optReturn.Result)
                 {
                     ShowRecordOperatorMessage(optReturn);
                     CurrentApp.WriteLog("GetRealPass",
                                         string.Format("Fail.\t{0}\t{1}", optReturn.Code, optReturn.Message));
                     return;
                 }
                 isSuccess = true;
             }
             catch (Exception ex)
             {
                 CurrentApp.WriteLog("GetRealPass", string.Format("Fail.\t{0}", ex.Message));
             }
         };
         mWorker.RunWorkerCompleted += (s, re) =>
         {
             mWorker.Dispose();
             if (ParentPage3 != null)
             {
                 ParentPage3.SetBusy(false, string.Empty);
             }
             if (ParentPage2 != null)
             {
                 ParentPage2.SetBusy(false, string.Empty);
             }
             if (!isSuccess)
             {
                 CurrentApp.WriteLog("GetRealPass", string.Format("Get real password fail."));
                 return;
             }
             PlayRecord();
         };
         mWorker.RunWorkerAsync();
     }
     catch (Exception ex)
     {
         ShowException(ex.Message);
     }
 }
Exemplo n.º 34
0
        // 根据册条码号或者记录路径,装入册记录
        // parameters:
        //      strBarcodeOrRecPath 册条码号或者记录路径。如果内容前缀为"@path:"则表示为路径
        //      strMatchLocation    附加的馆藏地点匹配条件。如果==null,表示没有这个附加条件(注意,""和null含义不同,""表示确实要匹配这个值)
        // return: 
        //      -2  册条码号或者记录路径已经在list中存在了(行没有加入listview中)
        //      -1  出错(注意表示出错的行已经加入listview中了)
        //      0   因为馆藏地点不匹配,没有加入list中
        //      1   成功
        internal virtual int LoadOneItem(
            string strPubType,
            bool bFillSummaryColumn,
            string[] summary_col_names,
            string strBarcodeOrRecPath,
            RecordInfo info,
            ListView list,
            string strMatchLocation,
            out string strOutputItemRecPath,
            ref ListViewItem item,
            out string strError)
        {
            strError = "";
            strOutputItemRecPath = "";
            long lRet = 0;

            // 判断是否有 @path: 前缀,便于后面分支处理
            bool bIsRecPath = StringUtil.HasHead(strBarcodeOrRecPath, "@path:");

            string strItemText = "";
            string strBiblioText = "";

            // string strItemRecPath = "";
            string strBiblioRecPath = "";
            XmlDocument item_dom = null;
#if NO
            string strBiblioSummary = "";
            string strISBnISSN = "";
#endif
            SummaryInfo summary = null;
            byte[] item_timestamp = null;


            if (info == null)
            {

            REDO_GETITEMINFO:
                lRet = Channel.GetItemInfo(
                    stop,
                    strBarcodeOrRecPath,
                    "xml",
                    out strItemText,
                    out strOutputItemRecPath,
                    out item_timestamp,
                    "recpath",
                    out strBiblioText,
                    out strBiblioRecPath,
                    out strError);
                if (lRet == -1)
                {
                    DialogResult temp_result = MessageBox.Show(this,
    strError + "\r\n\r\n是否重试?",
    this.FormCaption,
    MessageBoxButtons.RetryCancel,
    MessageBoxIcon.Question,
    MessageBoxDefaultButton.Button1);
                    if (temp_result == DialogResult.Retry)
                        goto REDO_GETITEMINFO;
                }
                if (lRet == -1 || lRet == 0)
                {
                    SetError(list,
                        ref item,
                        strBarcodeOrRecPath,
                        strError);
                    goto ERROR1;
                }

                summary = (SummaryInfo)this.m_summaryTable[strBiblioRecPath];
                if (summary != null)
                {
#if NO
                    strBiblioSummary = summary.Summary;
                    strISBnISSN = summary.ISBnISSn;
#endif
                }

                if (summary == null
                    && bFillSummaryColumn == true)
                {
                    string[] results = null;
                    byte[] timestamp = null;

                    stop.SetMessage("正在装入书目记录 '" + strBiblioRecPath + "' 的摘要 ...");

                    Debug.Assert(String.IsNullOrEmpty(strBiblioRecPath) == false, "strBiblioRecPath值不能为空");
                REDO_GETBIBLIOINFO:
                    lRet = Channel.GetBiblioInfos(
                        stop,
                        strBiblioRecPath,
                        "",
                        summary_col_names,
                        out results,
                        out timestamp,
                        out strError);
                    if (lRet == -1)
                    {
                        DialogResult temp_result = MessageBox.Show(this,
        strError + "\r\n\r\n是否重试?",
        this.FormCaption,
        MessageBoxButtons.RetryCancel,
        MessageBoxIcon.Question,
        MessageBoxDefaultButton.Button1);
                        if (temp_result == DialogResult.Retry)
                            goto REDO_GETBIBLIOINFO;
                    }
                    if (lRet == -1 || lRet == 0)
                    {
                        if (lRet == 0 && String.IsNullOrEmpty(strError) == true)
                            strError = "书目记录 '" + strBiblioRecPath + "' 不存在";

                        // strBiblioSummary = "获得书目摘要时发生错误: " + strError;
                        summary = new SummaryInfo();
                        summary.Values = new string[1];
                        summary.Values[0] = "获得书目摘要时发生错误: " + strError;

                    }
                    else
                    {
                        Debug.Assert(results != null && results.Length == summary_col_names.Length, "results必须包含 " + summary_col_names.Length + " 个元素");

#if NO
                        strBiblioSummary = results[0];
                        strISBnISSN = results[1];
#endif

                        // 避免cache占据的内存太多
                        if (this.m_summaryTable.Count > 1000)
                            this.m_summaryTable.Clear();

                        if (summary == null)
                        {
                            summary = new SummaryInfo();
                            summary.Values = new string[summary_col_names.Length];
                            for (int j = 0; j < summary_col_names.Length; j++)
                            {
                                summary.Values[j] = results[j];
                            }
                            this.m_summaryTable[strBiblioRecPath] = summary;
                        }
                    }
                }

                // 剖析一个册的xml记录,取出有关信息放入listview中
                if (item_dom == null)
                {
                    item_dom = new XmlDocument();
                    try
                    {
                        item_dom.LoadXml(strItemText);
                    }
                    catch (Exception ex)
                    {
                        strError = "册记录的XML装入DOM时出错: " + ex.Message;
                        goto ERROR1;
                    }
                }

            }
            else
            {
                // record 不为空调用时,对调用时参数strBarcodeOrRecPath不作要求

                strBarcodeOrRecPath = "@path:" + info.Record.Path;
                bIsRecPath = true;

                if (info.Record.RecordBody.Result.ErrorCode != ErrorCodeValue.NoError)
                {
                    SetError(list,
    ref item,
    strBarcodeOrRecPath,
    info.Record.RecordBody.Result.ErrorString);
                    goto ERROR1;
                }

                strItemText = info.Record.RecordBody.Xml;
                strOutputItemRecPath = info.Record.Path;
                // 2013/4/3
                if (info.Record.RecordBody != null)
                    item_timestamp = info.Record.RecordBody.Timestamp;
                //
                item_dom = info.Dom;
                strBiblioRecPath = info.BiblioRecPath;
                if (info.SummaryInfo != null)
                {
#if NO
                    strBiblioSummary = info.SummaryInfo.Summary;
                    strISBnISSN = info.SummaryInfo.ISBnISSn;
#endif
                    summary = info.SummaryInfo;
                }
            }


            // 附加的馆藏地点匹配
            if (strMatchLocation != null)
            {
                // TODO: #reservation, 情况如何处理?
                string strLocation = DomUtil.GetElementText(item_dom.DocumentElement,
                    "location");

                // 2013/3/26
                if (strLocation == null)
                    strLocation = "";

                if (strMatchLocation != strLocation)
                    return 0;
            }

            if (item == null)
            {
                item = AddToListView(list,
                    item_dom,
                    item_timestamp,
                    strOutputItemRecPath,
                    strBiblioRecPath,
#if NO
                    strBiblioSummary,
                    strISBnISSN,
#endif
                    summary_col_names,
                    summary);


                // 将新加入的事项滚入视野
                list.EnsureVisible(list.Items.Count - 1);

#if NO
                // 填充需要从订购库获得的栏目信息
                if (this.checkBox_load_fillOrderInfo.Checked == true)
                    FillOrderColumns(item, strPubType);
#endif
            }
            else
            {
                SetListViewItemText(item_dom,
                    item_timestamp,
                    true,
                    strOutputItemRecPath,
                    strBiblioRecPath,
#if NO
    strBiblioSummary,
    strISBnISSN,
#endif
                    summary_col_names,
                    summary,
                    item);
            }

            int nRet = VerifyItem(
                strPubType,
                strBarcodeOrRecPath,
                item,
                item_dom,
                out strError);
            if (nRet == -1)
                goto ERROR1;

            return 1;
        ERROR1:
            return -1;
        }
Exemplo n.º 35
0
        private void PlayRecord()
        {
            try
            {
                if (RecordInfoItem == null)
                {
                    return;
                }
                RecordInfo recordInfo = RecordInfoItem.RecordInfo;
                if (recordInfo == null)
                {
                    return;
                }
                if (ParentPage3 != null)
                {
                    ParentPage3.SetBusy(true, string.Empty);
                }
                if (ParentPage2 != null)
                {
                    ParentPage2.SetBusy(true, string.Empty);
                }
                string fileName     = string.Empty;
                string relativeName = string.Empty;
                VoicePlayer.IsEnabled = false;
                mWorker         = new BackgroundWorker();
                mWorker.DoWork += (s, de) =>
                {
                    try
                    {
                        OperationReturn optReturn;

                        //获取关联的录屏文件
                        GetRelativeRecordInfos();

                        //处理录音记录
                        RecordOperator recordOperator = new RecordOperator(recordInfo);
                        recordOperator.Debug             += (cat, msg) => CurrentApp.WriteLog(cat, msg);
                        recordOperator.Session            = CurrentApp.Session;
                        recordOperator.ListSftpServers    = ListSftpServers;
                        recordOperator.ListDownloadParams = ListDownloadParams;
                        recordOperator.ListEncryptInfo    = ListEncryptInfo;
                        recordOperator.Service03Helper    = Service03Helper;
                        //下载文件到AppServer
                        optReturn = recordOperator.DownloadFileToAppServer();
                        if (!optReturn.Result)
                        {
                            ShowRecordOperatorMessage(optReturn);
                            CurrentApp.WriteLog("DownloadAppServer",
                                                string.Format("Fail.\t{0}\t{1}", optReturn.Code, optReturn.Message));
                            return;
                        }
                        fileName = optReturn.Data.ToString();
                        var relativeRecord = RecordInfoItem.ListRelativeInfos.FirstOrDefault();
                        if (relativeRecord != null)
                        {
                            //如果有关联的录屏文件,下载录屏文件到AppServer
                            recordOperator.RecordInfo = relativeRecord;
                            optReturn = recordOperator.DownloadFileToAppServer();
                            if (!optReturn.Result)
                            {
                                CurrentApp.WriteLog("DownloadAppServer",
                                                    string.Format("Fail.\t{0}\t{1}", optReturn.Code, optReturn.Message));
                            }
                            else
                            {
                                relativeName = optReturn.Data.ToString();
                            }
                        }
                        recordOperator.RecordInfo = recordInfo;
                        //原始解密
                        optReturn = recordOperator.OriginalDecryptRecord(fileName);
                        if (!optReturn.Result)
                        {
                            ShowRecordOperatorMessage(optReturn);
                            CurrentApp.WriteLog("OriginalDecrypt",
                                                string.Format("Fail.\t{0}\t{1}", optReturn.Code, optReturn.Message));
                            return;
                        }
                        fileName = optReturn.Data.ToString();
                        recordOperator.RecordInfo = recordInfo;
                        //解密文件
                        optReturn = recordOperator.DecryptRecord(fileName);
                        if (!optReturn.Result)
                        {
                            ShowRecordOperatorMessage(optReturn);
                            CurrentApp.WriteLog("DecryptRecord",
                                                string.Format("Fail.\t{0}\t{1}", optReturn.Code, optReturn.Message));
                            return;
                        }
                        fileName = optReturn.Data.ToString();
                        recordOperator.RecordInfo = recordInfo;
                        //转换格式
                        optReturn = recordOperator.ConvertWaveFormat(fileName);
                        if (!optReturn.Result)
                        {
                            ShowRecordOperatorMessage(optReturn);
                            CurrentApp.WriteLog("ConvertWaveFormat",
                                                string.Format("Fail.\t{0}\t{1}", optReturn.Code, optReturn.Message));
                            return;
                        }
                        fileName = optReturn.Data.ToString();
                    }
                    catch (Exception ex)
                    {
                        CurrentApp.WriteLog("PlayRecord", string.Format("Fail.\t{0}", ex.Message));
                    }
                };
                mWorker.RunWorkerCompleted += (s, re) =>
                {
                    mWorker.Dispose();
                    VoicePlayer.IsEnabled = true;
                    if (ParentPage3 != null)
                    {
                        ParentPage3.SetBusy(false, string.Empty);
                    }
                    if (ParentPage2 != null)
                    {
                        ParentPage2.SetBusy(false, string.Empty);
                    }
                    PlayRecord(fileName, relativeName);
                };
                mWorker.RunWorkerAsync();
            }
            catch (Exception ex)
            {
                ShowException(ex.Message);
            }
        }
Exemplo n.º 36
0
        private bool readFiles(FileCollection fc)
        {
            bool result = false;
            try
            {
                //todo: when version is not compatible anymore, do a check on storage version!!

                int lsize = sizeof(long);
                byte[] memBuffer = new byte[10 * 1024 * 1024];
                using (MemoryStream ms = new MemoryStream(memBuffer))
                using (BinaryReader br = new BinaryReader(ms))
                using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_LOADINGDATA, STR_LOADINGDATA, 1, 0))
                {
                    FileStream fs = fc._fsGeocaches;
                    fs.Position = 0;
                    long eof = fs.Length;
                    while (fs.Position < eof)
                    {
                        RecordInfo ri = new RecordInfo();
                        ri.Offset = fs.Position;
                        fs.Read(memBuffer, 0, lsize + 1);
                        ms.Position = 0;
                        ri.Length = br.ReadInt64();
                        if (memBuffer[lsize] == 0)
                        {
                            //free
                            ri.FreeSlot = true;
                            ri.ID = string.Concat("_", ri.Offset.ToString());
                        }
                        else
                        {
                            //lazy loading
                            ri.FreeSlot = false;
                            int readCount = Math.Min(42, (int)(ri.Length - lsize - 1));
                            fs.Read(memBuffer, 0, readCount);
                            ms.Position = 0;
                            ri.ID = br.ReadString();
                        }
                        fs.Position = ri.Offset + ri.Length;
                        fc._geocachesInDB.Add(ri.ID, ri);
                    }

                    fs = fc._fsLogs;
                    fs.Position = 0;
                    eof = fs.Length;
                    while (fs.Position < eof)
                    {
                        RecordInfo ri = new RecordInfo();
                        ri.Offset = fs.Position;
                        fs.Read(memBuffer, 0, lsize + 1);
                        ms.Position = 0;
                        ri.Length = br.ReadInt64();
                        if (memBuffer[lsize] == 0)
                        {
                            //free
                            ri.FreeSlot = true;
                            ri.ID = string.Concat("_", ri.Offset.ToString());
                        }
                        else
                        {
                            //lazy loading
                            ri.FreeSlot = false;
                            int readCount = Math.Min(32, (int)(ri.Length - lsize - 1));
                            fs.Read(memBuffer, 0, readCount);
                            ms.Position = 0;
                            ri.ID = br.ReadString();
                        }
                        fs.Position = ri.Offset + ri.Length;
                        fc._logsInDB.Add(ri.ID, ri);
                    }

                    using (fs = File.Open(fc.WaypointsFilename, FileMode.OpenOrCreate, FileAccess.Read))
                    {
                        fs.Position = 0;
                        eof = fs.Length;
                        while (fs.Position < eof)
                        {
                            RecordInfo ri = new RecordInfo();
                            ri.Offset = fs.Position;
                            fs.Read(memBuffer, 0, lsize + 1);
                            ms.Position = 0;
                            ri.Length = br.ReadInt64();
                            if (memBuffer[lsize] == 0)
                            {
                                //free
                                ri.FreeSlot = true;
                                ri.ID = string.Concat("_", ri.Offset.ToString());
                            }
                            else
                            {
                                //lazy loading
                                ri.FreeSlot = false;
                                int readCount = Math.Min(32, (int)(ri.Length - lsize - 1));
                                fs.Read(memBuffer, 0, readCount);
                                ms.Position = 0;
                                ri.ID = br.ReadString();
                            }
                            fs.Position = ri.Offset + ri.Length;
                            fc._wptsInDB.Add(ri.ID, ri);
                        }
                    }

                    using (fs = File.Open(fc.UserWaypointsFilename, FileMode.OpenOrCreate, FileAccess.Read))
                    {
                        fs.Position = 0;
                        eof = fs.Length;
                        while (fs.Position < eof)
                        {
                            RecordInfo ri = new RecordInfo();
                            ri.Offset = fs.Position;
                            fs.Read(memBuffer, 0, lsize + 1);
                            ms.Position = 0;
                            ri.Length = br.ReadInt64();
                            if (memBuffer[lsize] == 0)
                            {
                                //free
                                ri.FreeSlot = true;
                                ri.ID = string.Concat("_", ri.Offset.ToString());
                            }
                            else
                            {
                                //lazy loading
                                ri.FreeSlot = false;
                                int readCount = Math.Min(32, (int)(ri.Length - lsize - 1));
                                fs.Read(memBuffer, 0, readCount);
                                ms.Position = 0;
                                ri.ID = br.ReadString();
                            }
                            fs.Position = ri.Offset + ri.Length;
                            fc._usrwptsInDB.Add(ri.ID, ri);
                        }
                    }

                    using (fs = File.Open(fc.LogImagesFilename, FileMode.OpenOrCreate, FileAccess.Read))
                    {
                        fs.Position = 0;
                        eof = fs.Length;
                        while (fs.Position < eof)
                        {
                            RecordInfo ri = new RecordInfo();
                            ri.Offset = fs.Position;
                            fs.Read(memBuffer, 0, lsize + 1);
                            ms.Position = 0;
                            ri.Length = br.ReadInt64();
                            if (memBuffer[lsize] == 0)
                            {
                                //free
                                ri.FreeSlot = true;
                                ri.ID = string.Concat("_", ri.Offset.ToString());
                            }
                            else
                            {
                                //lazy loading
                                ri.FreeSlot = false;
                                int readCount = Math.Min(100, (int)(ri.Length - lsize - 1));
                                fs.Read(memBuffer, 0, readCount);
                                ms.Position = 0;
                                ri.ID = br.ReadString();
                            }
                            fs.Position = ri.Offset + ri.Length;
                            fc._logimgsInDB.Add(ri.ID, ri);
                        }
                    }

                    using (fs = File.Open(fc.GeocacheImagesFilename, FileMode.OpenOrCreate, FileAccess.Read))
                    {
                        fs.Position = 0;
                        eof = fs.Length;
                        while (fs.Position < eof)
                        {
                            RecordInfo ri = new RecordInfo();
                            ri.Offset = fs.Position;
                            fs.Read(memBuffer, 0, lsize + 1);
                            ms.Position = 0;
                            ri.Length = br.ReadInt64();
                            if (memBuffer[lsize] == 0)
                            {
                                //free
                                ri.FreeSlot = true;
                                ri.ID = string.Concat("_", ri.Offset.ToString());
                            }
                            else
                            {
                                //lazy loading
                                ri.FreeSlot = false;
                                int readCount = Math.Min(64, (int)(ri.Length - lsize - 1));
                                fs.Read(memBuffer, 0, readCount);
                                ms.Position = 0;
                                ri.ID = br.ReadString();
                            }
                            fs.Position = ri.Offset + ri.Length;
                            fc._geocacheimgsInDB.Add(ri.ID, ri);
                        }
                    }

                }
                result = true;
            }
            catch
            {
            }
            return result;
        }
Exemplo n.º 37
0
 private void GetRelativeRecordInfos()
 {
     try
     {
         if (RecordInfoItem == null)
         {
             return;
         }
         RecordInfoItem.ListRelativeInfos.Clear();
         //bool isAutoRelative = false;
         //if (ListUserSettingInfos != null)
         //{
         //    var setting =
         //        ListUserSettingInfos.FirstOrDefault(s => s.ParamID == S3103Consts.USER_PARAM_AUTORELATIVEPLAY);
         //    if (setting != null && setting.StringValue == "1")
         //    {
         //        isAutoRelative = true;
         //    }
         //}
         //if (!isAutoRelative) { return; }
         if (RecordInfoItem.MediaType != 1)
         {
             return;
         }
         var recordInfo = RecordInfoItem.RecordInfo;
         if (recordInfo == null)
         {
             return;
         }
         OperationReturn optReturn;
         optReturn = XMLHelper.SeriallizeObject(recordInfo);
         if (!optReturn.Result)
         {
             CurrentApp.WriteLog("GetRelativeInfos", string.Format("Fail.\t{0}\t{1}", optReturn.Code, optReturn.Message));
             return;
         }
         WebRequest webRequest = new WebRequest();
         webRequest.Session = CurrentApp.Session;
         webRequest.Code    = 41;//(int)S3102Codes.GetRelativeRecordList
         webRequest.ListData.Add(optReturn.Data.ToString());
         Service31021Client client = new Service31021Client(
             WebHelper.CreateBasicHttpBinding(CurrentApp.Session),
             WebHelper.CreateEndpointAddress(
                 CurrentApp.Session.AppServerInfo,
                 "Service31021"));
         WebReturn webReturn = client.DoOperation(webRequest);
         client.Close();
         if (!webReturn.Result)
         {
             CurrentApp.WriteLog("GetRelativeInfos", string.Format("WSFail.\t{0}\t{1}", webReturn.Code, webReturn.Message));
             return;
         }
         if (webReturn.ListData == null)
         {
             CurrentApp.WriteLog("GetRelativeInfos", string.Format("WSFail.\tListData is null"));
             return;
         }
         int count = webReturn.ListData.Count;
         for (int i = 0; i < webReturn.ListData.Count; i++)
         {
             string strInfo = webReturn.ListData[i];
             optReturn = XMLHelper.DeserializeObject <RecordInfo>(strInfo);
             if (!optReturn.Result)
             {
                 CurrentApp.WriteLog("GetRelativeInfos", string.Format("Fail.\t{0}\t{1}", optReturn.Code, optReturn.Message));
                 return;
             }
             RecordInfo relativeRecord = optReturn.Data as RecordInfo;
             if (relativeRecord == null)
             {
                 CurrentApp.WriteLog("GetRelativeInfos", string.Format("WSFail.\tRelativeRecordInfo is null"));
                 return;
             }
             RecordInfoItem.ListRelativeInfos.Add(relativeRecord);
             CurrentApp.WriteLog("GetRelativeInfos", string.Format("{0}", relativeRecord.SerialID));
         }
         CurrentApp.WriteLog("GetRelativeInfos", string.Format("End.\t{0}", count));
     }
     catch (Exception ex)
     {
         CurrentApp.WriteLog("GetRelativeInfos", string.Format("Fail.\t{0}", ex.Message));
     }
 }
Exemplo n.º 38
0
        // 准备DOM和书目摘要等
        int GetSummaries(
            List<DigitalPlatform.CirculationClient.localhost.Record> records,
            out List<RecordInfo> infos,
            out string strError)
        {
            strError = "";
            infos = new List<RecordInfo>();

            // 准备DOM和书目摘要
            for (int i = 0; i < records.Count; i++)
            {
                if (stop != null)
                {
                    if (stop.State != 0)
                    {
                        strError = "用户中断1";
                        return -1;
                    }
                }

                RecordInfo info = new RecordInfo();
                info.Record = records[i];
                infos.Add(info);

                if (info.Record.RecordBody == null)
                {
                    strError = "请升级dp2Kernel到最新版本";
                    return -1;
                }

                if (info.Record.RecordBody.Result.ErrorCode != ErrorCodeValue.NoError)
                    continue;

                info.Dom = new XmlDocument();
                try
                {
                    info.Dom.LoadXml(info.Record.RecordBody.Xml);
                }
                catch (Exception ex)
                {
                    strError = "册记录的XML装入DOM时出错: " + ex.Message;
                    return -1;
                }

                // 准备书目记录路径
                string strParentID = DomUtil.GetElementText(info.Dom.DocumentElement,
"parent");
                string strBiblioDbName = this.MainForm.GetBiblioDbNameFromItemDbName(Global.GetDbName(info.Record.Path));
                if (string.IsNullOrEmpty(strBiblioDbName) == true)
                {
                    strError = "根据册记录路径 '" + info.Record.Path + "' 获得书目库名时出错";
                    return -1;
                }
                info.BiblioRecPath = strBiblioDbName + "/" + strParentID;


            }

            // 准备摘要
            if (this.checkBox_load_fillBiblioSummary.Checked == true)
            {
                // 归并书目记录路径
                List<string> bibliorecpaths = new List<string>();
                foreach (RecordInfo info in infos)
                {
                    bibliorecpaths.Add(info.BiblioRecPath);
                }

                // 去重
                StringUtil.RemoveDupNoSort(ref bibliorecpaths);

                // 看看cache中是否已经存在,如果已经存在则不再从服务器取
                for (int i = 0; i < bibliorecpaths.Count; i++ )
                {
                    string strPath = bibliorecpaths[i];
                    SummaryInfo summary = (SummaryInfo)this.m_summaryTable[strPath];
                    if (summary != null)
                    {
                        bibliorecpaths.RemoveAt(i);
                        i--;
                    }
                }

                // 从服务器获取
                if (bibliorecpaths.Count > 0)
                {
                REDO_GETBIBLIOINFO_0:
                    string strCommand = "@path-list:" + StringUtil.MakePathList(bibliorecpaths);

                    string[] formats = new string[2];
                    formats[0] = "summary";
                    formats[1] = "@isbnissn";
                    string[] results = null;
                    byte[] timestamp = null;

                    // stop.SetMessage("正在装入书目记录 '" + bibliorecpaths[0] + "' 等的摘要 ...");

                    // TODO: 有没有可能希望取的事项数目一次性取得没有取够?
                REDO_GETBIBLIOINFO:
                    long lRet = Channel.GetBiblioInfos(
                        stop,
                        strCommand,
                    "",
                        formats,
                        out results,
                        out timestamp,
                        out strError);
                    if (lRet == -1)
                    {
                        DialogResult temp_result = MessageBox.Show(this,
        strError + "\r\n\r\n是否重试?",
        "AccountBookForm",
        MessageBoxButtons.RetryCancel,
        MessageBoxIcon.Question,
        MessageBoxDefaultButton.Button1);
                        if (temp_result == DialogResult.Retry)
                            goto REDO_GETBIBLIOINFO;
                    }
                    if (lRet == -1 || lRet == 0)
                    {
                        if (lRet == 0 && String.IsNullOrEmpty(strError) == true)
                            strError = "书目记录 '" + StringUtil.MakePathList(bibliorecpaths) + "' 不存在";

                        strError = "获得书目摘要时发生错误: " + strError;
                        // 如果results.Length表现正常,其实还可以继续处理
                        if (results != null /* && results.Length == 2 * bibliorecpaths.Count */)
                        {
                        }
                        else
                            return -1;
                    }


                    if (results != null/* && results.Length == 2 * bibliorecpaths.Count*/)
                    {
                        // Debug.Assert(results != null && results.Length == 2 * bibliorecpaths.Count, "results必须包含 " + (2 * bibliorecpaths.Count).ToString() + " 个元素");

                        // 放入缓存
                        for (int i = 0; i < results.Length / 2; i++)
                        {
                            SummaryInfo summary = new SummaryInfo();

                            summary.Summary = results[i*2];
                            summary.ISBnISSn = results[i*2+1];

                            this.m_summaryTable[bibliorecpaths[i]] = summary;
                        }
                    }

                    if (results != null && results.Length != 2 * bibliorecpaths.Count)
                    {
                        // 没有取够,需要继续处理
                        bibliorecpaths.RemoveRange(0, results.Length / 2);
                        goto REDO_GETBIBLIOINFO_0;
                    }
                }

                // 挂接到每个记录附近
                foreach (RecordInfo info in infos)
                {
                    SummaryInfo summary = (SummaryInfo)this.m_summaryTable[info.BiblioRecPath];
                    if (summary == null)
                    {
                        strError = "缓存中找不到书目记录 '" + info.BiblioRecPath + "' 的摘要事项";
                        return -1;
                    }

                    info.SummaryInfo = summary;
                }

                // 避免cache占据的内存太多
                if (this.m_summaryTable.Count > 1000)
                    this.m_summaryTable.Clear();
            }

            return 0;
        }
Exemplo n.º 39
0
        private async Task CompleteAppendAsync(RecordInfo startRecordInfo, int messageCount, bool appendFailed)
        {
            if (startRecordInfo == null || startRecordInfo.Index == RecordInfo.InvalidIndex || messageCount <= 0)
            {
                return;
            }

            lock (this.Lock)
            {
                for (var i = 0; i < messageCount; i++)
                {
                    var recordInfo = new RecordInfo(startRecordInfo.Index + i, startRecordInfo.MaxQueueLength);
                    var find       = this.inflightAppends.SingleOrDefault(r => r.RecordInfo.Equals(recordInfo));
                    if (find == null)
                    {
                        MessageDispatcherEventSource.Current.Info(MessageDispatcherEventSource.EmptyTrackingId, this, nameof(this.CompleteAppendAsync), OperationStates.Empty, $"Record not found in InFlightAppends [Index={recordInfo.Index}]");
                        continue;
                    }

                    if (appendFailed)
                    {
                        inflightAppends.Remove(find);
                    }
                    else
                    {
                        find.IsCommited = true;
                    }
                }

                RecordInfo highestCommittedIndex = null;
                int        committedMessageCount = 0;
                foreach (var commitInfo in this.inflightAppends)
                {
                    if (commitInfo.IsCommited)
                    {
                        highestCommittedIndex = commitInfo.RecordInfo;
                        committedMessageCount++;
                    }
                    else
                    {
                        break;
                    }
                }

                if (committedMessageCount > 0)
                {
                    inflightAppends.RemoveRange(0, committedMessageCount);
                    this.lastCommittedIndex = highestCommittedIndex;
                    this.waiter.Set();
                }
            }

            if (!appendFailed)
            {
                using (var tx = this.stateManager.CreateTransaction())
                {
                    await this.metaDictonary.AddOrUpdateAsync(tx, this.lastCommittedIndexKeyName, this.lastCommittedIndex, (k, v) => this.lastCommittedIndex, TimeSpan.FromSeconds(30), CancellationToken.None);

                    await tx.CommitAsync();
                }
            }
        }
Exemplo n.º 40
0
		/// <summary>Creates an instance of this class.</summary>
		protected DataStorage(Type recordClass)
		{
			mRecordType = recordClass;
			mRecordInfo = new RecordInfo(recordClass);
			
		}
Exemplo n.º 41
0
 public override void ReadCompletionCallback(ref KeyStruct key, ref InputStruct input, ref OutputStruct output, TContext ctx, Status status, RecordInfo recordInfo)
 {
     Assert.IsTrue(status == Status.OK);
     Assert.IsTrue(output.value.vfield1 == key.kfield1);
     Assert.IsTrue(output.value.vfield2 == key.kfield2);
 }
Exemplo n.º 42
0
        public override bool LoadLogs(List<Framework.Data.Log> logs)
        {
            bool result = true;
            int index = 0;

            if (File.Exists(_fileCollection.DatabaseInfoFilename))
            {

                //int procStep = 0;
                DateTime nextUpdateTime = DateTime.MinValue;

                int lsize = sizeof(long);
                byte[] memBuffer = new byte[50 * 1024];
                using (MemoryStream ms = new MemoryStream(memBuffer))
                using (BinaryReader br = new BinaryReader(ms))
                {

                    int logCount = 0;

                    XmlDocument doc = new XmlDocument();
                    doc.Load(_fileCollection.DatabaseInfoFilename);
                    XmlElement root = doc.DocumentElement;
                    logCount = int.Parse(root.SelectSingleNode("LogCount").InnerText);

                    UpdateLoadingInBackgroundProgress(STR_LOADING_LOGS_BG, logCount, 0);

                    FileStream fs = _fileCollection._fsLogs;
                    fs.Position = 0;
                    long eof = fs.Length;
                    while (fs.Position < eof)
                    {
                        RecordInfo ri = new RecordInfo();
                        ri.Offset = fs.Position;
                        fs.Read(memBuffer, 0, lsize + 1);
                        ms.Position = 0;
                        ri.Length = br.ReadInt64();
                        if (memBuffer[lsize] == 0)
                        {
                            //free
                            ri.FreeSlot = true;
                            ri.ID = string.Concat("_", ri.Offset.ToString());
                            fs.Position = ri.Offset + ri.Length;
                        }
                        else if (memBuffer[lsize] == 2)
                        {
                            //lazy loading
                            ri.FreeSlot = false;
                            int readCount = Math.Min(42, (int)(ri.Length - lsize - 1));
                            fs.Read(memBuffer, 0, readCount);
                            ms.Position = 0;
                            ri.ID = br.ReadString();
                            fs.Position = ri.Offset + ri.Length;
                        }
                        else
                        {
                            //read
                            ri.FreeSlot = false;
                            Framework.Data.Log log = new Framework.Data.Log();

                            fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                            ms.Position = 0;
                            log.ID = br.ReadString();
                            ri.ID = log.ID;

                            log.DataFromDate = DateTime.Parse(br.ReadString());
                            log.Date = DateTime.Parse(br.ReadString());
                            log.Finder = br.ReadString();
                            log.GeocacheCode = br.ReadString();
                            log.ID = br.ReadString();
                            log.LogType = Utils.DataAccess.GetLogType(Core.LogTypes, br.ReadInt32());

                            log.Saved = true;
                            log.IsDataChanged = false;
                            logs.Add(log);

                            index++;
                            //procStep++;
                            //if (procStep >= 20000)
                            if (DateTime.Now >= nextUpdateTime)
                            {
                                UpdateLoadingInBackgroundProgress(STR_LOADING_LOGS_BG, logCount, index);
                                nextUpdateTime = DateTime.Now.AddSeconds(1);
                                //procStep = 0;
                            }
                        }
                        _fileCollection._logsInDB.Add(ri.ID, ri);
                    }
                }
            }
            return result;
        }
Exemplo n.º 43
0
 public override void ConcurrentReader(ref KeyStruct key, ref InputStruct input, ref ValueStruct value, ref OutputStruct dst, ref RecordInfo recordInfo, long address) => dst.value = value;
Exemplo n.º 44
0
        public override bool LoadGeocacheImages(List<Framework.Data.GeocacheImage> geocacheimgs)
        {
            bool result = true;
            int index = 0;
            int procStep = 0;

            if (File.Exists(_fileCollection.DatabaseInfoFilename))
            {

                int lsize = sizeof(long);
                byte[] memBuffer = new byte[5 * 1024];
                using (MemoryStream ms = new MemoryStream(memBuffer))
                using (BinaryReader br = new BinaryReader(ms))
                {

                    int geocacheimgCount = 0;

                    XmlDocument doc = new XmlDocument();
                    doc.Load(_fileCollection.DatabaseInfoFilename);
                    XmlElement root = doc.DocumentElement;
                    if (root.SelectSingleNode("GeocacheImagesCount") != null)
                    {
                        geocacheimgCount = int.Parse(root.SelectSingleNode("GeocacheImagesCount").InnerText);
                    }

                    using (FileStream fs = File.Open(_fileCollection.GeocacheImagesFilename, FileMode.OpenOrCreate, FileAccess.Read))
                    {
                        fs.Position = 0;
                        long eof = fs.Length;
                        while (fs.Position < eof)
                        {
                            RecordInfo ri = new RecordInfo();
                            ri.Offset = fs.Position;
                            fs.Read(memBuffer, 0, lsize + 1);
                            ms.Position = 0;
                            ri.Length = br.ReadInt64();
                            if (memBuffer[lsize] == 0)
                            {
                                //free
                                ri.FreeSlot = true;
                                ri.ID = string.Concat("_", ri.Offset.ToString());
                                fs.Position = ri.Offset + ri.Length;
                            }
                            else
                            {
                                //read
                                ri.FreeSlot = false;
                                Framework.Data.GeocacheImage li = new Framework.Data.GeocacheImage();

                                fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                ms.Position = 0;
                                li.ID = br.ReadString();
                                ri.ID = li.ID;

                                li.DataFromDate = DateTime.Parse(br.ReadString());
                                li.GeocacheCode = br.ReadString();
                                li.Description = br.ReadString();
                                li.Name = br.ReadString();
                                li.Url = br.ReadString();
                                li.MobileUrl = br.ReadString();
                                li.ThumbUrl = br.ReadString();

                                li.Saved = true;
                                li.IsDataChanged = false;
                                geocacheimgs.Add(li);

                                index++;
                                procStep++;
                                if (procStep >= 2000)
                                {
                                    UpdateLoadingInBackgroundProgress(STR_LOADING_GEOCACHEIMAGES_BG, geocacheimgCount, index);
                                    procStep = 0;
                                }
                            }
                            _fileCollection._geocacheimgsInDB.Add(ri.ID, ri);
                        }
                    }
                }
            }
            return result;
        }
Exemplo n.º 45
0
 public override bool InPlaceUpdater(ref KeyStruct key, ref InputStruct input, ref ValueStruct value, ref RecordInfo recordInfo, long address)
 {
     value.vfield1 += input.ifield1;
     value.vfield2 += input.ifield2;
     return(true);
 }
Exemplo n.º 46
0
        public override bool Load(bool geocachesOnly)
        {
            bool result = true;

            if (File.Exists(_fileCollection.DatabaseInfoFilename))
            {
                int lsize = sizeof(long);
                byte[] memBuffer = new byte[10 * 1024 * 1024];
                using (MemoryStream ms = new MemoryStream(memBuffer))
                using (BinaryReader br = new BinaryReader(ms))
                {

                    int gcCount = 0;
                    int logCount = 0;
                    int logimgCount = 0;
                    int geocacheimgCount = 0;
                    int wptCount = 0;
                    int usrwptCount = 0;

                    XmlDocument doc = new XmlDocument();
                    doc.Load(_fileCollection.DatabaseInfoFilename);
                    XmlElement root = doc.DocumentElement;
                    gcCount = int.Parse(root.SelectSingleNode("GeocacheCount").InnerText);
                    logCount = int.Parse(root.SelectSingleNode("LogCount").InnerText);
                    logimgCount = int.Parse(root.SelectSingleNode("LogImagesCount").InnerText);
                    wptCount = int.Parse(root.SelectSingleNode("WaypointCount").InnerText);
                    usrwptCount = int.Parse(root.SelectSingleNode("UserWaypointCount").InnerText);
                    if (root.SelectSingleNode("GeocacheImagesCount") != null)
                    {
                        geocacheimgCount = int.Parse(root.SelectSingleNode("GeocacheImagesCount").InnerText);
                    }

                    DateTime nextUpdateTime = DateTime.MinValue;
                    using (Utils.ProgressBlock fixscr = new Utils.ProgressBlock(this, STR_LOADING, STR_LOADINGDATA, 1, 0))
                    {
                        using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_LOADING, STR_LOADINGGEOCACHES, gcCount, 0))
                        {
                            int index = 0;
                            //int procStep = 0;
                            List<Framework.Data.Geocache> gcList = new List<Framework.Data.Geocache>();

                            FileStream fs = _fileCollection._fsGeocaches;
                            fs.Position = 0;
                            long eof = fs.Length;
                            while (fs.Position < eof)
                            {
                                RecordInfo ri = new RecordInfo();
                                ri.Offset = fs.Position;
                                fs.Read(memBuffer, 0, lsize + 1);
                                ms.Position = 0;
                                ri.Length = br.ReadInt64();
                                if (memBuffer[lsize] == 0)
                                {
                                    //free
                                    ri.FreeSlot = true;
                                    ri.ID = string.Concat("_", ri.Offset.ToString());
                                    fs.Position = ri.Offset + ri.Length;
                                }
                                else if (memBuffer[lsize] == 2)
                                {
                                    //lazy loading
                                    ri.FreeSlot = false;
                                    int readCount = Math.Min(32, (int)(ri.Length - lsize - 1));
                                    fs.Read(memBuffer, 0, readCount);
                                    ms.Position = 0;
                                    ri.ID = br.ReadString();
                                    fs.Position = ri.Offset + ri.Length;
                                }
                                else
                                {
                                    //read
                                    ri.FreeSlot = false;
                                    Framework.Data.Geocache gc = new Framework.Data.Geocache();

                                    fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                    ms.Position = 0;
                                    gc.Code = br.ReadString();
                                    ri.ID = gc.Code;

                                    gc.Archived = br.ReadBoolean();
                                    gc.AttributeIds = ReadIntegerArray(br);
                                    gc.Available = br.ReadBoolean();
                                    gc.City = br.ReadString();
                                    gc.Container = Utils.DataAccess.GetGeocacheContainer(Core.GeocacheContainers, br.ReadInt32());
                                    gc.CustomCoords = br.ReadBoolean();
                                    gc.Country = br.ReadString();
                                    if (br.ReadBoolean())
                                    {
                                        gc.CustomLat = br.ReadDouble();
                                        gc.CustomLon = br.ReadDouble();
                                    }
                                    gc.Difficulty = br.ReadDouble();
                                    gc.EncodedHints = br.ReadString();
                                    gc.Favorites = br.ReadInt32();
                                    gc.Flagged = br.ReadBoolean();
                                    gc.Found = br.ReadBoolean();
                                    gc.GeocacheType = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, br.ReadInt32());
                                    gc.ID = br.ReadString();
                                    gc.Lat = br.ReadDouble();
                                    gc.Lon = br.ReadDouble();
                                    gc.MemberOnly = br.ReadBoolean();
                                    gc.Municipality = br.ReadString();
                                    gc.Name = br.ReadString();
                                    gc.Notes = br.ReadString();
                                    gc.Owner = br.ReadString();
                                    gc.OwnerId = br.ReadString();
                                    gc.PersonaleNote = br.ReadString();
                                    gc.PlacedBy = br.ReadString();
                                    gc.PublishedTime = DateTime.Parse(br.ReadString());
                                    gc.State = br.ReadString();
                                    gc.Terrain = br.ReadDouble();
                                    gc.Title = br.ReadString();
                                    gc.Url = br.ReadString();
                                    gc.DataFromDate = DateTime.Parse(br.ReadString());
                                    gc.Locked = br.ReadBoolean();

                                    Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, Core.CenterLocation);
                                    gc.Saved = true;
                                    gc.IsDataChanged = false;
                                    //gcList.Add(gc);
                                    Core.Geocaches.Add(gc);

                                    index++;
                                    //procStep++;
                                    //if (procStep >= 1000)
                                    if (DateTime.Now>=nextUpdateTime)
                                    {
                                        progress.UpdateProgress(STR_LOADING, STR_LOADINGGEOCACHES, gcCount, index);
                                        nextUpdateTime = DateTime.Now.AddSeconds(1);
                                        //procStep = 0;
                                    }
                                }
                                _fileCollection._geocachesInDB.Add(ri.ID, ri);
                            }
                            //Core.Geocaches.Add(gcList);
                        }

                        if (!geocachesOnly)
                        {
                            using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGS, logCount, 0))
                            {
                                int index = 0;
                                nextUpdateTime = DateTime.MinValue;

                                List<Framework.Data.Log> lgList = new List<Framework.Data.Log>();

                                FileStream fs = _fileCollection._fsLogs;
                                fs.Position = 0;
                                long eof = fs.Length;
                                while (fs.Position < eof)
                                {
                                    RecordInfo ri = new RecordInfo();
                                    ri.Offset = fs.Position;
                                    fs.Read(memBuffer, 0, lsize + 1);
                                    ms.Position = 0;
                                    ri.Length = br.ReadInt64();
                                    if (memBuffer[lsize] == 0)
                                    {
                                        //free
                                        ri.FreeSlot = true;
                                        ri.ID = string.Concat("_", ri.Offset.ToString());
                                        fs.Position = ri.Offset + ri.Length;
                                    }
                                    else if (memBuffer[lsize] == 2)
                                    {
                                        //lazy loading
                                        ri.FreeSlot = false;
                                        int readCount = Math.Min(32, (int)(ri.Length - lsize - 1));
                                        fs.Read(memBuffer, 0, readCount);
                                        ms.Position = 0;
                                        ri.ID = br.ReadString();
                                        fs.Position = ri.Offset + ri.Length;
                                    }
                                    else
                                    {
                                        //read
                                        ri.FreeSlot = false;
                                        Framework.Data.Log log = new Framework.Data.Log();

                                        fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                        ms.Position = 0;
                                        log.ID = br.ReadString();
                                        ri.ID = log.ID;

                                        log.DataFromDate = DateTime.Parse(br.ReadString());
                                        log.Date = DateTime.Parse(br.ReadString());
                                        log.Finder = br.ReadString();
                                        log.GeocacheCode = br.ReadString();
                                        log.ID = br.ReadString();
                                        log.LogType = Utils.DataAccess.GetLogType(Core.LogTypes, br.ReadInt32());

                                        log.Saved = true;
                                        log.IsDataChanged = false;
                                        lgList.Add(log);

                                        index++;
                                        //procStep++;
                                        //if (procStep >= 1000)
                                        if (DateTime.Now >= nextUpdateTime)
                                        {
                                            progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGS, logCount, index);
                                            nextUpdateTime = DateTime.Now.AddSeconds(1);
                                            //procStep = 0;
                                        }
                                    }
                                    _fileCollection._logsInDB.Add(ri.ID, ri);
                                }
                                Core.Logs.Add(lgList);
                            }


                            using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, 0))
                            {
                                int index = 0;
                                int procStep = 0;

                                List<Framework.Data.Waypoint> wptList = new List<Framework.Data.Waypoint>();

                                using (FileStream fs = File.Open(_fileCollection.WaypointsFilename, FileMode.OpenOrCreate, FileAccess.Read))
                                {
                                    fs.Position = 0;
                                    long eof = fs.Length;
                                    while (fs.Position < eof)
                                    {
                                        RecordInfo ri = new RecordInfo();
                                        ri.Offset = fs.Position;
                                        fs.Read(memBuffer, 0, lsize + 1);
                                        ms.Position = 0;
                                        ri.Length = br.ReadInt64();
                                        if (memBuffer[lsize] == 0)
                                        {
                                            //free
                                            ri.FreeSlot = true;
                                            ri.ID = string.Concat("_", ri.Offset.ToString());
                                            fs.Position = ri.Offset + ri.Length;
                                        }
                                        else
                                        {
                                            //read
                                            ri.FreeSlot = false;
                                            Framework.Data.Waypoint wp = new Framework.Data.Waypoint();

                                            fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                            ms.Position = 0;
                                            wp.Code = br.ReadString();
                                            ri.ID = wp.Code;

                                            wp.Comment = br.ReadString();
                                            wp.DataFromDate = DateTime.Parse(br.ReadString());
                                            wp.Description = br.ReadString();
                                            wp.GeocacheCode = br.ReadString();
                                            wp.ID = br.ReadString();
                                            if (br.ReadBoolean())
                                            {
                                                wp.Lat = br.ReadDouble();
                                                wp.Lon = br.ReadDouble();
                                            }
                                            wp.Name = br.ReadString();
                                            wp.Time = DateTime.Parse(br.ReadString());
                                            wp.Url = br.ReadString();
                                            wp.UrlName = br.ReadString();
                                            wp.WPType = Utils.DataAccess.GetWaypointType(Core.WaypointTypes, br.ReadInt32());

                                            wp.Saved = true;
                                            wp.IsDataChanged = false;
                                            wptList.Add(wp);

                                            index++;
                                            procStep++;
                                            if (procStep >= 1000)
                                            {
                                                progress.UpdateProgress(STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, index);
                                                procStep = 0;
                                            }
                                        }
                                        _fileCollection._wptsInDB.Add(ri.ID, ri);
                                    }
                                }
                                Core.Waypoints.Add(wptList);
                            }

                            using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, 0))
                            {
                                int index = 0;
                                int procStep = 0;

                                List<Framework.Data.LogImage> lgiList = new List<Framework.Data.LogImage>();

                                using (FileStream fs = File.Open(_fileCollection.LogImagesFilename, FileMode.OpenOrCreate, FileAccess.Read))
                                {
                                    fs.Position = 0;
                                    long eof = fs.Length;
                                    while (fs.Position < eof)
                                    {
                                        RecordInfo ri = new RecordInfo();
                                        ri.Offset = fs.Position;
                                        fs.Read(memBuffer, 0, lsize + 1);
                                        ms.Position = 0;
                                        ri.Length = br.ReadInt64();
                                        if (memBuffer[lsize] == 0)
                                        {
                                            //free
                                            ri.FreeSlot = true;
                                            ri.ID = string.Concat("_", ri.Offset.ToString());
                                            fs.Position = ri.Offset + ri.Length;
                                        }
                                        else
                                        {
                                            //read
                                            ri.FreeSlot = false;
                                            Framework.Data.LogImage li = new Framework.Data.LogImage();

                                            fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                            ms.Position = 0;
                                            li.ID = br.ReadString();
                                            ri.ID = li.ID;

                                            li.DataFromDate = DateTime.Parse(br.ReadString());
                                            li.LogID = br.ReadString();
                                            li.Name = br.ReadString();
                                            li.Url = br.ReadString();

                                            li.Saved = true;
                                            li.IsDataChanged = false;
                                            lgiList.Add(li);

                                            index++;
                                            procStep++;
                                            if (procStep >= 1000)
                                            {
                                                progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, index);
                                                procStep = 0;
                                            }
                                        }
                                        _fileCollection._logimgsInDB.Add(ri.ID, ri);
                                    }
                                }
                                Core.LogImages.Add(lgiList);
                            }

                            using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGGEOCACHEIMAGES, geocacheimgCount, 0))
                            {
                                int index = 0;
                                int procStep = 0;

                                List<Framework.Data.GeocacheImage> lgiList = new List<Framework.Data.GeocacheImage>();

                                using (FileStream fs = File.Open(_fileCollection.GeocacheImagesFilename, FileMode.OpenOrCreate, FileAccess.Read))
                                {
                                    fs.Position = 0;
                                    long eof = fs.Length;
                                    while (fs.Position < eof)
                                    {
                                        RecordInfo ri = new RecordInfo();
                                        ri.Offset = fs.Position;
                                        fs.Read(memBuffer, 0, lsize + 1);
                                        ms.Position = 0;
                                        ri.Length = br.ReadInt64();
                                        if (memBuffer[lsize] == 0)
                                        {
                                            //free
                                            ri.FreeSlot = true;
                                            ri.ID = string.Concat("_", ri.Offset.ToString());
                                            fs.Position = ri.Offset + ri.Length;
                                        }
                                        else
                                        {
                                            //read
                                            ri.FreeSlot = false;
                                            Framework.Data.GeocacheImage li = new Framework.Data.GeocacheImage();

                                            fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                            ms.Position = 0;
                                            li.ID = br.ReadString();
                                            ri.ID = li.ID;

                                            li.DataFromDate = DateTime.Parse(br.ReadString());
                                            li.GeocacheCode = br.ReadString();
                                            li.Description = br.ReadString();
                                            li.Name = br.ReadString();
                                            li.Url = br.ReadString();
                                            li.MobileUrl = br.ReadString();
                                            li.ThumbUrl = br.ReadString();

                                            li.Saved = true;
                                            li.IsDataChanged = false;
                                            lgiList.Add(li);

                                            index++;
                                            procStep++;
                                            if (procStep >= 1000)
                                            {
                                                progress.UpdateProgress(STR_LOADING, STR_LOADINGGEOCACHEIMAGES, geocacheimgCount, index);
                                                procStep = 0;
                                            }
                                        }
                                        _fileCollection._geocacheimgsInDB.Add(ri.ID, ri);
                                    }
                                }
                                Core.GeocacheImages.Add(lgiList);
                            }

                            //using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, 0))
                            {
                                int index = 0;
                                int procStep = 0;

                                List<Framework.Data.UserWaypoint> uwplList = new List<Framework.Data.UserWaypoint>();

                                using (FileStream fs = File.Open(_fileCollection.UserWaypointsFilename, FileMode.OpenOrCreate, FileAccess.Read))
                                {
                                    fs.Position = 0;
                                    long eof = fs.Length;
                                    while (fs.Position < eof)
                                    {
                                        RecordInfo ri = new RecordInfo();
                                        ri.Offset = fs.Position;
                                        fs.Read(memBuffer, 0, lsize + 1);
                                        ms.Position = 0;
                                        ri.Length = br.ReadInt64();
                                        if (memBuffer[lsize] == 0)
                                        {
                                            //free
                                            ri.FreeSlot = true;
                                            ri.ID = string.Concat("_", ri.Offset.ToString());
                                            fs.Position = ri.Offset + ri.Length;
                                        }
                                        else
                                        {
                                            //read
                                            ri.FreeSlot = false;
                                            Framework.Data.UserWaypoint wp = new Framework.Data.UserWaypoint();

                                            fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                            ms.Position = 0;
                                            ri.ID = br.ReadString();
                                            wp.ID = int.Parse(ri.ID);

                                            wp.Description = br.ReadString();
                                            wp.GeocacheCode = br.ReadString();
                                            wp.Lat = br.ReadDouble();
                                            wp.Lon = br.ReadDouble();
                                            wp.Date = DateTime.Parse(br.ReadString());

                                            wp.Saved = true;
                                            wp.IsDataChanged = false;
                                            uwplList.Add(wp);

                                            index++;
                                            procStep++;
                                            if (procStep >= 1000)
                                            {
                                                //progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, index);
                                                procStep = 0;
                                            }
                                        }
                                        _fileCollection._usrwptsInDB.Add(ri.ID, ri);
                                    }
                                }
                                Core.UserWaypoints.Add(uwplList);
                            }

                        }
                    }
                }
            }

            return result;
        }
Exemplo n.º 47
0
            public void GetRecordsList(DateTime start_dt, DateTime end_dt)
            {
                MySqlConnection con = GetACDRDBConnection();
                MySqlCommand com = new MySqlCommand(String.Format(@"SELECT * FROM cdr WHERE recordingfile <> '' AND calldate >= '{0}' and calldate <= '{1}'", start_dt.ToString("yyyy-MM-dd HH:mm:ss"), end_dt.ToString("yyyy-MM-dd HH:mm:ss")), con);
                MySqlDataReader rdr = com.ExecuteReader();

                if (rdr.HasRows)
                    foreach (DbDataRecord record in rdr)
                    {
                        RecordInfo ri = new RecordInfo();
                        ri.calldate = Convert.ToDateTime(record["calldate"]);
                        ri.src = record["src"].ToString();
                        ri.dst = record["dst"].ToString();
                        ri.recordingfile = record["recordingfile"].ToString();
                        RecordsList.Add(ri);
                    }

                rdr.Close();
                con.Close();
            }