public static Commit MakeACommit(this IRepository repository)
 {
     var randomFile = Path.Combine(repository.Info.WorkingDirectory, Guid.NewGuid().ToString());
     File.WriteAllText(randomFile, string.Empty);
     repository.Index.Stage(randomFile);
     return repository.Commit("Test Commit", new Signature("Test User", "*****@*****.**", DateTimeOffset.UtcNow));
 }
 public static Commit MakeACommit(this IRepository repository)
 {
     var randomFile = Path.Combine(repository.Info.WorkingDirectory, Guid.NewGuid().ToString());
     File.WriteAllText(randomFile, string.Empty);
     repository.Index.Stage(randomFile);
     return repository.Commit("Test Commit", Constants.SignatureNow());
 }
        public static IWriteableStore SaveItem(this IWriteableStore store, IHasId obj)
        {
            if (store == null)
                return store;

            store.Commit(CommitBag.New().MarkItemSaved(obj));
            return store;
        }
        public static IWriteableStore SaveItems(this IWriteableStore store, List<IHasId> objs)
        {
            if (store == null)
                return store;

            store.Commit(new CommitBag().MarkItemsSaved(objs));
            return store;
        }
        public static IWriteableStore DeleteItem(this IWriteableStore store, StoredObjectId soid)
        {
            if (store == null)
                return store;

            store.Commit(new CommitBag().MarkItemDeleted(soid));
            return store;
        }
		/// <summary>
		/// 
		/// </summary>
		/// <param name="op"></param>
		/// <param name="hash"></param>
		/// <param name="commiter"></param>
		/// <param name="behavior"></param>
		/// <param name="sources"></param>
		/// <returns></returns>
		public static Commit Commit(this IMappingOperator op, string hash, string commiter, CommitHeadBehavior behavior, params string[] sources) {
			var commit = new Commit {Hash = hash, Author = new CommitAuthorInfo {Commiter = commiter, Time = DateTime.Now}};
			if (null != sources && 0 != sources.Length) {
				foreach (var s in sources) {
					commit.Sources.Add(s);
				}
			}
			return op.Commit(commit,behavior);
		}
        public static void CommitMany(this IPersistStreams persistence, int numberOfCommits, Guid? streamId = null)
        {
            Commit attempt = null;

            for (int i = 0; i < numberOfCommits; i++)
            {
                attempt = attempt == null ? (streamId ?? Guid.NewGuid()).BuildAttempt() : attempt.BuildNextAttempt();
                persistence.Commit(attempt);
            }
        }
        public static IWriteableStore DeleteItems(this IWriteableStore store, params StoredObjectId[] objs)
        {
            if (store == null)
                return store;

            var commitBag = CommitBag.New();
            commitBag.MarkItemsDeleted(objs.ToList());
            store.Commit(commitBag);
            return store;
        }
        public static void SaveItemIfUniqueElseThrow(this IStore store, IHasId obj)
        {
            if (store == null)
                return;

            //throw if the item exists
            var dup = store.Get(obj.GetStoredObjectId());
            if (dup != null)
                throw new InvalidOperationException("Item already exists " + obj.Id.ToString());

            store.Commit(new CommitBag().MarkItemSaved(obj));
        }
 public static void EnsureTestData(this ICoffeeStoreContext dbContext)
 {
     if (!dbContext.Coffee.Any(f => f.Name == "Caffe Latte"))
     {
         dbContext.Coffee.AddRange(
             new Coffee { Coffee_Id = 1, Name = "Caffe Latte", Retail = 4.35M },
             new Coffee { Coffee_Id = 2, Name = "Brewed Coffee", Retail = 4.60M },
             new Coffee { Coffee_Id = 3, Name = "Cappuccino", Retail = 4M },
             new Coffee { Coffee_Id = 4, Name = "Espresso", Retail = 4.50M },
             new Coffee { Coffee_Id = 5, Name = "Flat White", Retail = 4M }
             );
         dbContext.Commit();
     }
 }
 public static Task<string> Handle(this IStorageNode Node, string Request)
 {
     var req = JSON.Deserialize<NetworkRequest>(Request);
     switch (req.method)
     {
         case NetworkRequest.BeginTransaction:
             return Node.BeginTransaction().Then(n => n.ToString());
         case NetworkRequest.Read:
             return Node.Read(req.transactionID, req.key).Then(JSON.Serialize);
         case NetworkRequest.Commit:
             return Node.Commit(req.transactionID, req.updated, req.read).Then((n) => n.ToString());
         default:
             throw new NotImplementedException("The method " + req.method + " was not recognised.");
     }
 }
 //private readonly static ILog Log = LogManager.GetLogger(typeof(UnitOfWorkHelpers).FullName);
 public static void DoInTransaction(this IUnitOfWork uow, Action action)
 {
     uow.Begin();
     try
     {
         action.Invoke();
         uow.Commit();
     }
     catch (Exception ex)
     {
         //Log.Error(string.Format("Exception thrown in transaction. Action method: {0}, action Target: {1}.",
         //    action.Method, action.Target), ex);
         uow.RollBack();
         throw;
     }
 }
    public static Commit CreateFileAndCommit(this IRepository repository, string relativeFileName)
    {
        var randomFile = Path.Combine(repository.Info.WorkingDirectory, relativeFileName);
        if (File.Exists(randomFile))
        {
            File.Delete(randomFile);
        }

        var totalWidth = 36 + (pad++ % 10);
        var contents = Guid.NewGuid().ToString().PadRight(totalWidth, '.');
        File.WriteAllText(randomFile, contents);

        repository.Stage(randomFile);

        return repository.Commit(string.Format("Test Commit for file '{0}'", relativeFileName),
            Constants.SignatureNow(), Constants.SignatureNow());
    }
Exemple #14
0
    public static void SetActiveGrayScale(this exPlane s, bool active)
    {
        Vector2[] uv2 = new Vector2[s.meshFilter.mesh.uv.Length];
        for (int i = 0; i < uv2.Length; i++)
        {
            if(active)
            {
                uv2[i] = new Vector2(grayScaleU, 0f);
            }
            else
            {
                uv2[i] = new Vector2(nonGrayScaleU, 0f);
            }
        }

        s.meshFilter.mesh.uv2 = uv2;
        s.Commit();
    }
Exemple #15
0
    public static void SetSpriteIntensity(this exSprite f, float intensity)
    {
        //		if(f.meshFilter.mesh.uv.Length < 4)
        //		{
        //			return;
        //		}

        intensity = Mathf.Max(intensity, 0f);

        int length = f.meshFilter.mesh.uv.Length;
        Vector2 [] uv2 = new Vector2[length];
        for(int i=0; i<length; ++i)
        {
            uv2[i] = new Vector2(intensity, intensity);
        }

        f.meshFilter.mesh.uv2 = uv2;
        f.Commit();
    }
        public static void SaveEvictingItem(this IEvictingStore store, IHasId obj, IExpirable evictingCondition)
        {
            if (store == null)
                return;

            store.Commit(new CommitBag().MarkItemSaved(obj), evictingCondition);
        }
        private static void AddClimatologyAxis(this DataSet ds, string timeAxis, string climatologyAxis, int yearmin, int yearmax, int daymin, int daymax, int hourmin, int hourmax, Microsoft.Research.Science.Data.Climate.Common.IntervalToSplit its = IntervalToSplit.Days, int step = 0, bool calculateMonthlyIntervals = false)
        {
            #region arguments check
            if (daymin < 0 || daymax > 366)
            {
                throw new ArgumentException(String.Format("The minimum day in the year doesn't fall into permited interval. You've entered {0}. However it must be set to 1..366 or to GlobalConsts.DefaultValue.", daymax));
            }
            if (daymin < 0 || daymin > 366)
            {
                throw new ArgumentException(String.Format("The maximum day in the year doesn't fall into permited interval. You've entered {0}. However it must be set to 1..366 or to GlobalConsts.DefaultValue.", daymin));
            }
            if (hourmin < 0 || hourmin > 24)
            {
                throw new ArgumentException(String.Format("starting hour in the day doesn't fall into permited interval. You've entered {0}. However it must be set to 0..24 or to GlobalConsts.DefaultValue.", hourmin));
            }
            if (hourmax < 0 || hourmax > 24)
            {
                throw new ArgumentException(String.Format("The last hour in the day doesn't fall into permited interval. You've entered {0}. However it must be set to 0..24 or to GlobalConsts.DefaultValue.", hourmax));
            }

            if (yearmin > yearmax)
            {
                throw new ArgumentException(String.Format("The minimum requested year(you've entered {0}) must be less or equel to maximum requested year(you've entered {1}).", yearmin, yearmax));
            }

            if (hourmin > hourmax)
            {
                throw new ArgumentException("Hour min is more then hour max");
            }
            if (daymin > daymax)
            {
                throw new ArgumentException("Daymin is more then day max");
            }
            if (calculateMonthlyIntervals && its != IntervalToSplit.Days && step == 0)
                throw new InvalidOperationException("monthlyDaysSteps should be specified only for ");
            int[] monthDays = null;
            if (calculateMonthlyIntervals)
                monthDays = Enumerable.Range(1, 12).Select(i => DateTime.DaysInMonth(2001, i)).ToArray();
            if (ds.Variables.Contains(climatologyAxis))
                throw new InvalidOperationException("Dataset already contains specified climatology axis");
            if (timeAxis == null)
                timeAxis = ds.Variables.Where(v => v.TypeOfData == typeof(DateTime) && v.Rank == 1).Select(v => v.Name).FirstOrDefault();
            if (timeAxis == null)
            {
                if (ds.Variables.Contains("time"))
                {
                    int num = 1;
                    while (ds.Variables.Contains(string.Format("time{0}", num)))
                        num++;
                    timeAxis = string.Format("time{0}", num);
                }
                else
                    timeAxis = "time";
            }
            #endregion

            int n = 0;
            if (calculateMonthlyIntervals)//monthly timeseries
                n = 12;
            else
                switch (its)
                {
                    case IntervalToSplit.Years: n = (int)Math.Ceiling((yearmax - yearmin) / (double)step); break;
                    case IntervalToSplit.Days: n = (int)Math.Ceiling((daymax - daymin) / (double)step); break;
                    case IntervalToSplit.Hours: n = (int)Math.Ceiling((hourmax - hourmin) / (double)step); break;
                    default: throw new NotImplementedException();
                }
            if (ds.Variables.Contains(timeAxis))
            {
                if (ds.Variables[timeAxis].Rank > 1)
                    throw new ArgumentException("Specified time axis has rank more than 1");
                int len = ds.Variables[timeAxis].Dimensions[0].Length;
                if (len != 0 && len != n)
                    throw new ArgumentException("Specified time axis has length more than zero and not equal to supposed climatology axis length");
            }

            bool autocommit = ds.IsAutocommitEnabled;
            try
            {
                ds.IsAutocommitEnabled = false;

                int[] hourmins = new int[n];
                int[] hourmaxs = new int[n];
                int[] daymins = new int[n];
                int[] daymaxs = new int[n];
                int[] yearmins = new int[n];
                int[] yearmaxs = new int[n];
                DateTime[,] timeBounds = new DateTime[n, 2];
                DateTime[] times = new DateTime[n];


                int yi = (its == IntervalToSplit.Years) ? 1 : 0;
                int di = (its == IntervalToSplit.Days) ? 1 : 0;
                int hi = (its == IntervalToSplit.Hours) ? 1 : 0;

                int day = 1;
                for (int i = 0; i < n; i++)
                {
                    hourmins[i] = Math.Min((hi == 0) ? hourmin : (hourmin + hi * i * step), 24);
                    hourmaxs[i] = Math.Min((hi == 0) ? hourmax : (hourmin + hi * ((i + 1) * step - 1)), 24);
                    yearmins[i] = (yi == 0) ? yearmin : (yearmin + yi * i * step);
                    yearmaxs[i] = (yi == 0) ? yearmax : (yearmin + yi * ((i + 1) * step - 1));
                    if (!calculateMonthlyIntervals) //seasonly timeseries
                    {
                        daymins[i] = Math.Min((di == 0) ? daymin : (daymin + di * (i * step)), (yearmins[i] == yearmaxs[i] && DateTime.IsLeapYear(yearmins[i])) ? 366 : 365);
                        daymaxs[i] = Math.Min((di == 0) ? daymax : (daymin + di * ((i + 1) * step - 1)), (yearmins[i] == yearmaxs[i] && DateTime.IsLeapYear(yearmins[i])) ? 366 : 365);
                    }
                    else //monthly timeseries
                    {
                        daymins[i] = day;
                        daymaxs[i] = day + monthDays[i] - 1;
                        day += monthDays[i];
                    }
                    timeBounds[i, 0] = new DateTime(yearmins[i], 1, 1).AddDays(daymins[i] - 1).AddHours(hourmins[i]);
                    timeBounds[i, 1] = new DateTime(yearmaxs[i], 1, 1).AddDays(daymaxs[i] - 1).AddHours(hourmaxs[i]);
                    times[i] = new DateTime((yearmaxs[i] + yearmins[i]) / 2, 1, 1).AddDays((daymaxs[i] + daymins[i]) / 2).AddHours((hourmaxs[i] + hourmins[i]) / 2);
                }
                string sndDim = "nv";
                if (ds.Dimensions.Contains(sndDim))
                {
                    int num = 1;
                    while (ds.Dimensions.Contains(string.Format("{0}{1}", sndDim, num)))
                        num++;
                    sndDim = string.Format("{0}{1}", sndDim, num);
                }
                if (!ds.Variables.Contains(timeAxis))
                {
                    ds.Add(timeAxis, times, timeAxis);
                }
                else if (ds.Variables[timeAxis].Dimensions[0].Length == 0)
                {
                    ds.Variables[timeAxis].Append(times);
                }
                ds.Add(climatologyAxis, timeBounds, ds.Variables[timeAxis].Dimensions[0].Name, sndDim);
                ds.Variables[timeAxis].Metadata["climatology"] = climatologyAxis;
                ds.Commit();
            }
            finally
            {
                ds.IsAutocommitEnabled = autocommit;
            }
        }
        private static Variable Fetch(this DataSet ds, ClimateParameter parameter, string name, double[] latmins, double[] lonmins, string dimLat, string dimLon, double[] latmaxs = null, double[] lonmaxs = null, string dimTime = null, DateTime[] timeSlices = null, TimeBounds[] climatologyIntervals = null, string nameUncertainty = null, string nameProvenance = null, EnvironmentalDataSource dataSource = EnvironmentalDataSource.ANY)
        {
            if (timeSlices == null && climatologyIntervals == null)
                throw new ArgumentNullException("Both timeSlices and ClimatologyIntervals are null");
            if (latmaxs == null ^ lonmaxs == null)
                throw new ArgumentException("Only one of latmax and lonmax is set. please set both of them or none");
            object mv = double.NaN;
            string longName = GetLongName(parameter);

            bool isFetchingGrid = dimLat != dimLon; // otherwise, fetching point set, when all axes depend on the same dimension

            // Preparing FetchClimate method parameters
            int index = 0;
            int[] starthour, stophour, startday, stopday, startyear, stopyear;
            double[] minLats, minLons, maxLats, maxLons;

            int timesN = (climatologyIntervals != null) ? (climatologyIntervals.Length) : (timeSlices.Length);
            if (isFetchingGrid)
            {
                #region Preparing request for grid
                int latN = latmins.Length;
                int lonN = lonmins.Length;
                if (latN <= 0)
                    throw new ArgumentException("lats. Too short latitude axis");
                if (lonN <= 0)
                    throw new ArgumentException("lons. Too short longitude axis");
                int n = latN * lonN * timesN;
                if (n == 0) throw new ArgumentException("Empty region is requested");
                starthour = new int[n]; stophour = new int[n]; startday = new int[n]; stopday = new int[n]; startyear = new int[n]; stopyear = new int[n];
                minLats = new double[n]; minLons = new double[n];
                maxLats = new double[n]; maxLons = new double[n];
                if (climatologyIntervals != null)
                {
                    for (int j = 0; j < latN; j++)
                    {
                        double latmax = (latmaxs == null) ? latmins[j] : latmaxs[j];
                        double latmin = latmins[j];
                        for (int k = 0; k < lonN; k++)
                        {
                            double lonmax = (lonmaxs == null) ? lonmins[k] : lonmaxs[k];
                            double lonmin = lonmins[k];
                            for (int i = 0; i < timesN; i++)
                            {
                                startyear[index] = climatologyIntervals[i].MinYear;
                                startday[index] = climatologyIntervals[i].MinDay;
                                starthour[index] = climatologyIntervals[i].MinHour;

                                stopyear[index] = climatologyIntervals[i].MaxYear;
                                stopday[index] = climatologyIntervals[i].MaxDay;
                                stophour[index] = climatologyIntervals[i].MaxHour;

                                minLats[index] = latmin;
                                minLons[index] = lonmin;

                                maxLats[index] = latmax;
                                maxLons[index] = lonmax;

                                index++;
                            }
                        }
                    }
                }
                else
                {
                    for (int j = 0; j < latN; j++)
                    {
                        double latmin = latmins[j];
                        double latmax = (latmaxs == null) ? latmins[j] : latmaxs[j];
                        for (int k = 0; k < lonN; k++)
                        {
                            double lonmax = (lonmaxs == null) ? lonmins[k] : lonmaxs[k];
                            double lonmin = lonmins[k];

                            for (int i = 0; i < timesN; i++)
                            {
                                starthour[index] = stophour[index] = timeSlices[i].Hour;
                                startday[index] = stopday[index] = timeSlices[i].DayOfYear;
                                startyear[index] = stopyear[index] = timeSlices[i].Year;

                                minLats[index] = latmin;
                                minLons[index] = lonmin;

                                maxLats[index] = latmax;
                                maxLons[index] = lonmax;

                                index++;
                            }
                        }
                    }
                }
                #endregion
            }
            else // preparing request for pointset 
            {
                #region Preparing request for pointset
                int coordN = latmins.Length;
                int n = coordN * timesN;
                if (n == 0) throw new ArgumentException("Empty region is requested");
                if (latmaxs != null || lonmaxs != null)
                    throw new InvalidOperationException("In case of pointset fetching latmaxs and lonmaxs must be omited");
                starthour = new int[n]; stophour = new int[n]; startday = new int[n]; stopday = new int[n]; startyear = new int[n]; stopyear = new int[n];
                minLats = new double[n]; minLons = new double[n];
                maxLats = new double[n]; maxLons = new double[n];
                if (climatologyIntervals != null)
                {
                    for (int i = 0; i < timesN; i++)
                        for (int j = 0; j < coordN; j++)
                        {
                            startyear[index] = climatologyIntervals[i].MinYear;
                            startday[index] = climatologyIntervals[i].MinDay;
                            starthour[index] = climatologyIntervals[i].MinHour;

                            stopyear[index] = climatologyIntervals[i].MaxYear;
                            stopday[index] = climatologyIntervals[i].MaxDay;
                            stophour[index] = climatologyIntervals[i].MaxHour;

                            minLats[index] = maxLats[index] = latmins[j];
                            minLons[index] = maxLons[index] = lonmins[j];
                            index++;
                        }
                }
                else
                {
                    for (int i = 0; i < timesN; i++)
                        for (int j = 0; j < coordN; j++)
                        {
                            starthour[index] = stophour[index] = timeSlices[i].Hour;
                            startday[index] = stopday[index] = timeSlices[i].DayOfYear;
                            startyear[index] = stopyear[index] = timeSlices[i].Year;
                            minLats[index] = maxLats[index] = latmins[j];
                            minLons[index] = maxLons[index] = lonmins[j];
                            index++;
                        }
                }
                #endregion
            }

            // Fetching the data
            var resp = ClimateService.FetchClimateEx(parameter, new FetchingOptions() { DataSourceToUse = dataSource }, minLats, maxLats, minLons, maxLons, starthour, stophour, startday, stopday, startyear, stopyear);
            ClimateParameterValue[] climateData = resp.Values;
            string units = climateData.First().DefaultClientUnitsString;

            // Saving result in the dataset
            bool _ac = ds.IsAutocommitEnabled;
            Variable varData = null, varUncertainty = null, varProv = null;
            bool saveUncertainty = !String.IsNullOrWhiteSpace(nameUncertainty);
            bool saveProv = !String.IsNullOrWhiteSpace(nameProvenance);

            try
            {
                ds.IsAutocommitEnabled = false;
                index = 0;
                if (isFetchingGrid)
                {
                    #region Putting grid data into DataSet
                    int latN = latmins.Length;
                    int lonN = lonmins.Length;
                    if (dimTime != null)
                    {
                        double[, ,] data = new double[timesN, latmins.Length, lonmins.Length];
                        double[, ,] uncertainty = saveUncertainty ? new double[timesN, latmins.Length, lonmins.Length] : null;
                        string[, ,] provenance = saveProv ? new string[timesN, latmins.Length, lonmins.Length] : null;                        
                            for (int j = 0; j < latN; j++)
                                for (int k = 0; k < lonN; k++)
                                    for (int i = 0; i < timesN; i++)                        
                                {
                                    var cd = climateData[index++];
                                    data[i, j, k] = cd.GetValueInDefaultClientUnits();
                                    if (saveUncertainty)
                                        uncertainty[i, j, k] = cd.GetUncertaintyInDefaultClientUnits();
                                    if (saveProv)
                                        provenance[i, j, k] = cd.Provenance;
                                }                        
                        varData = ds.Add(name, units, mv, data, dimTime, dimLat, dimLon);
                        if (saveUncertainty) varUncertainty = ds.Add(nameUncertainty, units, mv, uncertainty, dimTime, dimLat, dimLon);
                        if (saveProv) varProv = ds.Add(nameProvenance, provenance, dimTime, dimLat, dimLon);
                    }
                    else
                    {
                        double[,] data = new double[latmins.Length, lonmins.Length];
                        double[,] uncertainty = saveUncertainty ? new double[latmins.Length, lonmins.Length] : null;
                        string[,] provenance = saveProv ? new string[latmins.Length, lonmins.Length] : null;
                        for (int i = 0; i < latN; i++)
                            for (int j = 0; j < lonN; j++)
                            {
                                var cd = climateData[index++];
                                data[i, j] = cd.GetValueInDefaultClientUnits();
                                if (saveUncertainty)
                                    uncertainty[i, j] = cd.GetUncertaintyInDefaultClientUnits();
                                if (saveProv)
                                    provenance[i, j] = cd.Provenance;
                            }
                        varData = ds.Add(name, units, mv, data, dimLat, dimLon);
                        varData.Metadata["Time"] = timeSlices[0];
                        if (saveUncertainty)
                        {
                            varUncertainty = ds.Add(nameUncertainty, units, mv, uncertainty, dimLat, dimLon);
                            varUncertainty.Metadata["Time"] = timeSlices[0];
                        }
                        if (saveProv)
                        {
                            varProv = ds.Add(nameProvenance, provenance, dimLat, dimLon);
                            varProv.Metadata["Time"] = timeSlices[0];
                        }
                    }
                    #endregion
                }
                else // saving pointset into the dataset
                {
                    #region Putting pointset data into Dataset
                    int coordN = latmins.Length;
                    if (dimTime != null)
                    {
                        double[,] data = new double[timesN, coordN];
                        double[,] uncertainty = saveUncertainty ? new double[timesN, coordN] : null;
                        string[,] provenance = saveProv ? new string[timesN, coordN] : null;
                        for (int i = 0; i < timesN; i++)
                            for (int j = 0; j < coordN; j++)
                            {
                                var cd = climateData[index++];
                                data[i, j] = cd.GetValueInDefaultClientUnits();
                                if (saveUncertainty)
                                    uncertainty[i, j] = cd.GetUncertaintyInDefaultClientUnits();
                                if (saveProv)
                                    provenance[i, j] = cd.Provenance;
                            }
                        varData = ds.Add(name, units, mv, data, dimTime, dimLat);
                        if (saveUncertainty) varUncertainty = ds.Add(nameUncertainty, units, mv, uncertainty, dimTime, dimLat);
                        if (saveProv) varProv = ds.Add(nameProvenance, provenance, dimTime, dimLat);
                    }
                    else
                    {
                        double[] data = new double[coordN];
                        double[] uncertainty = saveUncertainty ? new double[coordN] : null;
                        string[] provenance = saveProv ? new string[coordN] : null;
                        for (int i = 0; i < coordN; i++)
                        {
                            var cd = climateData[index++];
                            data[i] = cd.GetValueInDefaultClientUnits();
                            if (saveUncertainty)
                                uncertainty[i] = cd.GetUncertaintyInDefaultClientUnits();
                            if (saveProv)
                                provenance[i] = cd.Provenance;
                        }
                        varData = ds.Add(name, units, mv, data, dimLat);
                        varData.Metadata["Time"] = timeSlices[0];
                        if (saveUncertainty)
                        {
                            varUncertainty = ds.Add(nameUncertainty, units, mv, uncertainty, dimLat);
                            varUncertainty.Metadata["Time"] = timeSlices[0];
                        }
                        if (saveProv)
                        {
                            varProv = ds.Add(nameProvenance, provenance, dimLat);
                            varProv.Metadata["Time"] = timeSlices[0];
                        }
                    }
                    #endregion
                }

                FillMetadata(varData, climatologyIntervals, resp, longName);
                if (saveUncertainty) FillUncertaintyMetadata(varUncertainty, resp, longName);
                if (saveProv) FillProvenanceMetadata(varProv, resp, longName);
                ds.Commit();
            }
            finally
            {
                ds.IsAutocommitEnabled = _ac;
            }
            return varData;
        }
 public static void Commit(this IEsentTransaction transaction)
 {
     transaction.Commit(CommitTransactionGrbit.None);
 }
Exemple #20
0
 static public void SyncWith(this SessionBase sessionToUpdate, SessionBase sessionToRead, Func<SessionBase, UInt64, Change, bool> doUpdate)
 {
   UInt64 currentVersion;
   UInt64 pageToReadVersion;
   bool conflictFound = false;
   using (var reader = sessionToRead.BeginRead())
   {
     Changes changes = (Changes)sessionToRead.Open(5, 1, 1, false);
     if (changes != null)
     {
       using (var updater = sessionToUpdate.BeginUpdate())
       {
         var dbs = sessionToUpdate.OpenAllDatabases();
         ReplicaSync matchingReplicaSync = null;
         foreach (ReplicaSync sync in sessionToUpdate.AllObjects<ReplicaSync>())
         {
           if (sync.SyncFromHost == sessionToRead.SystemHostName && sync.SyncFromPath == sessionToRead.SystemDirectory)
           {
             matchingReplicaSync = sync;
             break;
           }
         }
         if (changes.ChangeList.Count > 0)
         {
           foreach (TransactionChanges transactionChanges in changes.ChangeList)
           {
             if (matchingReplicaSync == null || matchingReplicaSync.TransactionNumber < transactionChanges.TransactionNumber)
             {
               foreach (Change change in transactionChanges.ChangeList)
               {
                 Database dbToUpdate = sessionToUpdate.OpenDatabase(change.DatabaseId, false, false);
                 Database dbToRead = sessionToRead.OpenDatabase(change.DatabaseId, false, false);
                 string dbName = dbToRead != null ? dbToRead.Name : null;
                 if (change.Deleted)
                 {
                   if (dbToUpdate == null) // does not exist
                     continue;
                   if (change.PageId == 0) // Database delete
                   {
                     currentVersion = dbToUpdate.Page.PageInfo.VersionNumber;
                     if (currentVersion < change.Version)
                       sessionToUpdate.DeleteDatabase(dbToUpdate);
                     else
                     {
                       conflictFound = true;
                       if (doUpdate(sessionToUpdate, currentVersion, change))
                         sessionToUpdate.DeleteDatabase(dbToUpdate);
                     }
                   }
                   else
                   {
                     Page page = sessionToUpdate.OpenPage(dbToUpdate, change.PageId);
                     if (page == null) // page does not exist
                       continue;
                     currentVersion = page.PageInfo.VersionNumber;
                     if (currentVersion < change.Version)
                       sessionToUpdate.DeletePage(dbToUpdate, page);
                     else
                     {
                       conflictFound = true;
                       if (doUpdate(sessionToUpdate, currentVersion, change))
                         sessionToUpdate.DeleteDatabase(dbToUpdate);
                     }
                   }
                 }
                 else
                 {
                   if (dbToUpdate == null) // does not exist
                     dbToUpdate = sessionToUpdate.NewDatabase(change.DatabaseId, 0, dbName);
                   if (change.PageId > 0)
                   {
                     Page pageToUpdate = sessionToUpdate.OpenPage(dbToUpdate, change.PageId);
                     Page pageToRead = sessionToRead.OpenPage(dbToRead, change.PageId);
                     if (pageToRead == null) // upcoming (not yet processed) changes must have deleted this page
                       continue;
                     currentVersion = pageToUpdate == null ? 0 : pageToUpdate.PageInfo.VersionNumber;
                     pageToReadVersion = pageToRead.PageInfo.VersionNumber;
                     if (currentVersion < pageToReadVersion || dbToUpdate.IsNew)
                       sessionToUpdate.ReplacePage(dbToUpdate, pageToUpdate, pageToRead);
                     else
                     {
                       conflictFound = true;
                       if (doUpdate(sessionToUpdate, currentVersion, change))
                         sessionToUpdate.ReplacePage(dbToUpdate, pageToUpdate, pageToRead);
                     }
                   }
                 }
               }
             }
           }
           UInt64 lastTransactionNumber = changes.ChangeList.Last().TransactionNumber;
           if (matchingReplicaSync != null)
             matchingReplicaSync.TransactionNumber = lastTransactionNumber;
           if (conflictFound)
           {
             sessionToUpdate.Verify();
           }
           sessionToUpdate.Commit();
           if (matchingReplicaSync == null)
           {
             sessionToUpdate.BeginUpdate(); // separate transaction or else gets confused with databases added by sync
             matchingReplicaSync = new ReplicaSync(sessionToRead, lastTransactionNumber);
             sessionToUpdate.Persist(matchingReplicaSync);
             sessionToUpdate.Commit();
           }
         }
       }
     }
   }
 }
 public static Task<long> Commit(this IStorageNode Node, Task<long> TransactionID, Dictionary<string, string> Updated, string[] Read)
 {
     return TransactionID
         .Then((WriteID) => Node.Commit(WriteID, Updated, Read))
         .Unwrap();
 }
Exemple #22
0
		public static Task CommitAsynchronous(this OracleTransaction transaction)
		{
			return App.ExecuteAsynchronous<object>(delegate { }, delegate { transaction.Commit(); return null; }, CancellationToken.None);
		}
 public static void PublishWithLatency(this IServiceBus bus, IMessage message)
 {
     Task.Factory.StartNew(() =>
     {
         Thread.Sleep(3000);
         bus.Publish(message);
         bus.Commit();
     });
 }
Exemple #24
0
        /// <summary>
        /// Modifies the id of an object in a store
        /// </summary>
        /// <param name="store"></param>
        /// <param name="idToChange"></param>
        /// <param name="newId"></param>
        public static void ChangeStoredObjectId(this IStore store, StoredObjectId idToChange, object newId)
        {
            if (store == null)
                return;

            if (idToChange == null)
                return;

            //if we're not changing anything, skip
            if (idToChange.ObjectId.Equals(newId))
                return;

            //get the object to ensure it exists
            var obj = store.Get(idToChange);
            if (obj == null)
                return;
            
            //mark delete
            var cb = CommitBag.New();
            cb.MarkItemDeleted(idToChange);

            //change the id
            if (obj is IHasSettableId)
            {
                IHasSettableId ihs = obj as IHasSettableId;
                ihs.SetId(newId);
            }
            else
            {
                PropertyInfo pi = obj.GetType().GetProperty("Id", BindingFlags.Public | BindingFlags.Instance);
                pi.SetValue(obj, newId);
            }
            //mark save new item and commit
            cb.MarkItemSaved(obj);
            store.Commit(cb);
        }
		public static void CommitEx(this IDbTransaction transaction)
		{
			transaction.Commit();
		}
Exemple #26
0
 public static void CommitLazy(this Transaction transaction)
 {
     transaction.Commit(CommitTransactionGrbit.LazyFlush);
 }
        public static void SaveOneTimeItem(this IEvictingStore store, IHasId obj)
        {
            if (store == null)
                return;

            var expiry = EvictionPolicy.BuildTouchLimitExpirable(1);

            store.Commit(new CommitBag().MarkItemSaved(obj), expiry);
        }