-

   rss_rss_hh_new

 - e-mail

 

 -

 LiveInternet.ru:
: 17.03.2011
:
:
: 51

:


[ ] Red Architecture

, 21 2017 . 17:24 +


, Red?


. , , . . , . Red!

- ?


, .. code decoupling. , , , .. , , . , .., .

Red Architecture , .

Red Architecture , , .



Red Architecture :

  • ( -) /
  • (-), /
  • , , -

, KVO, NSNotification NSNotificationCenter, Delegate .. , -, . - Red Architecture , . .

:

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace Common
{
    public enum k {OnMessageEdit, MessageEdit, MessageReply, Unused, MessageSendProgress, OnMessageSendProgress, OnIsTyping, IsTyping, MessageSend, JoinRoom, OnMessageReceived, OnlineStatus, OnUpdateUserOnlineStatus }

    public class v : ObservableCollection >
    {
        static v i;

        static v sharedInstance()
        {
            if (i == null)
                i = new v();

            return i;
        }

        public static void h(System.Collections.Specialized.NotifyCollectionChangedEventHandler handler)
        {
            i.CollectionChanged += handler;
        }

        public static void m(System.Collections.Specialized.NotifyCollectionChangedEventHandler handler)
        {
            i.CollectionChanged -= handler;
        }

        public static void Add(k key, object o)
        {
            i.OnCollectionChanged(new System.Collections.Specialized.NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction.Add,
new List>(new KeyValuePair[] { new KeyValuePair(key, o) })));
        }

        protected v()
        {
        }
    }
}

, ObservableCollection. , , . , v . Red Architecture Consume now or never, v. Add() , . h() m() .

, k. , . ( ) , . , , , , k.OnMessageEdit. , , , , , , UI. , , , . .

.

k :

1. v .
2. , .

1:

, k , . .. Red Architecture Red Architecture . . Red Architecture . Red Architecture , , v.

v . .

, , . , . , , , .

, k, : , , . , .

, . v , Red Architecture. , v. MessageEdit OnMessageEdit MessageEdit , OnMessageEdit . v. , . , - .

v, h(), , .

2, :

void OnEvent(object sener, NotifyCollectionChangedEventArgs e)
{
	if (e.Action == NotifyCollectionChangedAction.Add)
	{
		var newItem = (KeyValuePair)e.NewItems[0];
		if (newItem.Key == k.OnMessageSendProgress)
		{
			var d = (Dictionary)newItem.Value;
			if ((string)d["guid"] == _guid && (ChatMessage.Status)d["status"] == ChatMessage.Status.Deleted)
			{
				Device.BeginInvokeOnMainThread(() =>
				{
					FindViewById(Resource.Id.message).Text = "";
				});
			}
		}
		else if (newItem.Key == k.OnMessageEdit)
		{
			var d = (Dictionary)newItem.Value;
			if ((string)d["guid"] == _guid)
			{
				Device.BeginInvokeOnMainThread(() =>
				{
					FindViewById(Resource.Id.message).Text = (string)d["message"];
				});
			}
		}
	}
}

OnEvent() , (). , if (e.Action == NotifyCollectionChangedAction.Add). , , :

	
var newItem = (KeyValuePair)e.NewItems[0];
if (newItem.Key == k.OnMessageSendProgress)

, . : var d = (Dictionary)newItem.Value;

, , , if ((string)d[guid] == _guid , : && (ChatMessage.Status)d[status] == ChatMessage.Status.Deleted). "\":

Device.BeginInvokeOnMainThread(() =>
{
	FindViewById(Resource.Id.message).Text = "";
});

Device.BeginInvokeOnMainThread() , OnEvent() , , UI .

FindViewById(Resource.Id.message).Text = "";
.

else if (newItem.Key == k.OnMessageEdit) , , .

:

(, ) . , , . , , . , , .

:

                   
 string s = Response.ResponseObject["success"].ToString();
 success = Convert.ToBoolean(s);
 if (success)
 {
     var r = Response.ResponseObject["data"].ToString();
     if(r.Contains("status")) // response not empty
     {
           Dictionary retVal = JsonConvert.DeserializeObject>(r);

           // convert status from web to internal type
           retVal["status"] = (ChatMessage.Status)Enum.ToObject(typeof(ChatMessage.Status), retVal["status"]);

           await PersistanceService.GetCacheMessagePersistance().UpdateItemAsync(retVal);
           v.Add(k.OnMessageSendProgress, retVal);
      }
}

status . status ChatMessage.Status v.Add() , .

null .. null, , , v.Add(k.SomeKey, null). null , , : v.Add(k.SomeKey, {errorCode: 10, errorMessage: Error! Try later.});

. (Consume now or never). ( ) . , . -. , , , , (, -, , , ).

, . , (, ) , . , .

, .

, , . .. , , , . , ( guid ), .

  , , . , , . () . , , . , Red Architecture . , , , , , .

Red Architecture , . . , , , , , v. v k.



, , (Clean Architecture) + :



  • . , , / . , , , . Red Architecture , . , , , .

  • / /

  • / , , (weak references), null, ..

  • . .

  • (, , ..) () . , Clean Architecture, , Red Architecture .

  • , .

  • . , , . , , ..

# Xamarin, Red Architecture .

, Agile, . Red Architecture Agile Scrum Kanban.
Original source: habrahabr.ru (comments, light).

https://habrahabr.ru/post/333870/

:  

: [1] []
 

:
: 

: ( )

:

  URL