예제 #1
0
        public GraphModel RemoveEdgeModel(AEdgeModel edgeModel, bool raise = true)
        {
            int weight = 0;

            if (edgeModel.Weight != null)
            {
                weight = int.Parse(edgeModel.Weight);
            }
            var source = new TVertex();
            var stock  = new TVertex();

            source.SetFromString(edgeModel.Source.VertexStr);
            stock.SetFromString(edgeModel.Stock.VertexStr);
            var    res = Graph.RemoveEdge(source, stock);
            string key = edgeModel.Key;

            if (res == ReturnValue.Succsess)
            {
                _models.Remove(key);
                if (raise)
                {
                    FieldUpdate?.Invoke(this, new ModelFieldUpdateArgs(FieldEvents.RemoveModel));
                }
                return(edgeModel);
            }
            else
            {
                throw new Exception(res.ToString());
            }
        }
예제 #2
0
        public List <GraphModel> RemoveVertexModel(AVertexModel vertexModel, bool raise = true)
        {
            var vertex = new TVertex();

            vertex.SetFromString(vertexModel.VertexStr);
            var retVal = Graph.RemoveVertex(vertex);
            List <GraphModel> removeModels = new List <GraphModel>();

            if (retVal == ReturnValue.Succsess)
            {
                removeModels.Add(vertexModel);
                _models.Remove(vertexModel.Key);
                _models.Values.ToList().ForEach(m =>
                {
                    var edge = m as AEdgeModel;
                    if (edge != null &&
                        (edge.Source.Key == vertexModel.Key ||
                         edge.Stock.Key == vertexModel.Key))
                    {
                        removeModels.Add(edge);
                        _models.Remove(edge.Key);
                    }
                });
                if (raise)
                {
                    FieldUpdate?.Invoke(this, new ModelFieldUpdateArgs(FieldEvents.RemoveModel));
                }
                return(removeModels);
            }
            else
            {
                throw new Exception(retVal.ToString());
            }
        }
예제 #3
0
        public List <GraphModel> RemoveGraphModels(List <GraphModel> models, bool raise = true)
        {
            List <AVertexModel> vertices = new List <AVertexModel>();
            List <AEdgeModel>   edges    = new List <AEdgeModel>();

            models.ForEach(m =>
            {
                var v = m as AVertexModel;
                if (v != null)
                {
                    vertices.Add(v);
                }
                else
                {
                    edges.Add((AEdgeModel)m);
                }
            });
            List <GraphModel> res = new List <GraphModel>();

            res.AddRange(edges.Select(e => RemoveEdgeModel(e, false)));
            res.AddRange(vertices.SelectMany(v => RemoveVertexModel(v, false)));
            if (raise)
            {
                FieldUpdate?.Invoke(this, new ModelFieldUpdateArgs(FieldEvents.RemoveModels));
            }
            return(res);
        }
예제 #4
0
        public void AddEdgeModel(AEdgeModel edgeModel, bool raise = true)
        {
            var weight = 0;

            if (edgeModel.Weight != null && edgeModel.Weight != "")
            {
                weight = int.Parse(edgeModel.Weight);
            }
            var source = new TVertex();
            var stock  = new TVertex();

            source.SetFromString(edgeModel.Source.VertexStr);
            stock.SetFromString(edgeModel.Stock.VertexStr);
            var res = Graph.AddEdge(source, stock, weight);

            if (res != ReturnValue.Succsess)
            {
                throw new Exception(res.ToString());
            }
            else
            {
                _models.Add(edgeModel.Key, edgeModel);
                if (raise)
                {
                    FieldUpdate?.Invoke(this, null);
                }
            }
        }
예제 #5
0
        public void UnionGraphs(string[] graphsNames, string newGrapName, bool raise = true)
        {
            if (graphsNames.Length < 2)
            {
                throw new Exception("количество графов для соединении должно быть не меньше двух");
            }
            if (!_storedGraphs.ContainsKey(graphsNames[0]) || !_storedGraphs.ContainsKey(graphsNames[1]))
            {
                throw new Exception("Некорректное имя/имена грфа");
            }
            var res = _storedGraphs[graphsNames[0]].Union(_storedGraphs[graphsNames[1]]);

            for (int i = 2; i < graphsNames.Length; i++)
            {
                if (!_storedGraphs.ContainsKey(graphsNames[i]))
                {
                    throw new Exception("Некорректное имя/имена грфа");
                }
                res = res.Union(_storedGraphs[graphsNames[i]]);
            }
            _storedGraphs.Add(newGrapName, res);
            if (raise)
            {
                FieldUpdate?.Invoke(this, new ModelFieldUpdateArgs(FieldEvents.UpdateStoredGraphs));
            }
        }
예제 #6
0
        public List <PointField> DoUpdate()
        {
            var returnList = new List <PointField>();

            while (_newEntries.Count > 0)
            {
                _currentlyChecking = _newEntries.Dequeue();

                var pointList = GetConnectedItems(_currentlyChecking);
                if (pointList == null)
                {
                    return(null);
                }

                if (pointList.Count > 1)
                {
                    var routeList = HandleListOfConnectedPoints(pointList);

                    foreach (var nodeList in routeList)
                    {
                        if (nodeList.Count >= 4)
                        {
                            var field = FindClosed(nodeList);
                            if (field != null)
                            {
                                returnList.Add(field);
                            }
                        }
                    }
                }

                _currentField[_currentlyChecking.Y, _currentlyChecking.X] = _currentlyChecking.Value;
            }
            return(returnList);
        }
예제 #7
0
 public void SaveGraphToFile(Stream stream, bool raise = true)
 {
     using (StreamWriter sw = new StreamWriter(stream, Encoding.UTF8))
     {
         string oriented = IsOrgraph ? "orgraph" : "graph";
         string weighted = IsWeighted ? "weighted" : "nonweighted";
         sw.WriteLine($"graphmodel {oriented} {weighted}");
         _models.Values.ToList().ForEach(m =>
         {
             var e = m as AEdgeModel;
             if (e == null)
             {
                 var v = m as AVertexModel;
                 sw.WriteLine($"[v] {v.Key} {v.Pos.x} {v.Pos.y}");
             }
             else
             {
                 sw.WriteLine($"[e] {e.Source.VertexStr} {e.Stock.VertexStr} {e.Weight}");
             }
         });
         sw.WriteLine("graphmodel end");
         Graph.SaveGraphToFile(sw);
     }
     if (raise)
     {
         FieldUpdate?.Invoke(this, new ModelFieldUpdateArgs(FieldEvents.SaveGrapToFile));
     }
 }
        private void SetStatisticsInExmDatabase(Job job, MessageItem messageItem, DateTime dateMessageSent, DateTime dateMessageFinished)
        {
            var sleepTime = 1000;

            for (var i = 0; i < RetryCount; i++)
            {
                try
                {
                    var messageRecipients = _recipientManager.GetMessageRecipients(200);
                    var totalCount        = checked ((int)messageRecipients.TotalCount);
                    var num                = messageItem.MessageType == MessageType.Regular ? 1 : 0;
                    var recipientsCount    = num != 0 ? FieldUpdate.Set(totalCount) : null;
                    var includedRecipients = num != 0 ? FieldUpdate.Set(_recipientManager.GetTargetRecipientCountFromIncludeLists()) : null;
                    var excludedRecipients = num != 0 ? FieldUpdate.Set(_recipientManager.GetTargetRecipientCountFromExcludeLists()) : null;
                    var globallyExcluded   = num != 0 ? FieldUpdate.Set(_recipientManager.GetTargetRecipientCountFromGlobalOptOutList()) : null;

                    _ecmDataProvider.SetMessageStatisticData(
                        messageItem.CampaignId.ToGuid(),
                        dateMessageSent,
                        dateMessageFinished,
                        recipientsCount,
                        includedRecipients,
                        excludedRecipients,
                        globallyExcluded, null, null
                        );
                    return;
                }
                catch (Exception)
                {
                    job.Status = $"Setting Statistics in the EXM database (retry {i} of {RetryCount})";
                    Thread.Sleep(sleepTime);
                    sleepTime += 1000;
                }
            }
        }
예제 #9
0
 public void UnmarkGraphModels(bool raise = true)
 {
     _models.Values.ToList().ForEach(m => m.Marked = false);
     if (raise)
     {
         FieldUpdate?.Invoke(null, null);
     }
 }
예제 #10
0
 public void CreateGraph(bool oriented, bool weighted, bool raise = true)
 {
     Graph   = new Graph <TVertex>(oriented, weighted);
     Status  = true;
     _models = new SortedDictionary <string, GraphModel>();
     if (raise)
     {
         FieldUpdate?.Invoke(this, new ModelFieldUpdateArgs(FieldEvents.InitGraph));
     }
 }
예제 #11
0
 public void Clear(bool raise = true)
 {
     Status  = false;
     _models = null;
     Graph   = null;
     if (raise)
     {
         FieldUpdate?.Invoke(this, new ModelFieldUpdateArgs(FieldEvents.RemoveGraph));
     }
 }
예제 #12
0
 public void RemoveStoredGraph(string name, bool raise = true)
 {
     if (_storedGraphs.ContainsKey(name))
     {
         _storedGraphs.Remove(name);
         if (raise)
         {
             FieldUpdate?.Invoke(this, new ModelFieldUpdateArgs(FieldEvents.UpdateStoredGraphs));
         }
     }
 }
예제 #13
0
 public void AddCurrentGraphInStoredGraphs(string name, bool raise = true)
 {
     if (Graph == null)
     {
         throw new Exception("Текущий граф еще не создан");
     }
     _storedGraphs.Add(name, new Graph <TVertex>(Graph));
     if (raise)
     {
         FieldUpdate?.Invoke(this, new ModelFieldUpdateArgs(FieldEvents.UpdateStoredGraphs));
     }
 }
예제 #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UpdateFieldOnlineRequest"/> class.
 /// </summary>
 /// <param name="document">The document.</param>
 /// <param name="field">Field data.</param>
 /// <param name="index">Object index.</param>
 /// <param name="nodePath">The path to the node in the document tree.</param>
 /// <param name="loadEncoding">Encoding that will be used to load an HTML (or TXT) document if the encoding is not specified in HTML.</param>
 /// <param name="password">Password for opening an encrypted document.</param>
 /// <param name="destFileName">Result path of the document after the operation. If this parameter is omitted then result of the operation will be saved as the source document.</param>
 /// <param name="revisionAuthor">Initials of the author to use for revisions.If you set this parameter and then make some changes to the document programmatically, save the document and later open the document in MS Word you will see these changes as revisions.</param>
 /// <param name="revisionDateTime">The date and time to use for revisions.</param>
 public UpdateFieldOnlineRequest(System.IO.Stream document, FieldUpdate field, int index, string nodePath = null, string loadEncoding = null, string password = null, string destFileName = null, string revisionAuthor = null, string revisionDateTime = null)
 {
     this.Document         = document;
     this.Field            = field;
     this.Index            = index;
     this.NodePath         = nodePath;
     this.LoadEncoding     = loadEncoding;
     this.Password         = password;
     this.DestFileName     = destFileName;
     this.RevisionAuthor   = revisionAuthor;
     this.RevisionDateTime = revisionDateTime;
 }
예제 #15
0
        private List <Point> GetConnectedItems(FieldUpdate update)
        {
            if (update == null)
            {
                return(null);
            }

            var connectedItems = new List <Point>();
            var x = update.X;
            var y = update.Y;

            if (_diagonal)
            {
                if (this[y - 1, x - 1] && _currentField[y - 1, x - 1] == update.Value)
                {
                    connectedItems.Add(new Point(x - 1, y - 1));
                }
                if (this[y - 1, x + 1] && _currentField[y - 1, x + 1] == update.Value)
                {
                    connectedItems.Add(new Point(x + 1, y - 1));
                }
                if (this[y + 1, x - 1] && _currentField[y + 1, x - 1] == update.Value)
                {
                    connectedItems.Add(new Point(x - 1, y + 1));
                }
                if (this[y + 1, x + 1] && _currentField[y + 1, x + 1] == update.Value)
                {
                    connectedItems.Add(new Point(x + 1, y + 1));
                }
            }


            if (this[y - 1, x] && _currentField[y - 1, x] == update.Value)
            {
                connectedItems.Add(new Point(x, y - 1));
            }
            if (this[y + 1, x] && _currentField[y + 1, x] == update.Value)
            {
                connectedItems.Add(new Point(x, y + 1));
            }
            if (this[y, x - 1] && _currentField[y, x - 1] == update.Value)
            {
                connectedItems.Add(new Point(x - 1, y));
            }
            if (this[y, x + 1] && _currentField[y, x + 1] == update.Value)
            {
                connectedItems.Add(new Point(x + 1, y));
            }

            return(connectedItems);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="UpdateFieldRequest"/> class.
 /// </summary>
 /// <param name="name">The filename of the input document.</param>
 /// <param name="index">Object index.</param>
 /// <param name="field">Field data.</param>
 /// <param name="nodePath">The path to the node in the document tree.</param>
 /// <param name="folder">Original document folder.</param>
 /// <param name="storage">Original document storage.</param>
 /// <param name="loadEncoding">Encoding that will be used to load an HTML (or TXT) document if the encoding is not specified in HTML.</param>
 /// <param name="password">Password for opening an encrypted document.</param>
 /// <param name="destFileName">Result path of the document after the operation. If this parameter is omitted then result of the operation will be saved as the source document.</param>
 /// <param name="revisionAuthor">Initials of the author to use for revisions.If you set this parameter and then make some changes to the document programmatically, save the document and later open the document in MS Word you will see these changes as revisions.</param>
 /// <param name="revisionDateTime">The date and time to use for revisions.</param>
 public UpdateFieldRequest(string name, int index, FieldUpdate field, string nodePath = null, string folder = null, string storage = null, string loadEncoding = null, string password = null, string destFileName = null, string revisionAuthor = null, string revisionDateTime = null)
 {
     this.Name             = name;
     this.Index            = index;
     this.Field            = field;
     this.NodePath         = nodePath;
     this.Folder           = folder;
     this.Storage          = storage;
     this.LoadEncoding     = loadEncoding;
     this.Password         = password;
     this.DestFileName     = destFileName;
     this.RevisionAuthor   = revisionAuthor;
     this.RevisionDateTime = revisionDateTime;
 }
예제 #17
0
        public bool MarkGraphModel(string key, bool raise = true)
        {
            GraphModel m;

            if (_models.ContainsKey(key) && !(m = _models[key]).Marked)
            {
                m.Marked = true;
                if (raise)
                {
                    FieldUpdate?.Invoke(null, null);
                }
                return(true);
            }
            return(false);
        }
예제 #18
0
        public bool SetWidth(string key, int width, bool raise = true)
        {
            GraphModel m;

            if (_models.ContainsKey(key) && !(m = _models[key]).Marked)
            {
                m.Width = width;
                if (raise)
                {
                    FieldUpdate?.Invoke(null, null);
                }
                return(true);
            }
            return(false);
        }
예제 #19
0
        public bool SetWeightMark(string key, string mark, bool raise = true)
        {
            AEdgeModel edge;

            if (_models.ContainsKey(key) && (edge = _models[key] as AEdgeModel) != null)
            {
                edge.AddMark = mark;
                if (raise)
                {
                    FieldUpdate?.Invoke(null, null);
                }
                return(true);
            }
            return(false);
        }
예제 #20
0
        public bool SetColor(string key, RGBcolor color, bool raise = true)
        {
            GraphModel m;

            if (_models.ContainsKey(key) && !(m = _models[key]).Marked)
            {
                m.Color = color;
                if (raise)
                {
                    FieldUpdate?.Invoke(null, null);
                }
                return(true);
            }
            return(false);
        }
예제 #21
0
        public void AddVertexModel(AVertexModel vertexModel, bool raise = true)
        {
            var vertex = new TVertex();

            vertex.SetFromString(vertexModel.VertexStr);
            var res = Graph.AddVertex(vertex);

            if (res == ReturnValue.Succsess)
            {
                _models.Add(vertexModel.Key, vertexModel);
                if (raise)
                {
                    FieldUpdate?.Invoke(this, new ModelFieldUpdateArgs(FieldEvents.AddModel));
                }
            }
        }
예제 #22
0
        public bool SetModelDefaultOptions(string key, bool raise = true)
        {
            GraphModel m;

            if (_models.ContainsKey(key) && !(m = _models[key]).Marked)
            {
                m.Color = GraphModel.DefaultColor;
                m.Width = GraphModel.DefaultWidth;
                if (raise)
                {
                    FieldUpdate?.Invoke(null, null);
                }
                return(true);
            }
            return(false);
        }
예제 #23
0
 public void RefreshDefault(bool removeAddMark = true, bool raise = true)
 {
     UnmarkGraphModels(false);
     _models.Values.ToList().ForEach(m =>
     {
         m.Color = GraphModel.DefaultColor;
         m.Width = GraphModel.DefaultWidth;
         var e   = m as AEdgeModel;
         if (e != null && removeAddMark)
         {
             e.AddMark = null;
         }
     });
     if (raise)
     {
         FieldUpdate?.Invoke(null, null);
     }
 }
예제 #24
0
        public void MoveVertexModel(string key, vec2 newPos, bool raise = true)
        {
            GraphModel model;

            if (_models.ContainsKey(key) && (model = _models[key]) is AVertexModel)
            {
                ((AVertexModel)model).UpdatePos(newPos);
                _models.Values.ToList().ForEach(m =>
                {
                    AEdgeModel edge = m as AEdgeModel;
                    if (edge != null && (edge.Source.Key == key || edge.Stock.Key == key))
                    {
                        edge.RefreshPos();
                    }
                });
                if (raise)
                {
                    FieldUpdate?.Invoke(this, null);
                }
            }
        }
예제 #25
0
        public void OpenGraphInFile(List <GraphModel> models, string graphDataText, bool raise = true)
        {
            bool res = true;

            Status = false;
            if (Graph != null)
            {
                res = UserInterface.AnswerTheQuestion("Граф уже создан!!! Вы действительно хотите открыть граф из файла? Текущий граф будет безвозвратно утерен.");
            }
            if (res)
            {
                _models = new SortedDictionary <string, GraphModel>();
                models.ForEach(m => _models.Add(m.Key, m));
                Graph  = new Graph <TVertex>(graphDataText);
                Status = true;
            }
            if (raise)
            {
                FieldUpdate?.Invoke(this, new ModelFieldUpdateArgs(FieldEvents.InitGraph));
            }
        }
        private void AdjustEmailStats(MessageItem messageItem, SendingProcessData sendingProcessData,
                                      DateTime dateMessageSent, DateTime dateMessageFinished)
        {
            var deployAnalytics = new DeployAnalytics();

            deployAnalytics.Process(new DispatchNewsletterArgs(messageItem, sendingProcessData));

            messageItem.Source.StartTime = dateMessageSent;
            messageItem.Source.EndTime   = dateMessageFinished;

            var innerItem = messageItem.InnerItem;

            using (new EditContext(innerItem))
            {
                innerItem.RuntimeSettings.ReadOnlyStatistics = true;
                innerItem[FieldIDs.Updated] = DateUtil.ToIsoDate(dateMessageSent);
            }

            var itemUtil     = new ItemUtilExt();
            var campaignItem = itemUtil.GetItem(messageItem.CampaignId);

            using (new EditContext(campaignItem))
            {
                campaignItem["StartDate"] = DateUtil.ToIsoDate(dateMessageSent);
                campaignItem[CampaignclassificationItem.FieldIDs.Channel] =
                    EcmFactory.GetDefaultFactory().Io.EcmSettings.CampaignClassificationChannel;
                campaignItem["EndDate"] = DateUtil.ToIsoDate(dateMessageFinished);
            }

            EcmFactory.GetDefaultFactory()
            .Gateways.EcmDataGateway.SetMessageStatisticData(messageItem.CampaignId.ToGuid(), dateMessageSent,
                                                             dateMessageFinished, FieldUpdate.Set(messageItem.SubscribersIds.Value.Count),
                                                             FieldUpdate.Set(messageItem.SubscribersIncludeCount.Value),
                                                             FieldUpdate.Set(messageItem.SubscribersExcludeCount.Value),
                                                             FieldUpdate.Set(messageItem.SubscribersGlobalOptOutCount.Value));
        }
예제 #27
0
 public void Refresh()
 {
     FieldUpdate?.Invoke(null, null);
 }
        private static void SetStatisticsInEXMDatabase(Job job, MessageItem messageItem, DateTime dateMessageSent, DateTime dateMessageFinished)
        {
            var sleepTime = 1000;

            for (var i = 0; i < RETRY_COUNT; i++)
            {
                try
                {
                    EcmFactory.GetDefaultFactory().Gateways.EcmDataGateway.SetMessageStatisticData(messageItem.CampaignId.ToGuid(), dateMessageSent, dateMessageFinished, FieldUpdate.Set(messageItem.SubscribersIds.Value.Count), FieldUpdate.Set(messageItem.SubscribersIncludeCount.Value), FieldUpdate.Set(messageItem.SubscribersExcludeCount.Value), FieldUpdate.Set(messageItem.SubscribersGlobalOptOutCount.Value));
                    return;
                }
                catch (Exception)
                {
                    job.Status = $"Setting Statistics in the EXM database (retry {i} of {RETRY_COUNT})";
                    Thread.Sleep(sleepTime);
                    sleepTime += 1000;
                }
            }
        }