public async Task <HttpResponseMessage> ApplyConflict(string filename, long remoteVersion, string remoteServerId, string remoteServerUrl)
        {
            var localMetadata = GetLocalMetadata(filename);

            if (localMetadata == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            var contentStream = await Request.Content.ReadAsStreamAsync();

            var current = new HistoryItem
            {
                ServerId = Storage.Id.ToString(),
                Version  = localMetadata.Value <long>(SynchronizationConstants.RavenSynchronizationVersion)
            };

            var currentConflictHistory = Historian.DeserializeHistory(localMetadata);

            currentConflictHistory.Add(current);

            var remote = new HistoryItem
            {
                ServerId = remoteServerId,
                Version  = remoteVersion
            };

            var remoteConflictHistory =
                new JsonSerializer().Deserialize <IList <HistoryItem> >(new JsonTextReader(new StreamReader(contentStream)));

            remoteConflictHistory.Add(remote);

            var conflict = new ConflictItem
            {
                CurrentHistory  = currentConflictHistory,
                RemoteHistory   = remoteConflictHistory,
                FileName        = filename,
                RemoteServerUrl = Uri.UnescapeDataString(remoteServerUrl)
            };

            ConflictArtifactManager.Create(filename, conflict);

            Publisher.Publish(new ConflictDetectedNotification
            {
                FileName        = filename,
                SourceServerUrl = remoteServerUrl
            });

            Log.Debug("Conflict applied for a file '{0}' (remote version: {1}, remote server id: {2}).", filename, remoteVersion, remoteServerId);

            return(GetEmptyMessage(HttpStatusCode.NoContent));
        }
Example #2
0
        /// <summary>
        /// создать заявку
        /// </summary>
        /// <param name="request">модель создания заявки</param>
        public async Task CreateApp(CreateApplicationRequest request)
        {
            try
            {
                var now = DateTime.UtcNow;
                var app = new BaseApplication
                {
                    Title       = request.Title,
                    Description = request.Description,
                    Status      = Status.Open,
                    DateModify  = now,
                    HistoryIds  = new List <long>().SerializeToJson()
                };
                db.BaseApplications.Add(app);
                db.SaveChanges();

                var histories = db.BaseHistories;
                var history   = new BaseHistory
                {
                    AppId      = app.Id,
                    DateModify = now,
                    StatusOld  = null,
                    StatusNew  = app.Status,
                    Comment    = null
                };
                db.BaseHistories.Add(history);
                db.SaveChanges();

                var appHistory = new JsonSerializer().Deserialize <List <long> >
                                     (new JsonTextReader
                                         (new StringReader(app.HistoryIds)));
                appHistory.Add(history.Id);
                app.HistoryIds = appHistory.SerializeToJson();
                db.SaveChanges();
            }
            catch
            {
            }
        }
Example #3
0
        /// <summary>
        /// изменить заявку
        /// </summary>
        /// <param name="request">модель изменения заявки</param>
        /// <returns></returns>
        public async Task EditApp(EditApplicationRequest request)
        {
            try
            {
                if (request.Comment == null)
                {
                    return;
                }

                var now = DateTime.UtcNow;

                var app          = db.BaseApplications.FirstOrDefault(x => x.Id == request.Id);
                var appStatusOld = app.Status;
                app.Status     = request.StatusNew;
                app.DateModify = now;
                db.SaveChanges();

                var history = new BaseHistory
                {
                    AppId      = app.Id,
                    DateModify = now,
                    StatusOld  = appStatusOld,
                    StatusNew  = app.Status,
                    Comment    = request.Comment
                };
                db.BaseHistories.Add(history);
                db.SaveChanges();

                var appHistory = new JsonSerializer().Deserialize <List <long> >
                                     (new JsonTextReader
                                         (new StringReader(app.HistoryIds)));
                appHistory.Add(history.Id);
                app.HistoryIds = appHistory.SerializeToJson();
                db.SaveChanges();
            }
            catch
            {
            }
        }
Example #4
0
        /// <summary>
        /// Create a new tabs list
        /// </summary>
        /// <param name="new_name">Name of your tabs list</param>
        /// <returns>ID of the new tabs list created</returns>
        public static async Task <int> CreateTabsListAsync(string new_name)
        {
            using (var reader = new StreamReader(await file.OpenStreamForReadAsync()))
                using (JsonReader JsonReader = new JsonTextReader(reader))
                {
                    try
                    {
                        int             id   = new Random().Next(999999);
                        List <TabsList> list = new JsonSerializer().Deserialize <List <TabsList> >(JsonReader);

                        list = list ?? new List <TabsList>();

                        list.Add(new TabsList {
                            ID = id, name = new_name, tabs = new List <InfosTab>()
                        });
                        await FileIO.WriteTextAsync(file, JsonConvert.SerializeObject(list, Formatting.Indented));

                        foreach (CoreApplicationView view in CoreApplication.Views)
                        {
                            await view.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                            {
                                Messenger.Default.Send(new STSNotification {
                                    Type = TypeUpdateTab.NewList, ID = new TabID {
                                        ID_TabsList = id
                                    }
                                });
                            });
                        }

                        return(id);
                    }
                    catch
                    {
                        return(0);
                    }
                }
        }
		public async Task<HttpResponseMessage> ApplyConflict(string filename, long remoteVersion, string remoteServerId,
															 string remoteServerUrl)
		{
			var localMetadata = GetLocalMetadata(filename);

			if (localMetadata == null)
				throw new HttpResponseException(HttpStatusCode.NotFound);

			var contentStream = await Request.Content.ReadAsStreamAsync();

			var current = new HistoryItem
			{
				ServerId = Storage.Id.ToString(),
				Version = long.Parse(localMetadata[SynchronizationConstants.RavenSynchronizationVersion])
			};

			var currentConflictHistory = Historian.DeserializeHistory(localMetadata);
			currentConflictHistory.Add(current);

			var remote = new HistoryItem
			{
				ServerId = remoteServerId,
				Version = remoteVersion
			};

			var remoteConflictHistory =
				new JsonSerializer().Deserialize<IList<HistoryItem>>(new JsonTextReader(new StreamReader(contentStream)));
			remoteConflictHistory.Add(remote);

			var conflict = new ConflictItem
			{
				CurrentHistory = currentConflictHistory,
				RemoteHistory = remoteConflictHistory,
				FileName = filename,
				RemoteServerUrl = Uri.UnescapeDataString(remoteServerUrl)
			};

			ConflictArtifactManager.Create(filename, conflict);

			Publisher.Publish(new ConflictDetected
			{
				FileName = filename,
				SourceServerUrl = remoteServerUrl
			});

			Log.Debug(
				"Conflict applied for a file '{0}' (remote version: {1}, remote server id: {2}).", filename, remoteVersion,
				remoteServerId);

			return new HttpResponseMessage(HttpStatusCode.NoContent);
		}
Example #6
0
        internal (bool, List <MyItem>) TryAddItems(string writepath, string readpath, string readpath2)
        {
            Block block = new Block();

            block.writeByte(GetPagesCount(readpath2));//how many pages will be
            List <MyItem> myItems;

            using (StreamReader streamReader = new StreamReader(readpath))//SDG.Framework.IO.Deserialization
            {
                JsonReader reader = (JsonReader) new JsonTextReader((TextReader)streamReader);
                myItems = new JsonSerializer().Deserialize <List <MyItem> >(reader);
            }
            if (myItems == null)
            {
                Logger.LogError($"Player has no items in path: {readpath}");
                return(false, null);
            }
            //else
            //{
            //    Console.WriteLine($"items count: {myItems.Count}");
            //}
            byte len = (byte)myItems.Count;

            for (byte i = 0; i < len; i++)
            {
                ItemAsset itemAsset = (ItemAsset)Assets.find(EAssetType.ITEM, myItems[i].ID);
                myItems[i].Size_x = itemAsset.size_x;
                myItems[i].Size_y = itemAsset.size_y;
                myItems[i].Rot    = 0;
                if (myItems[i].Count > 1)
                {
                    for (byte j = 0; j < myItems[i].Count - 1; j++)
                    {
                        myItems.Add(new MyItem(myItems[i].ID, myItems[i].x, myItems[i].Quality, 0, myItems[i].Size_x, myItems[i].Size_y, myItems[i].State));
                    }
                }
            }
            myItems.Sort(new MyItemComparer());
            //return (true, null);
            byte pages = GetPagesCount(readpath2);

            for (byte i = 0; i < pages; i++)
            {
                byte width, height, itemsCount;
                (width, height) = GetPageSize(readpath2, i);
                if (width == 0 && height == 0)
                {
                    //Console.WriteLine($"Page: {i} has width and height ZERO");
                    block.writeByte(0);
                    block.writeByte(0);
                    block.writeByte(0);
                    continue;
                }

                //Console.WriteLine("-------------------");
                //Console.WriteLine($"Operation on PAGE: {i}, width: {width}, height: {height}");
                (List <MyItem> selectedItems, List <MyItem> unSelectedItems) = SelectItems(width, height, myItems);
                //Console.WriteLine($"myItems count: {myItems.Count}, selectedItems count: {selectedItems.Count}, UNselectedItems count: {unSelectedItems.Count}");
                myItems = unSelectedItems;
                //Console.WriteLine($"selectedItems = null? {selectedItems == null}, unSelectedItems = null? {unSelectedItems == null}");
                itemsCount = (byte)selectedItems.Count;
                block.writeByte(width);
                block.writeByte(height);
                block.writeByte(itemsCount);
                //Console.WriteLine($"For Page: {i}, items count: {itemsCount}");
                for (byte j = 0; j < itemsCount; j++)
                {
                    ItemJar itemJar = new ItemJar(selectedItems[j].X, selectedItems[j].Y, selectedItems[j].Rot, new Item(selectedItems[j].ID, selectedItems[j].x, selectedItems[j].Quality, selectedItems[j].State));
                    block.writeByte(itemJar.x);
                    block.writeByte(itemJar.y);
                    block.writeByte(itemJar.rot);
                    block.writeUInt16(itemJar.item.id);
                    block.writeByte(itemJar.item.amount);
                    block.writeByte(itemJar.item.quality);
                    block.writeByteArray(itemJar.item.state);
                    //block.writeByte(itemJar == null ? (byte)0 : itemJar.x);
                    //block.writeByte(itemJar == null ? (byte)0 : itemJar.y);
                    //block.writeByte(itemJar == null ? (byte)0 : itemJar.rot);
                    //block.writeUInt16(itemJar == null ? (ushort)0 : itemJar.item.id);
                    //block.writeByte(itemJar == null ? (byte)0 : itemJar.item.amount);
                    //block.writeByte(itemJar == null ? (byte)0 : itemJar.item.quality);
                    //block.writeByteArray(itemJar == null ? new byte[0] : itemJar.item.state);
                }
            }
            Functions.WriteBlock(writepath, block, false);
            return(true, myItems);
        }