コード例 #1
0
        private async Task <Tuple <T, KinveyException, int> > HandlePushDELETE(PendingWriteAction pwa)
        {
            var             offset          = 0;
            KinveyException kinveyException = null;

            try
            {
                int result = 0;

                NetworkRequest <KinveyDeleteResponse> request = Client.NetworkFactory.buildDeleteRequest <KinveyDeleteResponse>(pwa.collection, pwa.entityId);
                KinveyDeleteResponse kdr = await request.ExecuteAsync().ConfigureAwait(false);

                if (kdr.count == 1)
                {
                    result = SyncQueue.Remove(pwa);

                    if (result == 0)
                    {
                        offset++;
                    }
                }
            }
            catch (KinveyException ke)
            {
                kinveyException = ke;
                offset++;
            }

            return(new Tuple <T, KinveyException, int>(default(T), kinveyException, offset));
        }
 public PasswordCracker(IPasswordProvider passwordProvider, Dictionary <string, bool> passwordsToCrack, SyncQueue <HashedPassword> crackedPasswords, Mutex mutex)
 {
     _passwordProvider = passwordProvider;
     _passwordsToCrack = passwordsToCrack;
     _crackedPasswords = crackedPasswords;
     _mutex            = mutex;
 }
コード例 #3
0
        private async Task <Tuple <T, KinveyException, int> > HandlePushPUT(PendingWriteAction pwa)
        {
            T               entity          = default(T);
            var             offset          = 0;
            KinveyException kinveyException = null;

            try
            {
                int result = 0;

                var localEntity = Cache.FindByID(pwa.entityId);

                NetworkRequest <T> request = Client.NetworkFactory.buildUpdateRequest <T>(pwa.collection, localEntity, pwa.entityId);
                entity = await request.ExecuteAsync().ConfigureAwait(false);

                Cache.UpdateCacheSave(entity, pwa.entityId);

                result = SyncQueue.Remove(pwa);

                if (result == 0)
                {
                    offset++;
                }
            }
            catch (KinveyException ke)
            {
                kinveyException = ke;
                offset++;
            }

            return(new Tuple <T, KinveyException, int>(entity, kinveyException, offset));
        }
コード例 #4
0
 protected Stream()
 {
     MaxBlockSize    = 1024;
     _outgoingStream = new SyncQueue <StreamBlock>(64);
     _outgoingThread = new Thread(OutgoingStreamDispatcher);
     _outgoingThread.Start();
 }
コード例 #5
0
        private void TagInventoryWithSyncQueue_Load(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Maximized;

            syncQueue = new SyncQueue();
            syncQueue.OnCheckDataExist       += new SyncQueue.CheckDataExistEventHandler(syncQueue_OnCheckDataExist);
            Program.ReaderXP.OnAsyncCallback += new EventHandler <CSLibrary.Events.OnAsyncCallbackEventArgs>(ReaderXP_OnAsyncCallback);
            Program.ReaderXP.OnStateChanged  += new EventHandler <CSLibrary.Events.OnStateChangedEventArgs>(ReaderXP_OnStateChanged);
        }
コード例 #6
0
        public EventProcessor()
        {
            _logBook = new LogBook();
            _messageQueue = new SyncQueue<LoggingEvent>();

            _timer = new Timer(10);
            _timer.Elapsed += HandleNextEvent;
            _timer.Start();
        }
コード例 #7
0
ファイル: AccountController.cs プロジェクト: bakern/FTPbox
        public AccountController()
        {
            IgnoreList = new IgnoreList();
            FileLog = new FileLog(this);
            FolderWatcher = new FolderWatcher(this);

            WebInterface = new WebInterface(this);
            SyncQueue = new SyncQueue(this);            

            Client = new Client(this);
        }
コード例 #8
0
 /// <summary>
 /// Initializes a new FileLoggerAppender
 /// </summary>
 public FileLoggerAppender()
 {
     LoggingLevels      = new List <LoggingLevel>();
     MaxLogCount        = -1;
     TimeSinceLastWrite = new TimeSpan(0, 0, 30);
     TimeBetweenChecks  = 30;
     MaxQueueCache      = 100;
     _queue             = new SyncQueue <LogItem>();
     OnLogWritten      += DefaultLogWriter;
     BeginLogWriter();
 }
コード例 #9
0
        public ReportsController()
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json");
            var configuration = builder.Build();

            key = configuration["key"];

            _processQueue          = new SyncQueue <Action>();
            _processQueue.NewItem += (sender, action) => action();
        }
コード例 #10
0
ファイル: Router.cs プロジェクト: krukovden/MyProjects
        private SyncQueue<EthernetPacket> query; //очередь для хранения пакетов

        #endregion Fields

        #region Constructors

        public Router(IPAddress ipSource, IPAddress ipDestination, PhysicalAddress MAC_source, PhysicalAddress MAC_destination, int port_interest)
        {
            ipSourceAddress = ipSource;

            ipDestinationAddress = ipDestination;

            MACsource = MAC_source;

            MACdestination = MAC_destination;

            Port = port_interest;

            query = new SyncQueue<EthernetPacket>();//очередь для пакетов

            proc = new Thread(ProcessPacket); //создаем поток для обработке пакетов
        }
コード例 #11
0
        public static async Task Run(
            [TimerTrigger("0 * * * * *")] TimerInfo timer,
            TraceWriter log)
        {
            var repository = new CalendarRepository(AzureWebJobsStorage);
            var queue      = new SyncQueue(AzureWebJobsStorage);

            log.Info("Reading unpaused calendars...");
            var calendars = await repository.ReadForProcessing();

            log.Info($"Queueing sync jobs for {calendars.Count():n0} calendars...");
            Task.WaitAll(calendars
                         .Select(c => new SyncJob(c))
                         .Select(queue.Enqueue)
                         .ToArray());
        }
コード例 #12
0
            void Update()
            {
                if (!_hasSyncItems)
                {
                    return;
                }
                lock (SyncLock) {
                    _syncBuffer.AddRange(SyncQueue);
                    SyncQueue.Clear();
                }

                foreach (var a in _syncBuffer)
                {
                    ExecuteSyncMethod(a);
                }
                _syncBuffer.Clear();
            }
コード例 #13
0
        public DataPool()
        {
            _lockObj = new object();

            _highPriorityQueue     = new SyncQueue <T>();
            _highPriorityFailQueue = new SyncQueue <T>();

            _curSceneQueue     = new SyncQueue <T>();
            _curSceneFailQueue = new SyncQueue <T>();

            _nextSceneQueue     = new SyncQueue <T>();
            _nextSceneFailQueue = new SyncQueue <T>();

            _lowQueue     = new SyncQueue <T>();
            _lowFailQueue = new SyncQueue <T>();

            _allFailQueue = new SyncQueue <T>();
        }
コード例 #14
0
        private async Task <PushDataStoreResponse <T> > PushMultiPostActionsAsync()
        {
            var response           = new PushDataStoreResponse <T>();
            var limit              = 10 * Constants.NUMBER_LIMIT_OF_ENTITIES;
            var offset             = 0;
            var pendingPostActions = SyncQueue.GetFirstN(limit, offset, "POST");

            while (pendingPostActions != null && pendingPostActions.Count > 0)
            {
                var tasks = new List <Task <Tuple <PushDataStoreResponse <T>, int> > >();

                var realCountOfMultiInsertOperations = pendingPostActions.Count / (double)Constants.NUMBER_LIMIT_OF_ENTITIES;
                realCountOfMultiInsertOperations = Math.Ceiling(realCountOfMultiInsertOperations);

                for (var index = 0; index < realCountOfMultiInsertOperations; index++)
                {
                    var pendingWritePostActionsForPush = pendingPostActions.Skip(index * Constants.NUMBER_LIMIT_OF_ENTITIES).Take(Constants.NUMBER_LIMIT_OF_ENTITIES).ToList();

                    if (pendingWritePostActionsForPush.Count > 0)
                    {
                        tasks.Add(HandlePushMultiPOST(pendingWritePostActionsForPush));
                    }
                }

                await Task.WhenAll(tasks.ToArray()).ConfigureAwait(false);

                foreach (var task in tasks)
                {
                    response.AddEntities(task.Result.Item1.PushEntities);
                    response.AddExceptions(task.Result.Item1.KinveyExceptions);
                    offset += task.Result.Item2;
                }

                response.PushCount += pendingPostActions.Count;

                pendingPostActions = SyncQueue.GetFirstN(limit, offset, "POST");
            }
            return(response);
        }
コード例 #15
0
        private async Task <Tuple <T, KinveyException, int> > HandlePushPOST(PendingWriteAction pwa)
        {
            T               entity          = default(T);
            var             offset          = 0;
            KinveyException kinveyException = null;

            try
            {
                int result = 0;

                string tempID = pwa.entityId;

                var localEntity = Cache.FindByID(pwa.entityId);

                JObject obj = JObject.FromObject(localEntity);
                obj["_id"]  = null;
                localEntity = Newtonsoft.Json.JsonConvert.DeserializeObject <T>(obj.ToString());

                NetworkRequest <T> request = Client.NetworkFactory.buildCreateRequest <T>(pwa.collection, localEntity);
                entity = await request.ExecuteAsync().ConfigureAwait(false);

                Cache.UpdateCacheSave(entity, tempID);

                result = SyncQueue.Remove(pwa);

                if (result == 0)
                {
                    offset++;
                }
            }
            catch (KinveyException ke)
            {
                kinveyException = ke;
                offset++;
            }

            return(new Tuple <T, KinveyException, int>(entity, kinveyException, offset));
        }
コード例 #16
0
ファイル: SyncQueue.cs プロジェクト: Skyish/isel-pc-1516-1
 public static void Main() {
    
    SyncQueue queue = new SyncQueue();
    
    Thread p1 = new Thread(() => {
       for (int i = 0; i < 1024; ++i) {
          queue.Put(new Object());
       }
    });
    
    Thread c1 = new Thread(() => {
       for (int i = 0; i < 1024; ++i) {
          queue.Take();
       }
    });
    
    c1.Start();
    p1.Start();
    
    p1.Join();
    c1.Join();
    
    Console.WriteLine("OK");
 }   
コード例 #17
0
 protected AsyncCommandExecutorBase()
 {
     _queue = new SyncQueue<AsyncCommandResult>();
 }
コード例 #18
0
        /// <summary>
        /// Executes a multi insert request.
        /// </summary>
        /// <returns>An async task with the request result.</returns>
        public override async Task <KinveyMultiInsertResponse <T> > ExecuteAsync()
        {
            var kinveyDataStoreResponse = new KinveyMultiInsertResponse <T>
            {
                Entities = new List <T>(),
                Errors   = new List <Error>()
            };

            switch (Policy)
            {
            case WritePolicy.FORCE_LOCAL:
                //local cache
                for (var index = 0; index < entities.Count; index++)
                {
                    try
                    {
                        var cacheSaveResult = CacheSave(entities[index]);
                        SyncQueue.Enqueue(cacheSaveResult.Item1);
                        kinveyDataStoreResponse.Entities.Add(cacheSaveResult.Item2);
                    }
                    catch (Exception ex)
                    {
                        kinveyDataStoreResponse.Entities.Add(default(T));

                        var error = new Error
                        {
                            Index  = index,
                            Code   = 0,
                            Errmsg = ex.Message
                        };
                        kinveyDataStoreResponse.Errors.Add(error);
                    }
                }

                ThrowExceptionIfOnlyErrors(kinveyDataStoreResponse, EnumErrorCategory.ERROR_DATASTORE_CACHE, EnumErrorCode.ERROR_DATASTORE_CACHE_MULTIPLE_SAVE);

                break;

            case WritePolicy.FORCE_NETWORK:
                // network
                kinveyDataStoreResponse = await HandleNetworkRequestAsync(entities).ConfigureAwait(false);

                ThrowExceptionIfOnlyErrors(kinveyDataStoreResponse, EnumErrorCategory.ERROR_BACKEND, EnumErrorCode.ERROR_JSON_RESPONSE);
                break;

            case WritePolicy.LOCAL_THEN_NETWORK:
                //local cache
                KinveyMultiInsertResponse <T> kinveyDataStoreNetworkResponse = null;

                var pendingWriteActions = new List <PendingWriteAction>();

                for (var index = 0; index < entities.Count; index++)
                {
                    try
                    {
                        var cacheSaveResult = CacheSave(entities[index]);
                        pendingWriteActions.Add(cacheSaveResult.Item1);
                        kinveyDataStoreResponse.Entities.Add(cacheSaveResult.Item2);
                    }
                    catch (Exception ex)
                    {
                        kinveyDataStoreResponse.Entities.Add(default(T));

                        var error = new Error
                        {
                            Index  = index,
                            Code   = 0,
                            Errmsg = ex.Message
                        };
                        kinveyDataStoreResponse.Errors.Add(error);
                    }
                }

                ThrowExceptionIfOnlyErrors(kinveyDataStoreResponse, EnumErrorCategory.ERROR_DATASTORE_CACHE, EnumErrorCode.ERROR_DATASTORE_CACHE_MULTIPLE_SAVE);

                KinveyException kinveyException = null;
                Exception       exception       = null;
                try
                {
                    // network
                    kinveyDataStoreNetworkResponse = await HandleNetworkRequestAsync(entities).ConfigureAwait(false);
                }
                catch (KinveyException kinveyEx)
                {
                    kinveyException = kinveyEx;
                }
                catch (Exception ex)
                {
                    exception = ex;
                }

                if (kinveyException != null || exception != null)
                {
                    foreach (var pendingAction in pendingWriteActions)
                    {
                        SyncQueue.Enqueue(pendingAction);
                    }

                    if (kinveyException != null)
                    {
                        throw kinveyException;
                    }
                }
                else
                {
                    for (var index = 0; index < kinveyDataStoreResponse.Entities.Count; index++)
                    {
                        if (kinveyDataStoreNetworkResponse.Entities[index] != null)
                        {
                            if (kinveyDataStoreResponse.Entities[index] != null)
                            {
                                var obj = JObject.FromObject(kinveyDataStoreResponse.Entities[index]);
                                var id  = obj["_id"].ToString();
                                Cache.UpdateCacheSave(kinveyDataStoreNetworkResponse.Entities[index], id);
                            }
                            else
                            {
                                CacheSave(kinveyDataStoreNetworkResponse.Entities[index]);
                            }
                        }
                        else
                        {
                            if (kinveyDataStoreResponse.Entities[index] != null)
                            {
                                var obj = JObject.FromObject(kinveyDataStoreResponse.Entities[index]);
                                var id  = obj["_id"].ToString();

                                var existingPendingWriteAction = pendingWriteActions.Find(e => e.entityId.Equals(id));

                                if (existingPendingWriteAction != null)
                                {
                                    SyncQueue.Enqueue(existingPendingWriteAction);
                                }
                            }
                        }
                    }

                    kinveyDataStoreResponse = kinveyDataStoreNetworkResponse;
                }

                ThrowExceptionIfOnlyErrors(kinveyDataStoreResponse, EnumErrorCategory.ERROR_BACKEND, EnumErrorCode.ERROR_JSON_RESPONSE);

                break;

            default:
                throw new KinveyException(EnumErrorCategory.ERROR_GENERAL, EnumErrorCode.ERROR_GENERAL, "Invalid write policy");
            }

            return(kinveyDataStoreResponse);
        }
コード例 #19
0
ファイル: RemoveRequest.cs プロジェクト: alexislom/dotnet-sdk
        public override async Task <KinveyDeleteResponse> ExecuteAsync()
        {
            var kdr = default(KinveyDeleteResponse);

            switch (Policy)
            {
            case WritePolicy.FORCE_LOCAL:
                // sync
                if (_query == null)
                {
                    // cache
                    kdr = Cache.DeleteByID(entityID);

                    var request = Client.NetworkFactory.buildDeleteRequest <KinveyDeleteResponse>(Collection, entityID);

                    var pendingAction = PendingWriteAction.buildFromRequest(request);
                    SyncQueue.Enqueue(pendingAction);
                }
                else
                {
                    // cache
                    kdr = Cache.DeleteByQuery(_query);

                    foreach (var id in kdr.IDs)
                    {
                        var request       = Client.NetworkFactory.buildDeleteRequest <KinveyDeleteResponse>(Collection, id);
                        var pendingAction = PendingWriteAction.buildFromRequest(request);
                        SyncQueue.Enqueue(pendingAction);
                    }
                }
                break;

            case WritePolicy.FORCE_NETWORK:
                // network
                if (_query == null)
                {
                    kdr = await Client.NetworkFactory.buildDeleteRequest <KinveyDeleteResponse>(Collection, entityID).ExecuteAsync();
                }
                else
                {
                    var mongoQuery = KinveyMongoQueryBuilder.GetQueryForRemoveOperation <T>(_query);
                    kdr = await Client.NetworkFactory.buildDeleteRequestWithQuery <KinveyDeleteResponse>(Collection, mongoQuery).ExecuteAsync();
                }
                break;

            case WritePolicy.NETWORK_THEN_LOCAL:
                if (_query == null)
                {
                    // cache
                    kdr = Cache.DeleteByID(entityID);

                    // network
                    kdr = await Client.NetworkFactory.buildDeleteRequest <KinveyDeleteResponse>(Collection, entityID).ExecuteAsync();
                }
                else
                {
                    // cache
                    kdr = Cache.DeleteByQuery(_query);

                    // network
                    var mongoQuery = KinveyMongoQueryBuilder.GetQueryForRemoveOperation <T>(_query);
                    kdr = await Client.NetworkFactory.buildDeleteRequestWithQuery <KinveyDeleteResponse>(Collection, mongoQuery).ExecuteAsync();
                }
                break;

            case WritePolicy.LOCAL_THEN_NETWORK:
                if (_query == null)
                {
                    // cache
                    kdr = Cache.DeleteByID(entityID);

                    var deleteRequest = Client.NetworkFactory.buildDeleteRequest <KinveyDeleteResponse>(Collection, entityID);

                    KinveyException kinveyException = null;
                    Exception       exception       = null;
                    try
                    {
                        // network
                        kdr = await deleteRequest.ExecuteAsync();
                    }
                    catch (KinveyException kinveyEx)
                    {
                        kinveyException = kinveyEx;
                    }
                    catch (Exception ex)
                    {
                        exception = ex;
                    }

                    if (kinveyException != null || exception != null)
                    {
                        var pendingAction = PendingWriteAction.buildFromRequest(deleteRequest);
                        SyncQueue.Enqueue(pendingAction);

                        if (kinveyException != null)
                        {
                            throw kinveyException;
                        }
                    }
                }
                else
                {
                    // cache
                    kdr = Cache.DeleteByQuery(_query);

                    // network
                    KinveyException kinveyException = null;
                    Exception       exception       = null;
                    try
                    {
                        var mongoQuery = KinveyMongoQueryBuilder.GetQueryForRemoveOperation <T>(_query);
                        kdr = await Client.NetworkFactory.buildDeleteRequestWithQuery <KinveyDeleteResponse>(Collection, mongoQuery).ExecuteAsync();
                    }
                    catch (KinveyException kinveyEx)
                    {
                        kinveyException = kinveyEx;
                    }
                    catch (Exception ex)
                    {
                        exception = ex;
                    }

                    if (kinveyException != null || exception != null)
                    {
                        foreach (var id in kdr.IDs)
                        {
                            var request       = Client.NetworkFactory.buildDeleteRequest <KinveyDeleteResponse>(Collection, id);
                            var pendingAction = PendingWriteAction.buildFromRequest(request);
                            SyncQueue.Enqueue(pendingAction);
                        }

                        if (kinveyException != null)
                        {
                            throw kinveyException;
                        }
                    }
                }
                break;

            default:
                throw new KinveyException(EnumErrorCategory.ERROR_GENERAL, EnumErrorCode.ERROR_GENERAL, "Invalid write policy");
            }

            return(kdr);
        }
コード例 #20
0
        private async Task <PushDataStoreResponse <T> > PushSingleActionsAsync(string action = null)
        {
            var response = new PushDataStoreResponse <T>();
            var offset   = 0;
            var limit    = 10;

            var pendingActions = string.IsNullOrEmpty(action) ? SyncQueue.GetFirstN(limit, offset) :
                                 SyncQueue.GetFirstN(limit, offset, action);

            while (pendingActions != null && pendingActions.Count > 0)
            {
                var tasks = new List <Task <Tuple <T, KinveyException, int> > >();
                foreach (PendingWriteAction pwa in pendingActions)
                {
                    if (string.Equals("POST", pwa.action))
                    {
                        tasks.Add(HandlePushPOST(pwa));
                    }
                    else if (string.Equals("PUT", pwa.action))
                    {
                        tasks.Add(HandlePushPUT(pwa));
                    }
                    else if (string.Equals("DELETE", pwa.action))
                    {
                        tasks.Add(HandlePushDELETE(pwa));
                    }
                }

                try
                {
                    await Task.WhenAll(tasks.ToArray()).ConfigureAwait(false);
                }
                catch (Exception e)
                {
                    response.AddKinveyException(new KinveyException(EnumErrorCategory.ERROR_DATASTORE_NETWORK,
                                                                    EnumErrorCode.ERROR_JSON_RESPONSE,
                                                                    e.Message,
                                                                    e));
                }

                var resultEntities   = new List <T>();
                var kinveyExceptions = new List <KinveyException>();
                var resultCount      = 0;
                foreach (var task in tasks)
                {
                    if (!EqualityComparer <T> .Default.Equals(task.Result.Item1, default(T)))
                    {
                        resultEntities.Add(task.Result.Item1);
                    }

                    if (task.Result.Item2 != null)
                    {
                        kinveyExceptions.Add(task.Result.Item2);
                    }

                    offset += task.Result.Item3;

                    resultCount++;
                }

                response.AddEntities(resultEntities);
                response.AddExceptions(kinveyExceptions);
                response.PushCount += resultCount;

                pendingActions = string.IsNullOrEmpty(action) ? SyncQueue.GetFirstN(limit, offset) :
                                 SyncQueue.GetFirstN(limit, offset, action);
            }

            return(response);
        }
コード例 #21
0
        private async Task <Tuple <PushDataStoreResponse <T>, int> > HandlePushMultiPOST(ICollection <PendingWriteAction> pendingWriteActions)
        {
            var offset   = 0;
            var response = new PushDataStoreResponse <T>();

            var multiInsertNetworkResponse = new KinveyMultiInsertResponse <T>
            {
                Entities = new List <T>(),
                Errors   = new List <Error>()
            };
            var localData   = new List <Tuple <string, T, PendingWriteAction> >();
            var isException = false;

            try
            {
                foreach (var pendingWriteAction in pendingWriteActions)
                {
                    var entity = Cache.FindByID(pendingWriteAction.entityId);

                    var obj = JObject.FromObject(entity);
                    obj["_id"] = null;
                    entity     = Newtonsoft.Json.JsonConvert.DeserializeObject <T>(obj.ToString());

                    localData.Add(new Tuple <string, T, PendingWriteAction>(pendingWriteAction.entityId, entity, pendingWriteAction));
                }

                var multiInsertNetworkRequest = Client.NetworkFactory.BuildMultiInsertRequest <T, KinveyMultiInsertResponse <T> >(Collection, localData.Select(e => e.Item2).ToList());
                multiInsertNetworkResponse = await multiInsertNetworkRequest.ExecuteAsync().ConfigureAwait(false);
            }
            catch (KinveyException ke)
            {
                response.AddKinveyException(ke);
                offset     += pendingWriteActions.Count;
                isException = true;
            }
            catch (Exception ex)
            {
                response.AddKinveyException(new KinveyException(EnumErrorCategory.ERROR_GENERAL,
                                                                EnumErrorCode.ERROR_GENERAL,
                                                                ex.Message,
                                                                ex));
                offset     += pendingWriteActions.Count;
                isException = true;
            }

            if (!isException)
            {
                for (var index = 0; index < localData.Count; index++)
                {
                    try
                    {
                        if (multiInsertNetworkResponse.Entities[index] != null)
                        {
                            Cache.UpdateCacheSave(multiInsertNetworkResponse.Entities[index], localData[index].Item1);

                            var removeResult = SyncQueue.Remove(localData[index].Item3);

                            if (removeResult == 0)
                            {
                                offset++;
                            }
                        }
                    }
                    catch (KinveyException ke)
                    {
                        response.AddKinveyException(ke);
                        offset++;
                    }
                    catch (Exception ex)
                    {
                        response.AddKinveyException(new KinveyException(EnumErrorCategory.ERROR_GENERAL,
                                                                        EnumErrorCode.ERROR_GENERAL,
                                                                        ex.Message,
                                                                        ex));
                        offset++;
                    }
                }
            }

            var entities = multiInsertNetworkResponse.Entities.Where(e => e != null).ToList();

            response.AddEntities(entities);

            foreach (var error in multiInsertNetworkResponse.Errors)
            {
                response.AddKinveyException(new KinveyException(EnumErrorCategory.ERROR_BACKEND, EnumErrorCode.ERROR_GENERAL, error.Errmsg));
                offset++;
            }

            var result = new Tuple <PushDataStoreResponse <T>, int>(response, offset);

            return(result);
        }
コード例 #22
0
 private void FinalizeDispose()
 {
     _queue = null;
 }
コード例 #23
0
ファイル: App.cs プロジェクト: RemSoftDev/Wouter
        public static bool InitSession(Context ApplicationContext)
#endif
        {
            LastInitCalled = DateTime.Now;

            if (IsSessionInitialized)
            {
                return(false);
            }


            //FoodJournal.Model.Data.FoodJournalBackup.Log("InitSession", null, null);

            IsSessionInitialized = true;

            // if we're still getting too many session logs, we could consider only proceeding here if FinalizeSession succeeded longer than 1 hour ago or something

            AppDomain.CurrentDomain.UnhandledException += (object sender, UnhandledExceptionEventArgs e) =>
            {
                LittleWatson.ReportException(e.ExceptionObject as Exception, "unhandledexception");
                if (e.IsTerminating)
                {
                    FinalizeSession();
                }
            };
            AppDomain.CurrentDomain.ProcessExit += (object sender, EventArgs e) =>
            {
                SessionLog.Push();
            };

#if WINDOWS_PHONE
            if (DateTime.Now > AppStats.Current.LastUpgrade.AddMonths(3))
            {
#else
            FoodJournal.Android15.AlarmService.ResetNotifications();
            InitializeLanguage();

            if (DateTime.Now > AppStats.Current.LastUpgrade.AddMonths(48))
            {
#endif

                SessionLog.RecordTrace("App Expired");

#if WINDOWS_PHONE
                if (MessageBox.Show(AppResources.ExpiredMessage, AppResources.ExpiredCaption, MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    (new Microsoft.Phone.Tasks.MarketplaceDetailTask()).Show();
                }

                SessionLog.RecordTrace("Terminating");
                Application.Current.Terminate();
#else
                new AlertDialog.Builder(ApplicationContext)
                .SetPositiveButton("Ok", (sender, args) =>
                {
                    //Navigate.navigationContext = ApplicationContext;
                    Navigate.StartReviewTask();
                })
                .SetNegativeButton("Cancel", (sender, args) =>
                {
                    SessionLog.RecordTrace("Terminating");
                    throw new Exception();
                })
                .SetMessage(AppResources.ExpiredMessage)
                .SetTitle(AppResources.ExpiredCaption)
                .Create()
                .Show();

                return(false);
#endif
            }

            //			UserSettings.Current.SelectedProperties = new List<Property> () {
            //				StandardProperty.Calories,
            //				StandardProperty.TotalFat,
            //				StandardProperty.Carbs,
            //				StandardProperty.Protein
            //			};

            try
            {
                // processes live tile and other settings:
                var x = UserSettings.Current;
            }
            catch (Exception ex)
            {
                LittleWatson.ReportException(ex);
            }

            // 9/6/15: I thikn this is not needed to be done this quickly anymore, and its a pretty heavy operation (loading SQL dependencies, etc)
            // commenting out for now

            // 9/19/15: this is messing with purchase stats, so bringing it back, but asynch for now
            BackgroundTask.Start(4000, () =>
            {
                if (AppStats.Current.SessionId == 1)
                {
                    MessageQueue.Push(AppStats.Current);
                }
                else
                {
                    MessageQueue.StartPump();
                }
            });

            SyncQueue.StartLoad();

            return(true);
        }
コード例 #24
0
ファイル: ProcessSession.cs プロジェクト: wenchun/NGinnBPM
 protected void SendTaskControlMessage(TaskExecutionEvents.TaskControlCommand msg)
 {
     ValidateMessage(msg);
     SyncQueue.Enqueue(msg);
 }
コード例 #25
0
ファイル: ManagerAgent.cs プロジェクト: nistec/MQueue
        /// <summary>
        /// Execute remote command from client to queue managment using <see cref="QueueMessage"/>.
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        internal static NetStream ExecManager(QueueMessage message)
        {
            QueueState state = QueueState.Ok;

            try
            {
                NetStream stream = null;
                switch (message.Command)
                {
                case QueueManagerCmd.Reply:
                    return(QueueEntry.GetAckStream(QueueState.Ok, QueueManagerCmd.Reply, message.Key));

                case QueueManagerCmd.QueueProperties:
                    if (_Queue == null)
                    {
                        return(null);
                    }
                    return(message.AsyncTask(() => Queue.PerformanceCounter.GetPerformanceProperties(), message.Command));


                case QueueManagerCmd.CloneItems:
                    if (_Queue == null)
                    {
                        return(null);
                    }
                    var       args = message.GetArgs();
                    CloneType ct   = EnumExtension.Parse <CloneType>(args.Get <string>("value"), CloneType.All);
                    return(message.AsyncTask(() => Queue.CloneItems(ct), message.Command));

                case QueueManagerCmd.GetAllKeys:
                    if (_Queue == null)
                    {
                        return(null);
                    }
                    return(message.AsyncTask(() => Queue.GetAllKeys(), message.Command));

                case QueueManagerCmd.GetAllKeysIcons:
                    if (_Queue == null)
                    {
                        return(null);
                    }
                    return(message.AsyncTask(() => Queue.GetAllKeysIcons(), message.Command));

                case QueueManagerCmd.StateCounterQueue:
                    return(message.AsyncTask(() => QueueStateCounter(QueueAgentType.Queue), message.Command));

                case QueueManagerCmd.StateCounterSync:
                    return(message.AsyncTask(() => QueueStateCounter(QueueAgentType.SyncQueue), message.Command));

                case QueueManagerCmd.StateCounterSession:
                    return(message.AsyncTask(() => QueueStateCounter(QueueAgentType.SessionQueue), message.Command));

                case QueueManagerCmd.StateCounterDataQueue:
                    return(message.AsyncTask(() => QueueStateCounter(QueueAgentType.DataQueue), message.Command));

                case QueueManagerCmd.GetStateCounterReport:
                    return(message.AsyncTask(() => QueueStateCounter(), message.Command));

                case QueueManagerCmd.GetPerformanceReport:
                    return(message.AsyncTask(() => PerformanceReport(), message.Command));

                case QueueManagerCmd.GetAgentPerformanceReport:
                    QueueAgentType agentType = QueuePerformanceCounter.GetAgent(message.Key);
                    return(message.AsyncTask(() => PerformanceReport(agentType), message.Command));

                case QueueManagerCmd.ResetPerformanceCounter:
                    message.AsyncTask(() => ResetPerformanceCounter());
                    return(null);

                case QueueManagerCmd.GetAllDataKeys:
                    if (_DbQueue == null)
                    {
                        return(null);
                    }
                    return(message.AsyncTask(() => DbQueue.GetAllDataKeys(), message.Command));

                case QueueManagerCmd.GetAllSyncQueueKeys:
                    if (_SyncQueue == null)
                    {
                        return(null);
                    }
                    return(message.AsyncTask(() => SyncQueue.QueueKeys().ToArray(), message.Command));

                case QueueManagerCmd.QueueLog:
                    return(message.AsyncTask(() => QueueLogger.Logger.QueueLog(), message.Command));

                case QueueManagerCmd.GetAllSessionsKeys:
                    if (_Session == null)
                    {
                        return(null);
                    }
                    return(message.AsyncTask(() => Session.GetAllSessionsKeys(), message.Command));

                case QueueManagerCmd.GetAllSessionsStateKeys:
                    if (_Session == null)
                    {
                        return(null);
                    }
                    stream = new NetStream();
                    SessionState st = (SessionState)message.GetArgs().Get <int>("state");
                    return(message.AsyncTask(() => Session.GetAllSessionsStateKeys(st), message.Command));

                case QueueManagerCmd.GetSessionItemsKeys:
                    if (_Session == null)
                    {
                        return(null);
                    }
                    return(message.AsyncTask(() => Session.GetSessionsItemsKeys(message.Id), message.Command));

                //=== Queue api===================================================
                case QueueCmd.ViewItem:
                case QueueCmd.RemoveItem:
                    return(Queue.ExecRemote(message));

                //=== Data Queue api===================================================
                case DataQueueCmd.GetItemProperties:
                case DataQueueCmd.RemoveTable:
                //case DataQueueCmd.GetDataStatistic:
                case DataQueueCmd.GetDataTable:

                    return(DbQueue.ExecRemote(message));

                //=== Sync Queue api===================================================

                case SyncQueueCmd.RemoveSyncItem:
                case SyncQueueCmd.GetSyncItem:
                //case SyncQueueCmd.GetSyncStatistic:
                case SyncQueueCmd.GetItemsReport:

                    return(SyncQueue.ExecRemote(message));

                //=== Session Queue api===================================================

                case SessionCmd.RemoveSession:
                case SessionCmd.GetExistingSession:

                    return(Session.ExecRemote(message));
                }
            }
            catch (System.Runtime.Serialization.SerializationException se)
            {
                state = QueueState.SerializationError;
                QueueLogger.Logger.LogAction(QueueAction.QueueException, QueueActionState.Error, "ExecManager error: " + se.Message);
            }
            catch (Exception ex)
            {
                state = QueueState.UnexpectedError;
                QueueLogger.Logger.LogAction(QueueAction.QueueException, QueueActionState.Error, "ExecManager error: " + ex.Message);
            }

            return(QueueEntry.GetAckStream(state, message.Command)); //null;
        }
コード例 #26
0
ファイル: SaveRequest.cs プロジェクト: alexislom/dotnet-sdk
        public override async Task <T> ExecuteAsync()
        {
            T savedEntity = default(T);
            NetworkRequest <T> request  = null;
            string             entityID = null;;

            JToken idToken = JObject.FromObject(entity) ["_id"];

            if (idToken != null &&
                !String.IsNullOrEmpty(idToken.ToString()))
            {
                entityID = idToken.ToString();
                request  = Client.NetworkFactory.buildUpdateRequest(Collection, entity, entityID);
            }
            else
            {
                request = Client.NetworkFactory.buildCreateRequest(Collection, entity);
            }

            switch (Policy)
            {
            case WritePolicy.FORCE_LOCAL:
                // sync
                PendingWriteAction pendingAction = PendingWriteAction.buildFromRequest(request);

                string saveModeLocal = request.RequestMethod;
                string tempIdLocal   = null;

                if (String.Equals("POST", saveModeLocal))
                {
                    tempIdLocal            = PrepareCacheSave(ref entity);
                    savedEntity            = Cache.Save(entity);
                    pendingAction.entityId = tempIdLocal;
                }
                else
                {
                    savedEntity = Cache.Update(entity);
                }

                SyncQueue.Enqueue(pendingAction);

                break;

            case WritePolicy.FORCE_NETWORK:
                // network
                savedEntity = await request.ExecuteAsync();

                break;

            case WritePolicy.NETWORK_THEN_LOCAL:
                // cache
                string saveModeNetworkThenLocal = request.RequestMethod;
                string tempIdNetworkThenLocal   = null;

                if (String.Equals("POST", saveModeNetworkThenLocal))
                {
                    tempIdNetworkThenLocal = PrepareCacheSave(ref entity);
                    Cache.Save(entity);
                }
                else
                {
                    Cache.Update(entity);
                }

                // network save
                savedEntity = await request.ExecuteAsync();

                if (tempIdNetworkThenLocal != null)
                {
                    Cache.UpdateCacheSave(savedEntity, tempIdNetworkThenLocal);
                }

                break;

            case WritePolicy.LOCAL_THEN_NETWORK:
                string saveModeLocalThenNetwork = request.RequestMethod;

                // cache
                if (String.Equals("POST", saveModeLocalThenNetwork))
                {
                    entityID    = PrepareCacheSave(ref entity);
                    savedEntity = Cache.Save(entity);
                }
                else
                {
                    savedEntity = Cache.Update(entity);
                }

                KinveyException kinveyException = null;
                Exception       exception       = null;
                try
                {
                    // network save
                    savedEntity = await request.ExecuteAsync();
                }
                catch (KinveyException kinveyEx)
                {
                    kinveyException = kinveyEx;
                }
                catch (Exception ex)
                {
                    exception = ex;
                }

                if (kinveyException != null || exception != null)
                {
                    // if the network request fails, save data to sync queue
                    var localPendingAction = PendingWriteAction.buildFromRequest(request);
                    localPendingAction.entityId = entityID;

                    SyncQueue.Enqueue(localPendingAction);

                    if (kinveyException != null)
                    {
                        throw kinveyException;
                    }
                }
                else
                {
                    Cache.UpdateCacheSave(savedEntity, entityID);
                }

                break;

            default:
                throw new KinveyException(EnumErrorCategory.ERROR_GENERAL, EnumErrorCode.ERROR_GENERAL, "Invalid write policy");
            }

            return(savedEntity);
        }
コード例 #27
0
 protected AsyncCommandExecutorBase()
 {
     _queue = new SyncQueue <AsyncCommandResult>();
 }
コード例 #28
0
 protected AsyncCommandExecutorBase(SyncQueue <AsyncCommandResult> queue)
 {
     _queue = queue;
 }
コード例 #29
0
 protected Stream()
 {
     MaxBlockSize    = 1024;
     outgoing_stream = new SyncQueue <StreamBlock>(64);
 }
コード例 #30
0
 protected AsyncCommandExecutorBase(SyncQueue<AsyncCommandResult> queue)
 {
     _queue = queue;
 }
コード例 #31
0
 /// <summary>
 /// 在job执行线程启动后,job执行循环开始前
 /// </summary>
 protected virtual void PreJobLoop()
 {
     JobQueue   = new SyncQueue <TJob>();
     CancelBits = new SyncBit32Map(0);
 }
コード例 #32
0
 public Consumer(Dictionary <string, bool> passwordsToCrack, SyncQueue <HashedPassword> crackedPasswords, Mutex mutex)
 {
     _passwordsToCrack = passwordsToCrack;
     _crackedPasswords = crackedPasswords;
     _mutex            = mutex;
 }
コード例 #33
0
ファイル: ProcessSession.cs プロジェクト: wenchun/NGinnBPM
 public void NotifyTaskEvent(TaskExecutionEvents.TaskExecEvent ev)
 {
     ValidateMessage(ev);
     SyncQueue.Enqueue(ev);
 }
コード例 #34
0
    private Boolean ThreadRun_Helper(SyncQueue<Int32?> queue, Boolean useComplexCheck, ref Int32? index) {
      try {
        index = queue.Dequeue();
        if (index == null) {
          return false;
        } else {
          var result = User32.SendMessage(this.LVHandle, Interop.MSG.LVM_ISITEMVISIBLE, index.Value, 0) != IntPtr.Zero;
          //var itemBounds = new User32.RECT();
          //var lvi = this.ToLvItemIndex(index.Value);

          //User32.SendMessage(this.LVHandle, MSG.LVM_GETITEMINDEXRECT, ref lvi, ref itemBounds);

          //var r = new Rectangle(itemBounds.Left, itemBounds.Top, itemBounds.Right - itemBounds.Left, itemBounds.Bottom - itemBounds.Top);

          //if (useComplexCheck)
          //	return index < Items.Count && r.IntersectsWith(this.ClientRectangle);
          //else
          //	return r.IntersectsWith(this.ClientRectangle);
          return result;
        }
      } catch {
        return false;
      }
    }