public OrderChangelog CreateChangelog(int startIndex, int count, string todoFilter, int datasetId)
 {
     using (geosyncEntities db = new geosyncEntities())
     {
         if (startIndex < 2)
         {
             var initialChangelog = (from d in db.StoredChangelogs
                                     where
                                     d.DatasetId == datasetId && d.StartIndex == 1 && d.Stored == true && d.Status == "finished"
                                     orderby d.DateCreated descending
                                     select d).FirstOrDefault();
             if (initialChangelog != null)
             {
                 OrderChangelog resp = new OrderChangelog();
                 resp.changelogId       = initialChangelog.ChangelogId.ToString();
                 _currentOrderChangeLog = resp;
                 return(resp);
             }
         }
         Logger.Info("CreateChangelog START");
         ChangelogManager chlmng = new ChangelogManager(db);
         _currentOrderChangeLog = chlmng.CreateChangeLog(startIndex, count, datasetId);
         chlmng.SetStatus(_currentOrderChangeLog.changelogId, ChangelogStatusType.queued);
     }
     return(_currentOrderChangeLog);
 }
        public OrderChangelog OrderChangelog(int startIndex, int count, string todoFilter, int datasetId)
        {
            // If startIndex == 1: Check if initital changelog exists
            if (startIndex == 1)
            {
                using (geosyncEntities db = new geosyncEntities())
                {
                    var initialChangelog = (from d in db.StoredChangelogs
                                            where
                                            d.DatasetId == datasetId && d.StartIndex == 1 && d.Stored == true && d.Status == "finished"
                                            orderby d.DateCreated descending
                                            select d).FirstOrDefault();

                    if (initialChangelog != null)
                    {
                        OrderChangelog resp = new OrderChangelog();
                        resp.changelogId = initialChangelog.ChangelogId.ToString();
                        return(resp);
                    }
                }
            }

            // If initial changelog don't exists or startIndex != 1
            return(_OrderChangelog(startIndex, count, todoFilter, datasetId));
        }
Exemple #3
0
 public static string Phone()
 {
     using (geosyncEntities db = new geosyncEntities())
     {
         var res = from sc in db.Services select sc.Phone;
         return(res.First());
     }
 }
Exemple #4
0
 public static string ContactInstructions()
 {
     using (geosyncEntities db = new geosyncEntities())
     {
         var res = from sc in db.Services select sc.ContactInstructions;
         if (res.First() != null)
         {
             return(res.First());
         }
         return("");
     }
 }
Exemple #5
0
 public static string OnlineResourcesUrl()
 {
     using (geosyncEntities db = new geosyncEntities())
     {
         var res = from sc in db.Services select sc.OnlineResourcesUrl;
         if (res.First() != null)
         {
             return(res.First());
         }
         return("");
     }
 }
Exemple #6
0
 public static string Adresse()
 {
     using (geosyncEntities db = new geosyncEntities())
     {
         var res = from sc in db.Services select sc.Deliverypoint;
         if (res.First() != null)
         {
             return(res.First());
         }
         return("");
     }
 }
Exemple #7
0
 public static string Fax()
 {
     using (geosyncEntities db = new geosyncEntities())
     {
         var res = from sc in db.Services select sc.Facsimile;
         if (res.First() != null)
         {
             return(res.First());
         }
         return("");
     }
 }
Exemple #8
0
 public static string SchemaLocation()
 {
     using (geosyncEntities db = new geosyncEntities())
     {
         var res = from sc in db.Services select sc.SchemaLocation;
         if (res.First() != null)
         {
             return(res.First());
         }
         return("");
     }
 }
Exemple #9
0
 public static string DbSchema(Int32 datasetId)
 {
     using (geosyncEntities db = new geosyncEntities())
     {
         var res = from d in db.Datasets where d.DatasetId == datasetId select d.DBSchema;
         if (res.First() != null)
         {
             return(res.First());
         }
         return("");
     }
 }
Exemple #10
0
 public static string ProviderName()
 {
     using (geosyncEntities db = new geosyncEntities())
     {
         var res = from sc in db.Services select sc.ProviderName;
         if (res.First() != null)
         {
             return(res.First());
         }
         return("");
     }
 }
Exemple #11
0
 public static string TransformationConnection(Int32 datasetId)
 {
     using (geosyncEntities db = new geosyncEntities())
     {
         var res = from d in db.Datasets where d.DatasetId == datasetId select d.TransformationConnection;
         if (res.First() != null)
         {
             return(res.First());
         }
         return("");
     }
 }
Exemple #12
0
 //20131016-Leg
 public static string TargetNamespacePrefix(Int32 datasetId)
 {
     using (geosyncEntities db = new geosyncEntities())
     {
         var res = from d in db.Datasets where d.DatasetId == datasetId select d.TargetNamespacePrefix;
         if (res.First() != null)
         {
             return(res.First());
         }
         return("");
     }
 }
Exemple #13
0
 public static string AccessConstraints()
 {
     using (geosyncEntities db = new geosyncEntities())
     {
         var res = from sc in db.Services select sc.AccessConstraints;
         if (res.First() != null)
         {
             return(res.First());
         }
         return("");
     }
 }
Exemple #14
0
 internal static string Version(int datasetId)
 {
     using (geosyncEntities db = new geosyncEntities())
     {
         var res = from d in db.Datasets where d.DatasetId == datasetId select d.Version;
         if (res.First() != null)
         {
             return(res.First());
         }
         return("1.0");
     }
 }
Exemple #15
0
 public static string LowerCornerCoords(Int32 datasetId)
 {
     using (geosyncEntities db = new geosyncEntities())
     {
         var res = from d in db.Datasets where d.DatasetId == datasetId select d.LowerCornerCoords;
         if (res.First() != null)
         {
             return(res.First());
         }
         return("");
     }
 }
Exemple #16
0
 public static string DownloadUriBase()
 {
     using (geosyncEntities db = new geosyncEntities())
     {
         var res = from sc in db.ServerConfigs select sc.FTPUrl;
         if (res.First() != null)
         {
             return(res.First());
         }
         return("");
     }
 }
Exemple #17
0
 public static string ServerMaxCount(Int32 datasetId)
 {
     using (geosyncEntities db = new geosyncEntities())
     {
         var res = from d in db.Datasets where d.DatasetId == datasetId select d.ServerMaxCount;
         if (res.First() != null)
         {
             return(res.First().ToString());
         }
         return("");
     }
 }
Exemple #18
0
 public static IList <Int32> GetListOfDatasetIDs()
 {
     using (geosyncEntities db = new geosyncEntities())
     {
         IList <Int32> idList = new List <Int32>();
         var           res    = from d in db.Datasets select d.DatasetId;
         foreach (Int32 id in res)
         {
             idList.Add(id);
         }
         return(idList);
     }
 }
Exemple #19
0
 public static string ServiceUrlWithQuestionMark()
 {
     using (geosyncEntities db = new geosyncEntities())
     {
         var    res   = from sc in db.Services select sc.ServiceURL;
         string url   = res.First();
         string slash = "";
         if (!url.EndsWith("/"))
         {
             slash = "/";
         }
         return(string.Format("{0}{1}?", url, slash));
     }
 }
Exemple #20
0
 public static IList <string> Keywords()
 {
     using (geosyncEntities db = new geosyncEntities())
     {
         var            res    = from sc in db.Services select sc.Keywords;
         IList <string> kw     = new List <string>();
         string         kws    = res.First();
         string[]       kwords = kws.Split(',');
         foreach (string s in kwords)
         {
             kw.Add(s);
         }
         return(kw);
     }
 }
        private OrderChangelog _OrderChangelog(int startIndex, int count, string todoFilter, int datasetId)
        {
            string downloadUriBase = ServerConfigData.DownloadUriBase().TrimEnd('/');

            using (geosyncEntities db = new geosyncEntities())
            {
                ChangelogManager chlmng = new ChangelogManager(db);

                chlmng.SetStatus(_currentOrderChangeLog.changelogId, ChangelogStatusType.working);
                //System.IO.File.Copy(Utils.BaseVirtualAppPath + sourceFileName, Utils.BaseVirtualAppPath + destFileName);
                try
                {
                    if (!Directory.Exists(destPath))
                    {
                        Directory.CreateDirectory(destPath);
                    }
                    MakeChangeLog(startIndex, count, PDbConnectInfo, _pWfsUrl, destPath + destFileName + ".xml",
                                  datasetId);
                }
                catch (Exception ex)
                {
                    chlmng.SetStatus(_currentOrderChangeLog.changelogId, ChangelogStatusType.cancelled);
                    Logger.ErrorException(
                        string.Format("Failed to make Change Log {0}", destPath + destFileName + ".xml"), ex);
                    throw ex;
                }

                // New code to handle FTP download
                ChangeLogHandler chgLogHandler = new ChangeLogHandler(Logger);
                string           inFile        = "";
                try
                {
                    inFile = destPath;
                    chgLogHandler.CreateZipFileFromFolder(inFile, zipFile, destFileName);
                    File.Copy(tmpzipFile, streamFileLocation);
                    File.Delete(tmpzipFile);
                }
                catch (Exception ex)
                {
                    chlmng.SetStatus(_currentOrderChangeLog.changelogId, ChangelogStatusType.cancelled);
                    Logger.ErrorException(string.Format("Failed to create or upload file {0}", zipFile), ex);
                    throw ex;
                }

                try
                {
                    string downLoadUri = string.Format(@"{0}/{1}", downloadUriBase, zipFile);
                    chlmng.SetStatus(_currentOrderChangeLog.changelogId, ChangelogStatusType.finished);
                    chlmng.SetDownloadURI(_currentOrderChangeLog.changelogId, downLoadUri);
                }
                catch (Exception ex)
                {
                    Logger.ErrorException(string.Format("Failed to create or upload file {0}", zipFile), ex);
                    throw ex;
                }

                Logger.Info(
                    "Kartverket.Geosynkronisering.ChangelogProviders.PostGISChangelog.OrderChangelog" +
                    " startIndex:{0}" + " count:{1}" + " changelogId:{2}", startIndex, count,
                    _currentOrderChangeLog.changelogId);

                Logger.Info("OrderChangelog END");
                return(_currentOrderChangeLog);
            }
        }
        public OrderChangelog GenerateInitialChangelog(int datasetId)
        {
            string downloadUriBase = ServerConfigData.DownloadUriBase().TrimEnd('/');

            using (geosyncEntities db = new geosyncEntities())
            {
                var initialChangelog = (from d in db.StoredChangelogs
                                        where d.DatasetId == datasetId && d.StartIndex == 1 && d.Stored == true && d.Status == "finished"
                                        orderby d.DateCreated descending
                                        select d).FirstOrDefault();
                if (initialChangelog != null && initialChangelog.DownloadUri != null)
                {
                    Uri uri = new Uri(initialChangelog.DownloadUri);
                    ChangelogManager.DeleteFileOnServer(uri);
                    db.StoredChangelogs.DeleteObject(initialChangelog);
                    db.SaveChanges();
                }
            }
            LastChangeId = 1;    // StartIndex always 1 on initial changelog
            int endIndex = Convert.ToInt32(GetLastIndex(datasetId));
            int count    = 1000; // TODO: Get from dataset table

            Logger.Info("GenerateInitialChangelog START");
            StoredChangelog ldbo = new StoredChangelog();

            ldbo.Stored     = true;
            ldbo.Status     = "queued";
            ldbo.StartIndex = (int)LastChangeId;

            ldbo.DatasetId   = datasetId;
            ldbo.DateCreated = DateTime.Now;

            //TODO make filter
            //TODO check if similar stored changelog is already done
            using (geosyncEntities db = new geosyncEntities())
            {
                // Store changelog info in database
                db.StoredChangelogs.AddObject(ldbo);

                OrderChangelog resp = new OrderChangelog();
                resp.changelogId = ldbo.ChangelogId.ToString();

                //New thread and do the work....
                // We're coming back to the thread handling later...
                //string sourceFileName = "Changelogfiles/41_changelog.xml";


                Directory.CreateDirectory(destPath);
                // Loop and create xml files
                while (OptimizedChangelLogIndex < OptimizedChangeLog.Count)
                {
                    string partFileName = DateTime.Now.Ticks + ".xml";

                    string fullPathWithFile = Path.Combine(destPath, partFileName);
                    MakeChangeLog((int)LastChangeId, count, PDbConnectInfo, _pWfsUrl, fullPathWithFile, datasetId);
                    LastChangeId += 1;
                }

                // Save endIndex to database
                ldbo.EndIndex = endIndex;

                // New code to handle FTP download
                ChangeLogHandler chgLogHandler = new ChangeLogHandler(ldbo, Logger);
                string           inFile        = "";
                try
                {
                    inFile = destPath;
                    chgLogHandler.CreateZipFileFromFolder(inFile, zipFile, destFileName);
                    ldbo.Status = "queued";
                    File.Copy(tmpzipFile, streamFileLocation);
                    File.Delete(tmpzipFile);
                    ldbo.Status = "finished";
                }
                catch (Exception ex)
                {
                    Logger.ErrorException(string.Format("Failed to create or upload file {0}", zipFile), ex);
                    throw ex;
                }

                try
                {
                    string downLoadUri = string.Format(@"{0}/{1}", downloadUriBase, zipFile);

                    ldbo.DownloadUri = downLoadUri;
                }
                catch (Exception ex)
                {
                    Logger.ErrorException(string.Format("Failed to create or upload file {0}", zipFile), ex);
                    throw ex;
                }


                try
                {
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    Logger.ErrorException(
                        string.Format(
                            "Failed on SaveChanges, Kartverket.Geosynkronisering.ChangelogProviders.PostGISChangelog.OrderChangelog startIndex:{0} count:{1} changelogId:{2}",
                            LastChangeId, count, ldbo.ChangelogId), ex);
                    throw ex;
                }
                Logger.Info(
                    "Kartverket.Geosynkronisering.ChangelogProviders.PostGISChangelog.OrderChangelog" +
                    " startIndex:{0}" + " count:{1}" + " changelogId:{2}", LastChangeId, count, ldbo.ChangelogId);

                Logger.Info("GenerateInitialChangelog END");
                return(resp);
            }
        }
 public WebFeatureServiceReplication()
 {
     db = new geosyncEntities();
 }
 public ChangelogManager(geosyncEntities _db)
 {
     db = _db;
 }