示例#1
0
        private void CTXFileCollection_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            _editSucceeded = false;
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
            {
                int     newIndex = e.NewStartingIndex;
                CTXFile newItem  = CTXFileCollection[newIndex];
                if (ctxFileRepo.Add(newItem))
                {
                    CurrentEntity  = newItem;
                    _editSucceeded = true;
                }
            }
            break;

            case NotifyCollectionChangedAction.Remove:
            {
                List <CTXFile> tempListOfRemovedItems = e.OldItems.OfType <CTXFile>().ToList();
                _editSucceeded = ctxFileRepo.Delete(tempListOfRemovedItems[0].RowID);
            }
            break;

            case NotifyCollectionChangedAction.Replace:
            {
                List <CTXFile> tempList = e.NewItems.OfType <CTXFile>().ToList();
                _editSucceeded = ctxFileRepo.Update(tempList[0]);
            }
            break;
            }
        }
示例#2
0
        public CTXFileSummaryView(CTXFile f)
        {
            Identifier = f.RowID;
            DateStart  = "";
            DateEnd    = "";
            if (f.DateStart != null)
            {
                DateStart = ((DateTime)f.DateStart).ToString("MMM-dd-yyyy HH:mm");
            }
            if (f.DateEnd != null)
            {
                DateEnd = ((DateTime)f.DateEnd).ToString("MMM-dd-yyyy HH:mm");
            }

            if (DateEnd.Length > 0 && DateStart.Length > 0)
            {
                Duration = ((DateTime)f.DateEnd - (DateTime)f.DateStart).ToString();
            }

            ErrorConvertingToXML = f.ErrorConvertingToXML;
            WaypointsForSet      = f.SetGearPtCount;
            WaypointsForHaul     = f.RetrieveGearPtCount;
            TrackpointsCount     = f.TrackPtCount;
            User                 = f.UserName;
            Gear                 = f.Gear;
            LandingSite          = f.LandingSite;
            Version              = f.AppVersion;
            XML                  = f.XML;
            CTXFile              = f;
            CTXFileName          = f.CTXFileName;
            DeviceID             = f.DeviceID;
            DownloadedFromServer = f.IsDownloadedFromServer;
            TrackingInterval     = f.TrackingInterval;
        }
        public List <CTXFile> GetServerContent(string url, string user, string pwd, bool download = false)
        {
            LastError       = "";
            _sessionOptions = new SessionOptions
            {
                Protocol   = Protocol.Ftp,
                HostName   = url,
                UserName   = user,
                Password   = pwd,
                PortNumber = 21,
            };

            List <CTXFile> list = new List <CTXFile>();

            using (var session = new Session())
            {
                try
                {
                    // Connect
                    session.Open(_sessionOptions);

                    // Enumerate files
                    var options = EnumerationOptions.EnumerateDirectories | EnumerationOptions.AllDirectories;
                    IEnumerable <RemoteFileInfo> fileInfos = session.EnumerateRemoteFiles("/CTData", null, options);

                    foreach (var fileInfo in fileInfos)
                    {
                        try
                        {
                            CTXFile f = new CTXFile {
                                IsDownloaded = Entities.CTXFileViewModel.Exists(fileInfo.Name), RemoteFileInfo = fileInfo, CTXFileName = fileInfo.Name
                            };
                            f.CTXFileTimeStamp = f.RemoteFileInfo.LastWriteTime;
                            list.Add(f);
                        }
                        catch (Exception ex)
                        {
                            Logger.Log(ex);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log(ex);
                    if (ex.Message == "Connection failed.\r\nConnection failed.")
                    {
                        LastError = "Connection failed";
                    }
                    else
                    {
                        LastError = ex.Message;
                    }
                    return(null);
                }
            }

            return(list);
        }
示例#4
0
        public int GetGPSTimerIntervalFromCTX(CTXFile ctxfile, bool?saveToDatabase)
        {
            if (ctxfile.XML == null || ctxfile.XML.Length == 0)
            {
                return(-1);
            }
            else
            {
                ctxfile.TrackingInterval = GetGPSTimerIntervalFromCTX(ctxfile.XML);

                if (saveToDatabase == null)
                {
                    return((int)ctxfile.TrackingInterval);
                }
                else if ((bool)saveToDatabase && UpdateRecordInRepo(ctxfile))
                {
                    return((int)ctxfile.TrackingInterval);
                }
                return(-1);
            }
        }
        private List <CTXFile> getFiles()
        {
            //Logger.Log($"about to start getting ctx from database");
            var list = new List <CTXFile>();
            var dt   = new DataTable();

            using (var conection = new OleDbConnection(Global.ConnectionString))
            {
                try
                {
                    conection.Open();
                    //string query = $"Select * from ctxFiles";
                    string query = @"Select RowID, FileName, DeviceID, CTXFilename, UserName, Gear,
                                     LandingSite, DateAdded, CTXFileTimeStamp, AppVersion,
                                     ErrorConvertingToXML, IsDownloadedFromServer, DateStart, DateEnd,
                                     TrackPts, SetGearPts, RetrieveGearPts, TrackTimeStampStart, TrackTimeStampEnd,
                                     TrackingInterval, TrackExtracted from ctxFiles";

                    var adapter = new OleDbDataAdapter(query, conection);
                    adapter.Fill(dt);
                    if (dt.Rows.Count > 0)
                    {
                        list.Clear();
                        foreach (DataRow dr in dt.Rows)
                        {
                            CTXFile ctxfile = new CTXFile();
                            ctxfile.RowID    = (int)dr["RowID"];
                            ctxfile.FileName = dr["FileName"].ToString();
                            ctxfile.DeviceID = dr["DeviceID"].ToString();
                            ctxfile.XML      = "";
                            //ctxfile.XML = dr["xml"].ToString();
                            ctxfile.CTXFileName            = dr["CTXFileName"].ToString();
                            ctxfile.UserName               = dr["UserName"].ToString();
                            ctxfile.Gear                   = dr["Gear"].ToString();
                            ctxfile.LandingSite            = dr["LandingSite"].ToString();
                            ctxfile.DateAdded              = DateTime.Parse(dr["DateAdded"].ToString());
                            ctxfile.CTXFileTimeStamp       = DateTime.Parse(dr["CTXFileTimeStamp"].ToString());
                            ctxfile.AppVersion             = dr["AppVersion"].ToString();
                            ctxfile.ErrorConvertingToXML   = (bool)dr["ErrorConvertingToXML"];
                            ctxfile.IsDownloadedFromServer = (bool)dr["IsDownloadedFromServer"];
                            ctxfile.TrackExtracted         = (bool)dr["TrackExtracted"];

                            if (dr["DateStart"].ToString().Length > 0)
                            {
                                ctxfile.DateStart = DateTime.Parse(dr["DateStart"].ToString());
                            }

                            if (dr["DateEnd"].ToString().Length > 0)
                            {
                                ctxfile.DateEnd = DateTime.Parse(dr["DateEnd"].ToString());
                            }

                            if (dr["TrackPts"].ToString().Length > 0)
                            {
                                ctxfile.TrackPtCount = (int)dr["TrackPts"];
                            }
                            if (dr["SetGearPts"].ToString().Length > 0)
                            {
                                ctxfile.SetGearPtCount = (int)dr["SetGearPts"];
                            }
                            if (dr["RetrieveGearPts"].ToString().Length > 0)
                            {
                                ctxfile.RetrieveGearPtCount = (int)dr["RetrieveGearPts"];
                            }
                            if (dr["TrackTimeStampStart"].ToString().Length > 0)
                            {
                                ctxfile.TrackTimeStampStart = DateTime.Parse(dr["TrackTimeStampStart"].ToString());
                            }
                            if (dr["TrackTimeStampEnd"].ToString().Length > 0)
                            {
                                ctxfile.TrackTimeStampEnd = DateTime.Parse(dr["TrackTimeStampEnd"].ToString());
                            }
                            if (dr["TrackingInterval"] != DBNull.Value)
                            {
                                ctxfile.TrackingInterval = (int)dr["TrackingInterval"];
                            }

                            list.Add(ctxfile);
                            //Logger.Log($"Added ctxfile ID: {ctxfile.RowID}");
                        }
                    }
                }
                catch (OleDbException dbex)
                {
                    switch (dbex.ErrorCode)
                    {
                    case -2147217865:
                        //table not found
                        CreateTable();
                        break;

                    case -2147217904:
                        //No value given for one or more required parameters.
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log(ex);
                }
            }
            return(list);
        }
        public bool Update(CTXFile f)
        {
            bool success = false;

            using (OleDbConnection conn = new OleDbConnection(Global.ConnectionString))
            {
                conn.Open();


                using (OleDbCommand update = conn.CreateCommand())
                {
                    if (f.DeviceID == null)
                    {
                        update.Parameters.Add("@deviceID", OleDbType.VarChar).Value = DBNull.Value;
                    }
                    else
                    {
                        update.Parameters.Add("@deviceID", OleDbType.VarChar).Value = f.DeviceID;
                    }

                    if (f.UserName == null)
                    {
                        update.Parameters.Add("@user", OleDbType.VarChar).Value = DBNull.Value;
                    }
                    else
                    {
                        update.Parameters.Add("@user", OleDbType.VarChar).Value = f.UserName;
                    }


                    if (f.Gear == null)
                    {
                        update.Parameters.Add("@gear", OleDbType.VarChar).Value = DBNull.Value;
                    }
                    else
                    {
                        update.Parameters.Add("@gear", OleDbType.VarChar).Value = f.Gear;
                    }

                    if (f.LandingSite == null)
                    {
                        update.Parameters.Add("@landingSite", OleDbType.VarChar).Value = DBNull.Value;
                    }
                    else
                    {
                        update.Parameters.Add("@landingSite", OleDbType.VarChar).Value = f.LandingSite;
                    }


                    if (f.DateStart == null)
                    {
                        update.Parameters.Add("@start", OleDbType.Date).Value = DBNull.Value;
                    }
                    else
                    {
                        update.Parameters.Add("@start", OleDbType.Date).Value = f.DateStart;
                    }

                    if (f.DateEnd == null)
                    {
                        update.Parameters.Add("@end", OleDbType.Date).Value = DBNull.Value;
                    }
                    else
                    {
                        update.Parameters.Add("@end", OleDbType.Date).Value = f.DateEnd;
                    }

                    if (f.NumberOfTrips == null)
                    {
                        update.Parameters.Add("@numbnerTrips", OleDbType.Integer).Value = DBNull.Value;
                    }
                    else
                    {
                        update.Parameters.Add("@numbnerTrips", OleDbType.Integer).Value = f.NumberOfTrips;
                    }


                    if (f.TrackPtCount == null)
                    {
                        update.Parameters.Add("@trackCount", OleDbType.Integer).Value = DBNull.Value;
                    }
                    else
                    {
                        update.Parameters.Add("@trackCount", OleDbType.Integer).Value = f.TrackPtCount;
                    }

                    if (f.TrackTimeStampStart == null)
                    {
                        update.Parameters.Add("@tracktimestart", OleDbType.Date).Value = DBNull.Value;
                    }
                    else
                    {
                        update.Parameters.Add("@tracktimestart", OleDbType.Date).Value = f.TrackTimeStampStart;
                    }

                    if (f.TrackTimeStampEnd == null)
                    {
                        update.Parameters.Add("@tracktimeend", OleDbType.Date).Value = DBNull.Value;
                    }
                    else
                    {
                        update.Parameters.Add("@tracktimeend", OleDbType.Date).Value = f.TrackTimeStampEnd;
                    }

                    if (f.SetGearPtCount == null)
                    {
                        update.Parameters.Add("@setCount", OleDbType.Integer).Value = DBNull.Value;
                    }
                    else
                    {
                        update.Parameters.Add("@setCount", OleDbType.Integer).Value = f.SetGearPtCount;
                    }

                    if (f.RetrieveGearPtCount == null)
                    {
                        update.Parameters.Add("@retreiveCount", OleDbType.Integer).Value = DBNull.Value;
                    }
                    else
                    {
                        update.Parameters.Add("@retreiveCount", OleDbType.Integer).Value = f.RetrieveGearPtCount;
                    }

                    if (f.FileName == null)
                    {
                        update.Parameters.Add("@fileName", OleDbType.VarChar).Value = DBNull.Value;
                    }
                    else
                    {
                        update.Parameters.Add("@fileName", OleDbType.VarChar).Value = f.FileName;
                    }

                    if (f.XML == null)
                    {
                        update.Parameters.Add("@xml", OleDbType.VarChar).Value = DBNull.Value;
                    }
                    else
                    {
                        update.Parameters.Add("@xml", OleDbType.VarChar).Value = f.XML;
                    }

                    if (f.CTXFileName == null)
                    {
                        update.Parameters.Add("@ctxFileName", OleDbType.VarChar).Value = DBNull.Value;
                    }
                    else
                    {
                        update.Parameters.Add("@ctxFileName", OleDbType.VarChar).Value = f.CTXFileName;
                    }

                    if (f.AppVersion == null)
                    {
                        update.Parameters.Add("@appVersion", OleDbType.VarChar).Value = DBNull.Value;
                    }
                    else
                    {
                        update.Parameters.Add("@appVersion", OleDbType.VarChar).Value = f.AppVersion;
                    }

                    update.Parameters.Add("@convert_xml_error", OleDbType.Boolean).Value      = f.ErrorConvertingToXML;
                    update.Parameters.Add("@fileTimeStamp", OleDbType.Date).Value             = f.CTXFileTimeStamp;
                    update.Parameters.Add("@isDownloadedFromServer", OleDbType.Boolean).Value = f.IsDownloadedFromServer;
                    update.Parameters.Add("@isTrackExtracted", OleDbType.Boolean).Value       = f.TrackExtracted;
                    update.Parameters.Add("@dateAdded", OleDbType.Date).Value = f.DateAdded;
                    if (f.TrackingInterval == null)
                    {
                        update.Parameters.Add("@trackingInterval", OleDbType.Integer).Value = DBNull.Value;
                    }
                    else
                    {
                        update.Parameters.Add("@trackingInterval", OleDbType.Integer).Value = f.TrackingInterval;
                    }
                    update.Parameters.Add("@rowID", OleDbType.Integer).Value = f.RowID;

                    update.CommandText = @"UPDATE ctxFiles SET 
                            DeviceID = @deviceID, 
                            UserName = @user, 
                            Gear = @gear, 
                            LandingSite = @landingSite, 
                            DateStart = @start, 
                            DateEnd = @end, 
                            NumberOfTrips = @numbnerTrips, 
                            TrackPts = @trackCount, 
                            TrackTimeStampStart = @tracktimestart, 
                            TrackTimeStampEnd = @tracktimeend, 
                            SetGearPts = @setCount, 
                            RetrieveGearPts = @retreiveCount, 
                            FileName = @fileName, 
                            XML = @xml, 
                            CTXFileName = @ctxFileName, 
                            AppVersion = @appVersion, 
                            ErrorConvertingToXML = @convert_xml_error, 
                            CTXFileTimeStamp = @fileTimeStamp, 
                            IsDownloadedFromServer = @isDownloadedFromServer, 
                            TrackExtracted = isTrackExtracted,
                            DateAdded = @dateAdded,
                            TrackingInterval = @trackingInterval
                            Where RowID = @rowID";

                    try
                    {
                        success = update.ExecuteNonQuery() > 0;
                    }
                    catch (OleDbException dbex)
                    {
                    }
                    catch (Exception ex)
                    {
                        Logger.Log(ex);
                    }
                }
            }
            return(success);
        }